trustwallet / wallet-core

Cross-platform, cross-blockchain wallet library.
https://developer.trustwallet.com/wallet-core
Apache License 2.0
2.86k stars 1.6k forks source link

[TON]: Eliminate nondeterminism in TON BoC serialization #4005

Closed 10gic closed 2 months ago

10gic commented 2 months ago

Fix issue https://github.com/trustwallet/wallet-core/issues/4004

The test case SignMessageToTransferAndDeployWalletV5R1 occasionally fails.

Root Cause

A HashMap is unordered, so iterating over it multiple times may yield different results. https://github.com/trustwallet/wallet-core/blob/af67cae30f132ec139b72b4b93d2b336b84a8c49/rust/frameworks/tw_ton_sdk/src/boc/boc_to_raw_boc.rs#L85

Resolution

Change the HashMap to an ordered data structure, such as a BTreeMap.