contracts-wizard icon indicating copy to clipboard operation
contracts-wizard copied to clipboard

Add Superchain interop message passing

Open ericglau opened this issue 7 months ago • 6 comments

In Solidity's Custom tab, this PR adds a Cross-Chain Messaging option that adds an example of Superchain interop message passing when enabled. This includes a function that can be called from a different network on the Superchain.

For example, when enabled, this adds the following functions by default:

  • callMyFunction which takes a chain ID argument, and sends a message to myFunction at a contract at the same address on the given chain ID
  • myFunction which receives messages from other chains. The name of this function is customizable (which affects the name of the above function as well).

Implementation checklist:

  • [x] Add UI elements to emphasize that this is only compatible with chains on the Superchain and requires deterministic deployments
  • [x] Add unit tests
  • [x] Add snapshot tests
  • [x] Update AI assistant definitions and MCP schemas
  • [x] Test/fix usage with AI assistant
  • [x] Add Optimism contracts for compilation tests
  • [x] Add Optimism contracts to Download Hardhat and Foundry packages
  • [x] Test an example contract locally using supersim, non-upgradeable (see comments below for test steps)
  • [x] Test an example contract locally using supersim, upgradeable (see comments below for test steps)
  • [x] Add changesets
  • [x] Add soldeer.lock

ericglau avatar Jul 04 '25 21:07 ericglau

Solid!, just one thing that you are probably aware of; the ai assistant seems to be generating crosschain messaging code very well, however the changes aren't getting correctly reflected on the UI, the contract code appears, but the checkboxes are kept unchecked as if nothing happened, they're not in sync with the code changes made by the ai

gonzaotc avatar Jul 28 '25 23:07 gonzaotc

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring alerts on:

View full report

socket-security[bot] avatar Jul 29 '25 23:07 socket-security[bot]

Also manually tested as follows. Note these are testcases only and do not represent best practices for actual deployments.

  • [x] Test an example contract locally using supersim, non-upgradeable (Custom, only Cross-Chain Messaging enabled)
    • Test steps:
      1. After generating the contract, download as Foundry project, run setup script, then update myFunction to emit an event e.g. emit ReceivedCrossChainMessage(messenger.crossDomainMessageSender());
      2. Follow these steps except using MyContract instead of Greeter, and deploying to the same address on chains A and B without constructor parameters.
      3. After calling the crosschain function, use cast logs to look for the event defined in step 1 on chain B.
  • [x] Test an example contract locally using supersim, upgradeable (Custom, Cross-Chain Messaging with Ownable and UUPS)
    • Test steps:
      1. After generating the contract, download as Hardhat project, run setup script, then update myFunction to emit an event, and update deploy.ts to set the owner address to the first address from supersim.
      2. Define supersim networks in Hardhat config, for example:
      3. Deploy to both chains:
        • npx hardhat run scripts/deploy.ts --network OPChainA
        • npx hardhat run scripts/deploy.ts --network OPChainB
      4. Create script callcrosschain.ts:
import { ethers } from "hardhat";
import { MyContract } from "../typechain-types";

async function main() {
  const ContractFactory = await ethers.getContractFactory("MyContract");
  const proxy = "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"; // use address from step above
  const instance = await ContractFactory.attach(proxy) as MyContract;
  await instance.callMyFunction(902);
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

e. Call the crosschain function using script: npx hardhat run scripts/callcrosschain.ts --network OPChainA f. After calling the crosschain function, use cast logs to look for the event defined in step 1 on chain B.

ericglau avatar Jul 31 '25 20:07 ericglau

@SocketSecurity ignore-all Not related

ericglau avatar Aug 02 '25 03:08 ericglau

@CoveMB

I am wondering in the Custom contract it seem Optimism option add both emitter and receiver functions is it standar or does contract usually implement on or the other?

In this example, we include both functions. If only one function is included, the emitter and/or receiver would need to take or track other addresses, which would be a more complex example. That can be considered as an enhancement if there is a need for it.

ericglau avatar Aug 06 '25 17:08 ericglau