I'm developing a smart contract in Solidity in which I need to evaluate the hash of two concatenated bytes32. I don't have to concatenate the bytes32 since the sha3 function supports more than one parameters and I'm using it as:
sha3(first, second);
Where first and second are bytes32.
I'd like to know how the concatenation is performed in order to replicate the same hash result locally, or using an online evaluator of the keccak-256 hash function.
Best Answer
The arguments are expressed as bytes, left-padded with zeroes to the maximum length of the data type you've passed in, and concatenated without any kind of delimiter.
In Python, given two hex-encoded
bytes32
s prepended with a0x
calledfirst
andsecond
, it looks something like:The
decode_hex
there is turning hex into an array of bytes.PS the modern versions of Solidity and pysha, and probably the relevant library in whatever language you're using, now have versions of keccak called
keccak
orkeccak256
, so it's probably better to standardize on those.