1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-22 13:21:03 +00:00

fixup! feat(legacy): support sortedmulti

This commit is contained in:
Ondřej Vejpustek 2024-12-12 14:40:30 +01:00
parent c9adb55c07
commit cf7312ccac
4 changed files with 42 additions and 7 deletions

View File

@ -401,6 +401,24 @@ uint32_t cryptoMultisigPubkeys(const CoinInfo *coin,
int cryptoMultisigPubkeyIndex(const CoinInfo *coin,
const MultisigRedeemScriptType *multisig,
const uint8_t *pubkey) {
uint32_t n = cryptoMultisigPubkeyCount(multisig);
uint8_t pubkeys[33 * n];
if (!cryptoMultisigPubkeys(coin, multisig, pubkeys)) {
return -1;
}
for (size_t i = 0; i < n; i++) {
if (memcmp(pubkeys + i * 33, pubkey, 33) == 0) {
return i;
}
}
return -1;
}
int cryptoMultisigXpubIndex(const CoinInfo *coin,
const MultisigRedeemScriptType *multisig,
const uint8_t *pubkey) {
for (size_t i = 0; i < cryptoMultisigPubkeyCount(multisig); i++) {
const HDNode *pubnode = cryptoMultisigPubkey(coin, multisig, i);
if (pubnode && memcmp(pubnode->public_key, pubkey, 33) == 0) {

View File

@ -88,6 +88,10 @@ int cryptoMultisigPubkeyIndex(const CoinInfo *coin,
const MultisigRedeemScriptType *multisig,
const uint8_t *pubkey);
int cryptoMultisigXpubIndex(const CoinInfo *coin,
const MultisigRedeemScriptType *multisig,
const uint8_t *pubkey);
uint32_t cryptoMultisigPubkeys(const CoinInfo *coin,
const MultisigRedeemScriptType *multisig,
uint8_t *pubkeys);

View File

@ -333,7 +333,7 @@ void fsm_msgGetAddress(const GetAddress *msg) {
desc[15] = (n < 10) ? ' ' : ('0' + (n / 10));
desc[16] = '0' + (n % 10);
multisig_index =
cryptoMultisigPubkeyIndex(coin, &(msg->multisig), node->public_key);
cryptoMultisigXpubIndex(coin, &(msg->multisig), node->public_key);
} else {
strlcpy(desc, _("Address:"), sizeof(desc));
}

View File

@ -170,10 +170,13 @@ def test_pubkeys_order(client: Client):
client, parse_path("m/45h/1"), coin_name="Bitcoin"
).node
# A dummy signature is used to ensure that the signatures are serialized in the correct order
dummy_signature = bytes(71)
multisig_unsorted_1 = messages.MultisigRedeemScriptType(
nodes=[node_internal, node_external],
address_n=[0, 0],
signatures=[b"", b"", b""],
signatures=[b"", dummy_signature],
m=1,
pubkeys_order=messages.MultisigPubkeysOrder.PRESERVED,
)
@ -181,7 +184,7 @@ def test_pubkeys_order(client: Client):
multisig_unsorted_2 = messages.MultisigRedeemScriptType(
nodes=[node_external, node_internal],
address_n=[0, 0],
signatures=[b"", b"", b""],
signatures=[dummy_signature, b""],
m=1,
pubkeys_order=messages.MultisigPubkeysOrder.PRESERVED,
)
@ -189,7 +192,7 @@ def test_pubkeys_order(client: Client):
multisig_sorted_1 = messages.MultisigRedeemScriptType(
nodes=[node_internal, node_external],
address_n=[0, 0],
signatures=[b"", b"", b""],
signatures=[b"", dummy_signature],
m=1,
pubkeys_order=messages.MultisigPubkeysOrder.LEXICOGRAPHIC,
)
@ -197,7 +200,7 @@ def test_pubkeys_order(client: Client):
multisig_sorted_2 = messages.MultisigRedeemScriptType(
nodes=[node_external, node_internal],
address_n=[0, 0],
signatures=[b"", b"", b""],
signatures=[b"", dummy_signature],
m=1,
pubkeys_order=messages.MultisigPubkeysOrder.LEXICOGRAPHIC,
)
@ -209,6 +212,16 @@ def test_pubkeys_order(client: Client):
client, "Bitcoin", parse_path("m/45h/0/0/0"), multisig=multisig_unsorted_2
)
pubkey_internal = btc.get_public_node(
client, parse_path("m/45h/0/0/0"), coin_name="Bitcoin"
).node.public_key
pubkey_external = btc.get_public_node(
client, parse_path("m/45h/1/0/0"), coin_name="Bitcoin"
).node.public_key
# This assertion implies that script pubkey of multisig_sorted_1, multisig_sorted_2 and multisig_unsorted_1 are the same
assert pubkey_internal < pubkey_external
prev_hash, prev_tx = forge_prevtx(
[(address_unsorted_1, 1_000_000), (address_unsorted_2, 1_000_000)]
)
@ -277,9 +290,9 @@ def test_pubkeys_order(client: Client):
multisig=multisig_sorted_2,
)
tx_unsorted_1 = "0100000001637ffac0d4fbd8a6c02b114e36b079615ec3e4bdf09b769c7bf8b5fd6f8e7817000000009200483045022100f062d71445509d84a5769f219f4f0158dc7ff4351d671e6fa6bfdb171435064802206e1104f1d14f010bcc166cca6a9bd24b4a497475f8e23167858b4a3e92ac6a67014751210262e9ac5bea4c84c7dea650424ed768cf123af9e447eef3c63d37c41d1f825e49210369b79f2094a6eb89e7aff0e012a5699f7272968a341e48e99e64a54312f2932b52aeffffffff01301b0f000000000017a91440bfd8ae9d806d5bd7cf475ce6a80535836285148700000000"
tx_unsorted_1 = "0100000001637ffac0d4fbd8a6c02b114e36b079615ec3e4bdf09b769c7bf8b5fd6f8e781700000000db00483045022100f062d71445509d84a5769f219f4f0158dc7ff4351d671e6fa6bfdb171435064802206e1104f1d14f010bcc166cca6a9bd24b4a497475f8e23167858b4a3e92ac6a6701480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014751210262e9ac5bea4c84c7dea650424ed768cf123af9e447eef3c63d37c41d1f825e49210369b79f2094a6eb89e7aff0e012a5699f7272968a341e48e99e64a54312f2932b52aeffffffff01301b0f000000000017a91440bfd8ae9d806d5bd7cf475ce6a80535836285148700000000"
tx_unsorted_2 = "0100000001637ffac0d4fbd8a6c02b114e36b079615ec3e4bdf09b769c7bf8b5fd6f8e781701000000910047304402204914036468434698e2d87985007a66691f170195e4a16507bbb86b4c00da5fde02200a788312d447b3796ee5288ce9e9c0247896debfa473339302bc928da6dd78cb014751210369b79f2094a6eb89e7aff0e012a5699f7272968a341e48e99e64a54312f2932b210262e9ac5bea4c84c7dea650424ed768cf123af9e447eef3c63d37c41d1f825e4952aeffffffff01301b0f000000000017a914320ad0ff0f1b605ab1fa8e29b70d22827cf45a9f8700000000"
tx_unsorted_2 = "0100000001637ffac0d4fbd8a6c02b114e36b079615ec3e4bdf09b769c7bf8b5fd6f8e781701000000da004800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000147304402204914036468434698e2d87985007a66691f170195e4a16507bbb86b4c00da5fde02200a788312d447b3796ee5288ce9e9c0247896debfa473339302bc928da6dd78cb014751210369b79f2094a6eb89e7aff0e012a5699f7272968a341e48e99e64a54312f2932b210262e9ac5bea4c84c7dea650424ed768cf123af9e447eef3c63d37c41d1f825e4952aeffffffff01301b0f000000000017a914320ad0ff0f1b605ab1fa8e29b70d22827cf45a9f8700000000"
_, tx = btc.sign_tx(
client,