This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
abi::encode_packed() returns incorrect value for U256s with leading zeroes #2704
Labels
bug
Something isn't working
Version
Since the formatting below got a bit weird: TLDR everything is v2.0.11
├── ethers v2.0.11
│ ├── ethers-addressbook v2.0.11
│ │ ├── ethers-core v2.0.11
│ ├── ethers-contract v2.0.11
│ │ ├── ethers-contract-abigen v2.0.11
│ │ │ ├── ethers-core v2.0.11 ()
│ │ ├── ethers-contract-derive v2.0.11 (proc-macro)
│ │ │ ├── ethers-contract-abigen v2.0.11 ()
│ │ │ ├── ethers-core v2.0.11 ()
│ │ ├── ethers-core v2.0.11 ()
│ │ ├── ethers-providers v2.0.11
│ │ │ ├── ethers-core v2.0.11 ()
│ ├── ethers-core v2.0.11 ()
│ ├── ethers-etherscan v2.0.11
│ │ ├── ethers-core v2.0.11 ()
│ ├── ethers-middleware v2.0.11
│ │ ├── ethers-contract v2.0.11 ()
│ │ ├── ethers-core v2.0.11 ()
│ │ ├── ethers-etherscan v2.0.11 ()
│ │ ├── ethers-providers v2.0.11 ()
│ │ ├── ethers-signers v2.0.11
│ │ │ ├── ethers-core v2.0.11 ()
│ ├── ethers-providers v2.0.11 ()
│ └── ethers-signers v2.0.11 ()
Platform
Darwin Kernel Version 21.6.0 (arm64, MacOS Monterey)
Description
abi::encode_packed
removes all leading zeroes from all uint256 (and I assume the same for all uint types). To be consistent with solidity and ethers-js it should keep these.I expected to see this happen:
solidity (0.8.0)
returns
0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658000000000000000000000000000000000000000000000000000000000000007b
.Instead, this happened:
ethers-rs
returns
9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb6587b
It is likely because this line
ethers-rs/ethers-core/src/abi/packed.rs
Line 118 in b730b74
n.bits()
instead ofn.bits() + n.trailing_zeroes()
.The text was updated successfully, but these errors were encountered: