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/interop/estimate-costs.mdx
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,21 +32,21 @@ import { InteropCallout } from '@/components/WipCallout'
32
32
33
33
There are several factors that determinate the cost of an [interop transaction](/interop/message-passing):
34
34
35
-
- How you pass the message.
36
-
You can either use [`CrossL2Inbox`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/CrossL2Inbox.sol) directly, or use the cross domain messenger, [`L2ToL2CrossDomainMessenger`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol), which uses `CrossL2Inbox` internally.
37
-
- The transaction type.
38
-
Every interop message has two transactions, an [initiating message](/interop/message-passing#initiating-message) in a transaction to the source chain, and an [executing message](/interop/message-passing#executing-message) in the destination chain.
39
-
- Whether autorelay is turned on.
40
-
If it is turned on for a particular chain there is still an executing message when using `L2ToL2CrossDomainMessenger`, but the chain operator pays for it so you may not care.
35
+
* How you pass the message.
36
+
You can either use [`CrossL2Inbox`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/CrossL2Inbox.sol) directly, or use the cross domain messenger, [`L2ToL2CrossDomainMessenger`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol), which uses `CrossL2Inbox` internally.
37
+
* The transaction type.
38
+
Every interop message has two transactions, an [initiating message](/interop/message-passing#initiating-message) in a transaction to the source chain, and an [executing message](/interop/message-passing#executing-message) in the destination chain.
39
+
* Whether autorelay is turned on.
40
+
If it is turned on for a particular chain there is still an executing message when using `L2ToL2CrossDomainMessenger`, but the chain operator pays for it so you may not care.
41
41
42
42
## CrossL2Inbox
43
43
44
-
This is the low level protocol used by all interop protocols, including `L2ToL2CrossDomainMessenger`.
44
+
This is the low level protocol used by all interop protocols, including `L2ToL2CrossDomainMessenger`.
45
45
46
46
### Initiating message
47
47
48
48
The initiating message here is just any log entry.
49
-
A log entry emitted by Solidity code has 1-4 topics (t) and an unlimited number of unstructured data bytes (n).
49
+
A log entry emitted by Solidity code has 1-4 topics (t) and an unlimited number of unstructured data bytes (n).
50
50
The gas cost is [*375(t+1)+8n*](https://www.evm.codes/?fork=cancun#a1).
51
51
52
52
### Executing message
@@ -67,13 +67,13 @@ And, of course, you need to call a function which requires a four byte selector.
67
67
68
68
So the number of bytes required is *132+32t+n*.
69
69
70
-
Every transaction posted costs at least *21,000* gas.
71
-
Compared with that, the hashing which costs approximately [*30+0.2×\<number of bytes\>*](https://www.evm.codes/?fork=cancun#20), is negligible.
70
+
Every transaction posted costs at least *21,000* gas.
71
+
Compared with that, the hashing which costs approximately [*30+0.2×\<number of bytes>*](https://www.evm.codes/?fork=cancun#20), is negligible.
72
72
We can usually ignore the [memory expansion cost](https://www.evm.codes/about#memoryexpansion), unless the validating contract uses a really large amount of memory.
73
73
74
74
The cost of using the message is beyond the scope here, because it depends on your application.
75
75
76
-
So the main cost drivers are the 21,000 transaction gas cost has plus the cost of posting a *132+32t+n* byte transaction.
76
+
So the main cost drivers are the 21,000 transaction gas cost has plus the cost of posting a *132+32t+n* byte transaction.
77
77
78
78
## Cross domain messenger
79
79
@@ -86,7 +86,7 @@ The initiating message is sent by [`L2ToL2CrossDomainMessenger.sendMessage`](htt
86
86
It writes to [specify that the hash has a sent message](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol#L157).
87
87
This would typically be written to previously empty storage, so the cost is *22,100* gas.
88
88
89
-
Then it [increments the nonce value](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol#L158).
89
+
Then it [increments the nonce value](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol#L158).
90
90
Overwriting previously used storage (which means storage where the present value is *not* zero) only costs *5,000* gas.
91
91
92
92
So, the initiating message costs a little over *27,100* gas, plus the negligible cost of emitting the log message, a few if statements, etc.
0 commit comments