-
Notifications
You must be signed in to change notification settings - Fork 795
abi.encodePacked mismatch between rust and solidity #2225
Comments
@DaniPopes is this right? ethers-rs/ethers-core/src/abi/packed.rs Line 118 in 73636a9
|
This function doesn't compile in Solidity with: The input is ambiguous, I'll assume that you tried this code instead: function get_keccak_hash_of_uint256(uint256 x) public pure returns(bytes32) {
return keccak256(abi.encodePacked(x));
} When called with This is because the number is padded to the length of uint256 (32 bytes). Our If you want the padding of a let n = ...;
let n = U256::from(n);
let mut buf = [0; 32];
n.to_big_endian(&mut buf);
let start = 32 - N / 8;
let uintN = Token::Bytes(buf[start..32].to_vec());
Please see the discussion in the PR (#2104 (comment)). |
aah, the encodePacked name is kinda of a misnomer I was under the impression the solidity encodePacked would only use the minimum number of bits required ? it dint seem that to be the case or I misunderstand it even now. |
Version
1.5.0
Platform
Darwin random-MacBook-Pro.local 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:39:46 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6020 arm64
Description
BUG : coded the same thing in solidity and rust, a function that returns the hash of a encodePacked uint256,
but apparently the outputs don't match,
Reason to do this :A sanity check since a more advance use case which I needed to do wasn't matching up with the solidity output, to my surprise the sanity check also failed
I tried this code(Rust Version):
Solidity Version :
I expected to see this happen(Solidity Output:
bytes32: 0x036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db0
Instead, this happened (rust output) : 0xdbb8d0f4c497851a5043c6363657698cb1387682cac2f786c731f8936109d795
Posted this on telegram , was told it could better be checked out as a gh issue with the code, hopefully with your help I can get to the bottom of this annoying discrepancy.
The text was updated successfully, but these errors were encountered: