Closed motorina0 closed 2 years ago
Thanks! I'll look into that over the weekend.
What worries me about these transactions:
non_witness_utxo
contains a transaction with witness. Might be a reason why parsing fails, but not sure why it fails not 100% of the time.witness_utxo
is not provided, I need to double-check the code.I'd suggest using witness_utxo
when you are preparing a segwit transaction, omitting non_witness_utxo
as it's required only for legacy transactions. PSBT will be also much smaller in this case.
not sure if you'll be able to sign this tx as witness_utxo is not provided, I need to double-check the code.
- it is possible, I did sign a
p2wpkh
I'd suggest using witness_utxo when you are preparing a segwit transaction
- I will try this
I'd suggest using witness_utxo when you are preparing a segwit transaction,
- the issue reproduces also when spending a non-segwit UTXO (
p2pkh
):cHNidP8BAHECAAAAAcCUt8KE/D0nm+GKT0KCkmGw4tE/raDvZ5ohtpmw/R/0AAAAAAD/////AtIEAAAAAAAAFgAUBygY8xLaUKwxTC433JZgWy68siOBIQAAAAAAABYAFFonoWnO1Lu/ARs8GRK4Hm7iV6PzAAAAAAABAOECAAAAAAEBrKHU59Ql5z9U9OrT/vezsW6p0zrq/H/e8D5wWTb0di8AAAAAAP7///8CECcAAAAAAAAZdqkUJhr0QZB180z3REQywqZhK26T4fOIrM/AJgAAAAAAFgAU/SWEMxW5Z01If9kcAnLp/bwZIdsCRzBEAiBAf8nXOVYQwEoNEvnPY1JtmRFRL5K5YpC/pUdaw14FrwIgaP27OUyV5ufX4VML+uzfklF48mkCf7i6D3/4DPOhdDoBIQLHvHqtEUjR4jJ4z+RqVGgIhvEE08kJyf0H2PRUxUcZUiZSIwAiBgIYl+QB5cHV6ahtrKXoXdMQqYIbwwEil0hyqwv5bPBEjxh/jg/pLAAAgAEAAIAAAACAAAAAAAEAAAAAIgIDbSKhCgivNNcoT4rF61UIW5tauSZClR2UIiLs5auGUW4Yf44P6VQAAIABAACAAAAAgAEAAAABAAAAAAA=
How can one debug this code? I would like to give it a try but I don't know where to start.
The strange thing is that I tried parsing all these transaction on a PC (using cpp example) and they all worked fine.
How do you check that transaction parsing failed? using if(psbt){...}
case?
One useful debug tip is to check value of ubtc_errno
that I introduced some time ago - it is an error code that is assigned to different values depending on what went wrong. PSBT error codes are defined in PSBT.cpp
. Now thinking about that it probably makes sense to move them to the header... They are not assigned everywhere, but better than nothing.
I'll try running it on the board as well, just need to get home and find TTGo. Let's see if it's a hardware-related issue.
How do you check that transaction parsing failed? using if(psbt){...} case?
- yes
PSBT psbt = parseBase64Psbt(psbtBase64); if (!psbt) {
Later Edit:
- value for
ubtc_errno
is2
(UBTC_ERR_PSBT_SCOPE)
I was able to reproduce the error on ESP32, gonna try to figure out what's wrong. Looks like it's failing parsing non-witness utxo in the input.
Fixed in https://github.com/micro-bitcoin/uBitcoin/commit/9309bbcc35e3d07030606c94ee6c1f3c3f6dd220 Please try with the current master and let me know if it works.
64-bit math on 32-bit systems is tricky, so I slightly changed the way how we parse txout amount - this was causing tx hash validation errors. TxOut amounts were parsed incorrectly if they are larger than max 32-bit value. You had large prevouts in the transactions and that revealed the bug =) I'll add this case into the test suite and think how we can run tests on the hardware.
Fix confirmed! It worked 🥳 Sample Testnet Tx spending a high amount.
Sometimes the PSBT parsing fails. I have managed to reproduce the issue only with
Testnet
transactions, it seams to work fine onMainnet
I have this simple logic for parsing a
base64
PSBT:Below there are two sample PSBTs, the only difference between them is the UTXO they spend (and the
non_witness_utxo
field).Parse OK:
Parse NOK: