Insufficient loop index (uint8) in getUserDeposits()
: risk of infinite loop due to an Overflow
In the function, the index i
of the loop is an uint8
and can therefore only have a maximum value of 255.
At the end of the loop, unchecked
implies that the function will not revert if i
= 256, but i
will take the value 0 (Overflow).
If a user has more than 255 deposits, the variable i
will never reach length
(>255).
The loop will therefore run indefinitely until there is no more gas and will revert with the “out of gas” error.
In the test below, the getUserDeposits()
function is called once after Alice has made 255 deposits.
On the second call, Alice has made a 256th deposit, and this time the function reverts as the loop in the function becomes infinite.
Add this function in PerpetualVault.t.sol :
The getUserDeposits()
function will always revert with the “out of gas” error for users with more than 255 deposits. It is therefore impossible to retrieve all the deposits id of this user.
In the front-end, this list of deposits allows the user to choose which deposit to withdraw.
Users cannot withdraw their deposits via the protocol's front-end.
Impact is HIGH
The likelihood is LOW because 256 deposits with a minimum of $1000 is a lot, but over 1 or more years this number can be reached (via DCA for example)
MEDIUM
Manual review
Increase index size of the loop in getUserDeposits()
to anticipate cases where a user has a large number of deposits.
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.