The SablierFlow
smart contract lacks event emissions for critical actions, such as adjusting the ratePerSecond
in a stream. This absence of event logging hinders transparency, monitoring, and auditing efforts, making it difficult for users and external systems to track important state changes within the contract.
In Ethereum and other blockchain platforms, events are essential for providing an off-chain record of on-chain activities. They enable users, developers, and monitoring tools to track and react to state changes in smart contracts. In the SablierFlow
contract, certain critical functions do not emit events when executed. Specifically, the adjustRatePerSecond
function changes the streaming rate but does not emit an event to signal this change.
Affected Function:
Issue Explanation:
Lack of Transparency: Without event emissions, users cannot verify when critical actions occur, leading to potential confusion or mistrust.
Monitoring Difficulties: External services that rely on events to monitor contract activity cannot detect these state changes.
Auditing Challenges: Auditors have a harder time tracing and verifying contract behaviors without event logs.
Proof of Concept (PoC):
First create the mock file: tests/mocks/ERC20Mock.sol
with this content:
Then create the main test file: tests/LackOfEventEmissionTest.t.sol
and run it using command forge test --mt testAdjustRatePerSecondWithoutEvent -vvvv
Explanation:
Setup Phase:
Deploys a mock ERC20 token and the SablierFlow
contract.
Mints tokens to the sender and sets up token approvals.
Logs each action for transparency.
Test Phase (testAdjustRatePerSecondWithoutEvent
):
Starts acting as the sender to perform actions.
Creates a stream with an initial rate.
Adjusts the ratePerSecond
without any time advancement.
Logs the rate adjustment action.
Notes that no event is emitted during the rate adjustment.
Stops acting as the sender.
Highlights that external monitoring tools cannot detect this critical state change due to the lack of event emission.
Transparency Issues: Users cannot verify state changes, leading to a lack of trust in the system.
Monitoring and Automation Challenges: External applications and services cannot respond to changes in real-time.
Auditing Difficulties: Without event logs, it becomes harder to audit the contract's behavior and ensure compliance.
Security Risks: Malicious actors could exploit the lack of transparency to manipulate contract behavior without detection.
Foundry: For testing and deployment of smart contracts.
Solidity Compiler (solc): Version 0.8.22 for compiling Solidity code.
Forge Std Library: Provides utilities for testing and logging.
Console Logs (console.log
): Used extensively for step-by-step tracing of the contract's internal state during execution.
Emit Events in Critical Functions:
Modify all critical functions to emit events that log important state changes. For the adjustRatePerSecond
function, an event can be added as follows:
Review and Update Other Functions:
Ensure that other critical functions also emit appropriate events, such as:
create
and createAndDeposit
deposit
and depositViaBroker
withdraw
cancelStream
pause
and unpause
(if applicable)
Ensure Event Consistency:
Use consistent naming conventions for events.
Include all relevant information in event parameters to aid off-chain processing.
Index important parameters (like streamId
, sender
, recipient
) to optimize event filtering.
Update Documentation and Interfaces:
Document all events in the contract's interface.
Provide clear explanations of when and why events are emitted.
Test Event Emissions:
Write unit tests to ensure events are emitted correctly.
Use testing frameworks to assert that the expected events are present after function execution.
By implementing these recommendations, the SablierFlow
contract will improve transparency and allow users, developers, and monitoring tools to track critical actions effectively. This enhances trust in the system and facilitates better auditing and security monitoring.
Note: Always thoroughly test contract changes in a development environment before deploying to production to ensure that new events do not introduce any unintended side effects.
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.