QuantAMM

QuantAMM
49,600 OP
View results
Submission Details
Severity: low
Invalid

Incorrect array length validation in matrix packing function

Summary

The _quantAMMPack128Matrix function in VectorRuleQuantAMMStorage contract fails to enforce the correct array length for storing packed matrix elements. For a 3x3 matrix example, the target array must be exactly 5 elements as specified in the comments, but the code allows for different lengths.

Vulnerability Details

Here's the current implementation:

uint targetArrayLength = _targetArray.length;
require(targetArrayLength * 2 >= _sourceMatrix.length * _sourceMatrix.length, "Matrix doesnt fit storage");

https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/QuantAMMStorage.sol#L386C7-L388C1

The comment clearly states:

// becomes array of 5 elements, the last being half filled
// | 1 2 | 3 4 | 5 6 | 7 8 | 9 _ |

https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/QuantAMMStorage.sol#L380C6-L382C43

For a 3x3 matrix with 9 elements:

  • Each storage slot holds 2 elements (except the last one)

  • 8 elements require 4 full slots

  • The 9th element requires 1 half-filled slot

  • Total required slots = 5

However, the validation only checks if the target array is large enough (>=) rather than enforcing an exact size match for optimal storage usage.

require(targetArrayLength * 2 >= _sourceMatrix.length * _sourceMatrix.length, "Matrix doesnt fit storage");

Similar issue is in _quantAMMUnpack128Matrix function:

https://github.com/Cyfrin/2024-12-quantamm/blob/a775db4273eb36e7b4536c5b60207c9f17541b92/pkg/pool-quantamm/contracts/QuantAMMStorage.sol#L429C8-L436C111


Impact

The current implementation allows arrays larger than necessary and it is inconsistent with the documented design.

Tools Used

Manual review

Recommendations

Implement the exact length validation.

Updates

Lead Judging Commences

n0kto Lead Judge 11 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas / Admin is trusted / Pool creation is trusted / User mistake / Suppositions

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Support

FAQs

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

Give us feedback!