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

Deprecate variable argument mode of keccak256/sha256/ripemd160 #3955

Closed
axic opened this issue Apr 19, 2018 · 10 comments
Closed

Deprecate variable argument mode of keccak256/sha256/ripemd160 #3955

axic opened this issue Apr 19, 2018 · 10 comments

Comments

@axic
Copy link
Member

axic commented Apr 19, 2018

Right now these functions accept a variable number of arguments and produce a tight packed version.

Some warnings are already displayed for tight packing literals. #982 proposes to turn those warnings into errors.

The new abi.encode*() methods offer a replacement to perform packing, which then can be passed to all these hashing functions.

Proposal is to raise a warning now when these hashing functions receive multiple arguments or the first and only argument isn't of bytes type.

@axic
Copy link
Member Author

axic commented Apr 20, 2018

A deprecation warning could be added which suggest to use keccak256(abi.encodePacked(...)).

@chriseth
Copy link
Contributor

This should also include call and delegatecall. Especially for those, empty arguments should be fine without warning.

@chriseth
Copy link
Contributor

chriseth commented May 9, 2018

Result of discussion: Add a warning for hash functions, and do the rest (including call*) with 0.5.0 proper.

@chriseth
Copy link
Contributor

chriseth commented May 9, 2018

Related: #3789

@AlexeyAkhunov
Copy link

Hi guys! I have noticed that there is a difference between versions 0.4.23 and 0.4.24 in how code for keccak256(abi.encodePacked(...)) is generated. In version 0.4.23, the memory segment which is result of abi.encodePacked is passed directly to keccak256, but in 0.4.24, an extra loop is generated, to create another copy of the same byte string in memory, before passing it to keccak256(). Both behaviours are equivalent, it is just 0.4.24 generates more code and spends more gas. Was it interntional?

@chriseth
Copy link
Contributor

@AlexeyAkhunov are you sure this is really the case or are you comparing sha3(x) to sha3(abi.encodePacked(x))? This will be optimized for 0.5.0, but we can only do it with a breaking change, I think.

@AlexeyAkhunov
Copy link

AlexeyAkhunov commented May 30, 2018

@chriseth This was specifically the line I was looking at: https://github.com/gnosis/safe-contracts/blob/76b70e83151530fa5d72d45f937abed8294be01a/contracts/GnosisSafePersonalEdition.sol#L152

I tried to do "solc --asm" (without optimiser) with 0.4.23 and 0.4.24, and there was an extra loop generated with 0.4.24. I will double-check again

@AlexeyAkhunov
Copy link

@chriseth I am going to make a very small 1-line example and confirm if it occurs there

@AlexeyAkhunov
Copy link

@chriseth I made a small example, and the loop is generated in both versions. I must have missed it somehow the first time. Sorry for trouble

@AlexeyAkhunov
Copy link

@chriseth I was indeed looking at the version which did not have abi.encodePacked() function earlier. Mystery is solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants