Using abi.encodePacked()
with multiple variable-length arguments in Solidity can lead to potential hash collisions, which may compromise data integrity or lead to unexpected behavior. This issue arises because abi.encodePacked()
concatenates dynamic types without delimiters, making it possible for different inputs to produce the same encoded result.
When abi.encodePacked()
is used with multiple variable-length arguments, such as strings or arrays, it does not include boundary markers between the concatenated elements. This can cause hash collisions where different sets of inputs yield the same hash output. In security-sensitive functions or data verification mechanisms, this lack of boundaries can be exploited to manipulate inputs and bypass verification processes.
For example, encoding ("foo", "bar")
using abi.encodePacked("foo", "bar")
will produce the same result as abi.encodePacked("fo", "obar")
. This ambiguity poses a risk, especially when the encoded result is used for hashing or digital signatures, as an attacker could potentially craft inputs that yield identical hashes and circumvent security checks.
If used in contexts involving hashing or digital signatures, such as authorization checks or metadata generation, hash collisions caused by abi.encodePacked()
can allow attackers to bypass verification or manipulate metadata.
Manual review
Instead of abi.encodePacked()
, use abi.encode()
to encode data safely. Unlike abi.encodePacked()
, abi.encode()
includes type information and padding in the encoding, which prevents hash collisions by making the encoding unambiguous. This simple switch mitigates the risk of hash collisions and ensures data integrity for security-sensitive operations.
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.