Skip to content
Business logic Audit finding Advanced

Late users will take more losses than expected when the underlying contract ( EthAnchor ) suffers investment losses

When the underlying EthAnchor strategy suffers investment losses, the vault's share price calculation causes later depositors to receive more shares than they should, diluting earlier depositors and potentially causing the last users to lose all their funds.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

Even though it’s unlikely in practice, but in theory, the underlying contract (EthAnchor) may suffer investment losses and causing decreasing of the PPS of AUST token. (There are codes that considered this situation in the codebase. eg. handling of depositShares > claimerShares).

However, when this happens, the late users will suffer more losses than expected than the users that withdraw earlier. The last few users may lose all their funds while the first users can get back 100% of their deposits.

Proof of Concept

// ### for deposits: d1, d2, d3, the beneficiary are: c1, c2, c2
    depositAmount          claimerShares
d1: + 100e18           c1: + 100e36
d2: + 100e18           c2: + 100e36
d3: + 100e18           c2: + 100e36

depositAmount of d1, d2, d3 = 100e18
c1 claimerShares: 100e36
c2 claimerShares: 200e36
total shares: 300e36

// ### when the PPS of AUST drop by 50%
totalUnderlyingMinusSponsored: 300e18 -> 150e18

// ### d2 withdraw
c2 claimerShares: 200e36
d2 depositAmount: 100e18
d2 depositShares: 300e36 * 100e18 / 150e18 = 200e36

Shares to reduce: 200e36
c2 claimerShares: 200e36 -> 0
c2 totalPrincipal: 200e18 -> 100e18
totalShares: 300e36 -> 100e36

underlying.safeTransfer(d2, 100e18)
totalUnderlyingMinusSponsored: 150e18 -> 50e18

Root Cause

When the strategy is losing money, share / underlying increases, therefore the computed depositShares: depositAmount * share / underlying will increase unexpectedly.

https://github.com/code-423n4/2022-01-sandclock/blob/a90ad3824955327597be00bb0bd183a9c228a4fb/sandclock/contracts/Vault.sol#L544-L548

While totalShares remain unchanged, but the computed depositShares is increasing, causing distortion of depositShares / totalShares, eg, ∑ depositShares > totalShares.

Recommendation

In order to properly handle the investment loss of the strategy, consider adding a new storage variable called totalLoss to maintain a stable value of share / adjustedUnderlying.

adjustedUnderlying = underlying + totalLoss

CrisBRM (Sandclock) confirmed and disagreed with severity

dmvt (judge) changed severity and commented:

This is a classic medium risk when using the definition provided by Code4rena:

2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.

The original report as published on Code4rena, by WatchPug. 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 share calculation uses the current underlying balance without accounting for losses, so when the strategy loses money, the computed deposit shares increase disproportionately, distorting the share distribution.

Impact

Later users could suffer more losses than expected, and the last few users may lose all their funds, while early users can recover their full deposits.

What the attacker needed

Underlying strategy suffers investment losses

The fix

The recommendation is to add a `totalLoss` variable to maintain a stable share-to-underlying ratio, adjusting the underlying value by adding total losses.

How it was found

  1. Three deposits of equal amount are made by two users.
  2. The underlying strategy loses 50% of its value.
  3. One user withdraws and receives their full deposit amount, reducing the total underlying.
  4. The remaining user's shares are diluted, and they may lose all funds if they withdraw last.

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.

This is a smart contract vault where people deposit funds and get shares in return. If the investments lose value, the way shares are calculated can become unfair: people who withdraw later may get less than they should, and some could lose everything, while early withdrawers are fully repaid.

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 WatchPug

View all

197 more disclosed reports, best first.

More from Sandclock 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.