text:
Fetch Balance of wallet without Core wallets of all coin?
I'm creating an exchange like service, I need some for showing all transaction to user like deposit and withdrawal but I'm not using core wallets of any coin, using paper wallets for wallet creation and I want to show balance of user and transaction. So, is there any API available for so that I can fetch such details of user? Please give such API for Altcoins also or provide me name of any wallet through which my task can be completed.

You can check the balance of an address even if it is not a core wallet by using block explorers. Here are two useful ones for checking the balance of a Bitcoin address:
https://blockchain.info/api/blockchain_api
and an Ethereum account:
https://etherscan.io/apis#accounts
You may wonder how it is possible to check the balance of an 'offline' paper wallet. It comes down to how Bitcoin (and other Bitcoin-like blockchains) work. At the most basic level, you have a private key. You can generate a public key from the private key and then an address from the public key. Bitcoins are sent to this address.
Blockchain explorers can check the balance of any address, even addresses that have not been generated yet! This is because an address is simply a string of letters and numbers that conform to a particular format.
You can read more about addresses here:
https://en.bitcoin.it/wiki/Address

i m integrating BTC,ETH,ETC,BCH,BTG,DASH,NEO,XRP,XMR on my site, whenever a user came to deposit it must work like other exchange, all the deposit and withdrawal shown to them, with each coin balance, i m not able to fetch the deposit made by user, as i m not able to find out balance. i just need a way to show the balance of user, deposited on their respective coin address, i can do it manually but i need a way to do  it using API for all coins deposit

Have you checked out the API's I've linked?


text:
Hashes and payment
I’m still learning about mining and all, but there’s one thing I still don’t understand. I was checking out the hashflare site and came across the store where you can buy hashes.
What I don’t get it, let’s say I purchase 10 gH/s as an example, which is like $11. Does that mean I pay $11 per every single 10 gH/s, or just a one time payment until the contract is over?

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
How to hack a Password of Private Key
I have a Private key and then after I entered it, there's another saying

"Input a required Password of Private Key"

So how can I hack or generate that?

"... and then after i entered it...", what software are you entering it into?

The private key you have is encrypted so to decrypt it you need to have a valid password that's why it is asking for the password. It can't be hacked, you need a correct password

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
How does Bitpay.com getting transactions info as its open source?
How does Bitpay.com wallet getting transactions info and listing unspents?
Are they connecting to Electrum servers peers or are they connecting to their servers?

The wallet connects to a server running bitcore software. This is software that provides an API for the wallet to use to get data about transactions on the blockchain. By default the server it connects to is run by bitpay. Bitpay sees all your addresses and transactions.

is it possible to connect to that server and get special address balance?

You can check your transaction's confirmation status and other payment details on any blockchain explorer (like BitPay's block explorer Insight). Look up your transaction using your transaction ID or the sending or receiving bitcoin addresses, which can all be found in your bitcoin wallet that sent the payment. For your transaction to be considered fully confirmed by most BitPay merchants, your transaction will need to have six confirmations.
More info: https://insight.bitpay.com/

I guess he is not asking about how to check a transaction ID, he would know how Bitpay checking address unspent or transactions in their app, for example in electrum blockchain. blockchain.address.get_history RPC command

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Command lnd not found even after installing lnd
I tried installing lnd using the commands shown in the installation guide.
I used these commands:
git clone https://github.com/lightningnetwork/lnd
cd lnd
make install

but when I try running the lnd command, I get this:
Command 'lnd' not found

I have go1.18.1 installed. I did execute these commands, but nothing changed:
export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin

Here are the $GOPATH and $PATH variables:
echo $GOPATH
/usr/local/go

echo $PATH
/home/ayoub/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ayoub/.dotnet/tools:/usr/local/go/bin:/usr/local/go/bin

How can I solve this issue?
I am running Ubuntu 20.04.
edit: Here is the output of sudo make install:
go install -v -tags="" -ldflags " -s -w -X github.com/lightningnetwork/lnd/build.Commit=v0.14.3-beta -X github.com/lightningnetwork/lnd/build.CommitHash=bd0c46b4fcb027af1915bd67a3da70e8ca5c6efe -X github.com/lightningnetwork/lnd/build.GoVersion=go1.18.1 -X github.com/lightningnetwork/lnd/build.RawTags=" github.com/lightningnetwork/lnd/cmd/lnd

What was the output from make install - were there any error messages?  2) you must have done something in between export GOPATH=~/go and echo $GOPATH to get /usr/local/go instead of /home/ayoub/go - what did you do exactly? 3) What is the output of type go?

I added the output in the question
I had GOPATH written in my ~/.bashrc, but even after removing it and re running the export GOPATH=~/go command nothing changed
the output of type go is go is /usr/local/go/bin/go

Since /usr/local/go/bin is in your path, that is probably where you should have go install the programs it compiles. However it isn't clear how you have go set up. Normally the go language tools would be kept separate from the go programs you compile and install.
Nevertheless, if the make command didn't emit error messages, go has compiled lnd and installed it somewhere (usually based on whatever value you had assigned to $GOPATH at that time).
I would find lnd using the following commands  ...
find /home/ayoub -name lnd
find /usr/local -name lnd

and then mv it to /usr/local/go/bin/lnd
I would also check ownership and permissions.


text:
Why are coefficients a=0 and b=7 used to define the Weierstrass equation in SECp256k1?
Most of the private to public key implementations I've come across do not make use of the equation y^2=x^3+7  (the weierstrass equation defining SECp256k1).
One that i often use is in the link below and does not use any external libraries.[EllipticCurvesPart4-PrivateKeyToPublicKey.py][1]
As you can tell, only the parameters a and b of the equation are used in the code. This brings up the following question :
Are a=0 and b=7 coefficients with special properties?Or they could have been any other number?
This is not about the parameters of SECP256k1 but has more to do with an observation i have come across where the curve under the specific values 0 and 7 translates into a different structure.
I would first appreciate knowing if there are any explanations that are more valid and perhaps verifiable that may negate this observation.
[1]: https://github.com/wobine/blackboard101/blob/master/EllipticCurvesPart4-PrivateKeyToPublicKey.py

I failed to find the full satisfactory answer, but I remember reading that these specific values make secp256k1 more computationally efficient. In particular, 7 was chosen because 7 % 4 = 3 and that makes point arithmetic more efficient.

from the various sources i've come across, i learned that the equation sort of defines the smallest subgroup that exists in a cyclic group of a prime order ( i.e group order n in secp256k1). If thats the case, then one does not expect that the smallest subgroup is modulated since the modulus is at the end of the bigger cyclic group and would have to have a prime order, and 4 isn't prime. Also  reference the shared  b is never used in private to public key derivation.  so how does a system running the code knows it is dealing with an EC?


text:
How to analyze BTC flow in many to many transaction
I am confused as to how should I analyze  many to many transaction.
I.e. many TX IN and many TX OUT

Is there a way to know in above setup which input address sent which amount to output address?
I've looked into the transaction algorithm and my conclusion is that it is all mostly random matching, am I right?
My goal is to show bitcoin transfers between addresses (ideally ignoring the transaction in the middle) to achieve something like this

Is there a way to know in above setup which input address sent which amount to output address?

No

I've looked into the transaction algorithm and my conclusion is that it is all mostly random matching, am I right?

No.

My goal is to show bitcoin transfers between addresses (ideally ignoring the transaction in the middle) to achieve something like this

That is not possible.
Bitcoin doesn't require that each input be associated with one or more specific outputs. The only requirement is that the sum of inputs is greater than, or equal to, the sum of outputs.
No nodes attempt to infer the sort of associations you describe. It is not needed. No one cares. It is irrelevant to Bitcoins purposes.
When creating such a transaction, A node will simply sum the required outputs, then gather sufficient inputs for that total. The choice of inputs need not be influenced by the specific individual outputs at all. Many wallets choose inputs based on privacy concerns. There is absolutely nothing to be gained by attempting to align each input amount with one or more individual output amounts. Any excess is dealt with by inserting a change output somewhere in the list of outputs.


text:
Error `settings.json file has no read or write access` - but permissions OK
I was downloading the whole Bitcoin blockchain and the download stopped and I got an error message that the settings.json file has no read or write access, but I checked the permissions of the file, and it has read/write access. I saw this question in other places but I couldn't find a solution that works for me. I am using MAC OS X with an external hard drive.
settings.json:
{

}

Edit: There was a problem with running the terminal command so I used the Bitcoin GUI. The download was around halfway done or so.

Have you tried running bitcoin-qt / bitcoind as root using e.g. sudo?


text:
Pruning a Bitcoin full node
I am running a full node and considering pruning to gain some disk space.
Does Bitcoin Core know how to prune the existing database or will it start the entire sync process over?
How much free disk space does the process require?
Will the pruned .dat file be deleted by the process?

Does Bitcoin Core know how to prune the existing database or will it start the entire sync process over?

It knows what to do and you will experience no resync or reindex when you do the pruning process (barring any unclean shutdowns or sudden power loss). There is no noticeable effect when pruning except that the size taken up on disk is much smaller.

How much free disk space does the process require?

No additional space is required. Disk space will be freed up by pruning, not consumed.

Will the pruned .dat file be deleted by the process?

Yes, that is how it frees disk space.

Thanks. I previously maxed out the partition available disk space, possibly 2-3 GB left. After attempting to prune, GUI not launching, I was not able to launch even without pruning settings. The former suggest/s/ed some temporary extra space may be required.
I might have interrupted the pruning process, in which case no progress status would show on 0.13.2?

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Unable to broadcast multi-sig transaction that has been double signed
Having same issue as this question trying on both electrum wallet in terminal and via coinb.in/#broadcast. Unclear from existing answer how to resolve
In terminal
Electrum v 2.7.9; Debian system
$ electrum broadcast <tx id>
> Daemon not running; try 'electrum daemon start'
$ electrum daemon start
> starting daemon (PID 12639)
$ electrum broadcast <tx id>
> Daemon not running; try 'electrum daemon start'

Via coinb.in
On coinb.in/#sign --> "The above transaction has been signed"
So, to broadcast:

16: mandatory-script-verify-flag-failed (Operation not valid with the current stack size)

I'm not sure what this error means or how to resolve it. Any help appreciated.
edit, transaction: 0100000001cd74eb23e3c3eb15dc7717c9cdb435e3253e155bc05573ff2702d29cca078fa401000000b40047304402200bb08d102f6faa620f03a6411de2841c7e977921897c70e9fdff48ebdd952cee022046441eb587e2086761c7809e6dd00a1d07767c151c32d08f9bb9919e4042689e014c695221034e52799f008f8704f76c3d1eef880dce25760d7db8d29687e54f7af74b49a3d82102f5fa6de45a2c251ca2872c655c43ae73fba0da88167fc8ab94145e874d841f3121034af4b449728a4b1d9150c55a99c9433bc19826ffb9ee77c6207fafa0eb82b4dc53aeffffffff01a8883800000000001976a9147e47475e78ef1ae629288f221601f2f6385173e088ac00000000

Could you post the raw transaction here?

@MeshCollider OP has been updated to include the transaction hex

The first input of your transaction spends a P2SH 2-of-3 multisig output, but only contains 1 signature. It needs 2.

Thanks--will have to check with counterparty who said they had signed it.


text:
Unconfirmed BTC after 48H, 0.000119 Fee!
My BTC has been unconfirmed for 48 hours now.
I deliberately made a relative big fee of 0.0001119 and still no confirms.
Could anyone here PLEASE help me I'm getting kind of desperate.
Any miner that could push it, I will send him an extra fee.
This is the transaction: https://blockchain.info/nl/tx/f40f229b36f94bfbaa97a9998107c0014a6ad079370566698ec1cb58f2c94cb8
I would REALLY appreciate any help, thanks in advance!!

Microtransactions can take pretty long, even with a relative big fee.
The confidence of your transaction is: 17.39% and miner preference is low:
https://live.blockcypher.com/btc/tx/f40f229b36f94bfbaa97a9998107c0014a6ad079370566698ec1cb58f2c94cb8/
At the moment there are a huge number of unconfirmed transactions:
https://blockchain.info/nl/unconfirmed-transactions
See also this site, it will show you the estimated confirmation time in minutes:
https://bitcoinfees.earn.com/#delay
But don't worry, you wont lose any BTC. If it takes too long you will get your balance back.

Thank you for replying. Is there any way to increase the confidence? I've had quite some succesful transactions in the past... Also the website I send it to will refund if the payment is confirmed within 30 days. Or will I get the refund nonetheless? Thanks again for your time.


text:
What happens when two txid's collide?
Let's suppose that I can create SHA256d collisions, and I use this ability to create two transactions that have the same hash, A and B. These transactions are not the same, but they hash to the same value.
I submit transaction A to the network, and wait until it has a few confirmations. Then, I submit transaction B. Will it get included into the chain? Will it overwrite transaction A?
If the answer to the previous two questions is yes, then what will happen if the block containing transaction B is reorganized out of the chain? Will transaction A be un-overwritten?

If you could generate SHA256 collisions easily I think you would probably want to go for the merkle tree first rather than TXID, being able to produce two blocks that have the same hash but different transactions would be extremely destructive and probably not noticed for a long time.

Another question: if you then create a transaction which spends A, and get it included in a block, will nodes randomly consider this block as valid/invalid depending on whether they resolve the input txid to A or B?

@Bitcoin Well, yes, but supposing that you used it to make duplicate transactions, what would happen?

I don't have the time to research it right now so I'm not going to put it in as an answer, but I guess it would follow the same rules as the two BIP30/34 duplicate TXID, if one is spent the other one is just destroyed. I think they are special cased in the source though so that might only apply to them specifically.

Remark: TXID collisions have happened in the past before. This is due to the coinbase transaction being identical, and derived transactions can be made to be identical too. This has been fixed by BIP 34 which forces every coinbase script to be different.

No. After transaction A is included into the chain, transaction B is invalid, and will not be mined. If it does show up in a mined block, the entire block is invalid.
It wasn't always like this. Initially, if a transaction had the same txid as a previous transaction, it would overwrite the first one. Then, if that block was reorganized out of the chain, the second transaction would be removed, but the first transaction would not be added. In other words, adding and removing the block would change the state of the unspent transaction set.
That was clearly ricidulous, so under BIP 30, including a second transaction with the same txid when any output from first is still unspent is invalid. It used to be enforced by the timestamp of the block, but it is now applied to every block in the blockchain except for the two that break this rule.


text:
How do I open my RPC console?
Someone just asked me to open the RPC console, as part of debugging something else. How do I do that?
I'm using Bitcoin-Qt.

Click Help > Debug window, then click on the Console tab.


text:
Verify Mycelium still has private key for spent address
I just realized that when I sent BTC from Mycelium, it split the value from a source address into two target addresses, but the BCH of course stayed at the original address. I'm concerned that I can't verify that the private keys Mycelium tracks cover the spent address. If I export my Mycelium keys to a wallet that supports BCH, will it still be able to access the BCH that was at the spent address?
The spent address (public key) is 1FfbdfD6bfwy1HXLTznGnUVsBTxZGMXDod and I can see Mycelium knows about the unspent output address that it still has, but I can't see what addresses it's private keys cover.

Mycelium uses a hierarchical deterministic (HD) wallet, which means all private and public keys follow from an initial master key value. Every time a spend transaction occurs from the wallet, you can see that another private key is generated from the master key and it keeps a count of how many private keys are used. Any application that can sweep such a wallet should be able to acquire all the private keys along with it. If not, other questions answer how to extract private keys from an HD wallet: Derive private keys from a HD key


text:
Is Bitcoin trading anonymous and untraceable?
I know little about bitcoin except they are digital currency.

I heard that bitcoin ownership or exchanges/trading is anonymous and untraceable by government. Is that true?
If I buy a bitcoin and pay by credit card, the money goes through banking system right? That would make it traceable wouldn't it?

Thanks in advance.
Appended: Thank you for the all answers that are informative. The reason I asked is because I heard that the underworld and money launderers etc. use bitcoin to evade governments' scrutiny which is part of the reason for its price soar. Guess there is no truth in that since transactions are traceable.

Possible duplicate of How anonymous are Bitcoin transactions?

No its not duplicate, He is talking about trading and this question is about bitcoin transactions

Bitcoin transactions are anonymous but traceable. Many wallets and exchanges are now linked to your bank account and ask you to furnish personal details beforehand. Hence, If needed they can trace you easily.
You can avoid it by buying BTC in cash.

Bitcoin is not both anonymous and untraceable, it is just anonymous. Let me explain.

Creating a Bitcoin wallet does not require you to provide identification, email, phone, or any personal data. You should be able to create Bitcoin wallets offline.

All Bitcoin transactions are traceable; I can view all transactions made by a bitcoin address at any point in time available on the blockchain. Of course these bitcoin addresses will seem cryptic since there is no relationship with identification.

Anonymity must however be protected. If you tell everyone that your bitcoin address is 1XYZ (example), then with a quick search, someone can relate the address to your name thus removing anonymity.

Trading on exchanges can also reveal your identity to centralized organizations. Depending on the jurisdiction of these organizations, the government may find a connection between your banking details and your Bitcoin address.

Well, You have linked too many things to each other.
It depends on the website that you are using to trade.
There's many ways to trace you:

providing your name or email address.
Your IP address.
Using same bitcoin address.

Almost all trading websites gets your IP address - Email etc..

Currency tranding and exchanging is traceable regardless the type of
  currency.
Using your credit card it's like your are buying your bitcoins from tax agency.

I suggest to buy bitcoin by cash and from a local store or by person if you do care about hiding your identity.
Bitcoin transactions is anonymous and almost hard to be traceable if you are using your own web wallet and using new bitcoin address for each transaction.


text:
How get address from ScriptSig: PUSHDATA(N)?
I'm from Ukraine and do not know much English, sorry. I want to parse blockchain, but I have problems. In block 728 will first txs (user-user). But input-script have not public keys. I read this Missing public key in transaction input. And don't understand how work it. For example first input in txs is
3046022100e26d9ff76a07d68369e5782be3f8532d25ecc8add58ee256da6c550b52e8006b022100b4431f5a9a4dcb51cbdcaae935218c0ae4cfc8aa903fe4e5bac4c208290b7d5d01
and explorer say what this address get 50 btc in this txs when confirm this block. But how connected this txs and this txs.
How get address from ScriptSig: PUSHDATA(73)?
EDIT
What you need to do to get an address from such transactions?

In general, you can't.
You need to look at the scriptPubKey of the output that is being spent.

How get scriptPubKey from this 3046022100e26d9ff76a07d68369e5782be3f8532d25ecc8add58ee256da6c550b52e8006b022100b4431f5a9a4dcb51cbdcaae935218c0ae4cfc8aa903fe4e5bac4c208290b7d5d01?

As I said, you can't. You need to look at the output being spent. The information you are looking for is not in the scriptSig.

so, edit question

The input script does not provide you the necessary information. You need more than just the input script, you also need to know the output that the input spends. This is specified as the outpoint for an input and consists of a txid and output index. Using that txid and output index, you lookup the output and pull from that the scriptPubKey. With the scriptPubKey, you can then compute the address.

How get address from scriptPubKey I know. But I not know how get txid and output index. Please help me.

The txid and output indexes are part of the transaction. See https://bitcoin.org/en/developer-reference#txin

authors: Временный Аккаунт


text:
Get the address from the transaction
I'm from Ukraine and do not know much English, sorry. For example first block https://blockchain.info/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f, when miner confirm this block he get bonus (50 BTC). And he make transaction https://blockchain.info/ru/tx/4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b, but in the first block be kept info about coinbase and script sig
Coin Base - 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73

Script sig - 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f OP_CHECKSIG

And address 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa and hash for generate address 62e907b15cbf27d5425399ebf6f0fb50ebb88f18

where did you get the address?
EDIT
How get address or hash for generate adress from publicScriptSig

The initial Bitcoin transactions are slightly different from what we use today.
Addresses don't technically exist as far as the blockchain is concerned. They are simply a human-friendly representation of the underlying Bitcoin Scripts, that come with some properties like checksums to prevent typographical errors.
Original Bitcoin transactions were simply Pay-to-pubkey (P2PK), such as the one you see in the Coinbase above. In this, 04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f is the public key (note that this is the full public key, and not hashed).
Many coin explorers choose to treat this as a regular Bitcoin address, and perform the encoding steps outlined here. You can use this tool to check the public key creates 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa as an uncompressed address (compressed keys were not known at the time of the genesis block, they were discovered later).
Modern day addresses are either P2PKH Pay-to-pubkey-hash (this hash is 62e907b15cbf27d5425399ebf6f0fb50ebb88f18 for the above key), P2SH pay-to-script-hash (this is used for multisig, and P2SH wrapped segwit), and P2WPKH pay-to-witness-pubkey-hash and P2WPSH pay-to-witness-script-hash segwit addresses (these start with bc1).
However, on the raw blockchain, all you will see is the Bitcoin Script that the addresses are encoding. Addresses are a purely human addition on top of the underlying transaction standards.

Thank you, but you say P2PKH - hash from public key, but https://imgur.com/a/Tw7SJvM. How get P2PK-hash from public key?

You can follow the steps here to get the exact hash, looks like the current version of the wiki is missing the complete example

authors: Временный Аккаунт


text:
Bitcoin blockchain doesn't continue installation
I successfully downloaded the Bitcoin blockchain on an external hard drive (as well as git repository). It was working and syncing just fine. I haven't used in a month or so, now the blockchain won't continue the download (starts download from beginning) even though I specified the datadir and blockdir. I tried the usual solutions such as setting the path of blocks and datadir (to the path in the external HDD). None of them work. I tried running the CLI and the GUI, same problem. It doesn't install it in the correct path.
Also, when it was reinstalling the whole blockchain, it puts the new blocks folder in the original blockdir (as a nested folder).
Am I missing a step?
Do I have to mount the HDD to the home directory? it is currently in /media
I am using Ubuntu 22.10
This is the datadir and blocksdir in bitcoin.conf file
datadir=/media/kibnakamoto/kntc/work/Bitcoin/
blocksdir=/media/kibnakamoto/kntc/work/Bitcoin/blocks/

I run the bitcoin-qt using the following command directory
/media/kibnakamoto/kntc/work/Bitcoin/src/qt/bitcoin-qt -conf=/media/kibnakamoto/kntc/work/bitcoin.conf
This sets the datadir to /media/kibnakamoto/kntc/work/Bitcoin/blocks and blocksdir to /media/kibnakamoto/kntc/work/Bitcoin/blocks/blocks
(kntc is the HDD name)
I have tried only setting datadir instead of both blocksdir and datadir

Remove the transaction index from your bitcoind options and share drive format info. Have you tried setting only datadir (no blockdir)?

@Mercedes I updated my question with more data. Hope that helps!

You should share drive format info. You are using one same directory for data and source, that's uncommon, use a different directory for data and source, specially in case you don't understand Git. Don't specify blocksdir until a simpler configuration is working.


text:
How is the hashrate calculated?
Where does the data come from?

As RedGrittyBrick already wrote, the difficulty to create new blocks is adjusted every 2016 blocks. The difficulty provides an expected amount of hashes performed to find a block, which allows a general estimate how much hashrate exists on the network. Additionally, some websites compare the number of published blocks with the expected number of blocks found to provide a higher resolution than whole difficulty periods. Since blocks are found in a random process, these charts often jump around a lot as even a constant hashrate can have a large variance of blocks found per day.
As an example, let's take a look at this chart of Blocks per Day for the last three months. The blocks found range from 89 on 2022-12-24 to 180 on 2023-01-06.
via transactionfee.info
Meanwhile, the self-reported hashrate of mining pools in the last three months looks like this:
via miningpoolstats.stream
While we do see a drop in the self-reported hashrate on Christmas Eve (partially explained by an extreme winter freeze in Texas that had miners yield power for heating homes) that aligns with the lowest block count, the self-reported hashrate ranges between 200 EH/s and 287 EH/s while the block count maximum is double the minimum.
This is underscored when we compare the self-reported figures with miningpoolstats.stream's estimated hashrate on the network:
via miningpoolstats.stream
So, the hashrate can be estimated from the difficulty of the blocks and the count of blocks found, but the random process makes it easy estimate much larger swings than seem to be present in the actual hashrate.

Great data! The shorter the sampling period, the more noise is in the result. I guess anything less than a day does not make sense, and even one day is too short. From the swings in this graph I guess the websites that I've seen use approx. one day as sampling period (e,g, https://www.coinwarz.com/mining/bitcoin/hashrate-chart).

The total network hashrate can be estimated from the network difficulty recorded in the block headers over a reasonable sample period.
There is a relationship between the two because the difficulty is adjusted every 2016 blocks (about two weeks at 10 minutes per block) with the aim of keeping block production rate near constant as total network hashrate changes.
See How can I calculate network hashrate for a given range of blocks where difficulty changes somewhere within the range? for calculation

When you say network difficulty recorded in the block headers here are you referring to the difficulty of the solution accepted by the network (over a sample period)?

@Poseidon, yes I was referring to the fifth data item described at https://en.bitcoin.it/wiki/Protocol_documentation#block : "bits" ... "The calculated difficulty target being used for this block " -- Looking at a period spanning a recalculation would give you an idea which direction the hashrate is trending. Murch's answer describes ways to get greater precision.

Ok thank you, I find this relevant because the bits is just the target difficulty while the network accepted solution difficulty represents the actual difficulty solved by a miner. They are relatively similar though.


text:
Ripple initial distribution of XRP coins
My understanding is there are 100 billion pre-mined XRP coins all belonging to Open Coin who have a vague plan to distribute them at some point in time, fairly. Does anyone else see a problem with this or is there more to it than that? It seems to be far more centralized than any central bank we have at the moment.

Seems like you want a discussion not a real SE question.

Hi Dave and Nick. What I was looking for was an answer such as 'Ripple does have pre-mined coins but this is irrelevant because the coins are used as an anti-spam mechanism and have no inherent value' .. or something like that. No need for a discussion and focused more around the strengths / weaknesses of the centralized distribution as pertaining to ripple than an explanation of how they are distributed - they have said themselves they won't reveal this.

This was extensively discussed @bitcointalk.org, for one example see:
https://bitcointalk.org/index.php?topic=146964.0
There is much more in other threads there.

Thanks - was hoping to get a more condensed version, it seems to me there is two schools of thought. 1 - they are used for anti-spam so have no inherent value, 2 - the are required for transactions so necessarily have value. These to opposing positions are made in the page you reference but it's hard to interpret which is correct.


text:
Which crypto-currency has the most even distribution of wealth?
Bitcoin, Ripple, PPCoin, Freicoin and most other cryptocurrencies have a significant portion of the currency in the hands of early adopters or a central group charged with 'distributing' the currency. Does anyone know which has been the most successful at distributing the coins evenly?
Thanks

Can't be answered, except maybe for ripple.

It's possible to track how many coins are owned by a given address, but there's no way (at least, no easy way) to associate an address with its actual owner; it's not possible to know for sure how wealth is distributed.

indeed it's impossible to say; on one hand, coins on one address may actually belong to multiple people (in the case of online wallets and exchanges), on the other hand, multiple addresses can belong to one wallet and to one person


text:
ANYONECANSPEND transaction vs. private key for giving bitcoin as a prize
I would like to create a game (kind of like a treasure hunt) where the winner finds a piece of hidden information that allows them to claim some bitcoin.
One way to do it is to create a transaction with OP_TRUE in the script so anyone can spend, and the winner is the person who finds this transaction and spends it to himself.
Another way is to create a new wallet, and the winner is the person who finds the private key.
Which way is better, what are the pros/cons?

There are people who just scan for transactions which have the standard anyone can spend constructions (OP_TRUE, in scriptPubKey or as p2sh) and just spend them. To avoid such people from discovering your transactions, you would have to use p2(w)sh with some other anyone can spend script which would have to be revealed as the prize. At that point, you might as well just use a normal p2(w)pkh script and make the prize the private key.
Additionally, anyone can spend scripts are non-standard and most wallet software do not have an easy way to create or spend transactions with anyone can spend scripts. If you have to provide hidden information as the prize, you might as well make that the private key.

I'm okay with making the spender figure out non-standard scripts, that would make the game more fun. As long as the transaction is valid.


text:
In bitcoinj, why is MemoryBlockStore not used by default?
My understanding of bitcoinj is that it is used to implement a "thin client" that doesn't store the entire blockchain- just the headers.
When I use the WalletAppKit, it creates a file "default.spvchain" that is 626Kib. This could easily fit in memory, so why is SPVBlockStore (using memory mapped file) used? Wouldn't MemoryBlockStore be a better choice?

If you don't persist the headers in some way then you'd have to reload them each time you launched. Loading the headers from scratch isn't a free operation. Its not just a matter of downloading 626k. It may be a small amount of data in the end but each header still needs to be verified (targets calculated and checked, etc). Not only that, but there are less obvious privacy implications of requesting the block chain from the network each time.
SPVBlockStore still uses memory mapped IO so its not like you take a performance hit, it just makes subsequent launches of the software faster.


text:
Why are the blocks out of order?
When I look at blockchain.info or blockexplorer.com, it shows the latest blocks.
The most recent block, #283653, has time 2014-02-01 22:42:08.
The previous block, #283652, has time 2014-02-01 22:45:57.
So the previous block has a timestamp larger than the most recent block. How is this possible?


text:
When was getheaders added?
Bitcoin 0.10 uses getheaders to synchronize. How long has this message been supported by other clients? How many existing nodes support it?

How long has this message been supported by other clients?

It was added by Satoshi in Bitcoin v0.3.18 (released on december 8th, 2010)

How many existing nodes support it?

All of them. It has been used by SPV clients for a long time to do fast synchronization without downloading all historical blocks.

Was the headers message also there along with the getheaders, or did the getheaders use to respond with blocks?

The headers message was also there.

The headers message includes a transaction count which is always zero, bitcoin-core even skips it with a comment "assume it is 0". It looks like this was supposed to ease writing software that could just apply its block parsing logic on that message. But technically that number of transactions is superfluous, right? So I believe it is just a historical artefact that does not serve any future purpose?

That's right. At the time, there was no separate CBlockHeader and CBlock; a header was just a CBlock with no transactions.

@PieterWuille could you please answer my question:
https://bitcoin.stackexchange.com/questions/95676/how-to-getheaders-from-blockchain

@PieterWuille or this one:
https://bitcoin.stackexchange.com/questions/95668/step-by-step-to-make-a-spv-bitcoin-node
I can't find how to create a spv client.


text:
What caused CVE-2012-2459? How was it fixed?
Gavin Andresen made an announcement about this denial of service issue in 2012 here, but it's light on technical details.

Just found the disclosure: https://bitcointalk.org/index.php?topic=102395.0

The full disclosure post is here: https://bitcointalk.org/?topic=102395
You can find it from the Bitcoin CVE list: https://en.bitcoin.it/wiki/CVEs


text:
Deprecation error on mac
I'm compiling on mac, and I get this error:
unsigned char *SHA256(const unsigned char *d, size_t n,unsigned char *md) DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;

Why does this happen, and how do I fix it?

In Mac OS X 10.7, Apple wants you to use their own crypto library instead of OpenSSL. This is pretty unlikely to ever be done by the bitcoin devs, so here's how to turn the warning off:
When running ./configure, give it the following argument:
./configure CXXFLAGS=-Wno-deprecated-declarations

This will disable the warning.

Only in 10.7? Then you're out of luck (with me). Only 10.6 and 10.9 here.

No need to edit ./configure, usage: ./configure CXXFLAGS=-Wno-deprecated-declarations

@Bitcoin_1o1 Thanks, edited.


text:
Block Some UTXO
Is it possible to block some UTXO like PIVX, does is possible in bitcoin?
if yes then how and doesn't it reduce supply from total supply of bitcoin?
Let's Assume that account A got 5 bitcoin from Some random account and he spend 2 bitcoin. when he transfer 2 bitcoin he will send 5 btc and receive back 3 BTC as for my understanding. now if i want to make some change in code and block that UTXO of 3 BTC can this be done using code.
Sorry for my poor english.

Could you please explain what "blocking UTXOs" means? This site's topic is Bitcoin, it seems that multiple prospective responders don't know what PIVX is.

Do you mean, "not create" with "block"? As in, how can you send a bitcoin transaction without creating a change output? What would your preferred outcome be: that when you use the 5 bitcoin, it creates the 2 BTC for the recipient, and the other 3 BTC are lost, that you find inputs that are exactly equal to the 2 BTC in the output and you just don't need to create change, or that the recipient gets tipped the remainder?

I don't know what PIVX is but you can send Bitcoin to an unspendable output (also known as burning). This does reduce how much Bitcoin can circulate, the initial supply steadily approaches 21 million but in theory any percentage of that can be burned.

No, i want to know about blocking some UTXO.

You'll have to explain what "blocking a UTXO" means, as that terminology does not exist in Bitcoin.


text:
Localhost peer not detected error when trying to connect to Bitcoind server via JSON RPC from Java Application
I am running Bitcoin Network on local Ubuntu machine. The network consists of multiple nodes. I want to connect to the network from a java application running on the same machine via JSON RPC. I can connect to the Bitcoind server from command line using bitcoin-cli. However, i cannot connect to the Bitcoind server from the Java application using Bitcoinj Libraray. I suspect that the problem is related to RPC authentication. I specified rpc username and password in the bitcoin.conf file and I tried to use Java Authenticator in my Java code. However, it hasn't solved the problem.
  Authenticator.setDefault(new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication()
 { return new PasswordAuthentication (rpcuser, rpcpassword.toCharArray());
                }});

My bitcoin.conf file is as follows:
regtest=1
server=1
listen=1
rpcuser=user
rpcpassword=password
fallbackfee=0.0001
[regtest]
port=10000
rpcport=20000
bind=127.0.0.1
rpcbind=127.0.0.1
rpcallowip=127.0.0.1

This is the log message I see when i start the Bitcoind server:
Server Log

List item

