A vulnerability exists in the SablierFlow
smart contract where it fails to validate the compliance of ERC20 tokens, particularly regarding the return values of transfer
and transferFrom
functions. This oversight can lead to unexpected behavior, including failed transactions, reentrancy attacks, and loss of funds when interacting with non-compliant or malicious ERC20 tokens.
The SablierFlow
contract interacts with ERC20 tokens by calling their transfer
and transferFrom
functions. It assumes that these functions always succeed and that the tokens comply fully with the ERC20 standard. However, not all tokens adhere strictly to the standard; some may not return a boolean value, always return true
regardless of success, or even revert unexpectedly.
Additionally, malicious tokens can exploit this lack of validation to perform reentrancy attacks or other harmful actions during token transfers.
Simply create the test file: tests/NonCompliantERC20.t.sol
, and run the test using command: forge test --mt testNonCompliantTokenFailure -vvvv
Explanation:
testStandardTokenFlow
: Confirms that the SablierFlow
contract functions correctly with a compliant ERC20 token, showcasing normal behavior.
testNonCompliantTokenFailure
: Demonstrates how the contract fails to handle a non-compliant token that reverts on transfer
. Since the contract doesn't check for such behavior, it can cause unexpected failures.
testMaliciousTokenWithdrawalFailure
: Shows how a malicious token can attempt a reentrancy attack during the transfer
function, exploiting the lack of reentrancy guards in the SablierFlow
contract.
testOverflowsWithHighRates
: Tests the contract's ability to handle overflow conditions by using extremely high ratePerSecond
values, which can cause arithmetic overflows if not properly handled.
Security Vulnerabilities:
Reentrancy Attacks: Malicious tokens can exploit the lack of reentrancy protection to perform unauthorized actions, potentially leading to the loss of funds.
Transaction Failures: Non-compliant tokens that do not adhere to the ERC20 standard can cause transactions to fail unexpectedly, disrupting the contract's functionality.
Financial Risks:
Loss of Funds: Users interacting with non-compliant or malicious tokens may experience loss of funds due to failed transactions or exploited vulnerabilities.
Contract Integrity: The overall trust in the SablierFlow
contract may be compromised if it cannot securely handle different types of ERC20 tokens.
Operational Issues:
Denial of Service: Repeated failures or attacks could render the contract unusable, affecting all users.
Incompatibility: Limits the range of tokens that can safely interact with the contract, reducing its utility.
Foundry: A fast and modular Ethereum development toolkit used for compiling and testing the smart contracts.
Solidity Compiler (solc): Version 0.8.22, utilized for compiling the Solidity contracts.
Forge Std Library: Provides utilities for testing, including console.log
for detailed output during test execution.
Console Logs (console.log
): Used extensively in the PoC to trace execution flow and internal state for clarity.
Use SafeERC20 Library:
Integrate OpenZeppelin's SafeERC20
library to safely handle ERC20 token interactions, which checks the return values and handles non-standard tokens.
Implement Reentrancy Guards:
Use OpenZeppelin's ReentrancyGuard
to protect functions that involve token transfers and state changes.
Validate ERC20 Compliance:
Before interacting with a token, perform checks to ensure it adheres to the ERC20 standard.
Consider adding a token registry where tokens are verified before use.
Handle Return Values Explicitly:
Always check the return values of transfer
and transferFrom
and handle cases where tokens do not return a boolean.
Enhance Testing Suite:
Expand unit tests to include various ERC20 token behaviors, including non-standard and malicious implementations.
Test edge cases like overflows, underflows, and reentrancy attacks thoroughly.
User Education:
Update documentation to inform users about the importance of using compliant tokens.
Provide guidelines or a list of recommended tokens known to be safe with the contract.
Regular Audits:
Conduct security audits to identify and fix vulnerabilities.
Stay updated with best practices in smart contract development.
By implementing these recommendations, the SablierFlow
contract will become more secure and reliable, capable of handling interactions with a variety of ERC20 tokens safely. This will protect users from potential losses and enhance the contract's reputation in the ecosystem.
Note: Always ensure that any changes to the contract are thoroughly tested in a controlled environment before deployment to the mainnet.
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.