diff --git a/ledger/src/signer/src/auth_tx.c b/ledger/src/signer/src/auth_tx.c index bca9eec5..25fb8dac 100644 --- a/ledger/src/signer/src/auth_tx.c +++ b/ledger/src/signer/src/auth_tx.c @@ -157,7 +157,7 @@ unsigned int auth_sign_handle_btctx(volatile unsigned int rx) { APDU_DATA_SIZE(rx) - apdu_offset); if (btctx_result() < 0) { - LOG("[E] Error parsing BTC tx: %u\n", btctx_result()); + LOG("[E] Error parsing BTC tx: %d\n", btctx_result()); // To comply with the legacy implementation THROW(AUTH_ERR_TX_HASH_MISMATCH); } diff --git a/ledger/src/signer/src/btctx.c b/ledger/src/signer/src/btctx.c index 75c2e37a..b4358bd7 100644 --- a/ledger/src/signer/src/btctx.c +++ b/ledger/src/signer/src/btctx.c @@ -90,7 +90,7 @@ uint8_t btctx_consume(uint8_t *buf, const uint8_t len) { processed = svarint_consume(buf + i, len - i); SAFE_MEMMOVE(ctx->raw, sizeof(ctx->raw), - MEMMOVE_ZERO_OFFSET, + ctx->raw_size, buf, len, i, @@ -103,6 +103,8 @@ uint8_t btctx_consume(uint8_t *buf, const uint8_t len) { i += processed - 1; switch (svarint_result()) { + case SVARINT_ERR_NONE: + break; case SVARINT_ST_DONE: switch (ctx->state) { case BTCTX_ST_VIN_COUNT: diff --git a/ledger/src/signer/src/trie.c b/ledger/src/signer/src/trie.c index 0a05bebf..011f222d 100644 --- a/ledger/src/signer/src/trie.c +++ b/ledger/src/signer/src/trie.c @@ -144,7 +144,7 @@ uint8_t trie_consume(uint8_t *buf, const uint8_t len) { processed = svarint_consume(buf + i, len - i); SAFE_MEMMOVE(ctx->raw, sizeof(ctx->raw), - MEMMOVE_ZERO_OFFSET, + ctx->raw_size, buf, len, i, diff --git a/ledger/src/signer/test/btctx/resources/tx-004.hex b/ledger/src/signer/test/btctx/resources/tx-004.hex new file mode 100644 index 00000000..f6dddab1 --- /dev/null +++ b/ledger/src/signer/test/btctx/resources/tx-004.hex @@ -0,0 +1 @@ +020000000396f1ed3e9075af583e8e1e2b50bd5e37c761f677418db75a295901380864d95e01000000fd270100000000004d1f016453210225e892391625854128c5c4ea4340de0c2a70570f33db53426fc9c746597a03f421025a2f522aea776fab5241ad72f7f05918e8606676461cb6ce38265a52d4ca9ed62102afc230c2d355b1a577682b07bc2646041b5d0177af0f98395a46018da699b6da21032822626c45fc1c4e3a3def5b4983636d6291a7a6677f66874c337e78bc3b77842103fb8e1d5d0392d35ca8c3656acb6193dbf392b3e89b9b7b86693f5c80f7ce858155ae670350cd00b27552210216c23b2ea8e4f11c3f9e22711addb1d16a93964796913830856b568cc3ea21d3210275562901dd8faae20de0a4166362a4f82188db77dbed4ca887422ea1ec185f1421034db69f2112f4fb1bb6141bf6e2bd6631f0484d0bd95b16767902c9fe219d4a6f53ae68ffffffff375b0696785b04a56b6a9f3f84a0fc3715837f7a2ab427f220ef2932b64a93ae01000000fd270100000000004d1f016453210225e892391625854128c5c4ea4340de0c2a70570f33db53426fc9c746597a03f421025a2f522aea776fab5241ad72f7f05918e8606676461cb6ce38265a52d4ca9ed62102afc230c2d355b1a577682b07bc2646041b5d0177af0f98395a46018da699b6da21032822626c45fc1c4e3a3def5b4983636d6291a7a6677f66874c337e78bc3b77842103fb8e1d5d0392d35ca8c3656acb6193dbf392b3e89b9b7b86693f5c80f7ce858155ae670350cd00b27552210216c23b2ea8e4f11c3f9e22711addb1d16a93964796913830856b568cc3ea21d3210275562901dd8faae20de0a4166362a4f82188db77dbed4ca887422ea1ec185f1421034db69f2112f4fb1bb6141bf6e2bd6631f0484d0bd95b16767902c9fe219d4a6f53ae68ffffffff8797d86f4653e0c778e54f527d4d9bd2b1b57715d0a0ae4dd7918ab7b468a2b002000000fd270100000000004d1f016453210225e892391625854128c5c4ea4340de0c2a70570f33db53426fc9c746597a03f421025a2f522aea776fab5241ad72f7f05918e8606676461cb6ce38265a52d4ca9ed62102afc230c2d355b1a577682b07bc2646041b5d0177af0f98395a46018da699b6da21032822626c45fc1c4e3a3def5b4983636d6291a7a6677f66874c337e78bc3b77842103fb8e1d5d0392d35ca8c3656acb6193dbf392b3e89b9b7b86693f5c80f7ce858155ae670350cd00b27552210216c23b2ea8e4f11c3f9e22711addb1d16a93964796913830856b568cc3ea21d3210275562901dd8faae20de0a4166362a4f82188db77dbed4ca887422ea1ec185f1421034db69f2112f4fb1bb6141bf6e2bd6631f0484d0bd95b16767902c9fe219d4a6f53ae68ffffffff05bbed0600000000001976a9148394379a5ab5974f2bd6368ce479e28fca91631e88acbbed0600000000001976a91409197f6153cb3a91bb51eec373360a1cb3b7c0e088acbbed0600000000001976a91409197f6153cb3a91bb51eec373360a1cb3b7c0e088acbbed0600000000001976a91409197f6153cb3a91bb51eec373360a1cb3b7c0e088ac061e5f000000000017a9145e6cf80958803e9b3c81cd90422152520d2a505c8700000000 \ No newline at end of file diff --git a/ledger/src/signer/test/btctx/test_btctx.c b/ledger/src/signer/test/btctx/test_btctx.c index 6eb24f01..0bea267d 100644 --- a/ledger/src/signer/test/btctx/test_btctx.c +++ b/ledger/src/signer/test/btctx/test_btctx.c @@ -483,6 +483,7 @@ int main() { test_vin_vout_counts("resources/tx-001.hex", 1, 3); test_vin_vout_counts("resources/tx-003.hex", 252, 2); + test_vin_vout_counts("resources/tx-004.hex", 3, 5); test_vin_prevtx( "resources/tx-001.hex", @@ -512,6 +513,13 @@ int main() { 200, 0x44332211); + test_vin_prevtx( + "resources/tx-004.hex", + 2, + "b0a268b4b78a91d74daea0d01577b5b1d29b4d7d524fe578c7e053466fd89787", + 2, + 0xffffffff); + test_vin_vout_script( "resources/tx-001.hex", false, @@ -560,6 +568,7 @@ int main() { test_raw_complete("resources/tx-001.hex"); test_raw_complete("resources/tx-002.hex"); test_raw_complete("resources/tx-003.hex"); + test_raw_complete("resources/tx-004.hex"); test_error("01000000ff1122334401"); test_error("01000000010c25db7dc67a51c2aa406514373c83a87b25cb313f530fbfa5" diff --git a/ledger/src/signer/test/trie/test_trie.c b/ledger/src/signer/test/trie/test_trie.c index b7b74bf9..e2ab32df 100644 --- a/ledger/src/signer/test/trie/test_trie.c +++ b/ledger/src/signer/test/trie/test_trie.c @@ -451,9 +451,16 @@ int main() { test_raw_complete("4e2670060290077e20feb9ffb4ed5abdcb42dc4e034fe2496cca6b38" "fd479dcd598cfa151b00038811111111111111112222222222222222" "33333333333333334444444444444444fdd705"); - test_raw_complete( - "4caaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbccccccccccccccccdddddddddddddddd1111" - "111111111111222222222222222233333333333333334444444444444444fdd705"); + test_raw_complete("70fffd2101" + "88aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaa9912ad32877a15a35716ddfa2d1fc51942b3f6ed" + "f747a58c39a2aebd185b9618f1000203"); + test_raw_complete("70ff28001122334412ad32877a15a35716ddfa2d1fc51942b3f6edf" + "747a58c39a2aebd185b9618f1000203"); + test_raw_complete("4f2870060290077e20feb9ffb4ed5abdcb42dc4e034fe2496cca6b3" + "8fd479dcd598cfa151b00038811222670060012ad32877a15a35716" + "ddfa2d1fc51942b3f6edf747a58c39a2aebd185b9618f1000203fdd" + "705"); test_flag_detection(); diff --git a/ledger/test/resources/616-sign-3input-5output-testnet.json b/ledger/test/resources/616-sign-3input-5output-testnet.json new file mode 100644 index 00000000..f840f9d2 --- /dev/null +++ b/ledger/test/resources/616-sign-3input-5output-testnet.json @@ -0,0 +1,16 @@ +{ + "name": "Sign a 3-input, 5-output testnet transaction", + "operation": "signAuthorized", + "runOn": "tcpsigner", + "expected": true, + "fake_ancestor_receipts_root": "736a36d733f0faff88dbd36332e773a82e8e5ce9829a34b4d5750c91d641fc74", + "btcTx": "020000000396f1ed3e9075af583e8e1e2b50bd5e37c761f677418db75a295901380864d95e01000000fd270100000000004d1f016453210225e892391625854128c5c4ea4340de0c2a70570f33db53426fc9c746597a03f421025a2f522aea776fab5241ad72f7f05918e8606676461cb6ce38265a52d4ca9ed62102afc230c2d355b1a577682b07bc2646041b5d0177af0f98395a46018da699b6da21032822626c45fc1c4e3a3def5b4983636d6291a7a6677f66874c337e78bc3b77842103fb8e1d5d0392d35ca8c3656acb6193dbf392b3e89b9b7b86693f5c80f7ce858155ae670350cd00b27552210216c23b2ea8e4f11c3f9e22711addb1d16a93964796913830856b568cc3ea21d3210275562901dd8faae20de0a4166362a4f82188db77dbed4ca887422ea1ec185f1421034db69f2112f4fb1bb6141bf6e2bd6631f0484d0bd95b16767902c9fe219d4a6f53ae68ffffffff375b0696785b04a56b6a9f3f84a0fc3715837f7a2ab427f220ef2932b64a93ae01000000fd270100000000004d1f016453210225e892391625854128c5c4ea4340de0c2a70570f33db53426fc9c746597a03f421025a2f522aea776fab5241ad72f7f05918e8606676461cb6ce38265a52d4ca9ed62102afc230c2d355b1a577682b07bc2646041b5d0177af0f98395a46018da699b6da21032822626c45fc1c4e3a3def5b4983636d6291a7a6677f66874c337e78bc3b77842103fb8e1d5d0392d35ca8c3656acb6193dbf392b3e89b9b7b86693f5c80f7ce858155ae670350cd00b27552210216c23b2ea8e4f11c3f9e22711addb1d16a93964796913830856b568cc3ea21d3210275562901dd8faae20de0a4166362a4f82188db77dbed4ca887422ea1ec185f1421034db69f2112f4fb1bb6141bf6e2bd6631f0484d0bd95b16767902c9fe219d4a6f53ae68ffffffff8797d86f4653e0c778e54f527d4d9bd2b1b57715d0a0ae4dd7918ab7b468a2b002000000fd270100000000004d1f016453210225e892391625854128c5c4ea4340de0c2a70570f33db53426fc9c746597a03f421025a2f522aea776fab5241ad72f7f05918e8606676461cb6ce38265a52d4ca9ed62102afc230c2d355b1a577682b07bc2646041b5d0177af0f98395a46018da699b6da21032822626c45fc1c4e3a3def5b4983636d6291a7a6677f66874c337e78bc3b77842103fb8e1d5d0392d35ca8c3656acb6193dbf392b3e89b9b7b86693f5c80f7ce858155ae670350cd00b27552210216c23b2ea8e4f11c3f9e22711addb1d16a93964796913830856b568cc3ea21d3210275562901dd8faae20de0a4166362a4f82188db77dbed4ca887422ea1ec185f1421034db69f2112f4fb1bb6141bf6e2bd6631f0484d0bd95b16767902c9fe219d4a6f53ae68ffffffff05bbed0600000000001976a9148394379a5ab5974f2bd6368ce479e28fca91631e88acbbed0600000000001976a91409197f6153cb3a91bb51eec373360a1cb3b7c0e088acbbed0600000000001976a91409197f6153cb3a91bb51eec373360a1cb3b7c0e088acbbed0600000000001976a91409197f6153cb3a91bb51eec373360a1cb3b7c0e088ac061e5f000000000017a9145e6cf80958803e9b3c81cd90422152520d2a505c8700000000", + "btcTxInput": 0, + "receipt": "f9032501830254c4b901000000000000002000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000008000000000000000000000000000000000000000000000400080000000000020000000000040000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000008000000000000000000000000040000000000000000000000000a000000004000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000100000000000000000000000010000000000f90215f858940000000000000000000000000000000001000006e1a01069152f4f916cbf155ee32a695d92258481944edb5b6fd649718fc1b43e515ea000000000000000000000000092c94ae16eefc9202bb8bcaf1f6b0c8702fb56eef89b940000000000000000000000000000000001000006f863a07a7c29481528ac8c2b2e93aee658fddd4dc15304fa723a5c2b88514557bcc790a08f5d32a9921e1d5f67a033b18135322d7eafa6a4cd471712d20ed89075971c7ba06a2c2fd9250bfc1a5b568a251a1561dbe948ef2fc7709a0f7c711edf6fd19125a000000000000000000000000000000000000000000000000000000000001e8480f9011b940000000000000000000000000000000001000006f842a0483d0191cc4e784b04a41f6c4801a0766b43b1fdd0b9e3e6bfdca74e5b05c2eba06a2c2fd9250bfc1a5b568a251a1561dbe948ef2fc7709a0f7c711edf6fd19125b8c0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000808c583df808142a02b3dcaf0295d5e67ed9f169e486ae727325388f81a8f3f9f751b9c673d7c35349da0cdfb5ec4f581cae82341f6ef195fc095f52d45f987d3c845bcbfba5640d5e6f7b4744805a25e378488a4be05e6d15ed7d0030afd2a9f0b92e5cc1064269c5979b586d78bd0fedf7dac6d7bdbf2d83c740528512b7453883010ea001", + "receiptMp": [ + "6080985a995eddd3cd09639f7fbd7d72695071b0ee73c7f48e277ffdece72b9bf5000328", + "4f246080985a995eddd3cd09639f7fbd7d72695071b0ee73c7f48e277ffdece72b9bf5000328246056226b1f09f7c1bc87b129f48779bdbc8ab566434b96cdc502e87354a60b410600042cfd9c07", + "5e040026700080ec50a69afe65fa4d8d3a103b05c72c9b40c89d8b55efdf3f52524c4a5d452816000110cd679910b1719ec12d8909752cd550ce8feae0534d94dfdfb4b0b7b51914f9a4fd2009", + "4d6b19a649ca98ae0d2010f75f0ee886f3b458948240553fa91f5f7294c14a689526700600edeebe95f8b46a3dd13d2558e64ec9f22373bd6005f472300ac5984ccf071b330001cbfd5e0b" + ] +} diff --git a/ledger/test/resources/616-get-after-success-sign.json b/ledger/test/resources/617-get-after-success-sign.json similarity index 100% rename from ledger/test/resources/616-get-after-success-sign.json rename to ledger/test/resources/617-get-after-success-sign.json