Summary
DebtToken's balanceOf
function uses potentially stale normalized debt values from LendingPool
, allowing users to manipulate their debt positions by timing transactions around index updates.
Vulnerability Details
balanceOf
relies on ILendingPool.getNormalizedDebt()
, which may not be updated.
DebtToken.sol#balanceOf
function balanceOf(address account) public view override(ERC20, IERC20) returns (uint256) {
uint256 scaledBalance = super.balanceOf(account);
return scaledBalance.rayMul(ILendingPool(_reservePool).getNormalizedDebt());
}
Impact
Incorrect debt calculations.
Tools Used
manual
Recommendations
Ensure LendingPool updates state before critical operations.
function updateState() public returns (uint256) {
uint256 previousIndex = _normalizedDebt;
uint256 timeDelta = block.timestamp - lastUpdateTimestamp;
if (timeDelta > 0) {
uint256 interestRate = _calculateInterestRate();
_normalizedDebt = _normalizedDebt.rayMul(
interestRate.rayMul(timeDelta)
);
lastUpdateTimestamp = block.timestamp;
emit StateUpdated(_normalizedDebt, interestRate);
}
return _normalizedDebt;
}
function borrow(uint256 amount) external {
updateState();
}
function repay(uint256 amount) external {
updateState();
}
function liquidate(address user) external {
updateState();
}