Skip to content

Fix dispatch logic, gas metering, and error handling in Gateway v2#1687

Closed
Copilot wants to merge 4 commits intoron/multi-contract-callsfrom
copilot/sub-pr-1676-another-one
Closed

Fix dispatch logic, gas metering, and error handling in Gateway v2#1687
Copilot wants to merge 4 commits intoron/multi-contract-callsfrom
copilot/sub-pr-1676-another-one

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

Addresses multiple issues in Gateway v2 message dispatch identified in PR #1676 review: incorrect failure tracking, missing gas enforcement, and poor error surfacing for atomic commands.

Changes

  • Fixed dispatch success tracking: Initialize dispatchSuccess = false to correctly reflect failures when catch blocks swallow errors

  • Enforced per-command gas metering: Added explicit {gas: command.gas} stipend to v2_dispatchCommand calls to prevent commands from consuming arbitrary gas

  • Improved error propagation:

    • InsufficientGasLimit now properly rethrows from v2_dispatch catch block
    • Updated AtomicCommandFailed signature to include (uint64 nonce, uint256 index) for debugging
    • Skip emitting CommandFailed event for atomic commands (event would be rolled back anyway)
  • Test fixes:

    • test_onlySelf_enforced_on_external_calls now verifies v2_dispatchCommand access control
    • Corrected atomicity test comment to reflect actual token balance after partial command execution

Example

// Before: no gas limit enforcement
try this.v2_dispatchCommand(command, message.origin) {}

// After: explicit gas stipend enforces command.gas limit
try this.v2_dispatchCommand{gas: command.gas}(command, message.origin) {}
catch (bytes memory reason) {
    // Rethrow InsufficientGasLimit to stop processing
    if (reason.length >= 4 && bytes4(reason) == IGatewayV2.InsufficientGasLimit.selector) {
        assembly { revert(add(reason, 32), mload(reason)) }
    }
    // For atomic commands, include diagnostic info in revert
    if (command.atomic) {
        revert IGatewayV2.AtomicCommandFailed(message.nonce, i);
    }
    // Only emit events for non-atomic failures
    emit IGatewayV2.CommandFailed(message.nonce, i);
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: yrong <4383920+yrong@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 26, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • foundry.paradigm.xyz
    • Triggering command: /usr/bin/curl curl -L REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Support multiple contract calls Fix dispatch logic, gas metering, and error handling in Gateway v2 Jan 26, 2026
Copilot AI requested a review from yrong January 26, 2026 12:58
@yrong yrong marked this pull request as ready for review January 26, 2026 13:45
@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 73.91304% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.43%. Comparing base (f418da7) to head (700a5f7).
⚠️ Report is 1 commits behind head on ron/multi-contract-calls.

Files with missing lines Patch % Lines
contracts/src/Gateway.sol 73.91% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@                     Coverage Diff                      @@
##           ron/multi-contract-calls    #1687      +/-   ##
============================================================
+ Coverage                     81.04%   81.43%   +0.38%     
============================================================
  Files                            22       22              
  Lines                          1029     1045      +16     
  Branches                        191      196       +5     
============================================================
+ Hits                            834      851      +17     
+ Misses                          178      176       -2     
- Partials                         17       18       +1     
Flag Coverage Δ
solidity 81.43% <73.91%> (+0.38%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yrong yrong closed this Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants