Severe Precision Issues in QuantAMMStorage
Due to Cast and Shift Operation
The QuantAMMStorage
contract contains severe vulnerabilities in its integer handling mechanisms, including overflow in the _quantAMMPackTwo128
function and precision loss during casting in the _quantAMMPack128Array
function. This could lead to data corruption, and potential fund losses in the protocol.
1. Integer Overflow in _quantAMMPackTwo128
Here's the implementation of _quantAMMPackTwo128
function in QuantAMMStorage contract:
The _quantAMMPackTwo128
function suffers from an integer overflow due to improper handling of left shift operations. The left shift operation (_leftInt << 128)
is performed without proper type casting, leading to bit loss during the operation.
2. Precision Loss in _quantAMMPack128Array
Here's the implementation of _quantAMMPack128Array
function in QuantAMMStorage contract:
Above function introduces precision loss when handling arrays with odd lengths. The last element is cast from int256 to int128 and back to int256, leading to truncation if the value exceeds the int128 range.
Data corruption and fund loss in storage.
Incorrect financial calculations and state representation.
Manual Review
Cast to uint256 before performing shift operations in _quantAMMPackTwo128
to prevent overflow and bit loss.
Add range checks in _quantAMMPack128Array
to ensure values fit within int128 range and avoid truncation.
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.