Skip to content

fix: remove redundant makerOrders.length > 0 check in _matchOrders() - #102

Open
dev-khimesh wants to merge 1 commit into
Polymarket:mainfrom
dev-khimesh:fix/remove-redundant-makerorders-length-check
Open

dev-khimesh wants to merge 1 commit into
Polymarket:mainfrom
dev-khimesh:fix/remove-redundant-makerorders-length-check

Conversation

@dev-khimesh

@dev-khimesh dev-khimesh commented Jul 11, 2026

Copy link
Copy Markdown

Description

The external matchOrders() already validates makerLength > 0 before calling _matchOrders(). Since _matchOrders is an internal function with a single caller (matchOrders), the duplicate require(makerOrders.length > 0, NoMakerOrders()) inside _matchOrders can never fail independently of the first check.

Gas Savings

  • Per call savings: ~20 gas (MLOAD + ISZERO + JUMPI)
  • Total historical TXs: ~129M matchOrders calls
  • Total potential savings: ~2.58B gas across all historical transactions

Change

Removed the redundant require(makerOrders.length > 0, NoMakerOrders()) from _matchOrders() in Trading.sol. The external matchOrders() entrypoint in CTFExchange.sol already 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() in Trading.sol.

matchOrders() in CTFExchange.sol already requires makerLength > 0 before 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 per matchOrders call).

Reviewed by Cursor Bugbot for commit c40b78b. Bugbot is set up for automated code reviews on this repo. Configure here.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GAS] Redundant makerOrders.length > 0 check across matchOrders() and _matchOrders()

1 participant