A critical integer overflow vulnerability has been identified in the _quantAMMPackTwo128 function of the QuantAMMStorage contract. This function is designed to pack two 128-bit integers into a single 256-bit storage slot, but its implementation can lead to silent data corruption due to an unprotected left shift operation.
The root cause is performing a large bit shift operation on an integer without proper type casting to preserve the bits during the shift operation. While the input validation prevents obviously invalid inputs, it doesn't protect against the mechanics of how Solidity handles large shift operations.
The vulnerability occurs in the left shift operation _leftInt << 128. While the function includes bounds checking to ensure input values are within int128 range, the shift operation itself is performed before any type casting, which can lead to bit loss during the shift operation.
In Solidity, when shifting integers, if the shift amount equals or exceeds the bit width of the type, the result is undefined. In this case, shifting a large int256 value by 128 bits can lead to data corruption, even if the original value was within the valid int128 range.
As an example consider these inputs:
_leftInt = 2^127 - 1 (maximum valid int128)
When shifted left by 128 bits, bits are lost during the operation
The resulting packed value will not correctly represent the original number in the upper 128 bits
Silent data corruption in storage
Incorrect financial calculations in the AMM
Potential economic losses if the corrupted values are used in trading calculations
System state inconsistency
Cast to uint256 before the shift operation to ensures no bits are lost during the shift.
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.