QuantAMM

QuantAMM
49,600 OP
View results
Submission Details
Severity: low
Invalid

removeOracle Function Does Not Follow CEI Pattern, Leading to Gas Wastage

Summary

In the UpdateWeightRunner contract, the removeOracle function is designed to allow the admin to remove an oracle. However, the function does not follow the Checks-Effects-Interactions (CEI) pattern, resulting in inefficient gas usage. If the function call fails, the admin incurs unnecessary gas costs that could have been avoided by reordering the code.

Vulnerability Details

Code Analysis

Current Implementation of removeOracle

function removeOracle(OracleWrapper _oracleToRemove) external {
approvedOracles[address(_oracleToRemove)] = false;
@> // @info: The require check is gas-inefficient due to its placement. It should appear before modifying state variables or emitting events.
require(msg.sender == quantammAdmin, "ONLYADMIN");
emit OracleRemved(address(_oracleToRemove));
}

Observations

  • Improper Code Order:
    The require check for admin validation is placed after the state update, which violates the CEI pattern.

  • Gas Wastage:
    If the require check fails, gas is still consumed for operations performed before the check, such as setting approvedOracles to false.

Impact

  1. Increased Gas Costs:
    Admin users will pay unnecessary gas fees on failed calls due to inefficient code placement.

  2. Violation of CEI Pattern:
    The Checks-Effects-Interactions pattern is a best practice in Solidity to ensure secure and gas-efficient execution. The current implementation deviates from this standard.

  3. Poor Code Quality:
    This issue reflects bad coding practice, potentially reducing the maintainability and readability of the contract.

Tools Used

Manual Review

Recommendations

Proposed Fix

Reorder the require check to ensure the function adheres to the CEI pattern. This adjustment ensures that the call is validated before performing any state changes or emitting events.

Updated removeOracle Function

function removeOracle(OracleWrapper _oracleToRemove) external {
+ require(msg.sender == quantammAdmin, "ONLYADMIN");
approvedOracles[address(_oracleToRemove)] = false;
- require(msg.sender == quantammAdmin, "ONLYADMIN");
emit OracleRemved(address(_oracleToRemove));
}

Benefits of the Fix

  1. Improved Gas Efficiency:
    Prevents unnecessary gas usage by ensuring state changes and events are only executed after the admin check passes.

  2. Adherence to Best Practices:
    Aligns the function with the CEI pattern, improving security and maintainability.

  3. Better Developer Experience:
    Enhances the readability and robustness of the codebase, making it easier for future developers to work with.

Here’s the refined markdown with proper grammar and expanded sections:


Updates

Lead Judging Commences

n0kto Lead Judge 11 months 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!