abi.encodePacked
results in Hash Collision sometimes when two dynamic arguments are encoded with it. From the https://docs.soliditylang.org/en/v0.8.17/abi-spec.html?highlight=collisions#non-standard-packed-mode:
If you use keccak256(abi.encodePacked(a, b)) and both a and b are dynamic types, it is easy to craft collisions in the hash value by moving parts of an into b and vice-versa. More specifically, abi.encodePacked("a", "bc") == abi.encodePacked("ab", "c").
https://docs.soliditylang.org/en/v0.8.17/abi-spec.html?highlight=collisions#non-standard-packed-mode
As the solidity docs describe, two or more dynamic types are passed to abi.encodePacked. Moreover, these dynamic values are user-specified function arguments in external functions, meaning anyone can directly specify the value of these arguments when calling the function. Many users can fail an issue while claiming their prizes because of this.
Alice, a very deserving user, make a function call to claim their amount
But due to abi.encodePacked's hash collision verification fails
And Alice is unable to claim his prize.
Manual Review
Use abi.encode()
instead of abi.encodePacked()
, which will prevent hash collisions
Reference: https://github.com/sherlock-audit/2022-10-nftport-judging/issues/118
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.