fix: remove redundant makerOrders.length > 0 check in _matchOrders() - #102
Open
dev-khimesh wants to merge 1 commit into
Open
dev-khimesh wants to merge 1 commit into
dev-khimesh wants to merge 1 commit into
Conversation
The external matchOrders() already validates makerLength > 0 before calling _matchOrders(). Since _matchOrders is only called from matchOrders, the second check is redundant and costs ~20 gas on every matchOrders call on the hot path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The external
matchOrders()already validatesmakerLength > 0before calling_matchOrders(). Since_matchOrdersis an internal function with a single caller (matchOrders), the duplicaterequire(makerOrders.length > 0, NoMakerOrders())inside_matchOrderscan never fail independently of the first check.Gas Savings
Change
Removed the redundant
require(makerOrders.length > 0, NoMakerOrders())from_matchOrders()inTrading.sol. The externalmatchOrders()entrypoint inCTFExchange.solalready enforces this invariant.Closes #101
Note
Low Risk
Behavior is unchanged for callers; the invariant is still enforced on the sole external entrypoint with no new code paths.
Overview
Removes the duplicate
require(makerOrders.length > 0, NoMakerOrders())at the start of internal_matchOrders()inTrading.sol.matchOrders()inCTFExchange.solalready requiresmakerLength > 0before it calls_matchOrders, and that internal function has no other callers, so the inner check could never fail on its own. Empty-maker protection is unchanged at the public entrypoint; this only drops redundant runtime work on every match (~20 gas permatchOrderscall).Reviewed by Cursor Bugbot for commit c40b78b. Bugbot is set up for automated code reviews on this repo. Configure here.