Skip to content

Commit

Permalink
feat(docs): update example 8.1 to reflect L2toL2CDM changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tremarkley committed Oct 8, 2024
1 parent eea9088 commit 6b96b8f
Showing 1 changed file with 56 additions and 48 deletions.
104 changes: 56 additions & 48 deletions docs/src/guides/interop/manually-relaying-interop-messages-cast.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- omit in toc -->
# Manually relaying interop messages with `cast`
# Manually relaying interop messages with `cast` and L2ToL2CrossDomainMessenger

This guide describes how to form a [message identifier](https://specs.optimism.io/interop/messaging.html#message-identifier) to execute a message on a destination chain.

Expand Down Expand Up @@ -45,9 +45,8 @@ Sending an interop message using the `L2ToL2CrossDomainMessenger`:

**on destination chain** (OPChainB 902)

3. call `CrossL2Inbox.executeMessage`
- this calls `L2ToL2CrossDomainMessenger.relayMessage`
- which then calls `L2NativeSuperchainERC20.relayERC20`
3. call `L2ToL2CrossDomainMessenger.relayMessage`
- this calls `L2NativeSuperchainERC20.relayERC20`

### Message identifier

Expand Down Expand Up @@ -100,13 +99,18 @@ cast logs --address 0x4200000000000000000000000000000000000023 --rpc-url http://

```sh
- address: 0x4200000000000000000000000000000000000023
blockHash: 0x81ddbe2f7ff770011077fcec89a7e3a3ca54f2b7ba110695dd22f2a730457f60
blockNumber: 18
data: 0x1ecd26f200000000000000000000000000000000000000000000000000000000000003860000000000000000000000000000000000000000000000000000000000000385000000000000000000000000000000000000000000000000000000000000000000000000000000000000000061a6ef395d217ed7c79e1b84880167a41779617200000000000000000000000061a6ef395d217ed7c79e1b84880167a41779617200000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000064d9f50046000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000003e800000000000000000000000000000000000000000000000000000000
blockHash: 0x644e640094d96e379fec06f3dfbb3b03ee54cde15450543a847f61a063977e90
blockNumber: 10
data: 0x000000000000000000000000420beef00000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000064d9f50046000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000003e800000000000000000000000000000000000000000000000000000000
logIndex: 1
removed: false
topics: []
transactionHash: 0x5fad43480766ee63bdd07864f6b811432b042fded2a7e05df643f0fac4490817
topics: [
0x382409ac69001e11931a28435afef442cbfd20d9891907e8fa373ba7d351f320
0x0000000000000000000000000000000000000000000000000000000000000386
0x000000000000000000000000420beef000000000000000000000000000000001
0x0000000000000000000000000000000000000000000000000000000000000000
]
transactionHash: 0xf6fcec6ae3941e33223cd6a63d0ffaeac1795b65c144db17e6ae7c8d3e2250dc
transactionIndex: 0
```

Expand All @@ -121,51 +125,61 @@ cast block 0xREPLACE_WITH_CORRECT_BLOCKHASH --rpc-url http://127.0.0.1:9545
**example result:**

```sh
baseFeePerGas 1
baseFeePerGas 301131671
difficulty 0
extraData 0x
gasLimit 30000000
gasUsed 62040
hash 0x81ddbe2f7ff770011077fcec89a7e3a3ca54f2b7ba110695dd22f2a730457f60
logsBloom 0x00000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000010000000000000000008000000000000000000000000000002000008000000000000000000000000000000000000000000000000020000000000000100000800000000000008000000000010000000000000000000000000000000000000040000000000000000000000000000000000000200000000000000000000000000000000010000000000000000000000000000800002000000200000000000000000000000002000000000000000000020000000000000000000000000000000000000000000000000000000000000000000
gasUsed 63173
hash 0x644e640094d96e379fec06f3dfbb3b03ee54cde15450543a847f61a063977e90
logsBloom 0x20000000000000020000000000000000000000080000000000000010000000000000000000000000000000000000000010000000000000000008000000000000000000000000000002000008000000000000000000000100000020000000000000000000020000000040000100000800000000000008000000000010000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000010000000000000000000000000040000002000000200000000000000000000000102000000800000000000020000000000000000000000000000000000000000000000000000000001400000000
miner 0x4200000000000000000000000000000000000011
mixHash 0x0000000000000000000000000000000000000000000000000000000000000000
nonce 0x0000000000000000
number 18
parentHash 0x552eae8494730d53e845b762042cebda51821ecf544562481a78eb1b36134b72
transactionsRoot 0x07ae44e7678b08e1d021fb83ede835cab2963f9627209bd8dc8cd4b6eb00df19
receiptsRoot 0xbb5c311ac46940b49e19aae1802f988a66e2e180a0432f169f9382a49d7e9893
number 10
parentHash 0xac9dc75fdf4ab41e5b90eefb103745eade25c4b98b48dff784df7d6d45c6144a
parentBeaconRoot
transactionsRoot 0x15e50417f6fa12895cb81dcf9db89f486d3a5760db538ebca97337d28c90f12a
receiptsRoot 0x1a3a7571e087a8200fba03d0c19d433c8293d99d7faa55d953c19006333fe75a
sha3Uncles 0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347
size 723
stateRoot 0xfa2449b5188bec99bda8a917e0494dce0f1a7d76ea1a8cc68edf42b6f8c1021b
timestamp 1726453637
withdrawalsRoot
size 731
stateRoot 0xb436dee5ab769a104f36e4c1ae3d09c79ec07a8741f0b724c06f0ab8264f1cd1
timestamp 1728428155 (Tue, 8 Oct 2024 22:55:55 +0000)
withdrawalsRoot
totalDifficulty 0
transactions: [
0x5fad43480766ee63bdd07864f6b811432b042fded2a7e05df643f0fac4490817
0xf6fcec6ae3941e33223cd6a63d0ffaeac1795b65c144db17e6ae7c8d3e2250dc
]
```

### 6. Prepare the identifier
### 6. Construct message payload

To construct the message payload we need to concatenate all the log topics and log data. These need to be concatenated as all the topics first in order and then the data:

```sh
# 0x + topics[0] + topics[1] + topics[2] + topics[3] + data
0x + 382409ac69001e11931a28435afef442cbfd20d9891907e8fa373ba7d351f320 + 0000000000000000000000000000000000000000000000000000000000000386 + 000000000000000000000000420beef000000000000000000000000000000001 + 0000000000000000000000000000000000000000000000000000000000000000 + 000000000000000000000000420beef00000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000064d9f50046000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000003e800000000000000000000000000000000000000000000000000000000
```

### 7. Prepare the identifier

Now we have all the information needed for the message (log) identifier.

| **Parameter** | **Value** | **Note** |
|---------------|--------------------------------------------|----------------------------|
| origin | 0x4200000000000000000000000000000000000023 | L2ToL2CrossDomainMessenger |
| blocknumber | 18 | from step 4 |
| blocknumber | 10 | from step 4 |
| logIndex | 1 | from step 4 |
| timestamp | 1726453637 | from step 5 |
| timestamp | 1728428155 | from step 5 |
| chainid | 901 | OPChainA chainID |

### 7. Send the relayMessage transaction
### 8. Send the relayMessage transaction

Call `executeMessage` on [CrossL2Inbox](https://github.com/ethereum-optimism/optimism/blob/92ed64e171c6eb9c6a080c626640e8836f0653cc/packages/contracts-bedrock/src/L2/CrossL2Inbox.sol#L133), which in turn calls `relayMessage` on [L2ToL2CrossDomainMessenger](https://github.com/ethereum-optimism/optimism/blob/92ed64e171c6eb9c6a080c626640e8836f0653cc/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol#L126)
Call `relayMessage` on [L2ToL2CrossDomainMessenger](https://github.com/ethereum-optimism/optimism/blob/a05feb362b5209ab6a200874e9d45244f12240d1/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol#L149)

```solidity
// CrossL2Inbox.sol (truncated for brevity)
// L2ToL2CrossDomainMessenger.sol (truncated for brevity)
contract CrossL2Inbox {
interface ICrossL2Inbox {
struct Identifier {
address origin;
uint256 blockNumber;
Expand All @@ -176,41 +190,35 @@ contract CrossL2Inbox {
// ...
function executeMessage(
Identifier calldata _id,
address _target,
bytes memory _message
function relayMessage(
ICrossL2Inbox.Identifier calldata _id,
bytes calldata _sentMessage
) payable
// ...
}
```


**`executeMessage` parameters**

- `Identifier calldata _id`: identifier pointing to the log on the source chain
- same as the identifier in step 6.
- `address _target`: address of the contract on the destination chain to call.
- address of the `L2ToL2CrossChainMessenger`
- `bytes memory _message`: calldata to call the contract on the destination chain with.
- `log.data` from the log emitted in step 4
**`relayMessage` parameters**

Note that in our case, both `_id.origin` and `_target` happen to be the same with `0x4200000000000000000000000000000000000023`, the `L2ToL2CrossChainMessenger` predeploy. But they do not have to be the same if you're not using the messenger contracts.
- `ICrossL2Inbox.Identifier calldata _id`: identifier pointing to the log on the source chain
- same as the identifier in step 7.
- `bytes calldata _sentMessage`: calldata to call the contract on the destination chain with.
- message payload from step 6.

Below is an example call, but make sure to replace them with the correct values you received in previous steps.

```sh
cast send 0x4200000000000000000000000000000000000022 \
"executeMessage((address, uint256, uint256, uint256, uint256), address, bytes)" \
"(0x4200000000000000000000000000000000000023, 18, 1, 1726453637, 901)" \
0x4200000000000000000000000000000000000023 \
0x1ecd26f200000000000000000000000000000000000000000000000000000000000003860000000000000000000000000000000000000000000000000000000000000385000000000000000000000000000000000000000000000000000000000000000000000000000000000000000061a6ef395d217ed7c79e1b84880167a41779617200000000000000000000000061a6ef395d217ed7c79e1b84880167a41779617200000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000064d9f50046000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000003e800000000000000000000000000000000000000000000000000000000 \
cast send 0x4200000000000000000000000000000000000023 \
"relayMessage((address, uint256, uint256, uint256, uint256), bytes)" \
"(0x4200000000000000000000000000000000000023, 10, 1, 1728428155, 901)" \
0x382409ac69001e11931a28435afef442cbfd20d9891907e8fa373ba7d351f3200000000000000000000000000000000000000000000000000000000000000386000000000000000000000000420beef0000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000420beef00000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000064d9f50046000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000003e800000000000000000000000000000000000000000000000000000000 \
--rpc-url http://127.0.0.1:9546 \
--private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
```

### 8. Check the balance on chain 902
### 9. Check the balance on chain 902

Verify that the balance of the L2NativeSuperchainERC20 on chain 902 has increased:

Expand Down

0 comments on commit 6b96b8f

Please sign in to comment.