The getUserDeposits function in the PerpetualVault contract is vulnerable to an integer overflow bug due to the use of a uint8 loop index when iterating through a user's deposit history. If a user has more than 256 deposits, the loop counter will overflow, causing incorrect execution behavior and potentially leading to infinite looping or unexpected reverts.
The issue arises in the following code snippet inside the getUserDeposits function:
The following test case demonstrates the vulnerability:
Function Reverts: If a user exceeds 256 deposits, calling getUserDeposits will fail, preventing them from retrieving their deposit history.
Incorrect Data Returned: If not handled correctly, the loop could return incomplete or incorrect deposit records.
Potential Denial of Service (DoS): Users with large deposit histories might be unable to retrieve their deposits, hindering withdrawals or accounting processes.
Manual Code Review
To fix this issue, update the loop index from uint8 to uint256:
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.