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

Potential Overflow in `cairoStringSerialize` and `cairoStringPack`

Summary

In cairoStringSerialize and cairoStringPack, string lengths and packing may lead to integer overflow if the input string is too large.

Vulnerability Details

In the cairoStringPack function:

uint256 packedLen = 1 + dataLen + 1 + 1;

The length calculation and subsequent packing might result in overflow if the string is excessively long, exceeding typical integer limits.

In the cairoStringSerialize function:

uint256[] memory packed = cairoStringPack(str);
for (uint256 i = 0; i < packed.length; i++) {
buf[offset + i] = packed[i];
}

If packed.length is very large, it might lead to out-of-bounds errors or inefficient gas usage.

Impact

Overflow in length calculations or packing may lead to unexpected contract behavior or excessive gas consumption. An attacker could exploit this to perform denial-of-service (DoS) attacks or cause the contract to behave unpredictably.

Tools Used

Manual Code Review

Recommendations

Limit Input Lengths: Implement checks to ensure that input strings do not exceed reasonable lengths:

require(bytes(str).length <= MAX_STRING_LENGTH, "String too long");

Use Safe Arithmetic: Consider using SafeMath libraries for all arithmetic operations to prevent overflow issues.

Gas Efficiency: Be aware of potential high gas costs due to large arrays or strings.

Updates

Lead Judging Commences

n0kto Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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