Skip to content
Smart contracts Audit finding Intermediate

First depositor can abuse exchange rate to steal funds from later depositors

The first depositor can deposit a tiny amount and then donate to the vault to inflate the share price, causing later depositors to receive fewer shares due to truncation. This allows the first depositor to steal funds from subsequent depositors.

0Kage Follow with 0x52, 0xAsen and 34 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-surge-judging/issues/125

Found by

0Kage, 0x52, 0xAsen, 0xc0ffEE, 0xhacksmithh, Ace-30, Bobface, Breeje, CRYP70, Chinmay, Cryptor, GimelSec, Juntao, MalfurionWhitehat, RaymondFam, SunSec, TrungOre, VAD37, __141345__, ak1, banditx0x, bin2chen, bytes032, carrot, cccz, chaduke, chainNue, ck, ctf_sec, dingo, gandu, gryphon, peanuts, rvi, unforgiven, usmannk, y1cunhui

Summary

Classic issue with vaults. First depositor can deposit a single wei then donate to the vault to greatly inflate share ratio. Due to truncation when converting to shares this can be used to steal funds from later depositors.

Vulnerability Detail

See summary.

Impact

First depositor can steal funds due to truncation

Code Snippet

https://github.com/sherlock-audit/2023-02-surge/blob/main/surge-protocol-v1/src/Pool.sol#L307-L343

Tool used

Solidity YouTube Tutorial

Recommendation

Either during creation of the vault or for first depositor, lock a small amount of the deposit to avoid this.

Discussion

xeious

GG. We left this one intentionally. Glad to see this many duplicates.

xeious

Fixed

xeious

https://github.com/Surge-fi/surge-protocol-v1/commit/35e725cc25a97c0ee4a76fc5523ede90ac4ea130

IAm0x52

Fix looks good. First deposit now creates a minimum liquidity that make advantageous manipulation nearly impossible

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

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 vault calculates shares by dividing the deposit by the total assets, and integer truncation allows the first depositor to manipulate the exchange rate by donating assets directly to the vault.

Impact

The first depositor can steal funds from later depositors due to truncation.

What the attacker needed

Be the first depositor; deposit a tiny amount; donate to inflate share price

The fix

The fix was to lock a small amount of the first deposit to create minimum liquidity, making manipulation nearly impossible.

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.

In a vault, shares represent ownership. The first person to deposit can make each share very expensive by donating extra tokens, so when others deposit, they get fewer shares than they should because the maths rounds down. The first depositor can then take the extra value, stealing from the later depositors.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by 0Kage

View all

7 more disclosed reports, best first.

More from Surge

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.