Many DeFi projects now operate accross L1 and L2 networks leading to an increase in the complexity of monitoring and incident response. Practicing coordination of responses across Layer 1 (L1) and Layer 2 (L2) networks requires not only a deep understanding of cross-chain communication but also a testing environment to simulate real-world scenarios. In this post, we’ll explore a framework for simulating cross-chain communication on parallel network forks, focusing on Ethereum L1 and Optimism L2 interactions, and how it can be used for incident response drills.
Find the GitHub repo here.
To request a wargame drill for your protocol visit https://www.securityalliance.org/wargames
With L2s like Optimism, Arbitrum, and zkSync, protocols now span multiple chains, leveraging the scalability and cost-efficiency of L2s while maintaining the security of L1. However, this multi-chain architecture introduces significant challenges for incident response:
Without a realistic testing environment, teams risk being unprepared for cross-chain incidents, which can lead to prolonged downtime or loss of funds. We can now simulate these scenarios through an updated framework for wargame drills.
This framework is designed to simulate cross-chain communication between Ethereum L1 and Optimism L2, with a focus on testing bridge transactions and message passing. By creating a realistic testing environment, teams can practice incident response in a controlled setting that mirrors production conditions.
To simulate cross-chain communication, we use forked environments of both Ethereum and Optimism. These environments are created using Tenderly Virtual Testnets, though the setup can be extended to other tools like Anvil. Key features of the test environment include:
The framework consists of three core components that work together to simulate cross-chain communication:
The Message Relayer is responsible for monitoring and relaying messages between L1 and L2. It:
CrossDomainMessenger
events on both chains.To create a realistic testing environment, we use automated bots to simulate user activity. These bots:
A monitoring system is essential for tracking cross-chain activity during these drills. Our setup includes:
Below are example test transactions showing a bot bridging ETH and USDC from our forked L1 to the forked L2. The same cross domain messenger can be used for more complex transactions including cross chain governance.
Events
ERC20DepositInitiated { "l1Token":"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" "l2Token":"0x7f5c764cbc14f9669b88837ca1490cca17c31607" "from":"0xe16b5254a61757c30581b46fdefa4465ec79efef" "to":"0xe16b5254a61757c30581b46fdefa4465ec79efef" "amount":"725811265" "extraData":"0x" } SentMessage { "target":"0x4200000000000000000000000000000000000010" "sender":"0x99c9fc46f92e8a1c0dec1b1747d010903e884be1" "message":"0x0166a07a0000000000000000000000007f5c764cbc14f9669b88837ca1490cca17c31607000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000e16b5254a61757c30581b46fdefa4465ec79efef000000000000000000000000e16b5254a61757c30581b46fdefa4465ec79efef000000000000000000000000000000000000000000000000000000002b43004100000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000" "messageNonce":"1766847064778384329583297500742918515827483896875618958121606201292775919" "gasLimit":"200000" }
Events
RelayedMessage { "msgHash":"0x733c45f903bcebd6120fd66d34c6a38e5643b47916932b99f7b4aa5019430035" } DepositFinalized { "_l1Token":"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" "_l2Token":"0x7f5c764cbc14f9669b88837ca1490cca17c31607" "_from":"0xe16b5254a61757c30581b46fdefa4465ec79efef" "_to":"0xe16b5254a61757c30581b46fdefa4465ec79efef" "_amount":"725811265" "_data":"0x" }
Events
ETHDepositInitiated { "from": "0x867e85779c4446a27489efcc91d6736b4e6029aa", "to": "0x867e85779c4446a27489efcc91d6736b4e6029aa", "amount": "857319916551426049", "extraData": "0x" } SentMessage { "target": "0x4200000000000000000000000000000000000010", "sender": "0x99c9fc46f92e8a1c0dec1b1747d010903e884be1", "message": "0x1635f5fd000000000000000000000000867e85779c4446a27489efcc91d6736b4e6029aa000000000000000000000000867e85779c4446a27489efcc91d6736b4e6029aa0000000000000000000000000000000000000000000000000be5cfebfcea500100000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000", "messageNonce": "1766847064778384329583297500742918515827483896875618958121606201292775921", "gasLimit": "200000" } SentMessageExtension1 (Required for passing native value) { "sender": "0x99c9fc46f92e8a1c0dec1b1747d010903e884be1", "value": "857319916551426049" }
Events
DepositFinalized { "_l1Token": "0x0000000000000000000000000000000000000000", "_l2Token": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000", "_from": "0x867e85779c4446a27489efcc91d6736b4e6029aa", "_to": "0x867e85779c4446a27489efcc91d6736b4e6029aa", "_amount": "857319916551426049", "_data": "0x" } MessageRelayed { "msgHash": "0xef8c6d1944657ba46fbca235d0a8ff887225a5ecd68066512cb2826839907672" }
To validate the accuracy of our simulation, we compare the test transaction with real bridge deposits on Optimism mainnet. We can inspect the logs and see the same events are emitted and transfers/ calls occur.
The message relayer service tracks SentMessage
events from L1 and relays them on L2. Key steps include:
CrossDomainMessenger
contract.The Grafana dashboard provides real-time insights into cross-chain activity, including transaction volumes, deposits initiated and finalized. This can be extended to include relevant metrics for the protocol being tested.
The framework uses Tenderly Virtual Testnets to create forked environments of Ethereum and Optimism. Key steps include:
The framework follows Optimism’s deposit specification to implement message passing. Key aspects include:
CrossDomainMessenger
contract.CrossDomainMessenger
address using a cheat code to the value of the relayed messageCrossDomainMessenger
contract to send the transaction without needing a private key or system transaction methodThe monitoring system tracks events on both chains and compares them with mainnet metrics. It includes:
While the framework provides a robust testing environment, it has some limitations:
The framework is available as an open-source project on GitHub. Key features include:
We’re actively working on improving the framework, with plans to:
By simulating cross-chain communication, teams can better prepare for real-world incidents and ensure the security and reliability of their protocols. We invite you to explore the framework, contribute to its development, and share your feedback.