<p>For each of your non-coinbase transactions, you have posted the byte order expected for the merkle computation. However you have the reverse byte order for your coinbase transaction. I believe you are incorrectly reversing that.</p>
<p>Additionally, the merkle root you have posted is also the reverse byte order of the actual merkle root. This should not be reversed.</p>

CC BY-SA 4.0
2023-10-10T00:41:24.003Z
2023-10-10T00:41:24.003Z
Ava Chow
<p>I wanted to test the <code>submitblock</code> rpc call in <strong>regtest</strong> but I seem to have some issues with the <code>transactions</code> I try to submit.</p>
<p>I have the following <strong>raw</strong> transactions:</p>
<p><code>02000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03016900ffffffff0158660c2a010000001976a914a08da9e35ab58e957204703da9d48967ddd1703b88ac00000000</code> <strong>(coinbase tx)</strong></p>
<p><code>02000000000101bd04d336a75e3f4cbf2bf249f529afd9d7740e0836be8384d2a392ddca161ecc0100000000fdffffff0240420f0000000000160014bf67ccfbc8e589a2192a74d2e16bc074889b425bf00ed305000000001600149f5283153368455efcd8a24faa97acb1a2c7f616024730440220249d8bcb08b183c15db2a03bcf2abde3d3e09e0d08a6f029fde2725a800de2a202201902749176353383ea8a78afa1080a84dd311453c3ebd95601c09db721cc9c250121024b162d93981a3e60448bbe4efcf57721f1e443ef280933ae7d20e90e612f5d4468000000</code> (tx1)</p>
<p><code>020000000001010453faefcc8f26e4734e965e3619deab009f6e4faa2971c34be334e28c67f2650000000000fdffffff0240420f00000000001600141b08d84ee1d89a0b682020d619653613737cb64cf01fe32901000000160014fe841631fe5df0584d22bdc6580c6127d25d25b302473044022073a8008fdef43bc637675114f760689439c4b94a9e59a73fe53919a6f3d4c4a302201f787059a139a6b80eceb02c49ee70ac552d3ca5713ea2c33dcfdceb38cc2850012103c7df223ee6eb22b9f183e807fc0fa3b672f62e9fc2a6316b0ca8fca24d907c7f68000000</code> (tx2)</p>
<p><code>02000000000101d43c09b3878100668c3c0f9bac461b092378b47deb989c819dc3f1c0cca4095f0100000000fdffffff022818eb230100000016001420184bf7efc25f9a1ecf99a9c532f5e2c93cdd1340420f000000000016001454e45729918ad5a7fa1130b0be47e6b5cfab16e20247304402200d06ed77a7b20419988d62760ee1aa2bccda92a22ddfbdd16f96319cc7862695022022730ff785e033ecfc5ffb57b6258368aba7896d9414e66c6932e4841033de40012103656e09a3a63bf08aa0ab9177edff3f87d0dbc95dd2f76fbc9ebb5f2323e8036f11000000</code> (tx3)</p>
<p>I calculated the txids for all of these tx <strong>(byte order already reversed)</strong>:
<code>6c13bf0a4bf648312d82fa454b2f4ad9a4ead32a805009d5949f981c4cf3bd3b</code> <strong>(coinbase txid)</strong>
<code>0773014af32002fcf11a603aa2c19503e36cb9ca87c6a8c7a8b7c7a1b7a38b11</code> (txid 1)
<code>143b545dd5809658cf082cd03cb1e9e7645d95afd54d79b71c93e3d4431c46e6</code> (txid 2)
<code>85e8dfe954afa4139c893dfda796d57700b059595a7986bc906637167de49060</code> (txid 3)</p>
<p>when put in order, I get the following merkle root:
<code>5e76726c3a221c7ef39bbbc6d0ca57dd85d320ac13dda01994c517b7c2fc1385</code></p>
<p>I submit the block via submitblock. from the merkle root on it looks like this:
<code>5e76726c3a221c7ef39bbbc6d0ca57dd85d320ac13dda01994c517b7c2fc1385c03d2465ffff7f20020000000402000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03016900ffffffff0158660c2a010000001976a914a08da9e35ab58e957204703da9d48967ddd1703b88ac0000000002000000000101bd04d336a75e3f4cbf2bf249f529afd9d7740e0836be8384d2a392ddca161ecc0100000000fdffffff0240420f0000000000160014bf67ccfbc8e589a2192a74d2e16bc074889b425bf00ed305000000001600149f5283153368455efcd8a24faa97acb1a2c7f616024730440220249d8bcb08b183c15db2a03bcf2abde3d3e09e0d08a6f029fde2725a800de2a202201902749176353383ea8a78afa1080a84dd311453c3ebd95601c09db721cc9c250121024b162d93981a3e60448bbe4efcf57721f1e443ef280933ae7d20e90e612f5d4468000000020000000001010453faefcc8f26e4734e965e3619deab009f6e4faa2971c34be334e28c67f2650000000000fdffffff0240420f00000000001600141b08d84ee1d89a0b682020d619653613737cb64cf01fe32901000000160014fe841631fe5df0584d22bdc6580c6127d25d25b302473044022073a8008fdef43bc637675114f760689439c4b94a9e59a73fe53919a6f3d4c4a302201f787059a139a6b80eceb02c49ee70ac552d3ca5713ea2c33dcfdceb38cc2850012103c7df223ee6eb22b9f183e807fc0fa3b672f62e9fc2a6316b0ca8fca24d907c7f6800000002000000000101d43c09b3878100668c3c0f9bac461b092378b47deb989c819dc3f1c0cca4095f0100000000fdffffff022818eb230100000016001420184bf7efc25f9a1ecf99a9c532f5e2c93cdd1340420f000000000016001454e45729918ad5a7fa1130b0be47e6b5cfab16e20247304402200d06ed77a7b20419988d62760ee1aa2bccda92a22ddfbdd16f96319cc7862695022022730ff785e033ecfc5ffb57b6258368aba7896d9414e66c6932e4841033de40012103656e09a3a63bf08aa0ab9177edff3f87d0dbc95dd2f76fbc9ebb5f2323e8036f11000000</code></p>
<p>still, I get the following error: bad-txnmrklroot</p>
<p>do I miss something obvious here or is it a little more complicated?</p>
<p>thanks in advance</p>

CC BY-SA 4.0
2023-10-09T22:48:33.997Z
I have not verified your calculations, but you should know that you shouldn't do any byte-swapping at all, anywhere, except for display (human) purposes. At the protocol level, you take the 32 bytes that come out of (double) SHA256, concatenate those 32 bytes literally with another hash to provide the input for a Merkle hashing step, and the 32-byte result of those hashes is placed literally, without any swapping, into the 80-byte block header.
Pieter Wuille
<transactions><json-rpc><development><bitcoin-cli><rpc-error-25>
bitcoin rpc submitblock merkle root + raw tx (bad-txnmrklroot)
FearXenon
# bitcoin rpc submitblock merkle root + raw tx (bad-txnmrklroot)

(Asked by: username_0 on 2023-10-09)

I wanted to test the `submitblock` rpc call in **regtest** but I seem to have some issues with the `transactions` I try to submit.

I have the following **raw** transactions:

`02000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03016900ffffffff0158660c2a010000001976a914a08da9e35ab58e957204703da9d48967ddd1703b88ac00000000` **(coinbase tx)**

`02000000000101bd04d336a75e3f4cbf2bf249f529afd9d7740e0836be8384d2a392ddca161ecc0100000000fdffffff0240420f0000000000160014bf67ccfbc8e589a2192a74d2e16bc074889b425bf00ed305000000001600149f5283153368455efcd8a24faa97acb1a2c7f616024730440220249d8bcb08b183c15db2a03bcf2abde3d3e09e0d08a6f029fde2725a800de2a202201902749176353383ea8a78afa1080a84dd311453c3ebd95601c09db721cc9c250121024b162d93981a3e60448bbe4efcf57721f1e443ef280933ae7d20e90e612f5d4468000000` (tx1)

`020000000001010453faefcc8f26e4734e965e3619deab009f6e4faa2971c34be334e28c67f2650000000000fdffffff0240420f00000000001600141b08d84ee1d89a0b682020d619653613737cb64cf01fe32901000000160014fe841631fe5df0584d22bdc6580c6127d25d25b302473044022073a8008fdef43bc637675114f760689439c4b94a9e59a73fe53919a6f3d4c4a302201f787059a139a6b80eceb02c49ee70ac552d3ca5713ea2c33dcfdceb38cc2850012103c7df223ee6eb22b9f183e807fc0fa3b672f62e9fc2a6316b0ca8fca24d907c7f68000000` (tx2)

`02000000000101d43c09b3878100668c3c0f9bac461b092378b47deb989c819dc3f1c0cca4095f0100000000fdffffff022818eb230100000016001420184bf7efc25f9a1ecf99a9c532f5e2c93cdd1340420f000000000016001454e45729918ad5a7fa1130b0be47e6b5cfab16e20247304402200d06ed77a7b20419988d62760ee1aa2bccda92a22ddfbdd16f96319cc7862695022022730ff785e033ecfc5ffb57b6258368aba7896d9414e66c6932e4841033de40012103656e09a3a63bf08aa0ab9177edff3f87d0dbc95dd2f76fbc9ebb5f2323e8036f11000000` (tx3)

I calculated the txids for all of these tx **(byte order already reversed)**:
`6c13bf0a4bf648312d82fa454b2f4ad9a4ead32a805009d5949f981c4cf3bd3b` **(coinbase txid)**
`0773014af32002fcf11a603aa2c19503e36cb9ca87c6a8c7a8b7c7a1b7a38b11` (txid 1)
`143b545dd5809658cf082cd03cb1e9e7645d95afd54d79b71c93e3d4431c46e6` (txid 2)
`85e8dfe954afa4139c893dfda796d57700b059595a7986bc906637167de49060` (txid 3)

when put in order, I get the following merkle root:
`5e76726c3a221c7ef39bbbc6d0ca57dd85d320ac13dda01994c517b7c2fc1385`

I submit the block via submitblock. from the merkle root on it looks like this:
`5e76726c3a221c7ef39bbbc6d0ca57dd85d320ac13dda01994c517b7c2fc1385c03d2465ffff7f20020000000402000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03016900ffffffff0158660c2a010000001976a914a08da9e35ab58e957204703da9d48967ddd1703b88ac0000000002000000000101bd04d336a75e3f4cbf2bf249f529afd9d7740e0836be8384d2a392ddca161ecc0100000000fdffffff0240420f0000000000160014bf67ccfbc8e589a2192a74d2e16bc074889b425bf00ed305000000001600149f5283153368455efcd8a24faa97acb1a2c7f616024730440220249d8bcb08b183c15db2a03bcf2abde3d3e09e0d08a6f029fde2725a800de2a202201902749176353383ea8a78afa1080a84dd311453c3ebd95601c09db721cc9c250121024b162d93981a3e60448bbe4efcf57721f1e443ef280933ae7d20e90e612f5d4468000000020000000001010453faefcc8f26e4734e965e3619deab009f6e4faa2971c34be334e28c67f2650000000000fdffffff0240420f00000000001600141b08d84ee1d89a0b682020d619653613737cb64cf01fe32901000000160014fe841631fe5df0584d22bdc6580c6127d25d25b302473044022073a8008fdef43bc637675114f760689439c4b94a9e59a73fe53919a6f3d4c4a302201f787059a139a6b80eceb02c49ee70ac552d3ca5713ea2c33dcfdceb38cc2850012103c7df223ee6eb22b9f183e807fc0fa3b672f62e9fc2a6316b0ca8fca24d907c7f6800000002000000000101d43c09b3878100668c3c0f9bac461b092378b47deb989c819dc3f1c0cca4095f0100000000fdffffff022818eb230100000016001420184bf7efc25f9a1ecf99a9c532f5e2c93cdd1340420f000000000016001454e45729918ad5a7fa1130b0be47e6b5cfab16e20247304402200d06ed77a7b20419988d62760ee1aa2bccda92a22ddfbdd16f96319cc7862695022022730ff785e033ecfc5ffb57b6258368aba7896d9414e66c6932e4841033de40012103656e09a3a63bf08aa0ab9177edff3f87d0dbc95dd2f76fbc9ebb5f2323e8036f11000000`

still, I get the following error: bad-txnmrklroot

do I miss something obvious here or is it a little more complicated?

thanks in advance

**Tags:** transactions, json-rpc, development, bitcoin-cli, rpc-error-25

> **Comments:**
> **username_1**: I have not verified your calculations, but you should know that you shouldn't do any byte-swapping at all, anywhere, except for display (human) purposes. At the protocol level, you take the 32 bytes that come out of (double) SHA256, concatenate those 32 bytes literally with another hash to provide the input for a Merkle hashing step, and the 32-byte result of those hashes is placed literally, without any swapping, into the 80-byte block header.  

---

## 1 answers

### Answer by username_2 on 2023-10-10. Score: 2 | Accepted answer

For each of your non-coinbase transactions, you have posted the byte order expected for the merkle computation. However you have the reverse byte order for your coinbase transaction. I believe you are incorrectly reversing that.

Additionally, the merkle root you have posted is also the reverse byte order of the actual merkle root. This should not be reversed.


---

