You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/stack/interop/reading-logs.mdx
+67-8Lines changed: 67 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,17 +11,18 @@ import { InteropCallout } from '@/components/WipCallout'
11
11
12
12
# Reading logs in superchain interop
13
13
14
-
Superchain interop enables developers to leverage current and historical logs from other blockchains within the Superchain interop cluster directly on their local chain. This feature allows for cross-chain log consumption with low latency in a trust-minimized way.
14
+
Superchain interop enables developers to leverage current and historical logs from other blockchains within the Superchain interop cluster directly on their local chain.
15
+
This allows for cross-chain log consumption with low latency in a trust-minimized way.
15
16
16
17
## Overview
17
18
18
-
While the [L2ToL2CrossDomainMessenger](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol) enables sending messages across chains, the [`CrossL2Inbox#validateMessage`](https://github.com/ethereum-optimism/optimism/blob/af091753917c1d7101314cbfe8ac5cbc2efe0e5e/packages/contracts-bedrock/src/L2/CrossL2Inbox.sol#L49)function allows smart contracts to verify and consume logs that were emitted on other chains within the Superchain ecosystem.
19
+
Instead of relying solely on [L2ToL2CrossDomainMessenger](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol), developers can use [`CrossL2Inbox#validateMessage`](https://github.com/ethereum-optimism/optimism/blob/af091753917c1d7101314cbfe8ac5cbc2efe0e5e/packages/contracts-bedrock/src/L2/CrossL2Inbox.sol#L49)and treat `CrossL2Inbox` as an oracle for logs that occurred on different chains or even their local chain.
19
20
20
-
This capability enables developers to:
21
+
This enables developers to:
21
22
22
-
* Reference attestations or events from other chains
23
-
* Build cross-chain applications that react to events happening across the Superchain
24
-
* Create novel financial products that leverage data from multiple chains
23
+
* Reference attestations or events from other chains.
24
+
* Build cross-chain applications that react to events happening across the Superchain.
25
+
* Create novel dApps that leverage data from multiple chains.
25
26
26
27
## Why use `CrossL2Inbox`?
27
28
@@ -35,8 +36,8 @@ This capability enables developers to:
35
36
36
37
The process works through the [`CrossL2Inbox`](https://github.com/ethereum-optimism/optimism/blob/af091753917c1d7101314cbfe8ac5cbc2efe0e5e/packages/contracts-bedrock/src/L2/CrossL2Inbox.sol#L33) contract, which serves as an oracle for logs from other chains in the Superchain:
37
38
38
-
1. A smart contract on Chain A emits a log (event)
39
-
2. Your contract on Chain B calls `CrossL2Inbox#validateMessage` with the log's identifier
39
+
1. A smart contract on `Chain A` emits a log (event)
40
+
2. Your contract on `Chain B` calls `CrossL2Inbox#validateMessage` with the log's identifier
40
41
3. The `CrossL2Inbox` contract verifies the log's authenticity
41
42
4. Your contract can then use the validated log data
42
43
@@ -66,6 +67,14 @@ sequenceDiagram
66
67
Note over Log: Event contains attestation data
67
68
```
68
69
70
+
1. The user initiates a request for an attestation through an application.
71
+
72
+
2. The application calls the `createAttestation()` function on the EAS (Ethereum Attestation Service) contract on the source chain.
73
+
74
+
3. The EAS contract processes the attestation request and emits an `AttestationCreated` event.
75
+
76
+
4. The event is recorded in the chain's log, containing all necessary attestation data.
77
+
69
78
### Destination chain: verifying the attestation
70
79
71
80
On the destination chain (e.g., Base), a DeFi application wants to verify this attestation:
@@ -88,6 +97,22 @@ sequenceDiagram
88
97
DeFi-->>User: Grant access based on attestation
89
98
```
90
99
100
+
1. The user requests access to a DeFi application on the destination chain, referencing an attestation created on the source chain.
101
+
102
+
2. The DeFi application calls `verifyAttestation()` on the `AttestationVerifier` contract, passing the attestation's identifier and event data.
103
+
104
+
3. The AttestationVerifier calls `validateMessage()` on the `CrossL2Inbox` contract, passing the attestation identifier and a hash of the event data.
105
+
106
+
4. The `CrossL2Inbox` contract interacts with the `OP-Supervisor` node to check if the specified log exists on the source chain.
107
+
108
+
5. The `OP-Supervisor` confirms the validity of the log to the `CrossL2Inbox` contract.
109
+
110
+
6. The `CrossL2Inbox` returns the validation result to the `AttestationVerifier`.
111
+
112
+
7. The `AttestationVerifier` returns the verification status to the DeFi application.
113
+
114
+
8. If validation is successful, the DeFi application grants the user access based on the verified attestation.
115
+
91
116
### Sample code for attestation verification
92
117
93
118
```solidity
@@ -150,6 +175,14 @@ flowchart TD
150
175
C -.-> F
151
176
```
152
177
178
+
1. First, identify which log from another chain you want to consume in your application.
179
+
180
+
2. Create an Identifier struct that contains all necessary information about the log, including the chain ID and the contract address that emitted the log.
181
+
182
+
3. Call the `validateMessage()` function on the `CrossL2Inbox` contract, passing the identifier and a hash of the log data.
183
+
184
+
4. After validation, process the log data according to your application's requirements.
185
+
153
186
## Important considerations
154
187
155
188
* This feature works between chains within the same Superchain interop cluster
@@ -186,6 +219,32 @@ flowchart LR
186
219
end
187
220
```
188
221
222
+
This diagram compares the two approaches for cross-chain communication:
223
+
224
+
### L2ToL2CrossDomainMessenger (Push Model):
225
+
226
+
1. A source contract calls `sendMessage()` on the `L2ToL2CrossDomainMessenger`.
227
+
228
+
2. The messenger emits an event to the event log.
229
+
230
+
3. An autorelayer detects the event and relays it to the destination chain.
231
+
232
+
4. The destination `L2ToL2CrossDomainMessenger` receives the relayed message.
233
+
234
+
5. The destination messenger executes the message on the target contract.
235
+
236
+
### CrossL2Inbox (Pull Model):
237
+
238
+
1. A source contract emits an event to the event log.
239
+
240
+
2. The `OP-Supervisor` node monitors events across chains.
241
+
242
+
3. A destination contract calls `validateMessage()` on the `CrossL2Inbox`.
243
+
244
+
4. The `CrossL2Inbox` verifies the log's existence by communicating with the `OP-Supervisor`.
245
+
246
+
5. The destination contract receives verification and proceeds with its logic.
247
+
189
248
## Next steps
190
249
191
250
*[Build a revolutionary app](/app-developers/get-started) that uses multiple blockchains within the Superchain
0 commit comments