From 8726c728f144bd151093fe9b4e06e14d9acbb364 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Tue, 10 Dec 2024 05:41:27 -0500 Subject: [PATCH] ffix: multisig tx decoding --- src/stacks_tx/deserialize.rs | 8 ------ tests/tx-decode-3.0.test.ts | 53 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/stacks_tx/deserialize.rs b/src/stacks_tx/deserialize.rs index 030cdfe..e1815d2 100644 --- a/src/stacks_tx/deserialize.rs +++ b/src/stacks_tx/deserialize.rs @@ -223,14 +223,6 @@ impl MultisigSpendingCondition { }; } - // must be given the right number of signatures - if num_sigs_given != signatures_required { - return Err(format!( - "Failed to parse multisig spending condition: got {} sigs, expected {}", - num_sigs_given, signatures_required - ))?; - } - // must all be compressed if we're using P2WSH if have_uncompressed && hash_mode == MultisigHashMode::P2WSH { return Err(format!( diff --git a/tests/tx-decode-3.0.test.ts b/tests/tx-decode-3.0.test.ts index 155ec89..df0c235 100644 --- a/tests/tx-decode-3.0.test.ts +++ b/tests/tx-decode-3.0.test.ts @@ -238,6 +238,59 @@ test("stacks 3.0 - decode tx - non-sequential multi-sig", () => { }); }); +test("stacks 3.0 - decode tx - non-sequential multi-sig 2", () => { + const tx = + "0x0000000001040506cb614d936db3a4c31b1a73e516e88d1f7579040000000000000015000000000006c34000000005000212e37e65b9741f09eeed659ceafe577020f15032d14f6de394c93ac2aeae2cd802013e4081ba21cf55a79d44364979bd69b1ff752af92a0402ca12cb9af1a46f0a11442b4fab5a47b8b25fda073e4e1f2782eba1de1dce18564ece471eb8693280b30200942b48e62e7c90aeb3c37f94022c60b8ecc1cf54d666812f6cbd267b12dc99df07c2955aabb9e136a6616eb20fe2bc5719cf3168644e379182ccbf51418de9ea02010df1a1161a65deafc79c170f5ef05707c399802c6257a1f1fb600414ed6ee08772b12a031e67682aeb179320da141b4679be718aa0545efca4714b3aa63db1660201f865ae066057deeeafaa4b7ad796b94f5d965e3de92699aedf49d9756b00c3617703979b67d9c0daa7f30184f722f7fa75edb0c6f4041a28d8e619323915a32000030302000000000216495ca29b5e23da51265dfc0388ea91539e5b67c510706f6e7469732d6272696467652d7635116d696e742d6274632d66726f6d2d627463000000060616495ca29b5e23da51265dfc0388ea91539e5b67c512706f6e7469732d6272696467652d7042544301000000000000000000000000004c4b400516d105ee658ba40a2e24662498dddc41a3d0452ab00200000021904e124b3d17611f769d641e4f366697ea850fe94c630e916b90feb6521f613d0102000000200000000000000000000145608686892318974350a6a12c218318f104f066f00c010000000000000000000000000004c51e"; + const decoded = decodeTransaction(tx); + expect(decoded).toEqual({ + "tx_id": "0xf38135deaacc8bbb1bedc9d5e976148ef45f32daa24867a071d7b9541e8e0988", + "version": 0, + "chain_id": 1, + "auth": { + "type_id": 4, + "origin_condition": { + "hash_mode": 5, + "signer": { + "address_version": 20, + "address_hash_bytes": "0x06cb614d936db3a4c31b1a73e516e88d1f757904", + "address": "SM3CPRADJDPV79633CD77S8PX26HYXBS0KS80ZD5" + }, + "nonce": "21", + "tx_fee": "443200", + "fields": [ + { "type_id": 0, "public_key": "0x0212e37e65b9741f09eeed659ceafe577020f15032d14f6de394c93ac2aeae2cd8" }, + { "type_id": 2, "signature": "0x013e4081ba21cf55a79d44364979bd69b1ff752af92a0402ca12cb9af1a46f0a11442b4fab5a47b8b25fda073e4e1f2782eba1de1dce18564ece471eb8693280b3" }, + { "type_id": 2, "signature": "0x00942b48e62e7c90aeb3c37f94022c60b8ecc1cf54d666812f6cbd267b12dc99df07c2955aabb9e136a6616eb20fe2bc5719cf3168644e379182ccbf51418de9ea" }, + { "type_id": 2, "signature": "0x010df1a1161a65deafc79c170f5ef05707c399802c6257a1f1fb600414ed6ee08772b12a031e67682aeb179320da141b4679be718aa0545efca4714b3aa63db166" }, + { "type_id": 2, "signature": "0x01f865ae066057deeeafaa4b7ad796b94f5d965e3de92699aedf49d9756b00c3617703979b67d9c0daa7f30184f722f7fa75edb0c6f4041a28d8e619323915a320" } + ], + "signatures_required": 3 + } + }, + "anchor_mode": 3, + "post_condition_mode": 2, + "post_conditions": [], + "post_conditions_buffer": "0x0200000000", + "payload": { + "type_id": 2, + "address_version": 22, + "address_hash_bytes": "0x495ca29b5e23da51265dfc0388ea91539e5b67c5", + "address": "SP14NS8MVBRHXMM96BQY0727AJ59SWPV7RMHC0NCG", + "contract_name": "pontis-bridge-v5", + "function_name": "mint-btc-from-btc", + "function_args": [ + { "repr": "'SP14NS8MVBRHXMM96BQY0727AJ59SWPV7RMHC0NCG.pontis-bridge-pBTC", "hex": "0x0616495ca29b5e23da51265dfc0388ea91539e5b67c512706f6e7469732d6272696467652d70425443", "type_id": 6 }, + { "repr": "u5000000", "hex": "0x01000000000000000000000000004c4b40", "type_id": 1 }, + { "repr": "'SP38GBVK5HEJ0MBH4CRJ9HQEW86HX0H9AP1HZ3SVZ", "hex": "0x0516d105ee658ba40a2e24662498dddc41a3d0452ab0", "type_id": 5 }, + { "repr": "0x904e124b3d17611f769d641e4f366697ea850fe94c630e916b90feb6521f613d01", "hex": "0x0200000021904e124b3d17611f769d641e4f366697ea850fe94c630e916b90feb6521f613d01", "type_id": 2 }, + { "repr": "0x0000000000000000000145608686892318974350a6a12c218318f104f066f00c", "hex": "0x02000000200000000000000000000145608686892318974350a6a12c218318f104f066f00c", "type_id": 2 }, + { "repr": "u312606", "hex": "0x010000000000000000000000000004c51e", "type_id": 1 } + ], + "function_args_buffer": "0x000000060616495ca29b5e23da51265dfc0388ea91539e5b67c512706f6e7469732d6272696467652d7042544301000000000000000000000000004c4b400516d105ee658ba40a2e24662498dddc41a3d0452ab00200000021904e124b3d17611f769d641e4f366697ea850fe94c630e916b90feb6521f613d0102000000200000000000000000000145608686892318974350a6a12c218318f104f066f00c010000000000000000000000000004c51e" + } + }); +}); + test('stacks 3.0 - decode tx - versioned smart contract Clariy 3', () => { const tx = '8080000000040005572d04565d56f67e84ad7e20deedd8e7bba2fd00000000000000000000000000000bb800010c3287ab0587cf952022e079d261baeacc533d8c92b754136271450eb121ba4c0849f3c47f5a6f967dd1088e8242a9f9ed0454bfadaa19c71d25c8812e47160a030200000000060307636f756e7465720000004e28646566696e652d646174612d76617220636f756e742075696e74207530290a28646566696e652d726561642d6f6e6c7920286765742d636f756e742920287661722d67657420636f756e742929'; const decoded = decodeTransaction(tx);