Server Log
And this is the error I am receiving on the application side:
Application side error message
I am using Bitcoin core version 22 for the server and Bitcoinj library version 16.1 (https://bitcoinj.org/getting-started) to connect to the server

Are you trying to connect to regtest? If so, you've specified a custom rpcport, does your Java code try to connect to that port?

@AndrewChow yes, i am trying to connect to a regtest network using the new rpcport I specified in the bitcoin.conf file.

Is there anyone who can help with this issue? @AndrewChow Any idea? Thanks

The issue is that you are trying to connect BitcoinJ to Bitcoin Core's RPC interface. However BitcoinJ is not a RPC client, it's a separate node(ish) implementation that connects to other nodes using the P2P protocol. The P2P interface and the RPC interface are separate and use different protocols, you cannot connect one to the other and expect them to work.
This issue can be solved by having BitcoinJ connect to port 10000 as that is the port that you have configured Bitcoin Core to listen on for P2P connections.


text:
what guarantee that miners will only include valid transactions in a block?
So, miners, if I got it right, before inserting a transaction into the Mempool, will request an arbitrary number of confirmations of full nodes that will search the entire blockchain to see if a wallet has credits to perform that transaction. But, being this process not required, could a miner simply create valid blocks with invalid transactions without any problem?

No, you don't have it right.
Nodes (which include miners) do not ask other node to do anything other than to give them data. There is no "confirmations of full nodes". Nodes will receive transactions and verify them themselves using the rules that are programmed into their software. If the transaction is valid (and also passes some other non-consensus rules), it will be stored in the mempool to be used in block creation.
Bitcoin is not an accounts based model so there are no wallets or accounts in the blockchain itself. As such, wallets do not have "credits". Rather validation requires searching for Unspent Transaction Outputs (UTXO) that are specified in a transaction's inputs. These UTXOs contain an amount and a script. The node will check that the sum of the input amounts is greater than or equal to the sum of the output amounts. Then it will execute the scripts for those inputs, and the scripts must return a result indicating success.
A miner cannot create a valid block with invalid transactions. Such blocks are, by definition, invalid. A block can only be valid if all of the transactions contained within it are valid. Other nodes will only accept a block if it is valid. Those other nodes do not just blindly trust miners - they will verify that all of the transactions in a block are valid.


text:
Error from launching single functional tests on macos
I'm getting acquainted with the functional testing suite in an attempt to become a bitcoin core developer.
I'm attempting to run a single test with this command.
python feature_shutdown.py
I receive an error such as this. In this error I notice a directory not being created.
'@abs_top_builddir@/src/bitcoind@EXEEXT@'
Is this behavior familiar to anyone? It seems like the string isn't being interpolated correctly.
2022-09-01T03:01:04.768000Z TestFramework (ERROR): Unexpected exception caught during testing
Traceback (most recent call last):
  File "/Users/user/git/bitcoin/test/functional/test_framework/test_framework.py", line 132, in main
    self.setup()
  File "/Users/user/git/bitcoin/test/functional/test_framework/test_framework.py", line 295, in setup
    self.setup_network()
  File "/Users/user/git/bitcoin/test/functional/test_framework/test_framework.py", line 389, in setup_network
    self.setup_nodes()
  File "/Users/user/git/bitcoin/test/functional/test_framework/test_framework.py", line 414, in setup_nodes
    self.start_nodes()
  File "/Users/user/git/bitcoin/test/functional/test_framework/test_framework.py", line 547, in start_nodes
    node.start(extra_args[i], *args, **kwargs)
  File "/Users/user/git/bitcoin/test/functional/test_framework/test_node.py", line 211, in start
    self.process = subprocess.Popen(self.args + extra_args, env=subp_env, stdout=stdout, stderr=stderr, cwd=cwd, **kwargs)
  File "/Users/user/opt/anaconda3/envs/bitcoin/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/Users/user/opt/anaconda3/envs/bitcoin/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '@abs_top_builddir@/src/bitcoind@EXEEXT@': '@abs_top_builddir@/src/bitcoind@EXEEXT@'
2022-09-01T03:01:04.825000Z TestFramework (INFO): Stopping nodes
2022-09-01T03:01:04.825000Z TestFramework (WARNING): Not cleaning up dir /var/folders/cj/1w9q8rc55v99_ynzxz46c3dr0000gn/T/bitcoin_func_test_2u9b62xc
2022-09-01T03:01:04.825000Z TestFramework (ERROR): Test failed. Test logging available at /var/folders/cj/1w9q8rc55v99_ynzxz46c3dr0000gn/T/bitcoin_func_test_2u9b62xc/test_framework.log
2022-09-01T03:01:04.826000Z TestFramework (ERROR):
2022-09-01T03:01:04.826000Z TestFramework (ERROR): Hint: Call /Users/user/git/bitcoin/test/functional/combine_logs.py '/var/folders/cj/1w9q8rc55v99_ynzxz46c3dr0000gn/T/bitcoin_func_test_2u9b62xc' to consolidate all logs
2022-09-01T03:01:04.826000Z TestFramework (ERROR):
2022-09-01T03:01:04.826000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2022-09-01T03:01:04.826000Z TestFramework (ERROR): @PACKAGE_BUGREPORT@
2022-09-01T03:01:04.826000Z TestFramework (ERROR): ```

Thank you for your time.

When I first was running the functional tests I had to uninstall/disable Anaconda and that cleared up a similar problem for me. Not sure if that is definitely the problem here.

I resolved this, anaconda did cause a lot of headaches for me, but I created a new environment. Thanks!

In your test/ folder, you should have a config.ini and config.ini.in file. Your config.ini should look something like:
BUILDDIR=/Users/username/code/bitcoin
EXEEXT=

whereas according to the log message it might rather be:
BUILDDIR=@abs_top_builddir@
EXEEXT=@EXEEXT@

If that's the case, probably something went wrong with the configuration process. The easiest potential fix would be to rerun ./configure and see if that resolves it?

Excellent! I'm wondering what the source of this config.ini and config.ini.in are? Does ./configure use config.ini.in and generate the .ini file?
My current configuration is for debugging. Ill rerun a few configure and see if that ends up making things work. Thanks for your time!

config.ini.in is in the repo, from which the build system (through ./configure) creates your own config.ini file

python3.6 is a little old.
try python3.10
NOTE:
using homebrew
brew search python
will display a list of available
python versions
try:
brew install python@3
ADDITIONAL NOTE:
brew install qt is NOT correct!
brew install qt@5 is correct!
You have to uninstall qt first! :)
then
brew install qt@5

Python 3.6 is fine, there should be no need to upgrade to run the test suite. Also, I'm not sure how qt is related to this?


text:
Can you explain this JS code?
Can someone explain this JS code to me please?
Maybe line by line? I am trying to understand and learn from it. Is this code creating a raw transaction based on an existing redeemScript? Or is it actually creating a redeemScript and then a transaction based on it?
I am on Windows server 2016 with Bitcoin Core and node installed.
Particulary this line I don't get it.
var scriptSig = bitcore.Script.fromASM('04678afd04678a ' + redeemScript.toHex())

What is 04678afd04678a?:
He is the entire code, found it on some JS examples from 2 years ago. It's about creating unsecured P2SH transactions.
> var bitcore = require('bitcore');
undefined
> var redeemScript = bitcore.Script.fromASM('OP_SHA256 894eeb82f9a851f5d1cb1be324
9f58bc8d259963832c5e7474a76f7a859ee95c OP_EQUAL');
undefined
> var scriptPubKey = redeemScript.toScriptHashOut();
undefined
> scriptPubKey
<Script: OP_HASH160 20 0x028d07ac41994c915b76e00490289f5933454f90 OP_EQUAL>
> scriptPubKey.toAddress()
<Address: 31vWDrvuRXaEaymhyuZqkbNBkPrVzw6DBc, type: scripthash, network: livenet>
> scriptPubKey.toHex()
'a914028d07ac41994c915b76e00490289f5933454f9087'
> var utxo = new bitcore.Transaction.UnspentOutput({
...   "txId" : "a0a08e397203df68392ee95b3f08b0b3b3e2401410a38d46ae0874f74846f2e9"
, //fake, don't try!
...   "outputIndex" : 0,
...   "script" : "a914028d07ac41994c915b76e00490289f5933454f9087",
...   "satoshis" : 60000,
...   "address" : "31vWDrvuRXaEaymhyuZqkbNBkPrVzw6DBc"
... });
> var address = '13mDYExLFx7stcYJN5uJRhzxwLuTEKNJbg';
undefined
> var tx = new bitcore.Transaction().from(utxo).to(address, 50000);
undefined
> tx.inputs[0]
{ output: <Output (60000 sats) <Script: OP_HASH160 20 0x028d07ac41994c915b76e0049
0289f5933454f90 OP_EQUAL>>,
  prevTxId: <Buffer a0 a0 8e 39 72 03 df 68 39 2e e9 5b 3f 08 b0 b3 b3 e2 40 14 1
0 a3 8d 46 ae 08 74 f7 48 46 f2 e9>,
  outputIndex: 0,
  sequenceNumber: 4294967295,
  _script: <Script: >,
                   _scriptBuffer: <Buffer > }
> tx.outputs
[ <Output (50000 sats) <Script: OP_DUP OP_HASH160 20 0x1e4d054693c02c60e3f77f87f5
ba79a281bf9141 OP_EQUALVERIFY OP_CHECKSIG>> ]
> var scriptSig = bitcore.Script.fromASM('04678afd04678a ' + redeemScript.toHex()
)
undefined
> tx.inputs[0].setScript(scriptSig);
{ output: <Output (60000 sats) <Script: OP_HASH160 20 0x028d07ac41994c915b76e0049
0289f5933454f90 OP_EQUAL>>,
  prevTxId: <Buffer a0 a0 8e 39 72 03 df 68 39 2e e9 5b 3f 08 b0 b3 b3 e2 40 14 1
0 a3 8d 46 ae 08 74 f7 48 46 f2 e9>,
  outputIndex: 0,
  sequenceNumber: 4294967295,
  _script: <Script: 7 0x04678afd04678a 35 0xa820894eeb82f9a851f5d1cb1be3249f58bc8
d259963832c5e7474a76f7a859ee95c87>,
             _scriptBuffer: <Buffer 07 04 67 8a fd 04 67 8a 23 a8 20 89 4e eb 82 f9 a8 51 f5
 d1 cb 1b e3 24 9f 58 bc 8d 25 99 63 83 2c 5e 74 74 a7 6f 7a 85 9e e9 5c 87> }
> var rawTx = tx.toString('hex');
undefined
> rawTx
'0100000001e9f24648f77408ae468da3101440e2b3b3b0083f5be92e3968df0372398ea0a0000000
002c0704678afd04678a23a820894eeb82f9a851f5d1cb1be3249f58bc8d259963832c5e7474a76f7
a859ee95c87ffffffff0150c30000000000001976a9141e4d054693c02c60e3f77f87f5ba79a281bf
914188ac00000000'
>

I am not a JS dev, but can read and understand the code. So this is a summary from what I can see in the tx. I try to concentrate on the important lines, and compare the script to the information in the wiki:
> var redeemScript = bitcore.Script.fromASM('OP_SHA256 894eeb82f9a851f5d1cb1be324
9f58bc8d259963832c5e7474a76f7a859ee95c OP_EQUAL');

this looks like the preparation for a P2SH tx. To be noted: it starts with OP_SHA256 (0xA8), whereas "normal" p2sh scripts start with OP_HASH160 (0xA9) - see next section "scriptPubKey". Looking at the way the script execution works, the SHA256 operator would try to perform a sha256 operation on the previous item on the stack... as a sha256 is not easily reversible, we cannot know, what string is converted to some hash, that can then be evaluated to TRUE, so the transaction remains valid... For sure it is the string that you were asking to explain (04678afd04678a).
> scriptPubKey
<Script: OP_HASH160 20 0x028d07ac41994c915b76e00490289f5933454f90 OP_EQUAL>

this is a standard script, which compares a previous item on the stack to the hash160 (0x028d07ac...). This is usually used in a P2SH, to compare a public key to its hash.
> var tx = new bitcore.Transaction().from(utxo).to(address, 50000);

prepare a data structure for the transaction with the target address and amount
> tx.inputs[0]

add the inputs (with the script)
> tx.outputs

create the outputs
> var scriptSig = bitcore.Script.fromASM('04678afd04678a ' + redeemScript.toHex()

the most interesting line! I follow up on it below, but first decode the tx:
VERSION 01000000
 TX_IN COUNT hex=01, decimal=1
  TX_IN[0] OutPoint hash A0A08E397203DF68392EE95B3F08B0B3B3E2401410A38D46AE0874F74846F2E9
  TX_IN[0] OutPoint index hex=00000000, reversed=00000000, decimal=0
  TX_IN[0] Script Length hex=2C, decimal=44
  TX_IN[0] Script Sig 0704678AFD04678A23A82...C8D259963832C5E7474A76F7A859EE95C87
  TX_IN[0] Sequence FFFFFFFF
 TX_OUT COUNT, hex=01, decimal=1
  TX_OUT[0] Value hex=50C3000000000000, reversed_hex=C350, dec=50000 Satoshi
  TX_OUT[0] PK_Script Length hex=19, dec=25
  TX_OUT[0] pk_script 76A9141E4D054693C02C60E3F77F87F5BA79A281BF914188AC
LOCK_TIME 00000000

so now analyzing the created script sig:

0704678AFD04678A23A820894EEB82F9A851F5D1CB1BE3249F58BC8D259963832C5E7474A76F7A859EE95C87

first we have "07", which pushes "next opcode bytes" (hex 07) on the stack. So the stack gets
04678AFD04678A

then follows a string beginning with 0x23. This means the next 35 Bytes go to the stack, so the rest of the script. The stack would look like this:
04678AFD04678A
OP_SHA256 20894EEB82F9A851F5D1CB1BE3249F58BC8D259963832C5E7474A76F7A859EE95C OP_EQUAL

So the string

04678afd04678a

hashes to 32 bytes (hex 0x20) of:

894EEB82F9A851F5D1CB1BE3249F58BC8D259963832C5E7474A76F7A859EE95C

When this is executed on the stack, it is equal, and as such the tx is valid. I have no windows system, but on unixoide systems one can verify at the command line, or with openssl:
printf $( echo 04678AFD04678A | sed 's/[[:xdigit:]]\{2\}/\\x&/g' ) > tmp_hex_fn
hexdump -C tmp_hex_fn
openssl dgst -sha256 <tmp_hex_fn

ATTENTION: using such a script on mainnet will probably loose the funds. A miner can change the tx, and put "his" script into the sigscript section, and divert the funds to his own addresses. Only use such unsecured tx on testnet.

Thank you! So to be clear please, two quick questions related.

On this line > var scriptSig = bitcore.Script.fromASM('04678afd04678a ' + redeemScript.toHex() the 046xxx is just a string (can be any string) which is currently hashed so it becomes equal to 894eeb82f9a851f5d1xxxxx or is the other way around where this 894eexxxxxxxxxx is the hash and the04678axx is the redeemScript?

What do you mean by "a miner can change the script"? Once the tx gets mined the redeemScript is revealed so it becomes vulnerable? I imagined that once the script is hashed that's irreversible.

1.) '04678afd04678a' is just a string, that get's sha256'd. 2.) The miner can change the script before (!) it goes into a block. The redeemscript is not part of the signature, so it can be changed, without invalidating the tx. To understand the concept of scripts and their execution, I recommend Andreas' book "Mastering Bitcoin", chapter 6 (Transactions, page 132ff). It is freely available online... I provided in a similar response for spending unsecured tx with funding  and spending tx in detail here:  https://bitcoin.stackexchange.com/questions/74753 (in the answer section).

Great explanation! Thanks for your explanation and response. Really helpful.


text:
How to spend an UTXO P2SH pay-to-script-hash
Anyone knows specific instructions on how to claim an unspent P2SH TX (pay-to-script-hash) based on a redeem script? No multisig.
I am looking for node.js JS instructions in bitcore-lib or similar.
Any suggestions or help appreciated.
Thanks :)
edited:

I hope you download from bitcoin.org, and verify the checksum/integrity of files. Then there is a very good example in Andreas‘ book, or even here: https://bitcoin.org/en/developer-examples#p2sh-multisig. As you said, you are not doing multisig, not a problem... can you show the raw tax, that you used? There is no link behind „coinb.in“... and here in the answer I have done a P2SH example: https://bitcoin.stackexchange.com/questions/74753/htlc-hash-time-lock-contract-using-bitcoin-qt/74953#74953

I have answered this in detail here https://bitcoin.stackexchange.com/questions/105796/how-to-spend-from-a-custom-p2sh-script-using-bitcore-lib/105797#105797

How to spend the output depends on the redeemscript. You have to provide a scriptSig that makes the script evaluate to True. More info on the wiki
If there are no signatures involved you can try to repeat the scriptSig that was revealed, although I doubt that would work as there are bots that do that automatically.


text:
Is there a Python or SageMath implementation for solving the ECDL problem for small secret multiplier?
I am looking for a Python script or SageMath code implementation for testing the Baby Step - Giant Stepand Pollard Rhoalgorithms on the secp256k1 curve.
I have read that these algorithms are well known for solving the ECDL problem for small numbers but I haven't found any code to test this.
edit:
I am looking for generating a small secret multiplier over the standard  secp256k1 curve parameters.
Here is an example for E=EllipticCurve(GF(modi), [0,7]) using the standard NIST parameters for G.
G=E(55066263022277343669578718895168534326250603453777594175500187360389116729240, 32670510020758816978083085130507043184471273380659243275938904335757337482424)

We know that for
P=E(69335761065767984070318781108127416310968753866933119760392423089576366173459, 113425617697416972613102767146321902225172329004525144463444008550345431352693)
when calculating discrete_log we get the small x=24734216105351567 as a result of P = x * G
Is there any such implementation that will calculate the small x?
Thanks!

In Sage.
Let's first define a finite field of size 2^32 (over which exhaustively searching would be painful but doable, but Pollard-Rho should be pretty fast).
sage F = GF(2^32 - 5)

And a prime-ordered elliptic curve over it (y^2 = x^3 + x + 13 happens to be prime)
sage: E = EllipticCurve(F, [1, 13])

Let's call the order of the curve n:
sage: n = E.order()
sage: n
4295040499
sage: n.is_prime()
True

Let's pick an arbitrary generator on that curve:
sage: G = E.gen(0)
sage: G
(4022957561 : 1193765470 : 1)
sage: G.order() == n
True

Now let's pick a random multiple of that generator:
sage: import random
sage: x = random.randrange(n)
sage: x
1334636724
sage: P = x * G
sage: P
(2051230087 : 1391923842 : 1)

And to find the discrete logarithm, simply use:
sage: discrete_log(P, G, n, operation='+')
1334636724

The same as our random secret multiplier x.
Sage uses Pollard-Rho and other algorithms internally.

Thank you but I am looking for generating a small secret multiplier over the standard  secp256k1 curve parameters. Here is an example for E=EllipticCurve(GF(modi), [0,7]) using the standard NIST (G=E) parameters. We know that for P=E(69335761065767984070318781108127416310968753866933119760392423089576366173459, 113425617697416972613102767146321902225172329004525144463444008550345431352693) when calculating discrete_log(P, G, n, operation='+') we get the small x=24734216105351567 as a result of P = x * G - how do I update your code to calculate this example? I clarified the Question.

If you're going to use Pollard's Rho over secp256k1, it'd need ~2^128 steps to complete. If you know the DL is very small perhaps the algorithm can be optimized using that information, but I'm not sure about the gains.

Yes, that was the advice I was looking for. Thanks a lot. Much appreciated :)


text:
Print all states of getting from a random 256 bit private key to a corresponding encoded BTC address
I wonder if it is possible to print what's going on under the hood regarding the process of getting from a random binary number to a BTC address.
It will look something like this:
Input: a random 256 binary number
Output: print()
Printing all possible sequential states from that number to a BTC address.
PRIVATE KEY STATES
binary privKey [k] -> decimal privKey -> hexadecimal privKey -> WIF privKey

PUBLIC KEY STATES
decimal pubKey print(x,y) -> print K where [K=(x,y)] -> hexadecimal PubKey (A) -> print A=RIPEMD160(SHA2569(K))

It will help a lot of people interested in the details of creating BTC addresses, from the elliptic curve private to public key process (K=k*G) to the other encoding steps until the final address.
On GitHub and other places, .js or .py libraries just print the WIF key and the address, and sometimes the hexadecimal public key as well.
Thanks.

If you really want this, I think your best bet is to take some existing code and add print statements wherever you like, or single-step it with a debugger.  I doubt you'll find code where this has already been done, mainly because I don't think it will actually be as informative as you guess.  The individual arithmetical computations aren't very informative one by one; it's better to understand the mathematical constructions that they express collectively.

Maybe my code bitcoin-in-tiny-pieces can serve to follow all the steps: each script is devoted to just a step of the process and has the minimal code to fulfil it.
Python is easy to follow if you're not a programmer, and there are comments that point to the documentation sources, though for example going from private to public key is all maths.
Each script is self-explanatory:

bitcoin-public-from-private.py
bitcoin-wif-from-private-key.py
bitcoin-address-from-public-key.py
bitcoin-get-address-balance.py

The bitcoin developper pages show the steps in all details for type 1 addresses.
For the type 1 addresses, there is a good link here to test results.
Then there is HD wallets, Segwit, and many other extensions...
Maybe it is good to start for type 1 addresses, and extend with your ideas of "under the hood crypto". I stick to Nate's comment though.


text:
What would happen to a LN channel if one of the parties followed a minority fork of Bitcoin?
Assuming a fork due to consensus-breaking rule change either hard-fork, UASF or similar. (So not including short reorgs.)
Would the channel simply become inactive/disabled and get "automatically" forced-closed after a while because of the disagreement between the 2 parties on the chainstate?
Is that handled by any BOLTs or is it let effectively as an implementation choice of the LN node developers?
EDIT: One very common scenario that may affect the answer is the following. Channel parties continuously update the force-closing commitments of the channel to account for the latest fee rates, this is done automatically by the nodes very often, without the node owners initiating it. A similar scenario is routing a payment for others.
Unless in all the core LN material interactions (send payment, receive payment, route payment, update channel state, update unilateral closing commitments) there isn't a need for the two parties to agree on the same chaintip beforehand, it seems the nodes could keep transacting while one node assumes BTCmain and the other BTCfork. And only when one of them tries to close/settle the channel will the issue will be identified (depending on replay-protection and maybe the block height difference?).

A LN channel (in its current form) is a 2-of-2 multisig UTXO coupled with pre-signed transactions each channel party holds onto, either to force-close the channel or to punish the other party for publishing an old state.
Following a hard fork, the UTXO will continue existing on the new chain, but the transactions will no longer be valid (assuming the new chain has replay protection). So in the event of an impending hard fork, either situation would occur for each channel:

The channel parties would sign and exchange transactions valid on the new chain in advance in order to either continue operating it or to cooperatively close it once the fork happens.
The parties would not agree to do the above, and one of them would close the channel in advance in order to be able to claim the forked coins.
The parties would assume the value lost in ignoring the new chain is not worth the hassle and do nothing. If they later agreed, they could still cooperatively spend the UTXO.

I doubt that any effort has been spent on mitigating such a fork scenario so far. Generally, the relevant questions are:

Do the two networks both persist, remain irreconcilable, and maintain meaningful value going forth?
Are transactions replayable between the two chaintips?
Do the relevant Lightning implementations support both networks?

Nothing happens automatically in Lightning, any action has to be initiated by one of the two channel owners.
I would expect the most likely outcome to be that one side would initiate a channel closing at some point, and that leading to a collaborative channel closure on one or both networks as long as the parties are still communicating.
If transactions are replayable between the two networks, even a unilateral channel closing attempt would propagate to both networks as we've seen in previous fork events that replayable transactions do get replayed. So even if the channel owners are not in touch, a unilateral close should have the expected outcome on both chains. Possibly the justice transaction would only get confirmed on one network because feerates are too divergent but the defender only cares about one network.
If one party doesn't care about the other network and transactions are not replayable or only uni-directionally replayable, perhaps one party could succeed at publishing an old state without the breach remedy being applied. Possibly Lightning software would need to get patched in that case to be able to create closing transactions on the other network. Since Lightning relies on pre-signed transactions, in that case maybe only a collaborative close would be possible and the funds would be lost on the chain that changed its transaction format because one of the owners does not care about it.
Either way, each fork would eventually bootstrap its own distinct network after the dust settles. The Lightning spec already prescribes that channels be labeled with the network they belong to, so once replayability and network identifiers are sorted the Lightning networks shouldn't cause conflicts further.

If transactions aren't replayable on the new chain, how could one party publish an old state?


text:
How is the merkle root verified if the mempools may be different?
How is the merkle root verified if the mempools are different? I already understand how its calculated. If a node has a mempool of transactions, and a miner has only some of those transactions and maybe some different ones, how can the node verify that the hash of the miners block which includes all the parameters and the merkle root is correct. As I understand, in order for a node to verify a block, they must first verify the validity of the paramaters in the block header. Thanks in advance!

The mempool and the Merkle root have nothing to do with one another.
Blocks consist of a set of transactions chosen by the miner (probably from their mempool, but it doesn't really matter - the composition of blocks is miners' perogative). That block consists of a list of transactions, and a block header that contains among other things a Merkle root committing to those transactions.
When blocks get propagated, nodes verify its Merkle root against its set of transactions. The receiver's mempool is entirely irrelevant in this process of deciding whether or not the received block is valid. Once a new block is accepted, transactions in the receiver's mempool which were included in the block (or conflict with transactions in the block) are removed.
Now, some block relay protocols (notably, BIP152 "compact blocks") take advance of the fact that receivers typically have most if not all transactions in a block already. BIP152 in particular just sends a short hash of each block transaction rather than the full contents immediately, letting the receiver request missing transactions if any. But none of this has anything to do with the block's Merkle root - that's an aspect of validating the block once it is received (and reconstructed). Compact blocks is a means of transmitting the block before validation happens.

Before compact blocks (BIP152), a new block received by a node would contain all its transactions in full. Validating the merkle root in the block header would then not involve the node's mempool at all, it would simply build a merkle tree from the received transactions and verify the merkle roots match. Of course, this meant that (nearly) all transactions were relayed over the network twice, with large bandwith spikes on each new block.
Since the introduction of compact blocks, your node instead only receives a list of short transaction IDs and a few transactions the peer thinks you might not have (most notably the coinbase transaction), looks up these transactions in its mempool, optionally asks the peer for any missing transactions, and then it can verify the merkle root as before.

Ah I see, so the node first checks for its mempool transactions, sends its mempool to peers to check if they are missing transactions and then calculates the merkle root with the rest of the transactions. Thank you!

One more thing, when a miner is choosing what transactions to use in its block, does they send those transactions to the node, who then validate if they correspond with their full list of transactions and then calculate the merkle root?

Not exactly sure what you mean by "sends its mempool to peers". The receiving node only asks its peer for transactions whose IDs were in the compact block but which weren't in its mempool.

For the miner question, you might benefit from reading the answers to What exactly is Mining?.


text:
How does node discovery and miner discovery work?
I am wondering how nodes discover other nodes and miners, basically, who to broadcast received transactions and blocks to. I'm assuming that when a new node or miner wants to be discovered, it broadcasts to all known nodes informing them that its a new node or miner. Then the node puts the node or miner on a list of IP addresses, to broadcast transactions and blocks accordingly.
What part did I get wrong?

I am wondering how nodes discover other nodes

Nodes learn about other nodes through:

DNS seeds (which run crawlers that maintain databases of network nodes)
From their peers (nodes gossip IP addresses of other nodes to each other)
From their own database of nodes (which is fed by the above two mechanisms)
From a hardcoded list built-in to the client, as a final fall back.

and miners

Miners are just nodes like all others; there is nothing special about them in this regard.

basically, who to broadcast received transactions and blocks to.

To clarify:

Nodes make connections to other nodes; this is what needs to be discovered. Every node makes a few random connections to other nodes, not to everyone in the network.
Nodes broadcast transactions and blocks (and IP addresses of other nodes) to these peers, not to everyone.

Eventually everyone will hear about every block, and most transactions, because everyone is connected to one another.

I'm assuming that when a new node or miner wants to be discovered, it broadcasts to all known nodes informing them that its a new node or miner.

It just rumors its IP address to its peers. Those peers will put the node's IP address in their peer database, and gossip it further to their peers. Over time, more and more nodes will learn about it.

Then the node puts the node or miner on a list of IP addresses, to broadcast transactions and blocks accordingly.

Nodes only ever communicate with their own peers (typically 8-10 outgoing connections, up to a few 100 incoming ones), but they can maintain databases of IP addresses with 10s of thousands of nodes. Most of those will never be connected with, but may be rumoured to others.

Could you explain how DNS seeding works?

@CJ-Programmer Very simply, it's a domain name that runs a custom DNS server which replies to every query with a number of "good" random IP address in the crawler's database. So if you resolve dnsseed.emzy.de for example, you get the IP address of a Bitcoin node that Emzy's crawler believes is decent.

Ah I see. Thanks for the knowledge!


text:
Should an offline address generated from private key send funds to wallet?
I'm trying to use the python package python-bitcoinlib to send a timelock transaction on testnet. The github has two examples to create an address, and then use that address to send the bitcoin to another address.
The problem is, when I send bitcoin to the generated address using my own private key, I never receive the bitcoin in my wallet. I'm able to broadcast the transaction to the second address, but I would like to have access to the bitcoin in case I change my mind before the timelock arrives. Here is the code:
from bitcoinutils.setup import setup
from bitcoinutils.transactions import Transaction, TxInput, TxOutput, Sequence
from bitcoinutils.keys import P2pkhAddress, P2shAddress, PrivateKey
from bitcoinutils.script import Script
from bitcoinutils.constants import TYPE_RELATIVE_TIMELOCK

def main():
    # always remember to setup the network
    setup('testnet')

    #
    # This script creates a P2SH address containing a CHECKSEQUENCEVERIFY plus
    # a P2PKH locking funds with a key as well as for 20 blocks
    #

    # set values
    relative_blocks = 20

    seq = Sequence(TYPE_RELATIVE_TIMELOCK, relative_blocks)

    # secret key corresponding to the pubkey needed for the P2SH (P2PKH) transaction
    p2pkh_sk = PrivateKey('cRvyLwCPLU88jsyj94L7iJjQX5C2f8koG4G2gevN4BeSGcEvfKe9')

    # get the address (from the public key)
    p2pkh_addr = p2pkh_sk.get_public_key().get_address()

    # create the redeem script
    redeem_script = Script([seq.for_script(), 'OP_CHECKSEQUENCEVERIFY', 'OP_DROP', 'OP_DUP', 'OP_HASH160', p2pkh_addr.to_hash160(), 'OP_EQUALVERIFY', 'OP_CHECKSIG'])

    # create a P2SH address from a redeem script
    addr = P2shAddress.from_script(redeem_script)
    print(addr.to_string())

if __name__ == "__main__":
    main()

When I run this code with my own private key, I get an address like:
2N3M2ZnDsw4FMDYTyMmtk6k12pBzbyKJvBR
From what I understand, that address is created from my private key, so shouldn't the funds I send to it go straight back to my wallet?

From what I understand, that address is created from my private key, so shouldn't the funds I send to it go straight back to my wallet?

Unless you told your wallet to expect transactions sent to that address, there is no way the wallet can guess that that address's hash is in fact the hash of a script it happens to have the private key to. Even if it did know, there is generally no way for the wallet to be able to spend funds sent to such scripts.
The receiver wallet, and it alone, is responsible for deciding what addresses it accepts funds on. You taking one of the wallets' keys, and constructing an arbitrary script with that key, hashing it, and putting that in an address, is you trying to do the wallets' job.
This is akin to you refunding a friend for a dinner by going to their place at night, digging a hole in their yard, burying the funds there, and then acting all surprised when they claim they didn't receive your money ("How do you mean? The money was on your property! It was yours!").
Having the keys to spend funds isn't sufficient for a receiver to accept funds. In fact, it may not even be necessary. If the private key is stored in a hardware wallet, software may well be configured to accept payments on addresses involving public keys it knows the hardware wallet has the private keys to. But it still needs to be configured to do so, just like in your example.


text:
Where is the rest of my bitcoin?
I sent bitcoin from one of my wallets to another wallet using one address (output)
then this is what I got only a fraction of my bitcoin the bigger amount went to another unknown address to me
https://blockchain.info/tx/9ddc08fd1faf741bfa77a606d7b7faf8ba92dd2229fc7525e7e00c6f704e60e1
total newbie here don't even ask why I transfer from one wallet to another...
this was a transfer from electrum wallet to mybitcoin wallet if that matters
this is the first transaction from the first bitcoin I bought
there no new adres for my change in my wallet

just to clarify to make sure I can answer this properly (if I can), you intended to send how much Bitcoin from address 3BMSebkKfRjJcFGp3moofZ2oVnDaFp8hm6? and to which address did you intend on sending it to, 1FAsfPJ5WCE6N9aqjzUqnuwEwEmLLzERru or 1Apg8f9n2CawhNdVSyKUmRgigv8qXffJgy ? Feel free to ask questions if you need me to clarify mine.

I sent .00247311 from 3BMSebkKfRjJcFGp3moofZ2oVnDaFp8hm6 to 1FAsfPJ5WCE6N9aqjzUqnuwEwEmLLzERru only .00047311 went to 1FAsfPJ5WCE6N9aqjzUqnuwEwEmLLzERru and the other .002 shows to be sent to 1Apg8f9n2CawhNdVSyKUmRgigv8qXffJg, if that's acreated change where is it then because is no where to be found in my wallet and my balance is 0 on3BMSebkKfRjJcFGp3moofZ2oVnDaFp8hm6 and .00047311 on 1FAsfPJ5WCE6N9aqjzUqnuwEwEmLLzERru

I'm sorry I don't know what you did, what is the name of your wallet? are you using BitcoinCore, or the Blockchain.info wallet? it seems you're using CoinBase, I'd email them for help and more information, or go to their help center.


text:
MimbleWimble on Bitcoin
As you know the Litecoin implementation of MimbleWimble on extensions blocks is already running on testnet. They will go mainnet in a year. I think this could be a great improvement for Bitcoin. We could use Bitcoin for private transactions when required, no need of coin mixers or Monero anymore. Exchanges like Coinbase will not delist Bitcoin as they already have ZCash which have public and private transactions too.
In the rare case there is a hidden inflation bug, new coins created in the extension block can't infiltrate the canonical chain because the amounts are public, so the bug would be detected sooner or later when someone can't send back his coins to the canonical chain.
The developer has said he's going to write a BIP and make a pull request to Bitcoin. What are the chances it's approved?
Regards

Nothing is stopping someone from implementing MW on a higher layer network, but I think the chance of seeing the Bitcoin protocol altered to include MW is very slim.

I understand you but implementing it on extension blocks makes a hidden inflation bug impossible on the main chain. Exchanges, shops and institution would accept only coins from the main chain, public transactions. The private coins would be used in person to person payments, or to erase your history before doing public payments. What would be risky is a hard fork with all transactions private, but extension blocks make it safe.

There is zero chance of it being used in Bitcoin.
There is prior incidents to gain wisdom from. Before zcash existed as an altcoin, zcoin was an implementation of a similar concept which people rallied behind and tried to ham fist into Bitcoin. It's essential, it's a mandatory, it's my right to be private! If you don't put zcoin into Bitcoin you are the manifestation of the devil himself, brought to destroy the fabric of society!
Unfortunately whenever things like this have been social pressured into existence for reasons of perceived valor, it has lead to problems. In the case of zcoin, it was later discovered that the implementation of zcoin slated for use in Bitcoin had an unbounded, invisible inflation bug which would have instantly ended the currency.
Bitcoin survives by being conservative with changes, not grabbing onto everything shiny.

I agree Bitcoin must be conservative, but implementing MW on extension blocks protects the main chain for any possible hidden inflation bug. People should have their savings in the main chain and move small amounts to the extension block to do private transactions with other people. In the worst case, the extension block is purged with a hard fork and people only lose the amount they had there. It's a small risk that most users would be happy to take. And don't forget is scalable privacy, not like Monero :)


text:
What good is to store all the transactions in the history
Bitcoin stores all the transactions that happened
in the blockchain.
Are really all the transactions needed? What good is it
to have transactions ten years old stored. Isn't it a waste
of discspace?

If you run a node in pruning mode, or a light client, you don't store the entire blockchain.

It really depends on how much certainty you want in the validity of a transaction. The more info you have, the more sure you can be that the transactions you're interested in are actually valid.

The bitcoin blockchain is a record of all transactions. This allows the user to independently validate transactions, and thus verify the authenticity of coins. However, you don't need to store all of the transactions for all time, by running a 'pruned node' you can keep disk-space usage low, while still verifying all transactions.
Background: bitcoins exist as 'Unspent Transaction Outputs' (UTXOs). Each individual transaction will consume some number of UTXOs as inputs*, and create new UTXO(s) as output(s).
Under this model, you can trace a UTXO back in time in order to validate it as being an authentic bitcoin transaction. For example, consider some bitcoin you receive today, lets call it 'UTXO-3'. In a simplified manner, you could trace the history of this UTXO-3 (to it's input 'UTXO-2', and so forth), until you find the coinbase transaction that mined the coins.
So ,going back in time, from your UTXO-3:
UTXO-3 <- UTXO-2 <- UTXO-1 <- Newly mined coins
This allows a bitcoin (UTXO) to be traced back to it's origin on the blockchain, which means you can validate it as an authentic bitcoin. Without this feature, you would be unable to verify for yourself that the bitcoin in question was created in a way which follows the network's rules. As mentioned above, bitcoin's design allows you to perform this verification without explicitly storing all transactions for all time (by running a pruned node).
Additionally, as Pieter mentioned in a comment, a user has the option to use a light-client, which does not require the user to store a copy of the blockchain locally (although this employs a slightly different trust model than running a full-node yourself).
.* (the exception to this rule is a coinbase transaction, which follows special rules to generate coins, without having any inputs)

Today I heard about the hashgraph with which you can dump all the history of the networks data.


text:
History of ideas behind a bitcoin protocol
Could you outline the logical sequence of main ideas (concepts) that contributed to the evolution of the bitcoin protocol from the beginning
to now?

You may try to explore Bitcoin-Core versions history

Should we start with the Caesar cipher and the conch shell? This question is too broad.

@RedGrittyBrick I learned Ceasar cipher in school :-) .Note the words "outline" and "main" in the question. These words should keep the answer narrower.

Bitcoin is roughly defined by the 2009 whitepaper. Long before, the idea of a trustless cryptographic money was discussed by Wei Dai; however, Wei Dai couldn't solve the double spend problem, which delayed the creation of magic crypto money until 2008 (yes, the Satoshi client was created before the whitepaper)
Inspired by: WeUseCoins.com

Which old version? https://web.archive.org/web/20180512222930/https://www.weusecoins.com/de/

@Willtech I have updated the link.

I accepted this answer with references and hope I can take notes from that and ask more narrower question later. Thanks a lot.


text:
401 unauthorized connection using python-bitcoinrpc
I'm running a Bitcoin testnet node on a Ubuntu 22.04 VM using UTM for Macbooks M1.
I'm trying to connect via json-rpc using https://github.com/jgarzik/python-bitcoinrpc.
1 - I installed the package etc..
2 - I edited my .conf file in /home/kk/snap/bitcoin-core/common/.bitcoin/bitcoin.conf:
server=1
testnet=1
daemon=1
prune=1000
fallbackfee=0.00001
rpcuser=kk
rpcpassword=testpass
rpcallowip=127.0.0.1
[test]
rpcbind=127.0.0.1
rpcport=18332

3 - I created a file called "btcrpc.py":
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from print import pprint

# rpc_user and rpc_password are set in the bitcoin. conf file
rpc_user = "kk"
rpc_pass = "testpass"
rpc_host = "127.0.0.1"
rpc_client = AuthServiceProxy(f'http://frpc_user}:{rpc_pass}@{rpc_host}:18332", timeout=120)

block_count = rpc_client.getblockcount()
print (block_count)

When I run btcrpc.py that's the error:

What am I doing wrong?


text:
Can one infer the multisig status of a P2TR spend?
Given raw transaction input/output data, is it possible to know if a Taproot output is multisig or not?
I'm getting raw block data from a bitcoin node, and want to classify each spend according to the script (P2PKH, P2SH, P2WSH, P2WPKH, P2MS and P2TR).
I want to be able to tell if an output represents a multisig spend, in particular for Taproot (P2TR).
Furthermore, if multisig, would it be possible to infer M and N?

This is possible with every output type except for P2TR. Taproot introduced to the Bitcoin protocol Schnorr signatures and Merklized Alternative Script Trees, both of which can be used to hide the true number of participants in a multisig.
Schnorr signatures
Taproot uses a new signature scheme called Schnorr signatures, which allows key aggregation. A single public key can belong to one user or be aggregated from multiple users using an n-of-n scheme like MuSig2 or even a threshold m-of-n scheme like FROST/ROAST. This makes multisig transactions smaller and therefore cheaper, but it also means you cannot tell if a multisig even happened, let alone its size.
Merklized Alternative Script Trees
A P2TR output can optionally commit to a script tree (MAST). The key difference from previous output types is that you can now have many alternative spending conditions, and only reveal the one that you end up using.
Even without key aggregation, this allows you to obfuscate the actual size of your multisig. For example, if you want a 2-of-3 multisig, you can create a script tree with three different 2-of-2 multisigs: A&B, B&C and A&C. Only one of these 2-of-2s will need to be revealed and nobody will be able to tell if the actual multisig was 2-of-2, 2-of-n for some higher n, or even a decoy multisig in which both keys were in fact owned by the same person.
You can use key aggregation in combination with script trees, for example to implement 2-of-3 using three different keys aggregated using 2-of-2 MuSig2. A footnote in BIP342 goes into a bit of detail on multisigs in script trees.

Thanks Vojtěch! So if I understand correctly, Schnorr signatures would completely obfuscate the multisig status. For MASTs however, would I be able to at least perform a binary check on whether there is/isn't a multisig present?

Not exactly, because a single key present in a leaf script could still be an aggregated key from any number of users, or belong to a 1-of-n multisig construction. There's just no way to tell what the underlying contract looks like.

I see. Thanks for the excellent response Vojtěch.

If the multisig was implemented through a script that involves multiple signature checks, then yes. Taproot script path spends reveal the full script used, so a technique very similar to P2WSH could be used (the script is the penultimate script stack element rather than the last one, but other than that, it's pretty much the same).
However, that is not the only means of implementing multisig policies, and the other ones aren't as recognizable.
A possibility is that the k-of-n multisig is implemented using several disjoint leaves in the taproot script tree, each script implementing a different k-of-k subset of the k-of-n. In this case you can see there are at least k keys, and based on the depth of the tree you may be able to estimate n, but it very much depends on guessing correctly that this is even what's going on.
It gets even harder if the multisig policy is implemented through MuSig key aggregation (a single key that represents a k-of-k agreement of multisig signers), or FROST native threshold signing (a single key that represents a whole k-of-n policy). These may be entirely indistinguishable on chain from simple single key policies.

Thanks Pieter. For the Taproot script path spend, the technique (similar to P2WSH) you mention, is it checking if the last byes of the penultimate entry in the witness script stack are 'ae' of 'af'? Or what would that look like?

(1) drop the annex (if the last witness stack element starts with byte 0x50, drop it) (2) if the (remaining) stack has only 1 element, it's a key path spend and not a script (3) check if it's a tapscript (identified by the final remaining start element starting with 0xc0 or 0xc1); if not, you know nothing. (4) analyze the script; CHECKMULTISIG(VERIFY) don't exist in tapscript, so the script will likely be "key1 CHECKSIGVERIFY key2 CHECKSIGVERIFY ... keyn CHECKSIG" (for n-of-n) or "key1 CHECKSIG key2 CHECKSIGADD ... keyn CHECKSIGADD k NUMEQUAL" for k-of-n.


text:
import private key into bitcoincore - getting error
I am a total dummy/layperson and cannot figure out how to import my private key into bitcoincore v23. I keep getting the error "this type of wallet does not support this command" when typing in "importprivkey" and then pasteing my private key.
Is there anyone that can talk to me about this like I am 5?!
Thank you kindly

Does this answer your question? How can a private key be imported to a descriptor wallet?

importprivkey can only be used with legacy wallets, you're apparently using a descriptor wallet. Simply create a new wallet with "Descriptor Wallet" unchecked and you'll be able to import the private key.

Thank you! Now I got an error that says Rescan is disabled when blocks are pruned. I created my private key using bitaddress.org. Should I have used something different? THANK YOU!

A private key generated using a website is not very secure. If you can, you should just generate keys with the wallet you use.

Thank you...I really don't know what I am doing. My exhusband created an offline wallet of sorts for me, but is not giving me all the information I need to move it online, only bits and pieces. He told me to use bitaddress.org to put in my password and then make a private key. Then to take the private key to bitcoin core to move it to a place that makes it accessible to me. I'm lost. But thank you so much for your time!

When choosing  File > Create Wallet I don't see the Descriptor Wallet checkbox.  Using Bitcoin Core 26.0.0.   Any ideas how to create a new Legacy wallet that I can then import private keys into?

i think they may have removed legacy wallets from later versions of bccore. but i am a total novice. i find all the various layers of security and what not thoroughly annoying/confusing XD  but  thats 'crypto' for ya.
im all ears to be corrected/informed.  i was able to make a legacy wallet using the instructions above using bitcoin core version 25.0


text:
Lib bitcoinconsensus verification returns SCRIPT_ERR_INVALID_STACK_OPERATION on a P2SH multisig output
I tried to verify an old transaction 6a26d2ecb67f27d1fa5524763b49029d7106e91e3cc05743073461a719776192 P2SH multisig input 0 using  lib bitcoinconsensus and I got SCRIPT_ERR_INVALID_STACK_OPERATION.
Here is the screencap of its
btcdeb --tx=0100000001f6ea284ec7521f8a7d094a6cf4e6873098b90f90725ffd372b343189d7a4089c0100000026255121029b6d2c97b8b7c718c325d7be3ac30f7c9d67651bce0c929f55ee77ce58efcf8451aeffffffff0130570500000000001976a9145a3acbc7bbcc97c5ff16f5909c9d7d3fadb293a888ac00000000 --txin=010000000168781ca236d8e70e4af8285852defabeff61c73db259cbbbebdf7bdac918c234010000004847304402206d186984373e0b781b85f49334cc9a249ffd13a448a5d1732096b011a10063e102206d280df8f4b5e6805f48eb04601ca6d97edd78f2b2d1104dc577e08fd788c78001ffffffff02cce80900000000001976a914fe58bbf690824bdaffb0431a709c27d7bdb6105e88ac801a06000000000017a91419a7d869032368fd1f1e26e5e73a4ad0e474960e8700000000

giving the same error.
How was this transaction verified by bitcoin core and what do I need to do to verify with lib bitcoinconsensus?

This transaction predates the activation of the BIP16 (P2SH) consensus rules on April 1st 2012, so there is no requirement that it is P2SH-valid. I don't know how to inform btcdeb that it shouldn't enforce P2SH rules.

Apparently btcdeb --modify-flags="-P2SH" ... disables BIP16. One can presumably supply bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH to bitcoinconsensus_verify_script() as well. My question is how does the core know when to supply this flag (pre- BIP16 transaction) and when not to?

Bitcoin Core knows when BIP16 (and other softforks) activated, so it sets the relevant flags on blocks for which the rules are active. Specifically, for BIP16 the activation is "buried", which means it's actually enabled for every block, except known exceptions.

@PieterWuille Thanks for clarifying. Why are these similar outputs listed here unspendable? Is it because the preimages can't be deserialized?

@gelenor We can't know for certain whether they are unspendable, but it is very likely. They were created prior to BIP16, so it's unlikely they were created in a way that's compatible with it.


text:
How to refund bitcoin after wallet recovery?
I lost my bitcoin balance after I forgot my wallet password in blockchain. Although I managed to get my wallet (same wallet with the same security phrase) recovered,my balance showed 0. Where did my bitcoin go ? Can I access them again?

What do you mean exactly by "same wallet"?

Actually, you said you lost your password to your blockchain wallet, and since you have the wallet and the security passphrase,
then actually you should check the btc address in which you have the fund on blockchain.info to see if your actually balance is there

Thanks for your answer , what do you mean by btc address ? Do you mean my wallet address?

yes your wallet address


text:
Computing HASH160 of a Taproot X-only 32 byte Public Key
I know that Taproot does not use pubkey hashes, but I want to compute a HASH160 of a 32 byte Taproot X-only public key anyway. The rationale is to compare it to an existing 20 byte HASH160 from a Witness V0 ScriptPubKey, to see if the same underlying public key is used in both outputs.
Is it correct to just pre-pend 0x02 byte to the 32-byte XOnlyPublicKey?
I sketched this using rust-bitcoin:
// Taproot. In the case of the key-path spend, the pub key is not tweaked.
//It is 32-byte only X-coordinate however, missing the 33-d byte Y "tie-breaker"
//https://archive.is/AsKEb
//From BIP 340: "To avoid gratuitous incompatibilities, we pick that option for P, and thus
//our X-only public keys become equivalent to a compressed public key that is the X-only key prefixed by the byte 0x02."
let witness_program_bytes = program.program().as_bytes();
//Y-coordinate absent:
assert_eq!(witness_program_bytes.len(), 32);
let mut witness_program_vec = witness_program_bytes.to_vec();
//BIP 340:
witness_program_vec.insert(0, 0x02);
// it is the actual compressed 33 byte pubkey
let pk = PublicKey::from_slice(&witness_program_vec).unwrap();

I'm not 100% sure about it, but if taproot output XOnlyPublicKey is not tweaked, and if you try to compare with existing p2wpkh output which uses the same public key, you should try both 0x02 or 0x03 as both Y coordinate are possible. As far as I know, even Y(0x02) is implicitly used for efficient and compatible verifications. Therefore, it's still possible to use XOnlyPublicKey which Y coordinate is odd(0x03), as taproot key output.
You can also refer this answer, which describes the implicit Y coordinate in detail.