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.
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.
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");
Dos and discrepamcy in state being packed by the _quantAMMUnpack128Array() due to array truncation
Manual review
Adjust the require statement to ensure that _sourceArray.length * 2 is equals to _targetArrayLength
Similar fix is needed in QuantAmmStorage.sol#QuantAmmUnpack32Array.
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.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.