A vulnerability was identified in the SablierFlow
smart contract where there is missing validation for broker parameters, specifically the broker fee percentage in the depositViaBroker
function. This allows brokers to set fees exceeding the maximum allowable limit or even manipulate fees to cause arithmetic overflows. Such issues can lead to financial losses for users and compromise the integrity of the contract.
In the SablierFlow
contract, the depositViaBroker
function allows deposits to be made through a broker, who can charge a fee specified as a percentage (UD60x18
format). There is a supposed maximum fee percentage (maxFeePercentage
), set to 10% (1e17 in UD60x18 format), intended to cap the broker's fee.
However, the contract lacks proper validation to enforce this maximum fee. As a result:
Brokers can set a fee equal to or exceeding the maximum limit without triggering a revert.
There is a risk of arithmetic overflows when large amounts and high fees are combined, potentially leading to incorrect fee calculations or contract failure.
Modify the mock file: tests/mocks/ERC20Mock.sol
with this content:
Create the main test file: tests/SablierFlowBrokerFeeTest.t.sol
and run the tests using command: forge test --mt testInternalFeeCalculationConsistency -vvvv
Now the test fails, meaning the revert didn’t happpen and the transaction for fee exceeding the maximum went through successfully
Explanation:
Setup Phase:
Contract Deployment:
Deploys ERC20Mock
token and MockNFTDescriptor
to satisfy dependencies.
Deploys the SablierFlow
contract.
Logs the addresses for clarity.
Token Minting and Approval:
Mints 1,000,000 tokens to the sender
.
sender
approves the SablierFlow
contract to spend tokens on their behalf.
Logs actions for transparency.
Test Cases:
testEdgeCaseMaxFee
:
Sets the broker fee just below the maximum allowed (10% - 1 wei).
Creates a stream and deposits via the broker.
Checks that the broker receives the correct fee.
Logs all steps and validates that no revert occurs.
testBoundaryMaxAllowableFee
:
Sets the broker fee exactly at the maximum allowed (10%).
Expects the transaction to revert, but due to missing validation, it might not.
Logs the attempt and the expectation.
testOverflowRiskWithHighFee
:
Attempts to deposit a very large amount with an excessively high broker fee (e.g., 50%).
Expects the transaction to revert due to overflow risk.
Highlights the lack of validation for preventing such scenarios.
testInternalFeeCalculationConsistency
:
Tests fee calculation when the broker fee is at the maximum allowed.
Expects a revert due to fee limits, emphasizing inconsistencies in internal calculations.
Underlying Issue:
The SablierFlow
contract does not enforce validation on the broker.fee
parameter within the depositViaBroker
function. This omission allows brokers to:
Set fees equal to or exceeding the maximum limit without reversion.
Input excessively high fees that can cause arithmetic overflows during fee calculation.
The lack of checks against maxFeePercentage
and absence of overflow protections pose significant risks to the contract's security and user funds.
Financial Loss for Users:
Users may be overcharged by brokers setting excessive fees.
Funds intended for the recipient may be unfairly diverted to brokers.
Contract Vulnerability:
Potential for arithmetic overflows leading to incorrect fee calculations.
May cause the contract to behave unexpectedly or fail.
Reputation Damage:
Trust in the SablierFlow
contract could be compromised.
Users may lose confidence due to potential exploitation.
Foundry: A fast, portable, and modular toolkit for Ethereum application development.
Solidity Compiler (solc): Version 0.8.22 used for compiling the smart contracts.
Forge Std Library: Provides utilities for testing, including console.log
for detailed output.
PRB Math Library: Used for fixed-point math operations (UD60x18
and UD21x18
types).
Implement Parameter Validation:
Enforce checks in the depositViaBroker
function to ensure broker.fee
does not exceed maxFeePercentage
.
Validate that broker.fee
is a reasonable value (e.g., non-negative).
Add Overflow Protections:
Use safe math operations when calculating fees to prevent overflows.
Consider using OpenZeppelin's SafeMath library or Solidity's built-in overflow checks.
Enhance Unit Testing:
Include tests for edge cases where broker.fee
is at, below, and above the maximum allowed.
Test for arithmetic overflows with large amounts and high fees.
Update Documentation:
Clearly document the acceptable range for broker fees.
Provide guidelines for brokers and users on fee expectations.
Code Review and Auditing:
Perform a thorough code review focusing on parameter validations.
Engage third-party auditors to assess the contract for similar vulnerabilities.
By addressing these issues, the SablierFlow
contract will:
Prevent brokers from setting excessive or harmful fees.
Protect users from potential financial losses.
Enhance the overall security and reliability of the contract.
Note: Always ensure that changes are thoroughly tested in a secure environment before deploying to production networks.
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.