NFTBridge
60,000 USDC
View results
Submission Details
Severity: low
Invalid

Potential hash collision in `requestHash` function due to packed encoding

Summary

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.

Vulnerability Details

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:

  1. salt = 1, collection = 0x0000000000000000000000000000000000000001, toL2Address = 0x0000000000000000000000000000000000000001, tokenIds = [1, 2]

  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.

Impact

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.

Tools Used

  • Manual code review.

Recommendations

To avoid hash collisions, use abi.encode instead of abi.encodePacked.

function requestHash(
uint256 salt,
address collection,
snaddress toL2Address,
uint256[] memory tokenIds
)
internal
pure
returns (uint256)
{
bytes32 hash = keccak256(
abi.encode(
salt,
// Cairo uses felts, which are converted into u256 to compute keccak.
// As we use abi.encode, we want the address to also be 32 bytes long.
uint256(uint160(collection)),
snaddress.unwrap(toL2Address),
tokenIds
)
);
return uint256(hash);
}

By using abi.encode, you ensure that the inputs are encoded in a way that includes length information, reducing the risk of hash collisions.

Updates

Lead Judging Commences

n0kto Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

invalid-encodePacked-collision-known-issue

Known issue: lightchaser

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.