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

Potential Hash Collision in Starklane's _consumeMessageAutoWithdraw Function

Summary

The _consumeMessageAutoWithdraw function in Starklane contract is responsible for processing withdrawal messages automatically. However, the use of abi.encodePacked() with dynamic types when generating the message hash using keccak256() poses a risk of hash collisions.

Vulnerability Details

Function _consumeMessageAutoWithdraw generates a hash (msgHash) using keccak256() function, with the input generated by abi.encodePacked(). However, abi.encodePacked() can lead to ambiguous encoding when used with dynamic types, such as arrays or strings, which may result in hash collisions. When the result of abi.encodePacked() is passed to keccak256(), different sets of input data can produce the same hash, potentially allowing malicious actors to manipulate or replay messages.

Impact

This vulnerability could lead to unauthorized withdrawals or the failure to correctly process withdrawal messages, compromising the security and reliability of the Starklane contract. An attacker could potentially craft inputs that result in the same hash, leading to the incorrect processing of messages or even financial loss.

Tools Used

Manual Review

Recommendations

To mitigate the risk of hash collisions, _consumeMessageAutoWithdraw function should be refactored to use abi.encode() instead of abi.encodePacked() when generating the hash. This ensures that dynamic types are encoded in a non-ambiguous way, preventing potential collisions.

function _consumeMessageAutoWithdraw(
snaddress fromL2Address,
uint256[] memory request
)
internal
{
bytes32 msgHash = keccak256(
abi.encode(
snaddress.unwrap(fromL2Address),
uint256(uint160(address(this))),
request.length,
request // Use abi.encode() instead of abi.encodePacked()
)
);
uint256 status = _autoWithdrawn[msgHash];
if (status == WITHDRAW_AUTO_CONSUMED) {
revert WithdrawAlreadyError();
}
_autoWithdrawn[msgHash] = WITHDRAW_AUTO_CONSUMED;
}
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.