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

Why bytes.concat() over abi.encode? #3

Open
RamanSB opened this issue Jul 16, 2024 · 0 comments
Open

Why bytes.concat() over abi.encode? #3

RamanSB opened this issue Jul 16, 2024 · 0 comments

Comments

@RamanSB
Copy link

RamanSB commented Jul 16, 2024

bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(account, amount))));

I noticed the following code for generating a Merkle leaf:
bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(account, amount))));
The goal is to perform a double hash to prevent second pre-image attacks. However, bytes.concat seems unnecessary for a single bytes32 value.

I would've suggested using abi.encode.

bytes32 leaf = keccak256(abi.encode(keccak256(abi.encode(account, amount))));

I appreciate that bytes.concat() accepts a bytesX (x is an integer <= 32) and returns bytes memory which is what we want to pass to our keccak256 to get the 2nd hash, but abi.encode also does the same thing which seems a lot more straightforward?

Chisel
image

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

No branches or pull requests

1 participant