The bot won’t be able to unstake or repay risky positions in the yield contract
The unstake and repay functions in the yield contract fetch the borrower's yield account using msg.sender instead of the actual borrower address. When the botAdmin tries to force-close a risky position, it uses the botAdmin's own yield account, causing the transaction to fail.
SpicyMeatball Follow with oakcobalt and bin2chen
Originally disclosed on Code4rena
Submitted by SpicyMeatball, also found by oakcobalt and bin2chen
https://github.com/code-423n4/2024-07-benddao/blob/main/src/yield/YieldStakingBase.sol#L312 https://github.com/code-423n4/2024-07-benddao/blob/main/src/yield/YieldStakingBase.sol#L384
Impact
When botAdmin attempts to unstake and repay risky positions, wrong account address will be used, causing the transaction to fail.
Proof of Concept
In the YieldStakingBase.sol contract, unstake and repay transaction can only be initiated by either the NFT owner or botAdmin. Unfortunately, there is a bug in which msg.sender is used to fetch borrower yield account address from the yieldAccounts mapping:
function _unstake(uint32 poolId, address nft, uint256 tokenId, uint256 unstakeFine) internal virtual {
UnstakeLocalVars memory vars;
>> vars.yieldAccout = IYieldAccount(yieldAccounts[msg.sender]);
require(address(vars.yieldAccout) != address(0), Errors.YIELD_ACCOUNT_NOT_EXIST);
function _repay(uint32 poolId, address nft, uint256 tokenId) internal virtual {
RepayLocalVars memory vars;
>> vars.yieldAccout = IYieldAccount(yieldAccounts[msg.sender]);
require(address(vars.yieldAccout) != address(0), Errors.YIELD_ACCOUNT_NOT_EXIST);
If botAdmin calls one of these functions, the protocol will attempt to use botAdmin yield account address instead of the borrower account, resulting in incorrect account data being used and transaction failure. Since botAdmin is the only address that can force close risky positions, this bug poses a high threat to the protocol.
Recommended Mitigation Steps
Allow specifying user address in unstake and repay functions:
+ function _unstake(uint32 poolId, address nft, address user, uint256 tokenId, uint256 unstakeFine) internal virtual {
UnstakeLocalVars memory vars;
+ vars.yieldAccout = IYieldAccount(yieldAccounts[user]);
+ require(user == msg.sender || botAdmin == msg.sender,
Errors.INVALID_CALLER);
require(address(vars.yieldAccout) != address(0), Errors.YIELD_ACCOUNT_NOT_EXIST);
thorseldon (BendDAO) confirmed and commented:
Fixed here.
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 functions use msg.sender to look up the yield account instead of the borrower's address, so when botAdmin calls them it retrieves the bot's own account.
Impact
The botAdmin cannot unstake or repay risky positions, so the protocol cannot force-close dangerous loans, which could lead to bad debt.
What the attacker needed
BotAdmin role; risky position exists
The fix
The functions should accept a user address parameter and look up the yield account for that user, while checking that the caller is either the user or botAdmin; the project confirmed it was fixed.
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.
In this smart contract, a special admin bot is supposed to close risky loans on behalf of users. But the code looks up the user's account using the caller's address (the bot) instead of the borrower's address, so it finds the wrong account and the action fails. This means the safety mechanism cannot work when it is needed most.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.