V2 remove redundancy & optimize gas usage#37
Merged
Conversation
## Summary Reduce external calls to mitigate ~45,000 gas overhead per CALL/STATICCALL introduced by Arbitrum Nitro v3.9.0 Multi-Constraint Pricing. ## Optimizations Applied - #1: Remove duplicate Verifier.getTokenFeeInfo() calls in Billing.sol - #2: Consolidate Verifier.paymentRecipient() fetch in _processVerifiedDelivery() - #3: Combine unlockForVerification + payFromCoordinator into single unlockAndPayForVerification() function in Router.sol - #5: Add Wallet.getSpenderInfo() to combine 3 external calls into 1 - Bytecode optimization: Remove duplicate memory function variants to fit Router within EIP-170 24KB limit with optimizer_runs=1,000,000
Gas optimization for Arbitrum Nitro v3.9.0 Multi-Constraint Pricing. Changes: - Add verifierFee field to Commitment struct to cache verifier fee - Billing._startBilling(): Store verifierFee when creating commitment - Billing._processVerifiedDelivery(): Use cached verifierFee instead of calling verifier.getTokenFeeInfo() again (saves ~45k gas) - Coordinator.getCommitment(): Fetch verifierFee for commitment reconstruction - Router.sendRequest(): Delegate to Coordinator.getCommitment() for idempotent requests (reduces Router bytecode size) - Update CommitmentUtils to accept verifierFee parameter - Update JavaScript commitment.js to include verifierFee field Benchmark results (reportComputeResult): - 64B payload: 677,920 -> 633,023 gas (-6.6%) - 256B payload: 675,412 -> 623,791 gas (-7.6%) - 512B payload: 688,157 -> 639,367 gas (-7.1%) - Average savings: ~50,000 gas per call
- #5: Remove redundant redundancyCount[requestId] = 0 assignment (mapping defaults to 0, saves ~2.1k gas SSTORE) - #6: Remove redundant isValidWallet() check in _markRequestInFlight (wallet already validated in createComputeSubscription) - #7: Replace require strings with custom errors in Router.sol (CoordinatorNotFound, WalletFactoryAlreadySet, InvalidWalletFactoryAddress) - #8: Pass client address as parameter to avoid SLOAD (saves ~2.1k gas by not reading subscription.client twice)
BREAKING CHANGE: This commit removes the `redundancy` parameter from the subscription system, changing from a multi-node response model to a single-node response per request. Key changes: - Remove `redundancy` field from ComputeSubscription and Commitment types - Simplify RequestLock struct in Wallet.sol (remove redundancy/paidCount) - Remove nodeResponded mapping from Coordinator (use commitment existence) - Update ComputeDelivered event from 6 to 5 parameters (remove interval) - Simplify lockForRequest from 5 to 4 parameters - Remove numRedundantDeliveries from fulfill() calls - Update EIP-712 type hash (remove redundancy from signed data) Gas savings: ~36,350 gas per request/response cycle Test results: 155 passed, 8 skipped - 3 skipped in DelegateeComputeTest (delegated flow bug) - 4 skipped in ComputeVerifierTest (pre-existing) - 1 skipped in SubscriptionBatchReaderTest (commitment sync bug)
Bug 1 - Delegated flow duplicate requests: - Add completion check in createSubscriptionDelegatee - Revert with SubscriptionCompleted if subscription is cancelled or fulfilled Bug 2 - Commitment sync on cancellation: - Call Coordinator.cancelRequest() in _cancelSubscriptionHelper - Ensures Router and Coordinator commitments stay in sync Test results: 158 passed, 5 skipped (Verifier-related)
- Update threshold from 1KB to 256 bytes to match production config - Add PayloadData detection in RAW_DATA handling for agent script - Fix output URI type: external input -> external output (S3 URL) - Add support for data:;base64, short format - Add TEST_UPLOAD_THRESHOLD and TEST_STORAGE_TYPE environment variables Result: ~13.5% gas reduction for reportComputeResult with external inputs
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 86313afe32
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Remove uint16 redundancy field from Commitment tuple encoding - Update createSubscription calls to match new contract signature - Add verifierFee field to buildCommitment function - Fix hash mismatch between off-chain and on-chain commitment encoding This fixes InvalidCommitment revert when submitting results to Coordinator.
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.
V2 remove redundancy & optimize gas usage