confirmBaseInterestAllocator() change BaseInterestAllocator may pay large getReallocationBonus
When the owner confirms a new base interest allocator, the old allocator's entire balance is transferred back into the pool, which can dramatically increase the pool's assets. A subsequent user calling reallocate() then receives an outsized bonus because the bonus calculation uses the large delta between current balance and target idle.
Submitted by bin2chen
owner can submit getPendingBaseInterestAllocator first, and then anyone can enable it by confirmBaseInterestAllocator().
function confirmBaseInterestAllocator(address _newBaseInterestAllocator) external {
address cachedAllocator = getBaseInterestAllocator;
if (cachedAllocator != address(0)) {
if (getPendingBaseInterestAllocatorSetTime + UPDATE_WAITING_TIME > block.timestamp) {
revert TooSoonError();
}
if (getPendingBaseInterestAllocator != _newBaseInterestAllocator) {
revert InvalidInputError();
}
@> IBaseInterestAllocator(cachedAllocator).transferAll();
asset.approve(cachedAllocator, 0);
}
asset.approve(_newBaseInterestAllocator, type(uint256).max);
getBaseInterestAllocator = _newBaseInterestAllocator;
getPendingBaseInterestAllocator = address(0);
getPendingBaseInterestAllocatorSetTime = type(uint256).max;
emit BaseInterestAllocatorSet(_newBaseInterestAllocator);
}
The current logic is:
- Take all the balance of the old
BaseInterestAllocatorand put it inPool. - Change
getBaseInterestAllocatorto the newBaseInterestAllocator.
If the old BaseInterestAllocator already has a large balance, the balance of the Pool will increase dramatically. Subsequent users executing reallocate() will get a big bonus getReallocationBonus.
function reallocate() external nonReentrant returns (uint256) {
(uint256 currentBalance, uint256 targetIdle) = _reallocate();
uint256 delta = currentBalance > targetIdle ? currentBalance - targetIdle : targetIdle - currentBalance;
@> uint256 shares = delta.mulDivDown(totalSupply * getReallocationBonus, totalAssets() * _BPS);
_mint(msg.sender, shares);
emit Reallocated(delta, shares);
return shares;
}
Assuming old BaseInterestAllocator balance: 1 M: shares = 1 M * (1 - optimalIdleRange.mid) * totalSupply * getReallocationBonus / totalAssets()
Impact
After change, BaseInterestAllocator may pay large getReallocationBonus.
Recommended Mitigation
Execute _reallocate() in the confirmBaseInterestAllocator() method without paying any getReallocationBonus.
function confirmBaseInterestAllocator(address _newBaseInterestAllocator) external {
address cachedAllocator = getBaseInterestAllocator;
if (cachedAllocator != address(0)) {
if (getPendingBaseInterestAllocatorSetTime + UPDATE_WAITING_TIME > block.timestamp) {
revert TooSoonError();
}
if (getPendingBaseInterestAllocator != _newBaseInterestAllocator) {
revert InvalidInputError();
}
IBaseInterestAllocator(cachedAllocator).transferAll();
asset.approve(cachedAllocator, 0);
}
asset.approve(_newBaseInterestAllocator, type(uint256).max);
getBaseInterestAllocator = _newBaseInterestAllocator;
getPendingBaseInterestAllocator = address(0);
getPendingBaseInterestAllocatorSetTime = type(uint256).max;
+ if (cachedAllocator != address(0)) {
+ _reallocate();
+ }
emit BaseInterestAllocatorSet(_newBaseInterestAllocator);
}
Assessed type
Context
0xA5DF (judge) decreased severity to Medium and commented:
Marking as Medium since it’ll only take the fee part (which is only a small percentage I guess). I guess also the allocator isn’t going to change very often.
Proactively reallocate (we got rid of the bonus though).
Status: Mitigation confirmed. Full details in reports from oakcobalt 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 confirmBaseInterestAllocator function transfers the old allocator's balance into the pool without immediately rebalancing, so the next reallocate call sees an artificially large delta and mints an excessive bonus.
Impact
After the allocator change, the next reallocate caller may receive a large bonus, though the judge noted it only affects the fee portion and the allocator is unlikely to change often.
What the attacker needed
Owner sets a pending allocator; waiting time passes; old allocator holds a large balance
The fix
The confirmBaseInterestAllocator function should call _reallocate() immediately after transferring the old allocator's balance, so no bonus is paid for that internal rebalancing.
How it was found
- The owner sets a pending base interest allocator.
- After the waiting time, anyone calls confirmBaseInterestAllocator to switch to the new allocator.
- The old allocator's entire balance is transferred back into the pool.
- A user then calls reallocate(), which calculates a large delta and mints a large bonus.
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 smart contract holds funds in a helper contract called an allocator. When the owner switches to a new allocator, all the old allocator's funds are moved back into the main pool. The pool then looks much larger than usual, and the next person who triggers a rebalancing action gets a bonus calculated from that inflated size, so they receive more than they 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.