Streaming Protocol contest - jonah1005's results

General Information

Platform: Code4rena

Start Date: 30/11/2021

Pot Size: $100,000 USDC

Total HM: 15

Participants: 36

Period: 7 days

Judge: 0xean

Total Solo HM: 4

Id: 62

League: ETH

Streaming Protocol

Findings Distribution

Researcher Performance

Rank: 25/36

Findings: 2

Award: $1,191.24

🌟 Selected for report: 1

πŸš€ Solo Findings: 0

Findings Information

🌟 Selected for report: WatchPug

Also found by: 0x0x0x, ScopeLift, gpersoon, gzeon, harleythedog, hyh, jonah1005, kenzo

Labels

bug
duplicate
3 (High Risk)

Awards

385.4189 USDC - $385.42

External Links

Handle

jonah1005

Vulnerability details

stream creator can steal flash loan fee by calling recoverTokens

Impact

The Stream creator can recover tokens that were mistakenly sent to the contract through. recoverTokens Locke.sol#L646-L677 The creator should only be able to recover the excess token. However, it doesn't handle the flash loan fee.

uint256 excess = ERC20(token).balanceOf(address(this)) - (depositTokenAmount - redeemedDepositTokens);

If recoverTokens is called before claimFees the users would be double-charged.

Proof of Concept

In order to simplify the POC I added a debug function donateFlashLoanFee in the Stream contract.

    function donateFlashLoanFee(uint256 amount) public {
        ERC20(depositToken).safeTransferFrom(msg.sender, address(this), amount);
        depositTokenFlashloanFeeAmount += uint112(amount);
    }

We can create a simplify Stream contract with no one stakes in the contract. The contract sends flashloanfee back to the streamCreator.

dai.functions.approve(stream.address, deposit_amount).transact()
stream.functions.donateFlashLoanFee(deposit_amount).transact()

w3.provider.make_request('evm_setNextBlockTimestamp', [hex(start_time + duration + duration)])

stream.functions.recoverTokens(dai.address, user).transact()
// output: 0
print(dai.functions.balanceOf(stream.address).call())

Tools Used

hardhat

The dev handles recovering rewardTokens perfectly.Locke.sol#L672 Recommended to follow it.

            uint256 excess = ERC20(token).balanceOf(address(this)) - (depositTokenAmount - redeemedDepositTokens) - depositTokenFlashloanFeeAmount;

#0 - 0xean

2022-01-14T20:52:26Z

dupe of #241

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax Β© 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter