The requestHash
function in the Protocol.sol
uses abi.encodePacked
for encoding inputs before hashing with keccak256
. This can lead to hash collisions if the input types and values are not unique enough, potentially causing different inputs to produce the same hash.
The requestHash
function is designed to compute a hash for a bridge request using the keccak256
hashing algorithm. The function uses abi.encodePacked
to encode the inputs, which performs packed encoding. Packed encoding does not include length information or padding, making it open to hash collisions.
For example,lets consider the following two sets of inputs:
salt = 1
, collection = 0x0000000000000000000000000000000000000001
, toL2Address = 0x0000000000000000000000000000000000000001
, tokenIds = [1, 2]
salt = 0
, collection = 0x0000000000000000000000000000000000000001
, toL2Address = 0x0000000000000000000000000000000000000001
, tokenIds = [1, 2, 1]
Both of these inputs could produce the same packed encoding and thus the same hash, leading to a collision.
Incorrect identification of unique requests. It could also lead to potential replay attacks or unauthorized actions if different inputs produce the same hash and also potential loss of funds or other assets.
Manual code review.
To avoid hash collisions, use abi.encode
instead of abi.encodePacked
.
By using abi.encode
, you ensure that the inputs are encoded in a way that includes length information, reducing the risk of hash collisions.
Known issue: lightchaser
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.