"Encountered invalid prev_hash" error during transaction signing
Closed this issue · 16 comments
I'm trying to sign a Komodo compatible coin (runtime fork that shares almost the same properties as KMD) but so far unsuccessfully. I keep getting "Encountered invalid prev_hash" error.
Below are transaction params that I feed into signTransaction method.
{
"versionGroupId":2301567109,
"branchId":1991772603,
"overwintered":true,
"version":4,
"push":false,
"coin":"kmd",
"outputs":[
{
"address":"R9HgJZo6JBKmPvhm7whLSR8wiHyZrEDVRi",
"amount":"100000000",
"script_type":"PAYTOADDRESS"
},
{
"address_n":[
2147483692,
2147483789,
2147483648,
"1",
"0"
],
"amount":"3056840732",
"script_type":"PAYTOADDRESS"
}
],
"inputs":[
{
"address_n":[
2147483692,
2147483789,
2147483648,
"0",
"8"
],
"prev_index":3,
"prev_hash":"3f530ae01546fe36c9314b247c3a1d24664e0f81332cfaa7324a545a6a144230",
"amount":"3156850732"
}
],
"refTxs":[
{
"hash":"3f530ae01546fe36c9314b247c3a1d24664e0f81332cfaa7324a545a6a144230",
"inputs":[
{
"prev_hash":"179f1d0cc062f9b5a72e72b22882b0447266ddb9b49a5327169403470884a247",
"prev_index":0,
"script_sig":"4730440220185248d2e16bed9f77227ff94651ace5935587cd899fbb9e49e9ba3579f2fd4f02203f01c27445218667a3855bf57a5358e58144b9d45ae69e0e11e2801ea059397c01",
"sequence":4294967294
}
],
"bin_outputs":[
{
"amount":3160624366,
"script_pubkey":"76a914530d11205fce56842fd6a9f506cc629a6a53ecb588ac"
},
{
"amount":3159915666,
"script_pubkey":"76a914da9f72d5f97aefef8aff7ad297f09b694c8503ee88ac"
},
{
"amount":3157068878,
"script_pubkey":"76a914d2eea7ece34983e6d73380f9b45a7e3ed288a51c88ac"
},
{
"amount":3156850732,
"script_pubkey":"76a91424cb55d8c9ea4f93f7845bb8d9defbe4234d557d88ac"
},
{
"amount":3156734367,
"script_pubkey":"76a9148032e2bf790e5bb2147e2764fc00488d70493e6f88ac"
},
{
"amount":3156380774,
"script_pubkey":"76a914b0613cd6b0520c4f9f43559ad00f8251f23730ad88ac"
},
{
"amount":3153147245,
"script_pubkey":"76a9149ba037dea6880e77a1154e7743dc887a9713a33988ac"
},
{
"amount":3151649879,
"script_pubkey":"76a91497470402d115276cc1e134607dcb8b80bd12e39788ac"
},
{
"amount":3151564706,
"script_pubkey":"76a9142a961492d9c1b2c45967a9a60735e7339c0df02b88ac"
},
{
"amount":458860163003333,
"script_pubkey":"2102849e12199dcc27ba09c3902686d2ad0adcbfcee9d67520e9abbdda045ba83227ac"
},
{
"amount":3150724949,
"script_pubkey":"76a914be9c2827bc341398b752ff78b50500f47311ddfe88ac"
}
],
"version":4,
"lock_time":1586784579,
"version_group_id":2301567109,
"branch_id":1991772603,
"extra_data":"0000000000000000000000",
"expiry": 0
}
],
"locktime":0
}
Here is a link to input transaction from Insight Explorer https://vote2020.explorer.dexstats.info/insight-api-komodo/tx/3f530ae01546fe36c9314b247c3a1d24664e0f81332cfaa7324a545a6a144230. Hope that helps.
Also, I created a local test in python and tried to run it against Trezor T emulator. Unfortunately I bump into exactly the same error. What am I doing wrong or missing? @szymonlesisz
Already solved, and added to docs. (see this comment: #594 (comment))
You're missing extra_data
and expiry
height fields in refTxs
I specifically set both as written in the docs. Yet still getting the error.
"extra_data":"0000000000000000000000", "expiry": 0
does expiry field need to be set to greater than zero?
expiry needs to be the exactly the same as in your refTx.
https://vote2020.explorer.dexstats.info/insight-api-komodo/tx/3f530ae01546fe36c9314b247c3a1d24664e0f81332cfaa7324a545a6a144230
in this case it's 473
I see now. Thank you for the help!
Unfortunately setting expiry field to 473 didn't help. I'm still getting the same error. Is there anything else that I'm missing? @szymonlesisz
paste your updated code again pls
{
"versionGroupId": 2301567109,
"branchId": 1991772603,
"overwintered": true,
"version": 4,
"push": false,
"coin": "kmd",
"outputs": [
{
"address": "R9HgJZo6JBKmPvhm7whLSR8wiHyZrEDVRi",
"amount": "100000000",
"script_type": "PAYTOADDRESS"
},
{
"address_n": [
2147483692,
2147483789,
2147483648,
"1",
"0"
],
"amount": "3056840732",
"script_type": "PAYTOADDRESS"
}
],
"inputs": [
{
"address_n": [
2147483692,
2147483789,
2147483648,
"0",
"8"
],
"prev_index": 3,
"prev_hash": "3f530ae01546fe36c9314b247c3a1d24664e0f81332cfaa7324a545a6a144230",
"amount": "3156850732"
}
],
"refTxs": [
{
"hash": "3f530ae01546fe36c9314b247c3a1d24664e0f81332cfaa7324a545a6a144230",
"inputs": [
{
"prev_hash": "179f1d0cc062f9b5a72e72b22882b0447266ddb9b49a5327169403470884a247",
"prev_index": 0,
"script_sig": "4730440220185248d2e16bed9f77227ff94651ace5935587cd899fbb9e49e9ba3579f2fd4f02203f01c27445218667a3855bf57a5358e58144b9d45ae69e0e11e2801ea059397c01",
"sequence": 4294967294
}
],
"bin_outputs": [
{
"amount": 3160624366,
"script_pubkey": "76a914530d11205fce56842fd6a9f506cc629a6a53ecb588ac"
},
{
"amount": 3159915666,
"script_pubkey": "76a914da9f72d5f97aefef8aff7ad297f09b694c8503ee88ac"
},
{
"amount": 3157068878,
"script_pubkey": "76a914d2eea7ece34983e6d73380f9b45a7e3ed288a51c88ac"
},
{
"amount": 3156850732,
"script_pubkey": "76a91424cb55d8c9ea4f93f7845bb8d9defbe4234d557d88ac"
},
{
"amount": 3156734367,
"script_pubkey": "76a9148032e2bf790e5bb2147e2764fc00488d70493e6f88ac"
},
{
"amount": 3156380774,
"script_pubkey": "76a914b0613cd6b0520c4f9f43559ad00f8251f23730ad88ac"
},
{
"amount": 3153147245,
"script_pubkey": "76a9149ba037dea6880e77a1154e7743dc887a9713a33988ac"
},
{
"amount": 3151649879,
"script_pubkey": "76a91497470402d115276cc1e134607dcb8b80bd12e39788ac"
},
{
"amount": 3151564706,
"script_pubkey": "76a9142a961492d9c1b2c45967a9a60735e7339c0df02b88ac"
},
{
"amount": 458860163003333,
"script_pubkey": "2102849e12199dcc27ba09c3902686d2ad0adcbfcee9d67520e9abbdda045ba83227ac"
},
{
"amount": 3150724949,
"script_pubkey": "76a914be9c2827bc341398b752ff78b50500f47311ddfe88ac"
}
],
"version": 4,
"lock_time": 1586784579,
"version_group_id": 2301567109,
"branch_id": 1991772603,
"extra_data": "0000000000000000000000",
"expiry": 473
}
],
"locktime": 0
}
do have this 3f530ae01546fe36c9314b247c3a1d24664e0f81332cfaa7324a545a6a144230
transaction hash (i cant find it in explorer)? i will try to generate extra_data from it, maybe they are somehow different than "00000..."
it's not on Komodo main chain as it's a different network
sorry i meant tx hex (raw) not the txid, like this one:
https://komodoblockexplorer.com/tx/074b75e64b55d92e37c50c4336bd5faf3d0cdb78135cce475ba75edc3798acf0
I've used the lib you pointed me out in the previous git issue https://github.com/trezor/trezor-utxo-lib/blob/trezor/src/transaction.js#L1200.
getExtraData returned <Buffer 00 00 00 00 00 00 00 00 00 00 00>
must be something else
also, i've tried to use a different refTx that has nExpiryHeight = 0, my Trezor One throws the same error
so it seems that nExpiryHeight has nothing to do with the error in this case
yes, this rawtx is what i need. I've parse this tx thru utxolib and get this result (it's working)
Your "input.prev_index" should be 9! not 0
"refTxs": [
{
"version": 4,
"hash": "3f530ae01546fe36c9314b247c3a1d24664e0f81332cfaa7324a545a6a144230",
"inputs": [
{
"prev_index": 9,
"sequence": 4294967294,
"prev_hash": "179f1d0cc062f9b5a72e72b22882b0447266ddb9b49a5327169403470884a247",
"script_sig": "4730440220185248d2e16bed9f77227ff94651ace5935587cd899fbb9e49e9ba3579f2fd4f02203f01c27445218667a3855bf57a5358e58144b9d45ae69e0e11e2801ea059397c01"
}
],
"bin_outputs": [
{
"amount": "3160624366",
"script_pubkey": "76a914530d11205fce56842fd6a9f506cc629a6a53ecb588ac"
},
{
"amount": "3159915666",
"script_pubkey": "76a914da9f72d5f97aefef8aff7ad297f09b694c8503ee88ac"
},
{
"amount": "3157068878",
"script_pubkey": "76a914d2eea7ece34983e6d73380f9b45a7e3ed288a51c88ac"
},
{
"amount": "3156850732",
"script_pubkey": "76a91424cb55d8c9ea4f93f7845bb8d9defbe4234d557d88ac"
},
{
"amount": "3156734367",
"script_pubkey": "76a9148032e2bf790e5bb2147e2764fc00488d70493e6f88ac"
},
{
"amount": "3156380774",
"script_pubkey": "76a914b0613cd6b0520c4f9f43559ad00f8251f23730ad88ac"
},
{
"amount": "3153147245",
"script_pubkey": "76a9149ba037dea6880e77a1154e7743dc887a9713a33988ac"
},
{
"amount": "3151649879",
"script_pubkey": "76a91497470402d115276cc1e134607dcb8b80bd12e39788ac"
},
{
"amount": "3151564706",
"script_pubkey": "76a9142a961492d9c1b2c45967a9a60735e7339c0df02b88ac"
},
{
"amount": "458860163003333",
"script_pubkey": "2102849e12199dcc27ba09c3902686d2ad0adcbfcee9d67520e9abbdda045ba83227ac"
},
{
"amount": "3150724949",
"script_pubkey": "76a914be9c2827bc341398b752ff78b50500f47311ddfe88ac"
}
],
"extra_data": "0000000000000000000000",
"lock_time": 1586784579,
"version_group_id": 2301567109,
"expiry": 473
}
]```
Thanks a bunch for debugging it! There was a mistake in my code :(
Hi, @szymonlesisz. I'm having another issue signing a Komodo compatible transaction. I double checked everything but still fail to find what am I missing. Can you have a look please? I assume it got something to do with nExpiry field? I read zip-0203 (https://zips.z.cash/zip-0203#specification) and it mentioned there that when both fields Locktime and nExpiry are set they must be equal to a height value not timestamp. Could this be an issue?
This is my Trezor object:
{
"versionGroupId":2301567109,
"branchId":1991772603,
"overwintered":true,
"version":4,
"push":false,
"coin":"kmd",
"locktime":0,
"outputs":[
{
"address":"RDbGxL8QYdEp8sMULaVZS2E6XThcTKT9Jd",
"amount":"100000000",
"script_type":"PAYTOADDRESS"
},
{
"address_n":[
2147483692,
2147483789,
2147483648,
"1",
"0"
],
"amount":"316920493200",
"script_type":"PAYTOADDRESS"
}
],
"inputs":[
{
"address_n":[
2147483692,
2147483789,
2147483648,
"0",
"9"
],
"prev_index":1,
"prev_hash":"a066734b1bd3bf37f4d13e58caadf3d40baff23987ca51cd7cbb24b22a7b6c9a",
"amount":"317020503200"
}
],
"refTxs":[
{
"hash":"a066734b1bd3bf37f4d13e58caadf3d40baff23987ca51cd7cbb24b22a7b6c9a",
"inputs":[
{
"prev_hash":"a037325dfb9630e24bffb10af6943609a62532cf510398b1a047d6506572b813",
"prev_index":1,
"script_sig":"47304402202b2f85a5cf752ebefb09643ef68ea1f1dee3bfc6b8119f5001b92a5bda301ab4022054d53fec36f3bf570d4e198f583f89e8a5be2bfc190da1857a06c26bf853718c012102bf8d4f63c16211de9a00123eadde26e74756cbd9c6dff24d551ed26cf1ad33ce",
"sequence":4294967294
}
],
"bin_outputs":[
{
"amount":487280618121128060,
"script_pubkey":"76a914fd38339028671bdf86b722ab6b842282b875a35b88ac"
},
{
"amount":317020503200,
"script_pubkey":"76a914b680d79bd4e070c8455e87dc6bdceb79c142301888ac"
}
],
"version":4,
"lock_time":1612044751,
"version_group_id":2301567109,
"branch_id":1991772603,
"extra_data":"0000000000000000000000",
"expiry":2718
}
]
}
Inputs:
Decoded https://wsb.explorer.dexstats.info/insight-api-komodo/tx/a066734b1bd3bf37f4d13e58caadf3d40baff23987ca51cd7cbb24b22a7b6c9a
Raw https://wsb.explorer.dexstats.info/insight-api-komodo/rawtx/a066734b1bd3bf37f4d13e58caadf3d40baff23987ca51cd7cbb24b22a7b6c9a
Decoded https://wsb.explorer.dexstats.info/insight-api-komodo/tx/a037325dfb9630e24bffb10af6943609a62532cf510398b1a047d6506572b813
Raw https://wsb.explorer.dexstats.info/insight-api-komodo/rawtx/a037325dfb9630e24bffb10af6943609a62532cf510398b1a047d6506572b813