# The bot won't be able to unstake or repay risky positions in the yield contract

YieldStakingBase uses msg.sender to look up the yield account, so botAdmin's unstake/repay of risky positions targets the wrong account and reverts.

- Payout: Audit contest
- Severity: high
- Program: BendDAO
- Found by: SpicyMeatball
- Disclosed: 2024-09-03
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-07-benddao-findings/issues/6
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-benddao%3AH-08
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:business-logic

**Target:** YieldStakingBase.sol yield staking contract (unstake/repay)
**Root cause:** _unstake and _repay resolve the borrower's yield account via yieldAccounts[msg.sender] instead of the position owner, so when botAdmin calls them the lookup returns botAdmin's (nonexistent) account.
**Steps:**
1. botAdmin calls unstake/repay for a risky borrower position
2. _unstake/_repay executes `vars.yieldAccout = IYieldAccount(yieldAccounts[msg.sender])` with msg.sender = botAdmin
3. require(yieldAccounts[botAdmin] != 0) fails or wrong account data is used
4. transaction reverts; risky position cannot be force-closed
**How found:** Code reading of the access-controlled unstake/repay paths revealed the account lookup keyed on msg.sender rather than the position owner, breaking the botAdmin force-close flow.
**Insight:** When a function is callable by both owner and an admin/bot, check every lookup keyed on msg.sender — admin paths need an explicit user parameter or they resolve the wrong account.

## Proof of concept (copied exactly from the original report)

**Buggy _unstake and _repay using msg.sender for yield account**

```
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);
```

