Skip to content
Business logic Audit finding Intermediate

WithdrawProxy allows redeem() to be called before withdraw reserves are transferred in

The WithdrawProxy contract allows redeem() to be called before the withdraw reserve is transferred in, because the onlyWhenNoActiveAuction modifier does not block calls when no auction has started and totalAssets() is based on the contract's current balance. An attacker could deposit a small amount to make totalAssets() positive and trick a depositor into redeeming early, causing them to receive less than their fair share and benefiting remaining holders.

obront Follow with unforgiven and rvierdiiev

Originally disclosed on Code4rena

Submitted by obront, also found by unforgiven and rvierdiiev

https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/WithdrawProxy.sol#L152-L161

The WithdrawProxy contract has the onlyWhenNoActiveAuction modifier on the withdraw() and redeem() functions. This modifier stops these functions from being called when an auction is active:

modifier onlyWhenNoActiveAuction() {
  WPStorage storage s = _loadSlot();
  if (s.finalAuctionEnd != 0) {
    revert InvalidState(InvalidStates.NOT_CLAIMED);
  }
  _;
}

Furthermore, both withdraw() and redeem() can only be called when totalAssets() > 0 based on logic within those functions.

The intention of these two checks is that the WithdrawProxy shares can only be cashed out after the PublicVault has called transferWithdrawReserve.

However, because s.finalAuctionEnd == 0 before an auction has started, and totalAssets() is calculated by taking the balance of the contract directly (ERC20(asset()).balanceOf(address(this));), a user may redeem their shares before the vault has been fully funded, and take less than their share of the balance, benefiting the other withdrawer.

Proof of Concept

  • A depositor decides to withdraw from the PublicVault and receives WithdrawProxy shares in return
  • A malicious actor deposits a small amount of the underlying asset into the WithdrawProxy, making totalAssets() > 0
  • The depositor accidentally redeems, or is tricked into redeeming, from the WithdrawProxy, getting only a share of the small amount of the underlying asset rather than their share of the full withdrawal
  • PublicVault properly processes epoch and full withdrawReserve is sent to WithdrawProxy
  • All remaining holders of WithdrawProxy shares receive an outsized share of the withdrawReserve

Recommended Mitigation Steps

Add an additional storage variable that is explicitly switched to open when it is safe to withdraw funds.

SantiagoGregory (Astaria) acknowledged and commented:

This is intentional, the UI will block people from redeeming early. The option is there both to save some gas, and as a last resort if an LP urgently needs money (it will only make it better for the rest of the LPs).

Picodes (judge) commented:

I do consider this a valid medium severity issue, considering there is the onlyWhenNoActiveAuction so the intent of the code is not to block people from redeeming early but to prevent them from doing so. Note that the sponsor is right to highlight that it could be desirable to have an emergencyRedeemFunction where LPs do not wait for the completion of auctions.


The original report as published on Code4rena, by obront. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Likely the onlyWhenNoActiveAuction modifier only checks if an auction has ended, not if it has started, and totalAssets() uses the contract's current balance, so early redemption is possible before the reserve is transferred.

Impact

A depositor could receive less than their fair share if they redeem early, and the remaining holders would receive more; the sponsor states this is intentional and the UI blocks early redemption, but the judge considers it a valid medium severity issue.

What the attacker needed

A depositor with WithdrawProxy shares; attacker can deposit a small amount; victim redeems early

The fix

The sponsor states this is intentional and the UI blocks early redemption, but the recommended mitigation is to add a storage variable that explicitly allows withdrawals only when safe.

How it was found

  1. A depositor decides to withdraw from the PublicVault and receives WithdrawProxy shares in return
  2. A malicious actor deposits a small amount of the underlying asset into the WithdrawProxy, making totalAssets() > 0
  3. The depositor accidentally redeems, or is tricked into redeeming, from the WithdrawProxy, getting only a share of the small amount of the underlying asset rather than their share of the full withdrawal
  4. PublicVault properly processes epoch and full withdrawReserve is sent to WithdrawProxy
  5. All remaining holders of WithdrawProxy shares receive an outsized share of the withdrawReserve

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.

A withdraw proxy holds shares that let people claim their portion of funds after a withdrawal. The code intended to stop people from cashing out too early, but a check was missing for the time before any auction starts. Someone could add a tiny amount to the contract and then convince a user to redeem, so that user gets very little while others get more later.

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.

More by obront

View all

46 more disclosed reports, best first.

More from Astaria contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.