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

abi.encodePacked for Uint #2658

Open
ratankaliani opened this issue Oct 31, 2023 · 0 comments
Open

abi.encodePacked for Uint #2658

ratankaliani opened this issue Oct 31, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@ratankaliani
Copy link

The implementation of abi.encodePacked for Uint's that are not U256 (ex. U64, U32) is incorrect.

Specifically into_token within encode_packed does not encode the parameters correctly.

Ex.
For abi.encodePacked(uint64, uint32), this is the expected output:

uint64 authoritySetId = 4;
uint32 trustedBlock = 10;
bytes memory encodedBytes = abi.encodePacked(authoritySetId,trustedBlock);
console.logBytes(encodedBytes);

Output:
0x00000000000000040000000a

However, when invoking the same with ethers-rs, this is the output:

let authority_set_id: u64 = 4;
let trusted_block_number: u32 = 10;

let input = encode_packed(&[
    authority_set_id.into_token(),
    trusted_block_number.into_token(),
]).expect("Failed to encode packed data.");
println!("input {:?}", hex::encode(input));

Output:
0x040a

The reason this is the case is that ethabi is the library that ethers-rs uses for encodePacked, and its implementation is deprecated.

Can we move ethers-rs ABI encoding to alloy-rs, which does abi.encodePacked here?

Beyond abi.encodePacked, alloy-rs should be substituted for ethabi as the latter is not actively maintained.

@rellfy Raised a similar issue here: #2494

@ratankaliani ratankaliani added the bug Something isn't working label Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant