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.
Commented
Apr 20, 2016 at 9:52
blah = sha3(blah blah)
and assembly { blah = sha3(blahblahblah) }
?