The getUserDeposits
function in the PerpetualVault
contract uses a uint8
type for the loop variable i
. This poses a potential integer overflow risk if the number of deposits (length
) exceeds 255, as uint8
can only store values from 0 to 255. If length
is greater than 255, the loop variable i
will overflow, leading to unexpected behavior such as infinite loops or incorrect results.
Here is the relevant code snippet:
uint8
Range: The uint8
type can only store values from 0 to 255. If length
exceeds 255, the loop variable i
will overflow when it reaches 256, resetting to 0.
Consequences:
Infinite Loop: If length
is greater than 255, the loop will never terminate because i
will repeatedly overflow and reset to 0.
Incorrect Results: If the loop does not terminate, the function may return incomplete or incorrect data, or it may run out of gas and revert.
A user has 300 deposits in the userDeposits
set.
The length
variable is set to 300.
The loop starts with i = 0
and increments until i = 255
.
When i
reaches 256, it overflows and resets to 0.
The loop continues indefinitely, causing the transaction to run out of gas or revert.
The impact is Medium because the getUserDeposits
function will always revert if a user has more than 256 deposits. The likelihood is Medium, so the severity is Medium.
Manual Review
Consider following fix:
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood 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.