Use of block.number
leads to incorrect interest calculations
#1141
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
M-09
primary issue
Highest quality submission among a set of duplicates
satisfactory
satisfies C4 submission criteria; eligible for awards
selected for report
This submission will be included/highlighted in the audit report
Lines of code
https://github.com/code-423n4/2023-04-rubicon/blob/511636d889742296a54392875a35e4c0c4727bb7/contracts/utilities/poolsUtility/Position.sol#L327
Vulnerability details
The interests that need to be paid upon closing a position are computed as follows:
The interest rate is computed using the block delta, between
block.number
and the starting block.The issue is that block production on Optimism is currently not fixed:
Proof of Concept
Run the following command several times in the repo, using an optimism rpc url:
You will see that block are not produced at a constant rate.
Impact
Interest rates are currently manipulable and will result in users having to repay more interests than expected upon closing positions.
Tools Used
Manual Analysis
Mitigation
Use
block.timestamp
instead ofblock.number
for interest calculation. It will involve a lot of refactoring as theCompound
contractsbathToken
currently inherits from use a "per block" system.The text was updated successfully, but these errors were encountered: