validateOffer() reentry to manipulate exchangeRate
The validateOffer function updates the pool's outstanding loan accounting before the loan principal is transferred out, temporarily inflating the pool's exchange rate. An attacker can use a malicious validator callback during loan emission to redeem pool shares at this inflated rate and receive more assets than entitled.
Submitted by bin2chen
The current mechanism of validateOffer() is to first book _outstandingValues to increase, but assets.balanceOf(address(this)) doesn’t decrease immediately.
function validateOffer(bytes calldata _offer, uint256 _protocolFee) external override onlyAcceptedCallers {
..
/// @dev Since the balance of the pool includes capital that is waiting to be claimed by the queues,
/// we need to check if the pool has enough capital to fund the loan.
/// If that's not the case, and the principal is larger than the currentBalance, then we need to reallocate
/// part of it.
if (principalAmount > undeployedAssets) {
revert InsufficientAssetsError();
} else if (principalAmount > currentBalance) {
IBaseInterestAllocator(getBaseInterestAllocator).reallocate(
currentBalance, principalAmount - currentBalance, true
);
}
@> /// @dev If the txn doesn't revert, we can assume the loan was executed.
@> _outstandingValues = _getNewLoanAccounting(principalAmount, _netApr(apr, _protocolFee));
}
I.e.: After this method is called, _getUndeployedAssets() is unchanged, but _getTotalOutstandingValue() is increased, so totalAssets() is increased, but totalSupply is unchanged, so exchangeRate is get bigger.
Originally, it was expected that after that, the Pool balance would be transferred at MultiSourceLoan, so _getUndeployedAssets() becomes smaller and exchangeRate returns to normal. But if it’s possible to do callback malicious logic before MultiSourceLoan transfers away the Pool balance, it’s possible to take advantage of this exchangeRate that becomes larger.
Example: Suppose _getUndeployedAssets() = 1000, _getTotalOutstandingValue() = 1000 and totalSupply = 2000.
So:
totalAssets() = 2000 exchangeRate = 1:1
-
Alice calls
MultiSourceLoan.emitLoan().offer.lender = pool.offer.principalAmount= 500.offer.validators = CustomContract-> for callback.
-
emitLoan() -> Pool.validateOffer()._getUndeployedAssets()= 1000 (no change)._getTotalOutstandingValue()= 1000 + 500 = 1500 (more 500).totalAssets()= 2500.exchangeRate= 1.25 : 1.
-
emitLoan()->_checkValidators()->CustomContract.validateOffer()- In
CustomContract.validateOffer()callpool.redeem(shares) useexchangeRate = 1.25 : 1to get more assets.
- In
-
emitLoan()->asset.safeTransferFrom(pool, receiver, 500)._getUndeployedAssets()= 500.exchangeRateExpect to return to normal.
Impact
Manipulating the exchangeRate to redeem additional assets.
Recommended Mitigation
In validateOffer(), restrict offer.validators to be an empty array to avoid callbacks.
Assessed type
Context
validateOfferchanged to view so validators cannot change state.
Status: Mitigation confirmed. Full details in reports from oakcobalt, minhquanym and bin2chen.
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
Likely the pool updates its outstanding loan accounting before transferring the principal out, creating a temporary mismatch between totalAssets and totalSupply that a callback can exploit.
Impact
An attacker could manipulate the exchange rate to redeem additional assets from the pool.
What the attacker needed
Ability to create a loan offer with a custom validator; pool has sufficient undeployed assets
The fix
The validateOffer function was changed to a view function so validators cannot change state.
How it was found
- Alice calls MultiSourceLoan.emitLoan() with the pool as lender, a principal amount, and a custom validator contract for callbacks.
- emitLoan calls Pool.validateOffer(), which increases outstanding value and thus totalAssets and exchangeRate.
- emitLoan calls _checkValidators(), invoking the custom validator's validateOffer(), which calls pool.redeem to redeem shares at the inflated exchange rate.
- emitLoan transfers the principal from the pool, which is expected to bring the exchange rate back to normal.
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.
A pool lets people deposit money and receive shares representing their portion. The value of each share (the exchange rate) is calculated from the pool's total assets divided by total shares. The bug is that the pool temporarily counts a new loan as an asset before the loan money has actually left the pool, so the share price briefly looks higher. A malicious contract can take advantage of that moment to cash out shares at the inflated price.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.