Solidity – Which Was Standard in Solidity Compiler Before Solidity 0.5: abi.encodePacked or abi.encode?

byteskeccaksolidity

Before Solidity v0.5, keccak256() took multiple arguments, and after v0.5 it requires a single bytes argument. Which of the two encoding types, encode/encodePacked, did the compiler use?

Best Answer

It was abi.encodePacked(). keccak256(abi.encodePacked(a, b, c)) on 0.5+ is equivalent to keccak256(a, b, c) in earlier versions.

Solidity v0.5.0 Breaking Changes > Semantic and Syntactic Changes

The functions .call(), .delegatecall(), staticcall(), keccak256(), sha256() and ripemd160() now accept only a single bytes argument. Moreover, the argument is not padded. This was changed to make more explicit and clear how the arguments are concatenated. Change every .call() (and family) to a .call("") and every .call(signature, a, b, c) to use .call(abi.encodeWithSignature(signature, a, b, c)) (the last one only works for value types). Change every keccak256(a, b, c) to keccak256(abi.encodePacked(a, b, c)).