Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sort addresses #928

Merged
merged 2 commits into from
Nov 26, 2024
Merged

fix: sort addresses #928

merged 2 commits into from
Nov 26, 2024

Conversation

rictorlome
Copy link
Collaborator

@rictorlome rictorlome commented Nov 26, 2024

Preventing errors such as:

Details: couldn't issue tx: failed verification: failed execution: standard tx 5BFNdkBJWZhqx3NkrnHMEhetJ4YtZC5QxLdNREGJGF9XznGvf failed execution: output failed verification: addresses not sorted and unique

reproduction steps (on master):
in examples/p-chain/base.ts, testing against fuji:
add the following lines options:

  const P_CHAIN_ADDRESS_2 = 'P-fuji14n4duc4qkmh4q5vvgyh03yrcf4yxtk2ap8mj8q';
  const changeAddresses = [
    bech32ToBytes(P_CHAIN_ADDRESS_2),
    bech32ToBytes(P_CHAIN_ADDRESS),
  ];
  changeAddresses.sort(bytesCompare);
  changeAddresses.reverse(); // NOTE: this will cause the error
  const tx = newBaseTx(context, [bech32ToBytes(P_CHAIN_ADDRESS)], utxos, [
    TransferableOutput.fromNative(context.avaxAssetID, BigInt(0.01 * 1e9), [
      bech32ToBytes(P_CHAIN_ADDRESS)
    ]),
  ], 
  {
    changeAddresses
  }

this should throw the error on master, but not on this branch.

after applying this fix, even this is fine:

  const { utxos } = await pvmapi.getUTXOs({ addresses: [P_CHAIN_ADDRESS, P_CHAIN_ADDRESS_2] });
  // NOTE: backwards sorted fromAddressBytes
  const tx = newBaseTx(context, [bech32ToBytes(P_CHAIN_ADDRESS_2), bech32ToBytes(P_CHAIN_ADDRESS)], utxos, [
    TransferableOutput.fromNative(context.avaxAssetID, BigInt(0.01 * 1e9), [
      bech32ToBytes(P_CHAIN_ADDRESS)
    ]),
  ], 
  {
    changeAddresses
  }

https://subnets-test.avax.network/p-chain/tx/Jjw7T3exyvJeBkEZqQhK87SBTrTu4Wj5DUrhj8Dc2RjdwAPra

@rictorlome rictorlome changed the title fix: sort addresses [WIP] fix: sort addresses Nov 26, 2024
Copy link
Collaborator

@bferenc bferenc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition, thank you! 👏

Copy link
Member

@erictaylor erictaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me. Thanks for adding the multi-sig indicies test.

@rictorlome rictorlome merged commit 2856c2f into master Nov 26, 2024
3 checks passed
@rictorlome rictorlome deleted the fix/sort-addresses branch November 26, 2024 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants