The UpdateWeightRunner::addOracle function performs two require validations: checking for proper access control (msg.sender == quantammAdmin) and ensuring the Oracle address is valid (oracleAddress != address(0)). While these validations are correct, their order can be optimized to prioritize the access control check, improving the function's clarity and efficiency by preventing unnecessary computations for unauthorized callers.
Current Implementation Order:
In this order, the function validates the oracle address even if the caller is unauthorized.
Optimized Order:
By placing the access control validation first, the function exits early for unauthorized users, saving gas and improving readability.
Updated implementation:
Unnecessary gas usage.
Manuel review
Reorder the require Statements:
Update the function to prioritize the access control validation:
Adopt Standard Practices for All Functions:
Ensure access control checks consistently come first in all relevant functions across the protocol to maintain efficiency and readability.
This report highlights the importance of structuring require statements for optimal performance and adherence to best practices in Solidity development. While the issue is not critical, addressing it contributes to a cleaner and more maintainable codebase.
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.
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.