Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ Extract the message leaf index:

#include_code get_claim_leaf_index /docs/examples/ts/aave_bridge/index.ts typescript

On the local network, L2 blocks are only produced when transactions are submitted. An L1-to-L2 message can only be consumed once an L2 block includes it, and the network waits until the message is at least 12 seconds old before including it. This utility deploys two dummy contracts (with random salts for unique addresses) to force block production. On devnet or testnet, blocks are produced continuously and this step is unnecessary:
On the local network, L2 blocks are only produced when transactions are submitted. An L1-to-L2 message can only be consumed once an L2 block includes it, and the local sandbox includes it as soon as it sees it. This utility deploys two dummy contracts (with random salts for unique addresses) to force block production. On devnet or testnet, blocks are produced continuously and this step is unnecessary, but there the sequencer first waits for the L1 block carrying the message to gain a child, which takes one more L1 block (around 12 to 14 seconds):

#include_code mine_blocks /docs/examples/ts/aave_bridge/index.ts typescript

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ Use viem to extract this information:

#include_code get_message_leaf_index /docs/examples/ts/token_bridge/index.ts typescript

This extracts the logs from the deposit and retrieves the leaf index. You can now claim it on L2. However, a message can only be claimed once an L2 block includes it, and the network waits until the message is at least 12 seconds old before including it, so expect 12 to 30 seconds of latency. If you called `claim` on the L2 contract immediately, it would return "no message available".
This extracts the logs from the deposit and retrieves the leaf index. You can now claim it on L2. However, a message can only be claimed once an L2 block includes it. On a live network the sequencer first waits for the L1 block carrying the message to gain a child, which takes one more L1 block (around 12 to 14 seconds), so expect 15 to 30 seconds of latency; the local sandbox consumes the message as soon as it sees it. If you called `claim` on the L2 contract immediately, it would return "no message available".

On a local network blocks are only produced when transactions are submitted, so add a utility function that forces a couple of blocks (it deploys a contract with a random salt):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ Bridge WETH from L1 to L2:
When depositing from L1 to L2, we use a secret/secret-hash pattern: generate a random secret on the client, send only the hash to L1 (in the deposit transaction), then later reveal the secret on L2 to claim the tokens. This prevents **front-running attacks**: a malicious sequencer (the node that orders and processes L2 transactions) cannot observe the L1 deposit and claim the tokens themselves because they don't know the secret. Only someone who knows the preimage can claim.
:::

Before claiming, we need to mine a couple of L2 blocks. An L1-to-L2 message is not available the moment it is sent -- the rollup only includes it in an L2 block once it is at least 12 seconds old, and it becomes consumable as soon as that block lands. We use a helper that deploys throwaway contracts to force these blocks:
Before claiming, we need to mine a couple of L2 blocks. An L1-to-L2 message is not available the moment it is sent -- it becomes consumable only once an L2 block includes it. The local sandbox includes it as soon as it sees it; on a live network the sequencer first waits for the L1 block carrying it to gain a child, which takes one more L1 block (around 12 to 14 seconds). We use a helper that deploys throwaway contracts to force these blocks:

#include_code mine_blocks /docs/examples/ts/example_swap/index.ts typescript

Expand Down
14 changes: 7 additions & 7 deletions l1-contracts/gas_benchmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@

| Function | Avg Gas | Max Gas | Calldata Size | Calldata Gas |
|----------------------|---------|-----------|---------------|--------------|
| propose | 199,366 | 225,550 | 996 | 15,936 |
| submitEpochRootProof | 991,032 | 1,029,525 | 14,148 | 226,368 |
| propose | 197,740 | 223,924 | 996 | 15,936 |
| submitEpochRootProof | 980,266 | 1,018,730 | 14,148 | 226,368 |
| setupEpoch | 32,042 | 113,837 | - | - |

**Avg Gas Cost per Second**: 3,643.2 gas/second
**Avg Gas Cost per Second**: 3,611.2 gas/second
*Epoch duration*: 0h 38m 24s

## Validators

| Function | Avg Gas | Max Gas | Calldata Size | Calldata Gas |
|----------------------|-----------|-----------|---------------|--------------|
| propose | 327,774 | 355,591 | 4,516 | 72,256 |
| submitEpochRootProof | 1,572,081 | 1,669,921 | 16,644 | 266,304 |
| aggregate3 | 376,665 | 390,039 | - | - |
| propose | 326,159 | 353,977 | 4,516 | 72,256 |
| submitEpochRootProof | 1,561,332 | 1,659,142 | 16,644 | 266,304 |
| aggregate3 | 375,051 | 388,425 | - | - |
| setupEpoch | 46,504 | 547,670 | - | - |

**Avg Gas Cost per Second**: 5,937.3 gas/second
**Avg Gas Cost per Second**: 5,905.5 gas/second
*Epoch duration*: 0h 38m 24s

40 changes: 20 additions & 20 deletions l1-contracts/gas_benchmark_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"no_validators": {
"propose": {
"calls": 150,
"min": 185722,
"mean": 199366,
"median": 195111,
"max": 225550,
"min": 184096,
"mean": 197740,
"median": 193486,
"max": 223924,
"calldata_size": 996,
"calldata_gas": 15936
},
Expand All @@ -18,21 +18,21 @@
},
"submitEpochRootProof": {
"calls": 4,
"min": 972329,
"mean": 991032,
"median": 981138,
"max": 1029525,
"min": 961647,
"mean": 980266,
"median": 970345,
"max": 1018730,
"calldata_size": 14148,
"calldata_gas": 226368
}
},
"validators": {
"propose": {
"calls": 150,
"min": 305434,
"mean": 327774,
"median": 327227,
"max": 355591,
"min": 303820,
"mean": 326159,
"median": 325613,
"max": 353977,
"calldata_size": 4516,
"calldata_gas": 72256
},
Expand All @@ -45,19 +45,19 @@
},
"submitEpochRootProof": {
"calls": 4,
"min": 1460323,
"mean": 1572081,
"median": 1579041,
"max": 1669921,
"min": 1449546,
"mean": 1561332,
"median": 1568320,
"max": 1659142,
"calldata_size": 16644,
"calldata_gas": 266304
},
"aggregate3": {
"calls": 55,
"min": 365547,
"mean": 376665,
"median": 376350,
"max": 390039
"min": 363933,
"mean": 375051,
"median": 374735,
"max": 388425
}
}
}
Loading
Loading