AFAIK there are 3 hash functions to choose from in solidity (sha3, sha256, and ripemd). sha3 is native while the others use precompiled contracts.
Which one of these is cheapest (in terms of gas)?
AFAIK there are 3 hash functions to choose from in solidity (sha3, sha256, and ripemd). sha3 is native while the others use precompiled contracts.
Which one of these is cheapest (in terms of gas)?
keccak256 (new alias for sha3) is cheapest.
Source: Yellow Paper
Appendix G mentions the gas cost of sha3 is:
Appendix E has the costs for the others.
sha256 (SHA2-256) costs:
ripemd is even more expensive:
sha3 built-in function (as opposed to the assembly directive) currently appear to create a contract invocation in Solidity, which is much more expensive than it needs to be.
– Nick Johnson
Apr 20 '16 at 09:52
blah = sha3(blah blah) and assembly { blah = sha3(blahblahblah) } ?
– bekah
Nov 28 '16 at 10:19
sha3 is not exactly keccak256. Ethereum source code for keccak256 confirms it.
– Tharindu Madushanka
Jul 29 '21 at 11:11
sha3. "The Ethereum hashing function, keccak256, sometimes (erroneously) called sha3"
https://github.com/ethereum/eth-hash
– Tharindu Madushanka
Jul 31 '21 at 03:54
keccak256(abi.encodePacked(...)) and via assembly {c := keccak256(add(encoded, 0x20), 40)}. The assembly version actually ended up costing 11 gas more.
– UTF-8
Jul 12 '22 at 11:26