text:
Why store Merkle tree of transactions rather than global ledger state?
I'm implementing my own Cryptocurrency similar to Bitcoin from scratch in C++ (just for learning and deeper understanding) and had an interesting design question.
My understanding is that the Merkle tree is only for nodes that do not want to download the entire blockchain ("lite nodes") ... so they can be sent a single transaction and verify it by getting the hashes of all previous blocks and a number of hashes logarithmic in the number of transactions within a particular block.
It seems to me you could accomplish something with similar functionality by instead computing the Merkle tree over the entire ledger state. Even with 1 billion accounts, this comes down to 30 hashes to verify a portion of the ledger. You would write the merkle root of the ledger state to the root of each block node. To verify a transaction you just download the new account value, along with the 30 or so hashes.
Assuming a 20byte wallet address + 8byte double for value ... we get ~28GB of data for a billion addresses... doable in memory on beefy modern server hardware.
This is how I am thinking of approaching it in my design -- am I missing something critical in the security model here?

It’s off topic here, but your understanding of the basics here is pretty lacking, I’d do a lot more research on the fundamentals before trying to design something better. You would be absolutely nuts to store monetary values as a float for example.

That's not super helpful. I'm trying to understand why this design wouldn't work. I'm not trying to design something better, just make something functional ... but I feel like I'm missing something.

Hashing the whole UTXO for Bitcoin takes many minutes, we expect the network to be able to synchronize in less than a second.

So if I understand correctly this design is infeasable due to performance rather than the security of the construction? Do you need to hash the UTXO entirely each time though? You don't need to re-construct the entire MerkleTree of the UTXO per block... you just need to re-compute log(N)*k nodes where k is the number of wallets that changed their value or were inserted. The main problem I see is that you will likely be only able to keep a Merkle tree for the current block due to memory limitations...so you would not be able to answer an arbitrary balance query for any block.

You are confusing a UTXO model and an account model, they are distinct architectural approaches. See: https://bitcoin.stackexchange.com/questions/49853/utxo-model-vs-account-balance-model

Thank You! this account model is more along the lines of what I was imagining. Was not aware other cryptocurrencies have used it before.

It seems to me that this would be a performance hit with no real benefits.
Committing a Merkle root of the UTXO set to each block would certainly be possible (of course you would need to devise an algorithm to build the Merkle tree deterministically, as each client would have to do that by itself), and with some clever performance optimizations (as you mentioned in the comments, you might not need to rebuild the entire Merkle tree for each block) it might be somewhat manageable.
However, SPV clients (who use the Merkle tree of transactions) can already "prove" (to the extent that non-full nodes can prove anything) that a UTXO has been created by a transaction. Using the Merkle root of the UTXO set would only add the ability to prove that the specific UTXO hasn't yet been spent by another transaction.
If the UTXO belongs to you then you probably don't need to ask other nodes if you've already spent it. If the UTXO doesn't belong to you then you probably don't need to know anything about it. In short, I don't see a use case.


text:
Default derivation path in Trezor Suite desktop app
This seems like a silly question but I could not find an answer after searching extensively. I currently have a Trezor Model One device that I'm accessing through both the Trezor Suite desktop app on macOS and the web app at wallet.trezor.io. Looking at the default account generated on the web app, I'm seeing that the xpub associated with the account is different than the xpub associated with the default account generated on the desktop app. I'm also seeing that the web app has the derivation path for the default account as m/49'/0'/0' where as the desktop app does not appear to have the derivation path listed anywhere. This remains consistent no matter what type of wallet/account I create (segwit, legacy, etc.). Is the derivation path for the default accounts on the desktop app intentionally hidden from the user?
For context, I'm working on a project that uses the Trezor Connect API to allow a user to fetch the wallet balances for their accounts. Because the derivation path is hidden, there is no way for me to pass the path into the API call to fetch their default account they generated on Trezor Suite. I also tried removing the path from the call entirely which should fetch all of their accounts and prompt the user to select which one they would like to expose but the default account was not listed there, either. (The accounts generated at m/{49, 44, 84}/0'/0' were the accounts that appeared when going this route.)
Thanks in advanced for any help!

Trezor offers a "password" or "hidden" wallet feature to fully exploit the bip39 protocol to generate addresses. However, sometimes people think that it is a necessary password, which is not. Are you trying to use this password? Take into account that the security pin is different from this password. You should use "standard" wallet which doesn't require password and this would just generate the addresses solely from the mnemonic phrase which is the most commonly used case.

Thank you, @OscarSerna. This was exactly the problem. If you want to post it as a non comment, I'll mark it as the correct answer.

Trezor offers a "passphrase" or "hidden" wallet feature to fully exploit the bip39 protocol to generate addresses. Think of this as the "salt" in the hashing algorithms.
This means that your mnemonic phrase would have an additional security layer by adding this "salt" or "passphrase" to your privare key.
This feature is really cool, and works great if you are setting up a wallet for the first time in your Trezor. However, Trezor fails at making this clear to the user, which causes that sometimes people think this is a necessary passphrase instead of an optional step. Therefore, when people are trying to reuse a wallet, this additional passphrase will cause the generation of different addresses to the ones that they are expecting.
To avoid this, simply use the "standard" wallet which doesn't require this additional passphrase, and this would generate the addresses solely from the mnemonic phrase which is the most commonly used case.
People often get confused with this passphrase because it is really easy to think that this password is an extra layer of security to access their Trezor, when in reality this is done through a pin number that the user can setup optionally.

source: Stack Exchange

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

sort: votes


text:
Clarification on false value in Script
From my interpretation of the bitcoin Script Wiki and the rust-bitcoin codebase, two items on the stack get interpreted by bitcoin Script as false:

The empty array []
The single byte 0x00

Q1: Is it correct to think that a 2-byte long or more array of 0s (even though as a number would get interpreted as 0) would not be interpreted by bitcoin Script as false? For example the script OP_PUSHBYTES_4 <0x00000000> would put a byte array of 0s on the stack but still equate to true? On the other hand the script OP_PUSHBYTES_1 <0x00> would interpret as false?
Q2: Will an opcode like OP_NOT work with/interpret both of the above as false? (the docs on rust-bitcoin, Push 1 if the top item is zero; otherwise, push 0. are not very explicit in that sense, and the bitcoin wiki is even worse).

For readers coming to this post: note that my assumption on Q1 was wrong, and in fact the script OP_PUSHBYTES_4 00000000 would evaluate to false.

For the purposes of determining whether a Script stack element is true/false in boolean context:

The empty array is false (the canonical encoding of the number 0).
Any array consisting of just 0x00 bytes is false (an overly long, but still valid encoding of the number 0).
Any array consisting of just 0x00 bytes, followed by a single 0x80 at the end, is false (encodings of "negative 0").
Everything else is true.

This boolean context is relevant for OP_IF, OP_NOTIF, OP_VERIFY, and OP_IFDUP, as well as for determining final success of Script evaluation. Opcodes like OP_BOOLOR and OP_BOOLAND actually interpret their arguments as integers, though the only practical difference is that integer arguments are limited to 4 bytes (violating this limit makes the entire script invalid).

Thanks for the answer @pieter-wuille. Here is a follow-up question I'd like to confirm with you. Are you saying that the script <ababababababababab> <01> OP_BOOLAND is invalid instead of true (because the first argument is 9 bytes long instead of 8 or less?

Yes, <ababababab> OP_1 OP_BOOLAND would also be invalid (5 bytes is more than 4).

Oh shoot yes 4 bytes is what I meant haha. Perfect thanks! I was working on this page. Cheers.

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


text:
What happens to the unused P2A outputs?
I'm looking at PayToAnchor outputs and have a few questions:

What happens to P2A outputs that are never needed in the end because their user didn't need a fee bump on their transaction? Do they just bloat the UTXO set?
I had heard that those would carry 0 value, but in fact all of them do. Is this related to the fact that usually (I think) all outputs need need to be above dust-value for transactions to be propagated? If so, how is that reconciled with the idea of having 0-value outputs (or am I just wrong about that and they've changed to be a minimum of the dust-value?).

Thanks!
Note: I'm happy to break the above into 2 questions if it's better for discoverability on BSE.

Great reading on P2A: the Pay to Anchor section of https://bitcoinops.org/en/bitcoin-core-28-wallet-integration-guide/

What happens to P2A outputs that are never needed in the end because their user didn't need a fee bump on their transaction? Do they just bloat the UTXO set?

Since these outputs require no witness data to be spent, presumably they will be swept once the amount of satoshis in the output is worth sweeping. The minimum amount in satoshis for P2A outputs as of Bitcoin Core 28.0 is 240 satoshis but they can also be any other larger value. This means if the going feerate for block inclusion drops low enough to make a sweep worth it, miners are incentivized to sweep it.

I had heard that those would carry 0 value, but in fact all of them do. Is this related to the fact that usually (I think) all outputs need need to be above dust-value for transactions to be propagated? If so, how is that reconciled with the idea of having 0-value outputs (or am I just wrong about that and they've changed to be a minimum of the dust-value?).

Currently, all non-OP_RETURN outputs have a non-0 satoshi value dust limit that's calculated based on the script size and some other heuristics.
The original idea for "Ephemeral Anchors" was split into two separate concepts: Pay To Anchor(P2A) which is the script format, and "Ephemeral Dust", which is the ability to have a dust output without unduly bloating the utxo set.
The latter idea is not bound to a specific output type, and is still being developed for a future Bitcoin Core release.

It costs 41 vbytes to spend a P2A output, so a 240 satoshi one would be profitable to spend at around 5.8 sat/vB, not 3.

Also, OP_RETURN outputs don't have a dust limit.

thanks, dropped the specific number because it depends on how much is being swept to avoid fixed costs and isn't that important. Salient point is it's well above minrelay.

Thanks @instagibbs! I see the break in the two ideas now and I understand why the current P2A are non-0. Do you have a link for this Ephemeral Dust idea (and how this non-bloating of the UTXO set is achieved if the output is 0)? I keep finding broken links to your BIP (https://github.com/instagibbs/bips/blob/ephemeral_anchor/bip-ephemeralanchors.mediawiki) and can't find it in the BIP repo directly. The optech (https://bitcoinops.org/en/topics/ephemeral-anchors/) page also doesn't address Ephemeral Dust directly. Cheers!

@thunderbiscuit https://github.com/bitcoin/bitcoin/pull/30239 here's the PR
It uses a couple interlocking rules if there's dust:

must be 0-fee
if spending from that dust transaction, child MUST spend the dust


text:
What needs to be done inorder to change difficulty?
I'm trying for a while to reduce difficulty of main network to do some experiments on transactions and maybe simulate some possible attacks.I came up to change nBits field in chainparams.cpp but it seems it is not enough and the new network didn't run properly. What else should I do exactly ?


text:
can I run bitcoin core with public key only
I'm looking a way for secure setup of web site that accepts bitcoin payments. Ideally I'd like to create wallet off-site and be able to deploy bitcoin core online with public key only that I believe should be enough to generate new addresses and watch for incoming payments

can I run bitcoin core with public key only

That would be a watch-only wallet - usually achieved by importing an externally derived address.

deploy bitcoin core online with public key only that I believe should be enough to generate new addresses

In principle you can derive addresses from a public key but, as far as I know, Bitcoin core doesn't provide any way to import a public key and derive addresses from it. But I haven't tried.
See

How to import an extended public key into bitcoin core 0.16
https://bitcoincore.org/en/doc/0.16.0/rpc/wallet/importpubkey/

You could always generate addresses from a public key externally and then use the Bitcoin core API to import those addresses. There are many Bitcoin libraries for popular programming languages.

How bitcoin addresses are generated?
https://godoc.org/github.com/btcsuite/btcutil#NewAddressPubKey


text:
Why is there an addrlocal field in the output of the RPC call getPeerInfo, and how SPVs handle it?
According to the Bitcoin core developer reference, the RPC call getPeerInfo has in its output a field called "addrlocal" which holds our IP from the worldview of the peer.
Why is this output there? Is it used anywhere? Does it have a use case?
Furthermore, they commented that "Most SPV nodes set this to 127.0.0.1:8333", why would an SPV node do that?

Why is this output there?

Because it is part of the version P2P message. getpeerinfo largely outputs the information provided by the version message.

Is it used anywhere? Does it have a use case?

Currently, no. However it may have been included in the version message because Bitcoin was originally designed for things to go directly to IP addresses. There used to be a Pay-to-IP thing where this could have been useful.

Furthermore, they commented that "Most SPV nodes set this to 127.0.0.1:8333", why would an SPV node do that?

Because it is easier to implement and no one actually uses it.

Why is this output there?

It is sent to the Bitcoin node by its peers in their version P2P messages.

Is it used anywhere? Does it have a use case?

Yes. Foremost, it is used in Bitcoin's P2P networking. When a node wishes to accept incoming Bitcoin network connections over the Internet but doesn't know its own IP address on the Internet, it can use the addrLocal reported by an outbound peer to discover what IP address the outbound peer sees this node's connection coming from. If this IP address is within valid Internet ranges, this node may then advertise this IP for future incoming connections. In Bitcoin Core, this discovery behavior is enabled or disabled by supplying the -discover option to bitcoind or bitcoin-qt.
addrLocal can also be used by applications that receive the information via the getPeerInfo RPC procedure you mention. If an application is wanting to make its own decisions about what IP address to advertise for a node, such as for a website, it can include this peer-supplied data in its decision. An application might also wish to determine how a peer connected to a node when this node offers multiple routes for peers to connect (e.g. via NAT, reverse proxies, forward proxies, tunnels, anonymizers, etc.)

Furthermore, they commented that "Most SPV nodes set this to 127.0.0.1:8333", why would an SPV node do that?

Either because the SPV node is actually running and connected locally or because the SPV node has lied. A use-case for any type of node lying might be the developer leaving in a placeholder value while they haven't finished implementing the network protocol's requirements fully, or if the connecting node wishes to obscure what route it took to connect to this node when there are multiple options available.
The "most SPV nodes" wording has largely been removed from documentation.


text:
Is it possible to identify UTXOs signed by HD wallets?
I was wondering if the fact that a transaction was created by an HD wallet can be somehow read off from the UTXO, or any other data available in the blockchain.
Theoretically, it is not required in any way to leak the fact that an HD wallet was used to create a transaction. However, this does not imply that this data is not leaked in currently used wallets.
Is there any information available on that? Thanks.

Almost every wallet today uses HD key derivation. You'd need to go back to software from 2016 or earlier to find any that don't. So I'd say your question is moot.
That said, there certainly are signals in on-chain transaction data that let you make informed guesses about what software may have created them, though they're not correlated with HD or not in practical implementations:

Order of transaction inputs and outputs. Some wallets follow BIP69 which specifies sorting the inputs and outputs; other wallets order them randomly.
Types of inputs used: if a transaction is spending a P2WPKH or P2TR UTXO, it was almost certainly created by a segwit resp. taproot wallet (or it was a CoinJoin transaction with another one that does).
Types of outputs used: if a transaction has a P2WPKH or P2TR output, it's almost certainly created by a wallet that supports BIP173 resp. BIP350 (which specify the address formats for such outputs).
Coin selection: there are many algorithms in used for selecting which UTXOs to spend to fund any given created transaction, including oldest-first, branch-and-bound, single-random-draw, knapsack, ... . Not every wallet implements the same ones, or implements them identically. From the set of inputs a transaction has it may be possible to infer something about which selection algorithm was used this way.
Anti fee-sniping: some wallets timelock their transactions so they can only be included in the current block height or later most of the time, which prevents a 51% attacker which creates a deep reorg from including the transaction there (making it harder for those to get the fee from the transaction).

Thank you for a very elaborate answer!

I just noticed: "You'd need to go back to software from 2016 or earlier to find any that don't. So I'd say your question is moot.". The truth is that I am particularly interested in old UTXOs, that is, UTXOs from between 2013 (when HD wallets were first introduced) and 2016 (when they were already pretty much universally adopted). I assume the fraction of current non HD UTXOs is negligible if not exactly zero.

No. The point of HD wallets is to create a deterministically generated sequence of addresses but which look random and not related to one another. So unless BIP32 is fundamentally broken, you should not be able to distinguish between a HD wallet and a wallet that simply generates addresses at random.
The only way you can know a HD wallet was used is if its owner gives you its extended public (or private) key.

I don't think that's relevant. It could be the case that it is impossible to know which addresses were derived from the same seed, but it could be recognized that a transaction was created by a specific wallet. For example, I don't think a wallet that follows BIP32, but adds a "created by wallet X" to the payload of transactions breaks BIP32 in any way. Of course that would be a stupid thing to do, but the point is that different wallets do output transactions with different aesthetics as pointed out by Pieter Wuille.

(To make it clear: what you said does hold for the public-key hashes themselves, but transactions contain more data than just that, and this data might leak information about the wallet used. That was the essence of my question.)

From just looking at a transaction, its output scripts, signatures etc. you really cannot tell if it was created by a HD wallet. What you can do is guess which wallet software created the transaction and go from there, but that requires information beyond what is available in the blockchain, and isn't always going to be accurate (two wallets might create similar looking transactions, your list of wallets won't include proprietary wallet software etc.).

Yeah, I understand. The mere fact that the transaction data can be used to infer anything about the likelihood that the transaction was created by an HD wallet is very problematic for me, and I am trying to understand the extent. Especially for transactions from 2013-2015, and I suspect it might be "easy" to identify transactions created by wallets known to not implement HD yet (which were abundant at this time).


text:
Does an unopened encrypted Electrum wallet relay its addresses/transactions to nodes?
I have Electrum 3.1.3 (windows) installed with an encrypted wallet, which is accessed over a VPN.
The Issue:
I accidentally opened the Electrum program without VPN protection, but the encrypted wallet (default_wallet) wasn't opened (i.e. I didn't enter the wallet password to open it).
So, is there a chance that the wallet addresses got relayed to electrum nodes with my non-VPN ip-address and in turn got compromised?
Reason for the question
When the Electrum program was clicked open, a lot of network packets were send & received, even though the wallet wasn't open.

No because until you provide the password at the start Electrum can't decrypt your wallet file so it doesn't know your addresses and can't query a server about related transactions. This only applies if you are using full wallet file encryption. You know you are doing that if you are asked a password at the start and not just when you try to spend your coins.
Another way is to go to wallet menu > password. The encrypt wallet file option should be checked there. A third way would be to go to file > save copy and examine the saved file in a plain text editor. If you find that it's all random unreadable characters (ciphertext) and not JSON code then you have full wallet encryption.
BTW you can configure a socks proxy under tools > network > proxy tab. If you configure a socks proxy that can only be accessed via your VPN you will never make the mistake of connecting without a VPN. However, note that a VPN does not anonymize you. It just prevents censorship. If you want anonymity use Tor but also note that all bitcoin transactions are public so it can never be truly anonymous.

I am using full wallet encryption, but as I stated, the moment I open Electrum (not the wallet) network packet activity is recognized, packets are being sent and received. So, in short just opening Electrum on my computer starts network activity (prior to opening of Electrum everything was zero, no packets received/sent), now the question is who/what does Electrum connect to, if there is a full wallet encryption.

It's probably downloading block headers from electrum servers. This does not reveal any private info. Like I said if the wallet file is encrypted electrum itself does not know your addresses until you provide the decryption password.


text:
How does Bitcoin use its communication protocol and its database model?
In terms of Bitcoin's communication protocol, how does Bitcoin allow nodes to communicate between each other?
Is Bitcoin's communication protocol the same as IPFS(InterPlanetary File System) and if not, is it a great idea to use IPFS for blockchain communication? Since IPFS can transfer large amount of data, then why not sending Blockchain data through it?
Second, I found out on Stack Exchange that Bitcoin uses LevelDB to store data. Does that mean that there is a central server / authority where LevelDB is running the entire chain? If yes, how does that make Bitcoin decentralized? If not, then is LevelDB run on every node?

is it a great idea to use IPFS for blockchain communication?

Bitcoin nodes form a P2P network, using TCP to communicate bitcoin-specific messages between one another. By using a self-defined protocol, the Bitcoin network's communications can be optimized and made robust against attacks, while not having rely on any external dependencies to do so.

Since IPFS can transfer large amount of data, then why not sending Blockchain data through it?

As far as I understand it, IPFS is designed to work as a distributed file system. In this regard, it may be a suitable choice for a user looking to download the blockchain during the bootstrapping phase of creating a new Bitcoin node, as an alternative to downloading the same files from the Bitcoin network itself. Similarly, there are copies of the blockchain available on the BitTorrent network.
Note that in most cases, it is safest to download the blockchain from the Bitcoin network itself, to ensure you receive an authentic copy, with no malicious files or code inserted into it.

Bitcoin uses LevelDB to store data. Does that mean that there is a central server / authority where LevelDB is running the entire chain?

No, there is no central server or authority in the Bitcoin network. Each node builds and maintains its own database, so that it can independently validate the current state of the network.


text:
How exactly are the undo files used when a re-org takes place?
It is obvious that the undo files (rev*.dat files) are stored to restore the blockchain to a previous version when a re-org takes place. What is not clear to me is what are the exact uses of the contents of these files.
I am basing my questions off of this answer explaining the contents of the undo files and this answer explaining thoroughly the structure of the chainstate database.
Firstly, why don't the CTxInUndo records contain any mention of the parent TXID of the outputs used? Won't this information be needed to insert these outputs back into the chainstate as UTXOs? How is the chainstate restored using only the information contained in these records?
Secondy, what about the outputs created by the transactions of this block? Since they should be removed from chainstate after a re-org, why are there no records for them in the undo files?
Lastly, why is the height in the CTxInUndo record stored as 2*height (+1 if it was a coinbase output) and not just height? Is the shift by a bit used to store if the transaction was coinbase or not?

Firstly, why don't the CTxInUndo records contain any mention of the parent TXID of the outputs used? Won't this information be needed to insert these outputs back into the chainstate as UTXOs? How is the chainstate restored using only the information contained in these records?

The block itself is also used in the undo operation. It lists the UTXOs (by txid and output index) which are being spent. The undo files contain the contents of those spent UTXOs in the same order.

Secondy, what about the outputs created by the transactions of this block? Since they should be removed from chainstate after a re-org, why are there no records for them in the undo files?

This information is also extracted from the block data, as it lists the transactions, so the txids of UTXOs that need to be removed in a rollback can be computed from that.

Lastly, why is the height in the CTxInUndo record stored as 2*height (+1 if it was a coinbase output) and not just height? Is the shift by a bit used to store if the transaction was coinbase or not?

UTXOs store the following information for each entry:

The txid that created it
The output index in the tx that created it
The scriptPubKey
The amount
The height it was created at (to be able to enforce relative timelocks)
Whether or not the tx that created it was a coinbase transaction (because the special maturity rules that apply to spending coinbase outputs).

These last two items need to be stored in the undo data, as they cannot be inferred from the spending transaction.
The encoding used is to store the height and coinbaseness as a single number (2*height + coinbase), so it only takes up minimal space in the database.


text:
Read Wallet addresses with C# and Berkeley
I have searched all threads, but still couldn't find an answer.
I am trying to read from a wallet that is not encrypted, but I am not able to proceed on retrieving the address values, they are byte[] but I can't convert them to the respective addresses.
        {
            BTreeDatabase bdb = OpenBTDB(srcWalletFileName);
            Cursor c1 = bdb.Cursor();
            var currValue = c1.First().Value;

            string NoEnc = currValue.ToString();
            string defaultEnc = Encoding.Default.GetString(currValue.Data);
            string utf8Enc = Encoding.UTF8.GetString(currValue.Data);
            string asciiEnc = Encoding.ASCII.GetString(currValue.Data);
            string utf16Enc = Encoding.BigEndianUnicode.GetString(currValue.Data);
            string utf32Enc = Encoding.UTF32.GetString(currValue.Data);
            string utf7Enc = Encoding.UTF7.GetString(currValue.Data);
            string isoEnc = Encoding.GetEncoding("ISO-8859-1").GetString(currValue.Data);
            string b64Enc = Convert.ToBase64String(currValue.Data);
            string bitEnc = BitConverter.ToString(currValue.Data);
            string streamR;
            using (MemoryStream stream = new MemoryStream(currValue.Data))
            {
                using (StreamReader streamReader = new StreamReader(stream))
                {
                    streamR = streamReader.ReadToEnd();
                }
            }

            bdb.Close();
        }```

All of the above give me strange characters for the Data and also for the Key.
Am I missing the correct encoding?
Can any one help?

A wallet.dat file contains much more than just addresses. In fact, it mostly does not contain addresses at all. There will be some addresses because they are added to the address book, but the wallet mostly deals with keys, with addresses being computed from the keys as needed.
There are also two wallet types - legacy wallets and descriptor wallets. Legacy wallets will store keys explicitly, while descriptor wallets generally do not. But descriptor wallets also use SQLite rather than BDB, so you are dealing with a legacy wallet.
For both types of wallet, each record in the wallet database will begin with a length prefixed string indicating what kind of data is stored there. If you want addresses from the address book, the  string will be name. This will then be followed by a length prefixed string for the address. The value of the record will be a length prefix string for the label to apply to that address. It may be empty (0 length).
To get all of the addresses for a legacy wallet, you will need to find all of the keys and compute addresses for each key. Keys are stored in key records. The public key follows the string key, and the private key will be the value of the record serialized using DER. See section C.4 of the secp paper for details on that.
For descriptor wallets, you can get the descriptor record and derive addresses from there. Individual keys and addresses are not stored for descriptor wallets.


text:
Do all keyholders in a multisig wallet have separate wallet addresses that all work as the "multisig wallet"?
I have a 3/5 multisig bitcoin wallet. I understand all 5 signers have their own set of private keys and public keys. What I don't understand is how the "receiving" addresses work. Does each set of keys have its own set of addresses and it doesn't matter which addresses funds are deposited to?

No, there is a single multisig address, which can be computed from all the participants' keys.
Funds can then be sent to that multisig address, and when 3 out of the 5 predetermined keys associated with the address sign, that money can be spent.

Thanks - question: when you say "single multisig adress", you mean several addresses from the extended public key? I've been sending to a new address on the multisig wallet every single transaction.

Yes, that's possible. In that case a new address is generated, each using a new key from every participant, which are generated in lock-step from those participants' xpubs. The point I was trying to make is that that each individual multisig address has contributions from each participant. It's not an address per participant.


text:
BTC Full Node Wallet
Is it possible to use a BTC full node (running on linux) to query an address and either see all of those address transactions or to get a list of their UTXO's so you can calculate a balance and see how much has been spent? If not, how do sites like BitRef accomplish this task? Simply put in BTC address and it shows all the transactions and the balance of the wallet in just a few seconds? Do they have some sort of DB they leverage in addition to the blockchain?


text:
Being paid in Bitcoin from another country
If I sold property in another country, could I be paid in bitcoin in a basic wallet to wallet transaction if the value is 500k+?

People voting to close this as "cryptocurrencies or projects that are not Bitcoin", why? The question is literally about bitcoin. It may be warranted to close this as offtopic due to being too dependent on jurisdiction, this site not being for legal advice, or lacking details.

Sure, as long as it's a legal transaction in your country.

Even if it isn't legal, the bitcoin transaction will still go through (though obviously you may encounter other troubles, from local law enforcement or whatever).

True. I assumed it was more of a "am I practically able to" and in that case if the payment isn't legally accepted, OP may run into problems getting the title to the property transferred or other such legal steps.


text:
Need help opening my bitcoins that was save to my computer
About 5 or so years I received some bitcoins, they were kept in a bitcoin wallet, well the wallet became unresponsive so I backed the wallet onto my computer, but now I have no knowledge of how to open them and put them in another will download now. Does anyone know how this is done thanks?

Which wallet software were you using? What sort of backup do you have saved?

What is the filename of the backup? This can help in identifying the software needed to restore the wallet.


text:
Hosting lightning node and non-custodial
In Bitcoin we can have a light wallet where we are connected to a full node, by doing this, we have to trust that the full node is feeding correct information, but at least we can store our keys in the light wallet itself.
I've been looking around for a similar solution in lightning and the closest I found are some lightning wallets which host a node in their clouds and an app which controls the node.
Unlike layer 1, keys are not needed in order to perform transactions, which means that you are not only trusting the information the node is providing, also they could perform transactions without your knowledge.
Am I missing something here? Why are those wallets called non-custodial?
I know you can run a full lightning node on you phone like acinq does, but a safe cloud-based solution would lower the barrier of entry for some users

Unlike layer 1, keys are not needed in order to perform transactions, which means that you are not only trusting the information the node is providing, also they could perform transactions without your knowledge.

Keys are required in lightning. Multiple, in fact.
The lightning node itself is identified by its public key. You need the private key to perform the secure handshake so that you can have encrypted and authenticated communication with peers. You also need the node's private key to sign any gossip information about your node or channels.
On forming channels, you need the private key for an unspent transaction output on the bitcoin network in order to fund the channel.
On operating channels, each channel has a unique funding key which is used to spend the 2-of-2 P2WSH output. You must have the corresponding private key to sign each commitment transaction and also the closing transaction - this must be done once per commitment.

That makes sense. Then if the private key stays in the app controlling the lightning node, it would be safe. But that's not how it's done right? right now, to access the RPC and send transactions you only need the macaroon which leads me to believe that the keys are stored and managed in the lightning node not on the app which controls the node.

It doesn't matter which application controls the keys. If you're running the node on a machine which you don't control, you can forego any hope of those keys being private. The private keys must be on your own machine only, and even then, should ideally be on a hardware security module where the private keys can not be exposed through side-channels if any other software on the machine is exploited. We're not at the point where these HSMs are ready yet, but they will be coming.

Then all services that configure the node or control the VPC in which is installed are custodial because right now all the signing is done at the node level, but there are people working on abstracting the signing logic so it can be ran separately and store keys on an HSM. Thanks for the explanation

I think you refer to those wallets (which some people refer to as remote controls) which run a lightning node somewhere in the cloud (it could be your own raspiblitz server at home) and provide an app that remotely controls the node. I think it is clear why this would be non custodial (at least if the software is open source and not messing around with your login credentials)
Stepan snigirev with the crypto advance team is currently working on a hardware wallet for lightning. Some code snippets can be found on Stephans gitrepos. The idea is to extract all signing and derivation from the lightning node to a hardware security module. In c Lightning this seems particularly easy as the hsmdaemon already exists as a standalone daemon.
Other than that Mark H is right when stating that private keys are needed almost all the time.

The ones I've seen control the VPC themselves, which means that at least those are custodial. HW for lightning sounds like a great idea!


text:
What can you do with the private key?
I am trying to understand all security regarding blockchain and bitcoins.
Let's say you have a bitcoin wallet which is secured, only you know the private key. This bitcoin address was created on one of the bitcoins wallet provided by bitcoin.org
What if a person has your private key? I know it's difficult but let's say he knows the 54 letters private key from hacking a database. How can that person interact with your wallet?
Does he have to know which wallet you use as well or can he use just the private key to 'log in'?

Anyone who knows the private key will have full access and control of any coins stored at the corresponding address.
When you put a password on a wallet or login account, that password is only for unlocking that instance of the wallet (it is possible to create another instance, that is not locked by your password). Once unlocked, the wallet will use the private key to sign transactions that move the coins, etc. But without the password an attacker can not unlock the wallet if it the wallet alone is found.
However, having the private key itself means you don’t need to unlock the wallet, because you already have the key. You can import the key into just about any other wallet software, and then use that wallet instance to move the coins, etc.
There is BIP38, which allows you to password protect a private key itself, but this is different, and a less common set up.

What if a person has your private key?

Then they have independent control over all the unspent Bitcoins associated with that private key. Once they have the private key there is nothing you can do to rescind their control (other than moving the Bitcoin into a new wallet before the other person does)

How can that person interact with your wallet?

They don't need to.
The only valuable thing in your wallet are the private keys.
Bitcoins are "stored" as unspent transaction outputs (UTXOs) in the blockchain - but the blockchain is completely public. Every full node (wallet, miner etc) has a copy of the blockchain.

Does he have to know which wallet you use as well ...

No, the other person doesn't need to know anything else.

... or can he use just the private key to 'log in'?

They don't use the private key to log in.
They can import the private key into any wallet software and use the private key to prove to all other bitcoin nodes that they have the right to spend any unspent bitcoin associated with that private key.
Knowing the private key allows them to construct a transaction spending your Bitcoins, they then broadcast that transaction to miners who add the transaction to the blockchain thus spending the Bitcoins (i.e. moving Bitcoins into another wallet which has a different private key)

You can secure your private keys using the Hardware Wallet such as Trezor https://cryptototem.com/trezor-wallet/. Such wallets are used for storing your coins and secure them from different interventions. The developers of such wallets ensure us that will not have any troubles with loss of coins and leakage of your personal data.


text:
What is single member blockchain?
I just heard about single member blockchains like quorum and hyperledger-fabric. So what does single member mean? Is this some kind of restriction or what?

The term single member is not correct. Hyperledger blockchains, such as Hyperledger Sawtooth or Hyperledger Fabric, are private blockchains or permissioned blockchains. You need permission to join the blockchain network. They are usually setup by consortiums (an example would be to track fisheries or other marketplace goods as it moves from harvester or producer to wholesaler to market to consumer).
Since the blockchain is permissioned, it does not usually use digital currency to function.


text:
Can't understand specific problem of Bitcoin anonymity
There is an problem shown in bitcoinwiki:

Someone runs both a money
  exchanger and a site meant to trap people. When Mr. Doe buys from the
  exchanger and uses those same coins to buy something from the trap
  site, the attacker can prove that these two transactions were made by
  the same person. The block chain would show:
Import coins from address A. Send 100 to B. Authorized by (signature).
Import coins from address B. Send 100 to C. Authorized by (signature).
Bitcoin transactions do not have a "from" address, but if the attacker
  believes that address B is controlled by Mr. Doe because the attacker
  received $5 from Mr. Doe's PayPal account and then sent 100 BTC to
  that address then they can infer the identity of the party sending to
  C. This assumption is not always correct because address B may have
  been an address held on behalf of Mr. Doe by a third party and the
  transaction to C may have been unrelated.

I can't understand several issues. Is "someone who runs both a money exchanger and a site meant to trap people" attacker? If so, than I (as attacker) already know the owner of address B, don't I? why I need trap site?

Maybe a more specific example would help:
Senator Doe buys 100 BTC at Ed's Exchange, where his ID is required.  He then withdraws those coins to his own address 1qwerty.  Wearing a trench coat and dark glasses, he uses those 100 BTC to make a purchase at Frank's Embarrassing Merchandise Emporium, sending them to Frank's freshly generated address 1abcxyz.
He thinks he's safe:

Ed knows that 1qwerty belongs to Senator Doe, and that Doe transferred them to the address 1abcxyz, but only Doe and Frank know that 1abcxyz belongs to Frank.  It was randomly generated, and just looking at the address doesn't reveal anything about whom it belongs to.
Frank knows that he sold something embarrassing to the owner of the address 1qwerty, but doesn't know the true identity of the disguised person who came into his shop.

So, thinks Doe, nobody knows that in fact it was Doe who made the embarrassing purchase.
But if Ed and Frank are cooperating, or are secretly the same person, then they can share their knowledge and learn that it was Doe that made the embarrassing purchase.  Now they can inform the newspapers and/or blackmail Doe.

I (as attacker) already know the owner of address B, don't I? why I
  need trap site?

You're right, if you sold the bitcoin and sent it to an address, and you know the identity of the person to whom it was sold (from KYC, for example), then you can associate that person that address. Since it is publicly verifiable on the blockchain, you don't need a trap site in order to see when that bitcoin is spent, but if you run a trap site, you can determine what they spent the Bitcoin on.


text:
CLN listnodes command occasionally returns too many features flags
The BOLT #9 specification shows a 52-bit field that represents various feature flags. That should require no more than 7 bytes, or less.
When I run the listnodes command, some of the nodes include features fields that are in the range of expected lengths, such as 808252a1 which is less than 7 bytes, but others are unexpectedly long, always beginning with the byte 80 followed by a long sequence of 00 bytes and then what appear to be the actual feature flags.
One of them looks like this: 800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000802000888252a1
Is this a bug of some sort, or is there some other information to be interpreted from these long sequences of feature flags?

The BOLT#9 specification lists all standardized or soon-to-be-standardized features, but developers are free to pick a higher bit to represent their custom feature. Oftentimes the spec engineers also use a high bit while developing a feature to avoid clashes and later drop it to a lower one for the standardization (this saves bytes as you noticed).
The above feature bitset decodes into:
['option_data_loss_protect',
 'option_upfront_shutdown_script(opt)',
 'gossip_queries(opt)',
 'var_onion_optin(opt)',
 'option_static_remotekey',
 'payment_secret',
 'basic_mpp(opt)',
 'option_anchors_zero_fee_htlc_tx(opt)',
 'option_channel_type',
 'AMP(LND)(opt)',
 'ExplicitChannelType(LND)(opt)',
 'unknown[55]',
 'ScriptEnforcedLease(LND)(opt)']

(maintaining the order the bits are set in the bitset)
The large number of 0 is due to bit 2023 being set: script_enforced_lease, an experimental feature by lnd, which iirc is used by their proprietary Pool implementation.


text:
Can I run LND without ZMQ?
The documentation for LND says:
; ZMQ socket which sends rawblock and rawtx notifications from bitcoind. By
; default, lnd will attempt to automatically obtain this information, so this
; likely won't need to be set (other than for a remote bitcoind instance).
; bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332
; bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333

Is there a way to turn that default off and not use ZMQ?

According to LND install guide, ZMQ is a requirement to run the daemon as long as bitcoind is being used as the backend:

Since lnd uses ZeroMQ to interface with bitcoind, your bitcoind installation must be compiled with ZMQ. Note that if you installed bitcoind from source and ZMQ was not present, then ZMQ support will be disabled, and lnd will quit on a connection refused error. If you installed bitcoind via Homebrew in the past ZMQ may not be included (this has now been fixed in the latest Homebrew recipe for bitcoin)


text:
Potential stale tip detected while shutting down Bitcoin Core
I tried to shut down Bitcoin Core and it took a very long time. So I looked in the log file and found the following messages:
2023-12-18T18:36:58Z Shutdown: In progress...
2023-12-18T18:36:58Z net thread exit
2023-12-18T18:49:47Z [net] Flushed 75923 addresses to peers.dat  1272ms
2023-12-18T19:02:52Z Potential stale tip detected, will try using extra outbound peer (last tip update: 2205 seconds ago)
2023-12-18T19:02:52Z [net] setting try another outbound peer=true
2023-12-18T19:04:48Z [net] Flushed 75923 addresses to peers.dat  1056ms
2023-12-18T19:13:22Z Potential stale tip detected, will try using extra outbound peer (last tip update: 2835 seconds ago)
2023-12-18T19:13:22Z [net] setting try another outbound peer=true
2023-12-18T19:19:51Z [net] Flushed 75923 addresses to peers.dat  3289ms

Before this happened, I was trying to get a lightning node to connect to the bitcoin node and one of the things I tried was to create a symbolic link to the bitcoin data directory because the lightning node could not access the directory directly because the name contains spaces.
Could that have caused this problem? If not, what else might have caused it?
More importantly, how long might this take?  The node has been "shutting down" now for almost an hour.

Is this the only output you're seeing? Is there CPU usage? Which version of Bitcoin Core is this? It seems wrong that it's trying to create extra outbound connections while shutting down...

It is version 25.0.0. If I run top, I don't see bitcoin-qt or bitcoind anywhere in the list, so I don't think it there is much CPU usage.

@PieterWuille And yes, the three messages shown above are the only output I see in debug.log and it repeats over and over.


text:
LND describegraph returns channels with null policies
The describegraph command for lncli returns several channels that have at least one policy set to null. In many cases, they are both set to null, and last_update is set to 0, as shown in the following example.
{
    "channel_id": "754441998110162945",
    "chan_point": "cb9eb6ae3f285da7cd120a83db7ceca4fee2c19eb72513530646e1bd340e1663:1",
    "last_update": 0,
    "node1_pub": "0227e8baab7b4397a88ea2bb3976a7fc8f975aa4fc28ef9272a33b6a1291ffff63",
    "node2_pub": "03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f",
    "capacity": "480000",
    "node1_policy": null,
    "node2_policy": null
}

How is null supposed to be interpreted?
The channel above has a page on 1ML. It shows channel policies for both peers. Why do the results I get show null for both peers?

I cannot know for sure the reason for this behavior but given the inner workings of the Gossip Protocol there is a high likelihood that the following is the reason.
Channels are anounced via the channel_announcement message. These messages contain more or less the information that you saw in your output. The capacity is not part of the message but retrieved by looking at the bitcoin node for the chan_point which is the funding transaction id and the output of the funding tx of the channel.
Nodes then independently send out channel_updates that contain their own routing policies. So what can happen is that your lightning node is new and has already received the channel announcement but no channel_update yet. Another possibility is that 1ML shows some old values of a channel update which your newis node may not see. This could happen if the the peers of the channel have been offline for some time or not sending out channel_updates for some time as nodes on the lightning network will only gossip channel_updates that are younger than two weeks. So in case there was no channel update within the last 14 days you will only get to see the announcement. There could be many other reasons if you want to digg deeper I suggest to read either BOLT 07 of the spec or the gossip chapter of mastering the Lightning Network.

From my experience the lncli describegraph doesn't render reliable data. I find lot's of dead edges and wrong "last_update" timestamps. Maybe cause my node is > 2years old. Fortunately, the lnd still seems to work correct. I.e. the listchannels works correct while the describegraph is full of dead nodes and dead channels with wrong timestamps.
Maybe routing problems are also related to this. Btw. is your output.json also about 73 MB?

Many channels with last_update =0 and node policy missing are closed channels. for most of them, it shows capacity as 0. Here is a breakdown of channels pulled on 04/02/2024.

Group
Group
Count

1
last update > 0, capacity > 0, Both policies are good - non-null
37067

2
last update = 0, capacity = 0, Both are null
13915

3
last update = 0, capacity > 0, Both are null
780

4
last update > 0, capacity > 0, One policy is null
68

5
last update > 0, capacity = 0, Both policies are good - non-null
28

6
last update > 0, capacity = 0, One policy is null
3

To understand how the data is getting captured, it would make sense to look at each group above, and based on channel_id figure out what's up with the channel. I have looked at more than 10 channel_id randomly from group 2 some time back, and mempool.space records those as closed.
The use case you have, non-zero capacity, last update, and node policy missing is a small fraction. 780 out of 50K. I would assume, it has to do more with channel update propagation as pointed out by Rene.
However, I'll update the thread as I learn more about the 'describegraph'.


text:
Unspent transaction I need some help
I had a business send me BTC to my exodus wallet.  The transaction is confirmed but about half of the transactions including mine say unspent.  It's been 4 days now.  Can I do anything to help the process?

If the transaction is confirmed, the process is done.  "Unspent" just means you haven't spent the coins yet.  But you can do so whenever you wish.

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


text:
How long until an Antminer S9 becomes obsolete and should be replaced?
I'm currently considering the purchase of a few Antminer S9 13.5 THs and I'd like to have an idea of how long I could (or should) plan to use one before replacing it with a newer model.
I've seen some forums suggest 8-12 months, while others suggest it might be as long as 2 years.
Clearly, a part of the answer is based how long I can squeeze a profit out of each machine. In terms of major costs, my local electricity cost is $USD 0.08 / kWh and I will purchase the units directly from the manufacturer (so around $USD 2,320 + tx + shipping).
I understand there are many more variables, like how much faster future miners become, how fast the difficulty rate increases, BTC pricing etc, but I'd appreciate any general guidelines or wisdom you can share. Cheers!

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


text:
Bitcoin sent to Bitcoin Cash address, How to Recover?
A friend asked for my Bitcoin Cash address to send some BCH, but after giving her my Bittrex Bitcoin Cash wallet address she instead accidentally sent Bitcoin and not Bitcoin Cash from her Blockchain.com wallet.
Of course the transaction has not shown up and she is now missing her Bitcoin. She and I have both emailed Blockchain.com Support and they have been unresponsive in helping to recover her missing Bitcoin so it can be sent to the proper address. Any help anyone may have is Greatly needed and Appreciated!! These mistakes can be very costly as Im sure, whoever may be reading this, already knows!! Thank you Anyone and Everyone for your time and support with help on this issue!!
Again, The Bitcoin was sent from Blockchain.com's wallet to a Bitcoin Cash wallet on the Bittrex exchange..... I have reached out to Bittrex customer support as well but still awaiting a reply! If recovered before someone has a chance to offer help, I will update this post with how it was done, but any and all help is GREATLY Appreciated!!

BTC and BCH have compatible keys. Bittrex holds the private key to the BCH address, which they can use to retreive your BTC coins. For how you should proceed, see here:
https://www.reddit.com/r/btc/comments/6tgp6j/accidentally_sent_btc_to_bch_address_on_bittrex/?st=jcrdb1oe&sh=b6eb1a3c

Thank you very much! As this is what I kinda thought, so opened a Ticket with Bittrex and waiting for reply now. I will defiantly let you know when and if I retrieve the coins!

@MDResearchInvestmentGroup best of luck!

Unfortunately, once the transaction is confirmed on the blockchain there is no way to retreive the funds and, that I know of, there is no way to zap the pending transaction from the distributed mempool, nor can I imagine a way. The transaction will likely be confirmed in due course.
Even if Blockchain.com zap the tx locally and the Bitcoin show up again in your friends wallet, once the transaction confirms on the blockchain the outputs used to create the transaction will be spent and that Bitcoin will not be spendable. This also protects against double spending.
The one possible solution to this problem is if your friends Blockchain.com wallet allows RBF (replace-by-fee), you could conceivably (and I do not know how granular transaction control is with Blockchain.com) replace the original transaction with a transaction paying instead back to herself and with a higher fee. A few caveats, RBF is opt-in and so would have to be enabled on the original transaction, Blockchain.com needs to have the user functionality necessary to do this and, once the original transaction is confirmed it is game over anyway.

Thank you very much! I am hoping Bittrex can help me using my Private Keys, but I will defiantly let you know either way!


text:
Assistance to receive my money
Pls, someone introduce Bitcoin mining to me, that I will be receiving 50% of money invested after 6hrs. He has me to pay him in order to fund my wallet. I transfer money to him,  he ask for my wallet ID and password. I refuse in the first instance but he said he want to connect my wallet to mining. The password was released. He funded the account. It reaches 7-8 hrs I didn't see any increase in my balance till the following day. I now decided to withdraw my money back. It then I noticed that there is imported Bitcoin address requesting for private key. I later click on menu to click on addresses  ,I saw archived address again...
Pls, what can I do to  receive my money?
I have changed my password. And I have my recovery phrase with me.
How can I remove imported address and private key. And the archive Bitcoin address.

This is a scam, withdraw your coins from that wallet and never use that wallet again!
Changing your password is not sufficient to protect your account at this point. If the scammer can log in to your wallet they can copy down the recovery seed phrase, and then recreate your wallet using other software. The password only protects your login, it would not stop the scammer from accessing your wallet using a different platform.
Mining requires specialized hardware, the scammer lied in saying he would 'set your account up to mine'. That is not how mining works.
Sorry for your losses. In the future do not EVER give your account info, passwords, seed phrases, private keys, etc, to anyone that you do not trust 100%.

Looks like you give someone your bitcoin login which is the worse thing you can do. Unless you know that person and can really be trusted, this could be a type of scam. Try to withdraw all your money and if you can't mean he got all your money.
Never invest with random peoples/website <= A very very high risk

By the way, your question and information that you provided me were unclear so this is what I can do for you.
Please put what type of wallet company are you using so we can provide you more detail

Btw he did lie to you, bitcoin mining is when you solve hashes and earn the profit based on how much your hash is (pool mining)


text:
How can size of a block be significantly small?
As we all know bitcoin block size should be sth about 1MiB. (Some blocks about 2MB). And this is because miners put all transactions to the block every 10 minutes.
So what happens technically that causes some tiny blocks to be relayed to the network occasionally?! For example: Block #593577
Let me add that its mined at same time with a couple of other blocks:

#593576
#593575

So maybe its gonna become an orphaned one.
But my question is about the reason behind mining & relaying such a tiny block with as small number of transactions as 46?! Is it because of sth like low number of connected peers? or weak network connection? Or what?!

Since the time between those blocks is so small (from 593576 to 593577 was only 16 seconds) a miner wouldn't have many transactions to add to the block they are mining (there just haven't been many transactions on the network within that period of time). Also, mining is random, if you happened to mine a block, wouldn't you want to get the block reward even if the block is small? The reward is much higher than the transaction fees. It wouldn't make sense to wait to try to mine a block until there are more transactions. In fact, you can mine a block with only the block reward and no other transactions, if you wanted.
So as more transactions come in, miners would presumably add them to their block in order to maximize the transaction fees they might get if they happen to mine the block.


text:
2 transaction in same address - Please help
Sent my  btc address 3 days ago for a payment to one of my customer  he didnt respond or paid . next day i provided the  same address to my another customer for a payment which he sent. Now today i received an email from my 1st customer that he paid the amount to same address that i provided 3 days ago . Please anyone here who can help me to recover the funds . I will lose my job & anyone here who is kind enough to help to simple tips .
https://www.blockchain.com/btc/address/15iga5K4hLMjDFox24mvjjuak2g3cKVtMK

Sorry, but your question is a bit confusing to understand. Please reword a bit for a better understanding for others.

Still confused. Which wallet are you using? Most wallets would just show that as your balance. I'm wondering if you copied an address that is not yours thinking it is yours and gave it to the customers. Thus getting the payments there would not add to your actual wallet. Please clarify as your question is still confusing. Thanks!

The address you linked has received two payments, if you control the private keys for that address then you have nothing to worry about, those coins are in your control.
Generally, it is not best practices to reuse an address, as it is very bad for your privacy (and, potentially the privacy of your customers). However, in terms of being able to spend the coins later, there is no technical issue with receiving more than one payment to an address.
You should be able to spend the two UTXOs as normal.

Thank you sir but how can i find private keys on blockchain wallet & re - use the coin - Help please please please

As a user, you shouldn't need to worry about private keys in this situation, the software will handle it. If you received the coins to an address generated by your blockchain.info wallet, then you should simply be able to spend the coins using your blockchain.info wallet. No extra steps. BUT, if you received the coins to a 'watch-only' address that was added to the blockchain.info wallet, then that wallet will not have the private keys. In that case, you will need to find the wallet/person that controls the private key to that address. There is no way to 'recover' a private key otherwise.


text:
Do pools distribute "jobs" to miners based on "failed" solutions which have already been submitted?
My question is this: How exactly does the stratum protocol distribute "work" to miners? More specifically, since mining can be compared (in many regards) to "brute forcing" a cryptographic hash (i.e. hashing random inputs until, by luck, a random input matches a desired output), wouldn't it make sense to keep track of potential solutions submitted and confirmed as invalid for a particular block, and to somehow communicate that to miners so the same work is not being done over and over again?
I realize this would require a lot of overhead, but it would seem worthwhile. Is there any mechanism to ensure two independent miners do not waste time working on the same inputs? Could sending a different seed for random number generation to every miner upon the start of a new round of mining have effect? I've read simplistic descriptions of mining as simply incrementing the nonce until a solution is found, but I've also read much more detailed explanations which would imply much more is involved. Even if only the nonce is changed in the input, the pool would still need to assign each miner a unique nonce to try after each submission, no?
As a final, semi-unrelated question regarding the implications of storing solutions: Say a pool stored every solution it had ever received, considering the massive size of the bitcoin network, would this not eventually become a statistically significant (in terms of usability) database of sha256 collisions? And eventually, could enough data be collected to come up with a derivation for SHA256? At minimum, could a pool with malicious intent temporarily divert unknowing miners's computing power to crack SHA256 based TLS signatures or PGP public keys? Especially a pool which also controlled the hardware and software on the majority of its devices (e.g. Antpool).

The same work is never ever given out twice. There is also no need to keep track of it, as there is an infinite space of candidate blocks to choose from.

Possible duplicate of How do mining pools work?

I've read simplistic descriptions of mining as simply incrementing the nonce until a solution is found, but I've also read much more detailed explanations which would imply much more is involved. Even if only the nonce is changed in the input, the pool would still need to assign each miner a unique nonce to try after each submission, no?

Miners do change more than just the nonce, and it is this fact that allows a mining pool to ensure that two miners don't produce the same work twice.
Because mining always involves the transactions used in the block, changing those transactions will effect the merkle root and thus the result. One of those transactions is the coinbase transaction which is something that miners have control over. In particular, the input script for the coinbase transaction's input can contain up to 100 bytes of aribtrary data. So miners will use this space as an extra nonce (known as the extranonce). They will have a nonce there too in order produce new coinbase transactions which lets them produce different merkle roots and thus different block headers. The extranonce allows miners to have more nonces than from just the 32 bit nonce in the block header.
Mining pools make use of this extranonce to ensure unique work. They will give a miner part of an extranonce (e.g the first half). Then the miner can use the rest of the extranonce as an extranonce for themselves. This lets miners still have a large search space so that they are not constantly asking the pool for more work. By giving miners different extranonce halves, the pool can be sure that two miners will not be hashing the same thing multiple times.

Say a pool stored every solution it had ever received, considering the massive size of the bitcoin network, would this not eventually become a statistically significant (in terms of usability) database of sha256 collisions?

Eventually, yes. But it's going to be a very long time before that happens. The entire Bitcoin network has done ~2^90 hashes total. However to even get to a 50% chance of a collision, you need ~2^128 hashes. 2^90 is 1/274877906944 of 2^128. So the amount of time to even get to 2^128 hashes is many times the number of years that the universe has even existed. So in theory, yes, there could be enough hashes computed that a collision is found be sheer brute force. But for all intents and purposes, it isn't going to happen.


text:
Why is -blockmaxweight set to 3996000 by default?
The configuration parameter -blockmaxweight in Bitcoin Core allows miners to set a maximum block weight they want to mine. Oddly, the default value of this parameter is 3996000 as opposed to the SegWit limit of 4000000 WU. Why is that?

It's there so that the miner can replace the coinbase transaction with their own, possibly to add more outputs.

Just to make sure, what exactly do you mean by "replace the coinbase transaction"? If I understand correctly, the block template generated by Bitcoin Core has no coinbase transaction.

The internal code for block template computation (which uses that -blockmaxweight setting) does add a dummy coinbase transaction. The point is just that the block template generation does not yet know what actual coinbase transaction you'll want to plug in before starting mining, so it leaves some slack space for that.


text:
How to run a private bitcoin network with low difficulty?
I want to test and develop an open source mining pool. I don't have access to an ASIC miner or GPU, so I have to use my CPU to simulate mining and see how the pool really works.
The problem is the bitcoin testnet difficulty is so high and the CPU can't mine, produce blocks and get reward. I need a low difficulty private bitcoin in order to test the mining process. How can I achieve that?

Does the “regtest” help you?

Use regtest
Chain selection options:

  -regtest
       Enter regression test mode, which uses a special chain in which blocks
       can be solved instantly. This is intended for regression testing
       tools and app development.

  -testnet
       Use the test chain

Using this mode, you can manually mine blocks by issuing the following command, where nBlocks is the number of blocks to mine. You will need atleast 101 blocks before your first mining reward becomes available.
bitcoin-cli generate nBlock

Thank you. But when I generate new blocks manually, where does the block reward go? Is there any block reward at all? What does the miner do?

This is automatically assigned to your default account configured within bitcoind. Be aware that the regression test move also has a maturity period where the coins generated by a block can only be moved after there are another 100 blocks on top, so you only have access to the mining reward after 100 blocks.
There is also a more recent way in which you can specify this address using the generatetoaddress RPC call which mines to an address of your choice instead of a new internal newly generated address.
gr0kchain@bitcoindev $ bitcoin-cli help generatetoaddress


text:
json-rpc of bitcoin not working for testnet(curl command)
I am trying this command to get transaction from bitcoin testnet:
curl  --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "gettransaction", "params": ["txId"] }' -H 'content-type: text/plain;' http://username:password@IP:PORT/

And i am getting following error
{ "result":null, "error":{"code" :-32601, "message" : "Method not found"}, id:curltext}

Is your core compiled with the wallet? Because gettransaction RPC get wallet transactions, and hence need wallet capabilities. For general transactions, you should use getrawtransaction instead.
I ran it here (with wallet enabled) and works just fine.

You're passing invalid transaction to the gettransaction method.

no that's not the case. I am passing a valid txId.


text:
How many transaction can I broadcast simultaneously?
Let's say I build two transactions, and in the second one I add an input which refers to an output of the first one. Then I broadcast simultaneously the two transactions.
Now, I know that in Bitcoin exists a Transaction Chaining mechanism, still there is a limit on how many transactions I can chain this way (25 as I remember).
When that limit is reached, do I have to wait for the next block to chain more transactions, or just a couple of seconds so that each node can reconstruct the chain ?
Thank you very much.

You need to wait for the transactions to be confirmed in a block. The limit is on the number of unconfirmed transactions that can be chained together and is completely unrelated to how quickly the transactions were received.
The chain can only be extended once the unconfirmed transaction chain shrinks, and that can only happen as transactions are confirmed. It is important to note that the entire chain may not be confirmed in the same block and that the next block may not include any transactions in the chain of unconfirmed transactions.

Can you share where the CPFP tx chain limit is documented? Thank you!


text:
How can I convert iTunes Gifts card to Bitcoin
Hello I really want to know how to convert iTunes gift cards to cans or Bitcoin

Same way you convert them to dollars.

You will need to find someone (or some service) that wants to buy your gift card, and pay you in bitcoin. There is no way to just 'convert it' into bitcoin, per say.

There are services for that. https://paxful.com is one that comes to mind.

Welcome to bitcoin stackexchange - please note that the [help/on-topic] explains why site or service recommendations are off-topic here.


text:
Does xmr-stak use Stratum?
Using Wireshark to analyze packets sent by xmr-stak, I found them to be inconsistent with those of Stratum (https://en.bitcoin.it/wiki/Stratum_mining_protocol).
From Wireshark:
{
  "method": "login",
  "params": {
    "login": "33vberEwdZYECfGsbqNJQC7M1MCHYT9Mjm.alpha0",
    "pass": "x",
    "rigid": "",
    "agent": "xmr-stak/2.4.2/e10e8e6/master/lin/nvidia-cpu/aeon-cryptonight-monero/0"
  },
  "id": 1
}

According to Stratum documentation:
{
  "method": "mining.authorize",
  "params": [
    "33vberEwdZYECfGsbqNJQC7M1MCHYT9Mjm.alpha0",
    "x"
  ]
}

If not, what protocol does xmr-stak use?

Yes Monero mining pools generally use the Stratum protocol for communication between the pool and the miners. However a modified version of the Stratum protocol is used. I've yet find proper documentation like the one you've linked, so your best bet is to look through the source code for the exact definition.
Also there is a separate Stackexchange for the Monero community, so your likely to get even better help there.


text:
What is the right way to restart bitcoind if it crashes?
I am very new to this and apologies if it has been asked before but I can't seem to find a clear answer after looking extensively.
I am trying to run a full node. I started bitcoind -daemon and everything worked fine, the blockchain was syncing. It crashed the next day because I hadn't set my options for swap memory correctly.
After fixing that issue, I did bitcoind -daemon again and it looked like everything was being done from the start. Should I be doing bitcoind -reindex-chainstate from now on if the process stops? Or did I not understand correctly and simply doing bitcoind will resume syncing but requires some verification first?
Also, in any of the above cases, is it the same process once the blockchain has synced?
This is on a Raspberry Pi 3B+ with an external HDD for storage.
Thanks a lot in advance.

If you check in your debug.log you should be able to see if there is any error when you started the node. Probably when the node shutdown uncleanly some of the tables were in an inconsistent state.
Presuming everything is fine and it is not stuck, it is okay to just start with bitcoind -daemon and it will do what it needs to.

Awesome, thought that might be the case. Thanks a lot for your answer, really appreciate it!


text:
Using CoreBitcoin in Swift to create raw transaction
I am new to coding, and only know swift, obj-C is still foreign to me. I have a functioning wallet but for now am relying on BlockCypher API to build a transaction which I do NOT want to do.  Can anyone please help tell me what I am doing wrong in the following code snippet.  I am creating a raw transaction however i get a weird response when decoding it where the address arrays are empty or null. Something is very wrong, if anyone has any experience I would so greatly appreciate it as this is driving me crazy.
import UIKit

class BuildTransactionViewController: UIViewController, BTCTransactionBuilderDataSource {
var addressToSpendFrom = "n1QQYAHbw3q6UjWN6Q4d9oqa6u5iUDnPHT"
var privateKeyToSign = "cNeZkP1QPQ37C4rLvoQ8xZ5eujcjsYHZMj8CLfPPohYPvfKhzHWu"
var receiverAddress = "n1v9HH9Abs36fYf8KbwnFUfzR4prLBXhtW"
var inputData = [NSDictionary]()
var scriptArray = [String]()
var transaction = BTCTransaction()

override func viewDidLoad() {
    super.viewDidLoad()

    getUTXOforAddress(address: addressToSpendFrom)
}

func getUTXOforAddress(address: String) {

    var url:NSURL!
    url = NSURL(string: "https://api.blockcypher.com/v1/btc/test3/addrs/\(address)?unspentOnly=true")

    let task = URLSession.shared.dataTask(with: url! as URL) { (data, response, error) -> Void in

        do {

            if error != nil {

                print(error as Any)
                DispatchQueue.main.async {
                    displayAlert(viewController: self, title: "Error", message: "Please check your interent connection.")
                }

            } else {

                if let urlContent = data {

                    do {

                        let jsonUTXOResult = try JSONSerialization.jsonObject(with: urlContent, options: JSONSerialization.ReadingOptions.mutableLeaves) as! NSDictionary

                        print("json = \(jsonUTXOResult)")

                        if let utxoCheck = jsonUTXOResult["txrefs"] as? NSArray {

                            self.inputData = utxoCheck as! [NSDictionary]
                            print("utxoCheck = \(utxoCheck)")

                            for item in self.inputData {

                               let transactionHash = (item)["tx_hash"] as! String
                                let value = (item)["value"] as! Int

                                var url:NSURL!
                                url = NSURL(string: "https://api.blockcypher.com/v1/btc/test3/txs/\(transactionHash)")

                                let task = URLSession.shared.dataTask(with: url! as URL) { (data, response, error) -> Void in

                                    do {

                                        if error != nil {

                                            print(error as Any)
                                            DispatchQueue.main.async {
                                                displayAlert(viewController: self, title: "Error", message: "Please check your interent connection.")
                                            }

                                        } else {

                                            if let urlContent = data {

                                                do {

                                                    let txHashResult = try JSONSerialization.jsonObject(with: urlContent, options: JSONSerialization.ReadingOptions.mutableLeaves) as! NSDictionary

                                                    print("txHashResult = \(txHashResult)")

                                                    if let outputsCheck = txHashResult["outputs"] as? NSArray {

                                                        print("outputs = \(outputsCheck)")

                                                        for output in outputsCheck {

                                                            if let valueCheck = (output as! NSDictionary)["value"] as? Int {

                                                                if valueCheck == value {

                                                                    let script = (output as! NSDictionary)["script"] as! String
                                                                    self.scriptArray.append(script)
                                                                    print("script = \(script)")
                                                                }

                                                            }

                                                        }

                                                        print("inputData = \(self.inputData)")
                                                        print("scriptArray = \(self.scriptArray)")
                                                        self.callBTCTransaction()

                                                    }

                                                } catch {

                                                    print("JSon processing failed")
                                                    DispatchQueue.main.async {
                                                        displayAlert(viewController: self, title: "Error", message: "Please try again.")
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                task.resume()
                            }
                       }

                    } catch {

                        print("JSon processing failed")
                        DispatchQueue.main.async {
                            displayAlert(viewController: self, title: "Error", message: "Please try again.")
                        }
                    }
                }
            }
        }
    }

    task.resume()

}

func callBTCTransaction() {

    let address = BTCAddress(string: self.receiverAddress)
    let newTransaction = BTCTransactionBuilder()
    newTransaction.dataSource = self
    newTransaction.shouldSign = true
    newTransaction.changeAddress = BTCAddress(string: self.addressToSpendFrom)
    newTransaction.outputs = [BTCTransactionOutput(value: BTCAmount(1000), address: address)]
    newTransaction.feeRate = BTCAmount(2000)
    var result:BTCTransactionBuilderResult? = nil
    do {
        result = try newTransaction.buildTransaction()
        print("transactionRaw = \(String(describing: result?.transaction.hex))")
    } catch {
        print("error = \(error as Any)")
    }
}

func transactionBuilder(_ txbuilder: BTCTransactionBuilder!, keyForUnspentOutput txout: BTCTransactionOutput!) -> BTCKey! {
    print("transactionBuilder")

    let key = BTCKey.init(wif: self.privateKeyToSign)
    key?.isPublicKeyCompressed = true

    return key
}

func unspentOutputs(for txbuilder: BTCTransactionBuilder!) -> NSEnumerator! {

    let outputs = NSMutableArray()

    for (index, item) in inputData.enumerated() {

        let txout = BTCTransactionOutput()
        txout.value = BTCAmount((item).value(forKey: "value") as! Int64)
        txout.script = BTCScript.init(hex: self.scriptArray[index])
        txout.index = UInt32((item).value(forKey: "tx_output_n") as! Int)
        txout.confirmations = UInt((item).value(forKey: "confirmations") as! Int)
        let transactionHash = (item)["tx_hash"] as! String
        txout.transactionHash = transactionHash.data(using: .utf8)
        outputs.add(txout)

    }

    print("outputs = \(outputs)")

    return outputs.objectEnumerator()
}

}

I will offer a bounty of $50 in Bitcoin to anyone who helps me to resolve this so that it returns a proper hex transaction.

I can't comment due to low reputation. Take a look at this link: https://github.com/oleganza/CoreBitcoin/blob/master/CoreBitcoinTestsOSX/BTCTransactionTests.swift
Basically, they create a tx like that:
    let tx = BTCTransaction()

    var spentCoins = BTCAmount(0)

    // Add all outputs as inputs
    for txout in txouts {
        let txin = BTCTransactionInput()
        txin.previousHash = txout.transactionHash
        txin.previousIndex = txout.index
        tx.addInput(txin)

        print("txhash: http://blockchain.info/rawtx/\(BTCHexFromData(txout.transactionHash))")
        print("txhash: http://blockchain.info/rawtx/\(BTCHexFromData(BTCReversedData(txout.transactionHash))) (reversed)")

        spentCoins += txout.value
    }

    print(String(format: "Total satoshis to spend:       %lld", spentCoins))
    print(String(format: "Total satoshis to destination: %lld", amount))
    print(String(format: "Total satoshis to fee:         %lld", fee))
    print(String(format: "Total satoshis to change:      %lld", spentCoins - (amount + fee)))

    // Add required outputs - payment and change
    let paymentOutput = BTCTransactionOutput(value: amount, address: destinationAddress)
    let changeOutput = BTCTransactionOutput(value: (spentCoins - (amount + fee)), address: changeAddress)

    // Idea: deterministically-randomly choose which output goes first to improve privacy.
    tx.addOutput(paymentOutput)
    tx.addOutput(changeOutput)

    for i in 0 ..< txouts.count {
        // Normally, we have to find proper keys to sign this txin, but in this
        // example we already know that we use a single private key.

        let txout = txouts[i] // output from a previous tx which is referenced by this txin.
        let txin = tx.inputs[i] as! BTCTransactionInput

        let sigScript = BTCScript()

        let d1 = tx.data

        let hashType = BTCSignatureHashType.SIGHASH_ALL

        let getHash: NSData?
        do {
            getHash = try tx.signatureHashForScript(txout.script, inputIndex: UInt32(i), hashType: hashType)
        } catch {
            errorOut = error
            getHash = nil
        }

        let d2 = tx.data

        XCTAssertEqual(d1, d2, "Transaction must not change within signatureHashForScript!")

        // 134675e153a5df1b8e0e0f0c45db0822f8f681a2eb83a0f3492ea8f220d4d3e4
        guard let hash = getHash else { return (nil, errorOut) }
        print(String(format: "Hash for input %d: \(BTCHexFromData(hash))", i))
        let signatureForScript = key.signatureForHash(hash, hashType: hashType)
        sigScript.appendData(signatureForScript)
        sigScript.appendData(key.publicKey)

        let sig = signatureForScript.subdataWithRange(NSRange(location: 0, length: signatureForScript.length - 1))  // trim hashtype byte to check the signature.
        XCTAssertTrue(key.isValidSignature(sig, hash: hash), "Signature must be valid")

        txin.signatureScript = sigScript
    }

    // Validate the signatures before returning for extra measure.

    do {
        let sm = BTCScriptMachine(transaction: tx, inputIndex: 0)

        do {
            try sm.verifyWithOutputScript((txouts.first as BTCTransactionOutput!).script.copy() as! BTCScript)
        } catch {
            print("Error: \(error)")
            XCTFail("should verify first output")
        }

    }

In my case, I recover tx that was built on the JS backend, and I am only signing it. I'll post my code example later.


text:
Why am I getting error: "Signature must be zero for failed CHECK(MULTI)SIG operation" when using signrawtransactionwithkey
I am using descriptor based importmulti like so to import a 2 of 3 HD multisig cold storage wallet into my node:
curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "importmulti", "params":[[{ "desc": "wsh(multi(2,tpubDEqRrG87fge2UkHV8PqHBtdPqtP7f5uvwj9wXf5cLkHTF17YwSS8aq4w4fjg5qFZiCvWuyJN45AZQtt9RmuQ4FUN7wN1GWKx215x1xa7Cz9/*,tpubDEv2nBbgaQ2upnS9QhBkqPvjKtLR2qyunQRNcLM3oBRLWLBqvrueByzBMR1J9mAL1z52wwQcVC5JziSskRDT8mhZWHwgRFzNoSVKgPhxTQB/*,tpubDENB49beL6joYGvVuXVqDx45f6Ev2C5xAYP7EZ2znfaJC9ZRrAWSDShy5z5KVtpZTqbrZBkwWtZ5iCzRe17EKu1W4Hq4Undk15hEXBYsgQv/*))#m6ttjdpt", "timestamp": 1567526400, "range": [0, 199], "watchonly": true, "label": "2of3" }], ''{"rescan": true}''] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:18332/wallet/2_of_3

I then fund the first address and build unsigned transaction with the new watch-only utxo:
curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "createrawtransaction", "params":[''[{"txid":"0a172b70ce09ad04b646a37381326e7b0730791237312776d3d760baf9abbdd4","vout": 1,"sequence": 1}]'', ''{"tb1qmmjj0qqglwp23rd776plxt00ej5qjd3svs33sjp5xsj2r4d7kuaq6wgkeg":0.001, "tb1q833pzpnl3qs5ksrleu697qvyy4h8vdyat8zfsufq75fkc5dlzvnq2uagu7":0.00799748}'', 0, true] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:18332/

I then sign the transaction with the 1st private key:
curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "signrawtransactionwithkey", "params":["0200000001d4bdabf9ba60d7d376273137127930077b6e328173a346b604ad09ce702b170a01000000000100000002a086010000000000220020dee5278008fb82a88dbef683f32defcca809363064231848343424a1d5beb73acc700b00000000002200203c6211067f88214b407fcf345f0184256e76349d59c4987120f5136c51bf132600000000", ''["cRcXi9tzP7BREA1Hnnpc27DJ5BUnpJqoLWPeHyGQqLvdhFyabu3L"]'', ''[{ "txid": "0a172b70ce09ad04b646a37381326e7b0730791237312776d3d760baf9abbdd4", "vout": 1, "scriptPubKey": "0020ad06a391657e433d8a6c06f1c663c49660275f5b1c9f3f62e36eb88e36289504", "witnessScript": "522102a3122d181aa6ea499feea9474a8da11a2e93e26138268069159fa75f90bd8e592102defeb6336a5e0c517027071fe0baee3f5fed4a3860a0000ca8b792735e1aa4172103d4d296ed881bb4c21f8ed5da6654e6109f853d21d18044e6be07d26f541a0ef153ae", "amount": 0.00899772 }]''] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:18332/

Which returns:
complete = 0;
    errors =     (
                {
            error = "Unable to sign input, invalid stack size (possibly missing key)";
            scriptSig = "";
            sequence = 1;
            txid = 0a172b70ce09ad04b646a37381326e7b0730791237312776d3d760baf9abbdd4;
            vout = 1;
            witness =             (
                "",
                "",
                522102a3122d181aa6ea499feea9474a8da11a2e93e26138268069159fa75f90bd8e592102defeb6336a5e0c517027071fe0baee3f5fed4a3860a0000ca8b792735e1aa4172103d4d296ed881bb4c21f8ed5da6654e6109f853d21d18044e6be07d26f541a0ef153ae
            );
        }
    );
    hex = 02000000000101d4bdabf9ba60d7d376273137127930077b6e328173a346b604ad09ce702b170a01000000000100000002a086010000000000220020dee5278008fb82a88dbef683f32defcca809363064231848343424a1d5beb73acc700b00000000002200203c6211067f88214b407fcf345f0184256e76349d59c4987120f5136c51bf132603000069522102a3122d181aa6ea499feea9474a8da11a2e93e26138268069159fa75f90bd8e592102defeb6336a5e0c517027071fe0baee3f5fed4a3860a0000ca8b792735e1aa4172103d4d296ed881bb4c21f8ed5da6654e6109f853d21d18044e6be07d26f541a0ef153ae00000000;

I then sign with the second key which is where I am getting my error:
curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "signrawtransactionwithkey", "params":["02000000000101d4bdabf9ba60d7d376273137127930077b6e328173a346b604ad09ce702b170a01000000000100000001b0ba0d0000000000220020dee5278008fb82a88dbef683f32defcca809363064231848343424a1d5beb73a03000069522102a3122d181aa6ea499feea9474a8da11a2e93e26138268069159fa75f90bd8e592102defeb6336a5e0c517027071fe0baee3f5fed4a3860a0000ca8b792735e1aa4172103d4d296ed881bb4c21f8ed5da6654e6109f853d21d18044e6be07d26f541a0ef153ae00000000", ''["cV6sxQh4jtkPqrGAGvAW6iZvV86zVc6QnYvFvcc72AcjQMKrF4MK"]'', ''[{ "txid": "0a172b70ce09ad04b646a37381326e7b0730791237312776d3d760baf9abbdd4", "vout": 1, "scriptPubKey": "0020ad06a391657e433d8a6c06f1c663c49660275f5b1c9f3f62e36eb88e36289504", "witnessScript": "522102a3122d181aa6ea499feea9474a8da11a2e93e26138268069159fa75f90bd8e592102defeb6336a5e0c517027071fe0baee3f5fed4a3860a0000ca8b792735e1aa4172103d4d296ed881bb4c21f8ed5da6654e6109f853d21d18044e6be07d26f541a0ef153ae", "amount": 0.00899772 }]''] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:18332/

Which returns the error:
complete = 0;
    errors =     (
                {
            error = "Signature must be zero for failed CHECK(MULTI)SIG operation";
            scriptSig = "";
            sequence = 1;
            txid = 0a172b70ce09ad04b646a37381326e7b0730791237312776d3d760baf9abbdd4;
            vout = 1;
            witness =             (
                "",
                304402205d7605839e0c2f50fce5a6eda9d614d464651d8f0c2f56659c3d897991661665022013c4c99324ee35bd72cb322cc7e165408932600a13579f8175125ec96bdb1ef701,
                "",
                522102a3122d181aa6ea499feea9474a8da11a2e93e26138268069159fa75f90bd8e592102defeb6336a5e0c517027071fe0baee3f5fed4a3860a0000ca8b792735e1aa4172103d4d296ed881bb4c21f8ed5da6654e6109f853d21d18044e6be07d26f541a0ef153ae
            );
        }
    );
    hex = 02000000000101d4bdabf9ba60d7d376273137127930077b6e328173a346b604ad09ce702b170a01000000000100000001b0ba0d0000000000220020dee5278008fb82a88dbef683f32defcca809363064231848343424a1d5beb73a040047304402205d7605839e0c2f50fce5a6eda9d614d464651d8f0c2f56659c3d897991661665022013c4c99324ee35bd72cb322cc7e165408932600a13579f8175125ec96bdb1ef7010069522102a3122d181aa6ea499feea9474a8da11a2e93e26138268069159fa75f90bd8e592102defeb6336a5e0c517027071fe0baee3f5fed4a3860a0000ca8b792735e1aa4172103d4d296ed881bb4c21f8ed5da6654e6109f853d21d18044e6be07d26f541a0ef153ae00000000;

What is strange is it works when I sign a third time every time, even when signing with the same private key:
curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "signrawtransactionwithkey", "params":["02000000000101df620faaa3b1a253492fb77c6c503b9be64e5c74eba4946b99e0fa6835c83ca200000000000100000002a0860100000000001976a914344a0f48ca150ec2b903817660b9b68b13a6702688acbcba0d0000000000220020ad06a391657e433d8a6c06f1c663c49660275f5b1c9f3f62e36eb88e362895040400473044022056fd48b2c3d56044275baab3876377eb549281ddebf0ab54976f34f6eb6ae1c102204f2c0fb4a9e6cfaac95ec443d808b3d42ea4277fd20d54f23890a47618aacaf7014730440220665129661b75ddfa4375791cc47942313dc16e1f515524318f6786aa5f824e9602205af5fdef5608be722e824dec93447cd976733114a1134d1b96a5578863e3b8b70169522102a3122d181aa6ea499feea9474a8da11a2e93e26138268069159fa75f90bd8e592102defeb6336a5e0c517027071fe0baee3f5fed4a3860a0000ca8b792735e1aa4172103d4d296ed881bb4c21f8ed5da6654e6109f853d21d18044e6be07d26f541a0ef153ae00000000", ''["cV6sxQh4jtkPqrGAGvAW6iZvV86zVc6QnYvFvcc72AcjQMKrF4MK"]'', ''[{ "txid": "a23cc83568fae0996b94a4eb745c4ee69b3b506c7cb72f4953a2b1a3aa0f62df", "vout": 0, "scriptPubKey": "0020ad06a391657e433d8a6c06f1c663c49660275f5b1c9f3f62e36eb88e36289504", "witnessScript": "522102a3122d181aa6ea499feea9474a8da11a2e93e26138268069159fa75f90bd8e592102defeb6336a5e0c517027071fe0baee3f5fed4a3860a0000ca8b792735e1aa4172103d4d296ed881bb4c21f8ed5da6654e6109f853d21d18044e6be07d26f541a0ef153ae", "amount": 0.01 }]''] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:18332/

Returns:
complete = 1;
    hex = 02000000000101df620faaa3b1a253492fb77c6c503b9be64e5c74eba4946b99e0fa6835c83ca200000000000100000002a0860100000000001976a914344a0f48ca150ec2b903817660b9b68b13a6702688acbcba0d0000000000220020ad06a391657e433d8a6c06f1c663c49660275f5b1c9f3f62e36eb88e362895040400473044022056fd48b2c3d56044275baab3876377eb549281ddebf0ab54976f34f6eb6ae1c102204f2c0fb4a9e6cfaac95ec443d808b3d42ea4277fd20d54f23890a47618aacaf7014730440220665129661b75ddfa4375791cc47942313dc16e1f515524318f6786aa5f824e9602205af5fdef5608be722e824dec93447cd976733114a1134d1b96a5578863e3b8b70169522102a3122d181aa6ea499feea9474a8da11a2e93e26138268069159fa75f90bd8e592102defeb6336a5e0c517027071fe0baee3f5fed4a3860a0000ca8b792735e1aa4172103d4d296ed881bb4c21f8ed5da6654e6109f853d21d18044e6be07d26f541a0ef153ae00000000;

Any idea what could be causing this error?


text:
How to use deriveaddresses via a curl command
I am trying to use curl via SSH to utilize the deriveaddresses bitcoin-cli rpc command.
let descriptor = "wpkh(xpub6Dy2ikUu5mXbDdhw2vAP1C4eiQM8rTz1NiWQt2BzGi83iHC2gEgTSD54JveyuHF9VLAqNkCGnee1jdBL7nA3JNorbqjSSS8DEV6Hn3PuNBt/*)#mn5jvyc3"
    let command = "curl --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"deriveaddresses\", \"params\": [\"\(descriptor)\" 99] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:8332/"

    var error: NSError?

    let queue = DispatchQueue(label: "com.app.getInitialNodeConnection")
    queue.async {

        if let responseString = self.ssh.session?.channel.execute(command, error: &error) {

            guard let responseData = responseString.data(using: .utf8) else { return }

            do {

                let json = try JSONSerialization.jsonObject(with: responseData, options: [.allowFragments]) as Any

                print("json = \(json)")

            } catch {

            }

        }

    }`

I get the following error:
json = {
    error =     {
        code = "-32700";
        message = "Parse error";
    };
    id = "<null>";
    result = "<null>";
}
Is it not working because I need to escape special characters in the descriptor?

I figured it out, just need a comma after the descriptor param.
let descriptor = "\"wpkh(xpub6Dy2ikUu5mXbDdhw2vAP1C4eiQM8rTz1NiWQt2BzGi83iHC2gEgTSD54JveyuHF9VLAqNkCGnee1jdBL7nA3JNorbqjSSS8DEV6Hn3PuNBt/*)#mn5jvyc3\""
    let command = "curl --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"deriveaddresses\", \"params\":[\(descriptor), 99] }' -H 'content-type: text/plain;' http://user:password@127.0.0.1:8332/"

    var error: NSError?

    let queue = DispatchQueue(label: "com.FullyNoded.getInitialNodeConnection")
    queue.async {

        if let responseString = self.ssh.session?.channel.execute(command, error: &error) {

            guard let responseData = responseString.data(using: .utf8) else { return }

            do {

                let json = try JSONSerialization.jsonObject(with: responseData, options: [.allowFragments]) as Any

                print("json = \(json)")

            } catch {

            }

        }

    }`