Skip to content
Business logic Audit finding Intermediate

Storage variable unstreamed can be artificially inflated

The storage variable `unstreamed` is incremented on stake but not decremented on withdraw, allowing a malicious user to artificially inflate it by staking and immediately withdrawing. This inflated value could deter other users from staking, benefiting the attacker by reducing competition for rewards.

harleythedog Follow

Originally disclosed on Code4rena

Submitted by harleythedog, also found by csanuragjain, gpersoon, hubble, and WatchPug

Impact

The storage variable unstreamed keeps track of the global amount of deposit token in the contract that have not been streamed yet. This variable is a public variable, and users that read this variable likely want to use its value to determine whether or not they want to stake in the stream.

The issue here is that unstreamed is incremented on calls to stake, but it is not being decremented on calls to withdraw. As a result, a malicious user could simply stake, immediately withdraw their staked amount, and they will have increased unstreamed. They could do this repeatedly or with large amounts to intentionally inflate unstreamed to be as large as they want.

Other users would see this large amount and be deterred to stake in the stream, since they would get very little reward relative to the large amount of unstreamed deposit tokens that appear to be in the contract. This benefits the attacker as less users will want to stake in the stream, which leaves more rewards for them.

Proof of Concept

See stake here: https://github.com/code-423n4/2021-11-streaming/blob/56d81204a00fc949d29ddd277169690318b36821/Streaming/src/Locke.sol#L417

See withdraw here: https://github.com/code-423n4/2021-11-streaming/blob/56d81204a00fc949d29ddd277169690318b36821/Streaming/src/Locke.sol#L455

Notice that stake increments unstreamed but withdraw does not affect unstreamed at all, even though withdraw is indeed removing unstreamed deposit tokens from the contract.

Tools Used

Inspection

Recommended Mitigation Steps

Add the following line to withdraw to fix this issue:

unstreamed -= amount;

brockelmore (Streaming Protocol) confirmed

The original report as published on Code4rena, by harleythedog. 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 `withdraw` function fails to decrement the `unstreamed` variable when removing unstreamed deposit tokens.

Impact

Other users may be deterred from staking due to the inflated `unstreamed` value, leaving more rewards for the attacker.

What the attacker needed

Ability to stake and withdraw

The fix

Add a line to `withdraw` to decrement `unstreamed` by the withdrawn amount.

How it was found

  1. Call `stake` to increase `unstreamed`.
  2. Immediately call `withdraw` to remove the staked amount without decreasing `unstreamed`.
  3. Repeat or use large amounts to inflate `unstreamed` arbitrarily.

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 smart contract keeps a public number called `unstreamed` to show how many deposit tokens are not yet streamed. When someone stakes, this number goes up, but when they withdraw, it does not go down. So an attacker can make this number very large by staking and quickly withdrawing, tricking others into thinking there are many unstreamed tokens, which might discourage them from staking.

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 harleythedog

View all

14 more disclosed reports, best first.

More from Streaming Protocol 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.