Project

One World
NFTDeFi
15,000 USDC
View results
Submission Details
Severity: low
Invalid

Missing Events After State Variable Changes

Root Cause:

Functions that modify the state variable number do not emit any events. Emitting events after state changes is a best practice, as it allows off-chain services and users to track and react to these changes.

// src/Counter.sol
function setNumber(uint256 newNumber) public {
number = newNumber;
}
function increment() public {
number++;
}

Impact:

  • Reduced Transparency: Without events, external observers cannot easily track changes to the number variable.

  • Difficulty in Off-Chain Monitoring: Services like wallets, explorers, or dApps rely on events to update their interfaces and functionalities.

  • Challenges in Debugging and Auditing: Lack of emitted events makes it harder to trace the history of state changes, complicating debugging and security auditing efforts.


Recommendations:

  • Specify Exact Solidity Compiler Version:

    Use a fixed compiler version to ensure consistent behavior across deployments. For example:

    pragma solidity 0.8.13;
  • Update Function Visibility to external Where Appropriate:

    Change functions not called internally to external to optimize gas usage:

    function setNumber(uint256 newNumber) external {
    number = newNumber;
    }
    function increment() external {
    number++;
    }
  • Explicitly Set EVM Target Version:

    In your compiler settings, specify an EVM version compatible with your deployment network to avoid unsupported opcodes:

    {
    "compilerOptions": {
    "evmVersion": "Berlin"
    }
    }
  • Emit Events After State Changes:

    Define events and emit them in functions that modify state variables:

    event NumberSet(uint256 newNumber);
    function setNumber(uint256 newNumber) public {
    number = newNumber;
    emit NumberSet(newNumber);
    }
    event NumberIncremented(uint256 newNumber);
    function increment() public {
    number++;
    emit NumberIncremented(number);
    }

By addressing these issues, the contract will adhere to best practices, improve efficiency, ensure compatibility across different networks, and enhance transparency and traceability for users and developers.


Overall Impact:

  • Enhanced Security: Fixing these issues reduces the risk of vulnerabilities due to compiler changes or network incompatibilities.

  • Optimized Gas Usage: Proper function visibility can lead to cost savings for users interacting with the contract.

  • Improved User Experience: Emitting events and ensuring network compatibility enhance the reliability and usability of the contract.

  • Future-Proofing: Specifying exact compiler and EVM versions safeguards the contract against unforeseen changes in the Solidity language or Ethereum Virtual Machine.

Updates

Lead Judging Commences

0xbrivan2 Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
0xbrivan2 Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!