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(dyn-abi): abi-encode-packed always pads arrays #519

Merged
merged 2 commits into from
Feb 7, 2024

Conversation

bernard-wagner
Copy link
Contributor

@bernard-wagner bernard-wagner commented Feb 7, 2024

Motivation

abi.encodePacked() always pads array elements as 32-bytes.

The behavior for tuples and structs is worth discussing since the solidity encoder does not support either. Tuples are useful at the top-level, but should probably be disallowed when nested.

Compare fixed_array_of_addresses to the equivalent Solidity code:

address[2] memory fixed_array_of_addresses;
fixed_array_of_addresses[0] = 0x1111111111111111111111111111111111111111;
fixed_array_of_addresses[1] = 0x2222222222222222222222222222222222222222;
abi.encodePacked(fixed_array_of_addresses); // 0x00000000000000000000000011111111111111111111111111111111111111110000000000000000000000002222222222222222222222222222222222222222

@bernard-wagner
Copy link
Contributor Author

@DaniPopes hoping to get your thoughts on this.

@DaniPopes
Copy link
Member

DaniPopes commented Feb 7, 2024

I see, this makes sense (link):

The encoding of an array is the concatenation of the encoding of its elements with padding.

We should probably do the same as Solidity, which disables all structs and nested dynamic arrays: https://github.com/ethereum/solidity/blob/bf59ff8bdf4fe104e558cb697abfc8f3b33daaba/libsolidity/analysis/TypeChecker.cpp#L59
We can do this in a follow-up PR.

@bernard-wagner bernard-wagner marked this pull request as ready for review February 7, 2024 19:40
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

lgtm, needs fmt

@DaniPopes DaniPopes merged commit 4edbe01 into alloy-rs:main Feb 7, 2024
21 checks passed
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.

2 participants