Vault_Base_ERC20#_updateVirtualPrice calculates interest incorrectly if updated frequently
The virtual price update function calculates interest in 3-minute increments but stores the current timestamp instead of the truncated interval time, causing interest to be lost when called frequently. An attacker with a large loan could repeatedly call the function to effectively halve their interest accumulation.
Source: https://github.com/sherlock-audit/2022-11-isomorph-judging/issues/158
Found by
Jeiwan, libratus, wagmi, hansfriese, KingNFT, Atarpara, HollaDieWaldfee, 0x52, rvierdiiev, bin2chen
Summary
Updating the virtual price of an asset happens in discrete increments of 3 minutes. This is done to reduce the chance of DOS loops. The issue is that it updates the time to an incorrect timestamp. It should update to the truncated 3 minute interval but instead updates to the current timestamp. The result is that the interest calculation can be abused to lower effective interest rate.
Vulnerability Detail
function _updateVirtualPrice(uint256 _currentBlockTime, address _collateralAddress) internal {
( ,
,
,
uint256 interestPer3Min,
uint256 lastUpdateTime,
uint256 virtualPrice,
) = _getCollateral(_collateralAddress);
uint256 timeDelta = _currentBlockTime - lastUpdateTime;
//exit gracefully if two users call the function for the same collateral in the same 3min period
//@audit increments
uint256 threeMinuteDelta = timeDelta / 180;
if(threeMinuteDelta > 0) {
for (uint256 i = 0; i < threeMinuteDelta; i++ ){
virtualPrice = (virtualPrice * interestPer3Min) / LOAN_SCALE;
}
collateralBook.vaultUpdateVirtualPriceAndTime(_collateralAddress, virtualPrice, _currentBlockTime);
}
}
_updateVirtualPrice is used to update the interest calculations for the specified collateral and is always called with block.timestamp. Due to truncation threeMinuteDelta is always rounded down, that is if there has been 1.99 3-minute intervals it will truncate to 1. The issue is that in the collateralBook#vaultUpdateVirtualPriceAndTime subcall the time is updated to block.timestamp (_currentBlockTime).
Example: lastUpdateTime = 1000 and block.timestamp (_currentBlockTime) = 1359.
timeDelta = 1359 - 1000 = 359
threeMinuteDelta = 359 / 180 = 1
This updates the interest by only as single increment but pushes the new time forward 359 seconds. When called again it will use 1359 as lastUpdateTime which means that 179 seconds worth of interest have been permanently lost. Users with large loan positions could abuse this to effectively halve their interest accumulation. Given how cheap optimism transactions are it is highly likely this could be exploited profitably with a bot.
Impact
Interest calculations will be incorrect if they are updated frequently, which can be abused by users with large amounts of debt to halve their accumulated interest
Code Snippet
Tool used
Manual Review
Recommendation
Before updating the interest time it should first truncate it to the closest 3-minute interval:
if(threeMinuteDelta > 0) {
for (uint256 i = 0; i < threeMinuteDelta; i++ ){
virtualPrice = (virtualPrice * interestPer3Min) / LOAN_SCALE;
}
+ _currentBlockTime = (_currentBlockTime / 180) * 180;
collateralBook.vaultUpdateVirtualPriceAndTime(_collateralAddress, virtualPrice, _currentBlockTime);
}
Discussion
kree-dotcom
Fixed https://github.com/kree-dotcom/isomorph/commit/ae410496c024af5b061cf85997f225ae46fd56e6
lastUpdateTime is now only updated to the timestamp which we covered with our 3 minute interest update steps.
0x00052
Fixes look good. lastUpdateTime is now updated to the truncated time
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The function updates the last update time to the current block timestamp rather than truncating it to the nearest 3-minute interval, so partial intervals are discarded.
Impact
Interest calculations become incorrect when updated frequently, and a user with a large debt could exploit this to halve their accumulated interest, especially on low-cost chains like Optimism.
What the attacker needed
A loan position in the protocol; ability to call the update function frequently; low transaction costs (e.g., on Optimism)
The fix
The fix truncates the current block time to the nearest 3-minute interval before updating the stored time, ensuring no partial intervals are lost.
How it was found
- Call _updateVirtualPrice with a current block time that is not a multiple of 180 seconds after the last update.
- Observe that interest is incremented only for complete 3-minute intervals but the stored last update time becomes the current timestamp.
- Call the function again shortly after; the time delta starts from the new timestamp, losing the remainder seconds from the previous call.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This is a smart contract bug where interest is supposed to be added every 3 minutes. But when the function runs, it records the exact current time instead of rounding down to the last 3-minute mark. So if you call it often, you skip some interest payments and pay less than you should.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.