The SablierFlow smart contract lacks proper enforcement of token standards, specifically assuming that all ERC-20 tokens used do not impose transfer fees or support callback mechanisms like those in ERC-777 tokens. This oversight allows malicious actors to exploit the contract by using tokens with transfer fees or callback functionalities, leading to incorrect balance updates, insolvency of streams, and potential reentrancy attacks.
Explanation:
We create a MockERC20WithFee
contract that inherits from OpenZeppelin's ERC-20 implementation. This mock token introduces a transfer fee mechanism where a percentage of each transfer is redirected to the contract itself. This simulates tokens like certain versions of USDT that impose transfer fees.
Explanation:
Here, we deploy the MockERC20WithFee
with an initial supply and a 2% transfer fee. The sender approves the Flow contract to spend 500 tokens and then creates a new stream while depositing 500 tokens. Due to the transfer fee, only 490 tokens (500 - 2%
) are actually deposited into the stream.
Explanation:
After depositing, we retrieve the stream's balance. The expected balance is 490 tokens instead of 500 due to the 2% transfer fee deducted during the deposit. This discrepancy leads to incorrect debt calculations within the Flow contract.
Explanation:
We create a MaliciousERC777
contract that inherits from OpenZeppelin's ERC-777 implementation. The tokensReceived
callback is overridden to re-enter the withdraw
function of the Flow contract during a token transfer. This setup aims to exploit potential reentrancy vulnerabilities within the Flow contract's withdrawal mechanisms.
Explanation:
By depositing the malicious ERC-777 token into a stream and then attempting a withdrawal, the tokensReceived
callback is triggered. This callback re-enters the withdraw
function, potentially allowing the attacker to withdraw more funds than intended or manipulate the contract's state, exploiting any reentrancy vulnerabilities present.
Incorrect Balance Updates:
Transfer Fees: Tokens with transfer fees result in the Flow contract receiving fewer tokens than expected. This underfunding can lead to streams becoming insolvent prematurely, affecting both senders and recipients.
Reentrancy Attacks:
ERC-777 Callbacks: Malicious tokens leveraging callback mechanisms can re-enter critical functions like withdraw
, potentially draining funds, altering debt calculations, or disrupting the contract's state integrity.
Manual Review
Implement a validation mechanism during token deposit and withdrawal processes to ensure that the token adheres to standard ERC-20 behavior.
Explanation:
Before accepting any token for streaming, the contract verifies that the token has the expected number of decimals and does not support callback mechanisms. This prevents tokens with transfer fees or ERC-777 functionalities from being used.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.