Skip to content

Commit c58f69f

Browse files
committed
Described mermaid diagrams
1 parent c271a6e commit c58f69f

File tree

1 file changed

+67
-8
lines changed

1 file changed

+67
-8
lines changed

pages/stack/interop/reading-logs.mdx

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ import { InteropCallout } from '@/components/WipCallout'
1111

1212
# Reading logs in superchain interop
1313

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.
1516

1617
## Overview
1718

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.
1920

20-
This capability enables developers to:
21+
This enables developers to:
2122

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.
2526

2627
## Why use `CrossL2Inbox`?
2728

@@ -35,8 +36,8 @@ This capability enables developers to:
3536

3637
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:
3738

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
4041
3. The `CrossL2Inbox` contract verifies the log's authenticity
4142
4. Your contract can then use the validated log data
4243

@@ -66,6 +67,14 @@ sequenceDiagram
6667
Note over Log: Event contains attestation data
6768
```
6869

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+
6978
### Destination chain: verifying the attestation
7079

7180
On the destination chain (e.g., Base), a DeFi application wants to verify this attestation:
@@ -88,6 +97,22 @@ sequenceDiagram
8897
DeFi-->>User: Grant access based on attestation
8998
```
9099

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+
91116
### Sample code for attestation verification
92117

93118
```solidity
@@ -150,6 +175,14 @@ flowchart TD
150175
C -.-> F
151176
```
152177

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+
153186
## Important considerations
154187

155188
* This feature works between chains within the same Superchain interop cluster
@@ -186,6 +219,32 @@ flowchart LR
186219
end
187220
```
188221

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+
189248
## Next steps
190249

191250
* [Build a revolutionary app](/app-developers/get-started) that uses multiple blockchains within the Superchain

0 commit comments

Comments
 (0)