Position doesn’t distribute rewards to users
The Position contract holds cTokens that earn Compound rewards, but it never claims them, so position owners do not receive their rewards and other market users have their rewards diluted.
Submitted by Ruhum, also found by immeas, John and rvierdiiev.
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/poolsUtility/Position.sol#L350-L379 https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/utilities/poolsUtility/Position.sol#L271-L277 https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/BathHouseV2.sol#L113-L128
In Compound V2, both borrowers and suppliers are eligible to earn rewards. The Position contract allows users to create long/short positions for each market. For that, it both supplies and borrows tokens from a compound market. So while the user is the one who provided the initial tokens to open up a position, it’s the Position contract that holds the cTokens that earn the rewards. These rewards are not distributed to position owners. Instead, they are locked up as the Position contract never claims them. That also means that anybody else who uses the market has their rewards diluted.
Proof of Concept
Whenever cTokens are minted, transferred or burned, the Comptroller is notified to distribute rewards. When cTokens are minted, mintFresh() triggers Comptroller.mintAllowed() which distributes rewards through distributeSupplierComp().
// CToken.sol
function mintFresh(address minter, uint mintAmount) internal {
/* Fail if mint not allowed */
uint allowed = comptroller.mintAllowed(address(this), minter, mintAmount);
// ...
}
// Comptroller.sol
function mintAllowed(
address cToken,
address minter,
uint mintAmount
) external override returns (uint) {
// Pausing is a very serious situation - we revert to sound the alarms
require(!mintGuardianPaused[cToken], "mint is paused");
// Shh - currently unused
minter;
mintAmount;
if (!markets[cToken].isListed) {
return uint(Error.MARKET_NOT_LISTED);
}
// Keep the flywheel moving
updateCompSupplyIndex(cToken);
distributeSupplierComp(cToken, minter);
return uint(Error.NO_ERROR);
}
The Position contract supplies and borrows tokens from the market when opening up a new position or updating an existing one:
/// @notice borrow `_amount` of underlying token of `_cToken`
function _borrow(address _cToken, uint256 _amount) internal {
require(
CErc20Interface(_cToken).borrow(_amount) == 0,
"_borrow: BORROW FAILED"
);
}
function _supply(
address _token,
address _bathToken,
uint256 _amount
) internal returns (uint256 _bathTokenAmount) {
uint256 _initBathTokenAmount = IERC20(_bathToken).balanceOf(
address(this)
);
IERC20(_token).safeApprove(_bathToken, _amount);
require(
CErc20Interface(_bathToken).mint(_amount) == 0,
"_supply: MINT FAILED"
);
uint256 _currentBathTokenAmount = IERC20(_bathToken).balanceOf(
address(this)
);
assembly {
switch _initBathTokenAmount
case 0 {
_bathTokenAmount := _currentBathTokenAmount
}
default {
_bathTokenAmount := sub(
_currentBathTokenAmount,
_initBathTokenAmount
)
}
}
}
In BathHouseV2 we can see that the protocol expects to use the Comptroller rewards mechanism. It calls claimComp() to harvest those rewards for the caller:
/// @notice claim available rewards
/// across all the pools
function claimRewards(
address[] memory buddies,
address[] memory rewardsTokens
) external {
// claim rewards from comptroller
comptroller.claimComp(msg.sender);
// get rewards from bathBuddy
for (uint256 i = 0; i < buddies.length; ++i) {
IBathBuddy(buddies[i]).getReward(
IERC20(rewardsTokens[i]),
msg.sender
);
}
}
To claim the rewards, the Position contract also has to call claimComp(), but it never does. Thus, the rewards are accrued to the Position contract but never claimed.
Recommended Mitigation Steps
The Position contract has to distribute rewards to users.
Considering this to be High severity because of certain and total loss of yield without additional requirements.
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 Position contract never calls claimComp() to collect the rewards it accrues, so they remain unclaimed.
Impact
Position owners lose all of their yield, and other users of the market have their rewards diluted.
What the attacker needed
User opens a position via Position contract
The fix
The Position contract should claim and distribute the accrued rewards to position owners.
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.
When you supply tokens to a lending market, you earn extra reward tokens. Here, a helper contract holds the supplied tokens, so it earns the rewards instead of the user. Because the helper never collects those rewards, they are stuck and everyone else's share is reduced.
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.