QuantAMM

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

Incorrect Equality Check in _quantAMMUnpack128Array Function

Summary

The _quantAMMUnpack128Array function in the provided Solidity code incorrectly sets an equality check in the require statement to >= instead of ==. This can lead to unintended behavior and potential errors in the function's logic.

Vulnerability Details

The require statement checks if _sourceArray.length * 2 is greater than or equal to _targetArrayLength (>=) instead of checking for equality (==). This can allow for cases where the lengths do not match as intended, leading to potential errors.

https://github.com/Cyfrin/2024-12-quantamm/blob/main/pkg/pool-quantamm/contracts/QuantAMMStorage.sol#L338-L346

function _quantAMMUnpack128Array(
int256[] memory _sourceArray, //50
uint _targetArrayLength // 50
) internal pure returns (int256[] memory targetArray) {
//
require(_sourceArray.length * 2 >= _targetArrayLength, "SRC!=TGT"); //should be require(_targetArrayLength == _sourceArray.length * 2, "SRC!=TGT");
targetArray = new int256[](_targetArrayLength); //targetArray is truncated if _targetArrayLength is wrong
uint targetIndex;

The _quantAMMUnpack128Array is often utilized by the updateRule.sol, QuantumVarianceBasedRule.sol and QuantumVarianceBasedRule.sol to repack states from 256 bits to 128 bit integers. The resulting integers(_targetArrayLength) is always going to be double the sourceArray length but the way the function is structured in this code will leave room for an occasion whereby the _targetArrayLength can be lesser than the expected index, thereby truncating the resulting 128 bit target array.

Also as being commented in the require statement the sourceArraylength * 2 Is expected to be strictly equal to the target array length ; , "SRC!=TGT");

Impact

Dos and discrepamcy in state being packed by the _quantAMMUnpack128Array() due to array truncation

Tools Used

Manual review

Recommendations

Adjust the require statement to ensure that _sourceArray.length * 2 is equals to _targetArrayLength

--require(_sourceArray.length * 2 >= _targetArrayLength, "SRC!=TGT");
++require(_sourceArray.length * 2 == _targetArrayLength, "SRC!=TGT");
targetArray = new int256[](_targetArrayLength);
uint targetIndex;

Similar fix is needed in QuantAmmStorage.sol#QuantAmmUnpack32Array.

Updates

Lead Judging Commences

n0kto Lead Judge 7 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.