Paymaster gas optimization#6614
Closed
gonzaotc wants to merge 6 commits into
Closed
Conversation
…ne calldata load (-712 gas/op, -20.5k deploy) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…roduct fits one word (-966 gas/op base, -1,932 guaranteed, +17.1k deploy) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…PaymasterUserOp (-199 gas/op, +0.9k deploy) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…documented EntryPoint invariant (-72 gas/postOp) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…feCast.toUint (-12 gas/op, -3.4k deploy) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: f77682c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Note
AI-generated with the Solidity Gas Optimizer skill in council mode: 4 models (Composer, Fable 5, GPT-5.6 Sol, Grok 4.5) each ran the full audit independently, the runs were merged and adjudicated, and every finding below was re-measured on this branch. All tests pass, but it's encouraged to review before merging to confirm behavior is unaffected.
Run
handleOpsprobes, since the gas reporter cannot attribute calls made through the EntryPoint predeploydb06a6ef/d017d3e5; the scope tree is byte-identical across both commitsResults
Five independent gas optimization candidates survived adjudication, one commit each and keyed by the IDs below. It's recommended to review them one by one, via the commits view.
PaymasterSigner._signableUserOpHashmulDiv512-bit path when the product fits one wordPaymasterERC20._erc20CostPaymasterSigner._decodePaymasterUserOpPaymasterERC20._refundSafeCast.toUintPaymasterERC721Owner._validatePaymasterUserOpGAS-H-01 · parse both paymaster gas limits with one calldata load (
PaymasterSigner._signableUserOpHash)ERC4337Utilsaccessor calls with onelength < 52check and one 32-byte load ofpaymasterAndData[20:52], split on the stack into the verification and postOp gas limits; the encoded hash is byte-identical, including the zero fallback for short data.[20:52]offsets and the 128-bit split are spelled out locally in EIP-712 hashing code, duplicating layout knowledge theERC4337Utilsaccessors centralize. Cherry-picks independently.GAS-H-02 · skip the
mulDiv512-bit path when the product fits one word (PaymasterERC20._erc20Cost)high == 0from the already-computedmul512and finishes the common case withMath.ceilDiv, keepingmulDivfor the genuine multi-word case and preserving thetype(uint256).maxsaturation sentinel, including thedenominator == 0edge.Math.mulDivrecomputes it internally; the one-word case needs only a ceiling division. The function runs twice per sponsored operation and four times per guaranteed one.mulDiv(the equivalence at thehigh == 0boundary and both sentinel edges was independently verified in review), plus +17.1k deployment gas per concrete paymaster. Cherry-picks independently.mulDivprimitive inMath, which remains the API-level alternative.GAS-M-01 · one-window timestamp decode (
PaymasterSigner._decodePaymasterUserOp)bytes12and splits it with casts (uint48(bytes6(validity)),uint48(bytes6(validity << 48))) instead of two adjacent bounds-checked 6-byte slices; the short-data path is unchanged.GAS-L-01 · unchecked refund subtraction under the EntryPoint invariant (
PaymasterERC20._refund)prefundAmount - actualAmount_inunchecked.actualGasCost <= maxCost, soactualAmount_ <= prefundAmountholds and the compiler's underflow check is unreachable; removing it saves 72 gas on every postOp refund.trySafeTransfer(reverting withPaymasterERC20FailedRefund) instead of aPanic. Cherry-picks independently.GAS-L-02 · branchless validation data via
SafeCast.toUint(PaymasterERC721Owner._validatePaymasterUserOp)SafeCast.toUint(token().balanceOf(userOp.sender) == 0)instead of a ternary selecting betweenSIG_VALIDATION_FAILEDandSIG_VALIDATION_SUCCESS.🤖 Generated with Claude Code