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
+19-14Lines changed: 19 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,10 +24,10 @@ import { InteropCallout } from '@/components/WipCallout'
24
24
# Estimating the cost of interop messages
25
25
26
26
<Callouttype="info">
27
-
At the time of writing (May 2025) the cost of a hundred interop messages is just a few cents.
28
-
Unless the cost of OP Stack transactions rises significantly, the cost of interop is not an important consideration.
27
+
As of May 2025, the cost of 100 interop messages is just a few cents.
28
+
Unless OP Stack transaction costs increase significantly, interop costs should not be a primary consideration in your implementation decisions.
29
29
30
-
To see the current cost of gas, go to a [block explorer](https://optimism.blockscout.com/) and look at a recent transaction.
30
+
To see the current cost of gas, go to a [block explorer](https://optimism.blockscout.com/) and look at a recent transaction.
31
31
</Callout>
32
32
33
33
There are several factors that determine the cost of an [interop transaction](/interop/message-passing):
@@ -37,17 +37,17 @@ There are several factors that determine the cost of an [interop transaction](/i
37
37
* The transaction type.
38
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
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.
40
+
When enabled for a specific chain, the `L2ToL2CrossDomainMessenger` still executes a message, but the chain operator covers the execution costs.
41
41
42
42
## CrossL2Inbox
43
43
44
44
This is the low level protocol used by all interop protocols, including `L2ToL2CrossDomainMessenger`.
45
45
46
46
### Initiating message
47
47
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).
50
-
The gas cost is [*375(t+1)+8n*](https://www.evm.codes/?fork=cancun#a1).
48
+
The initiating message is any log entry.
49
+
A log entry emitted by Solidity code contains 1-4 topics (t) and unlimited unstructured data bytes (n).
50
+
The gas cost is calculated as [375(t+1)+8n](https://www.evm.codes/?fork=cancun#a1).
51
51
52
52
### Executing message
53
53
@@ -61,19 +61,24 @@ The executing message cost has several components:
61
61
The first and second components depend on the log entry.
62
62
`CrossL2Inbox.validateMessage` only requires a 32 byte hash of the log entry, but actually using it typically requires the information that has been hashed.
63
63
64
-
Additionally, you need to provide the `CrossL2Inbox` with how to find the log entry.
65
-
This is encoded in a [fivemember structure](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/CrossL2Inbox.sol#L7-L19), so *32×5=160* bytes.
66
-
And, of course, you need to call a function which requires a four byte selector.
64
+
Additionally, you must provide the `CrossL2Inbox` with the information needed to locate the log entry.
65
+
This information is encoded in a [five-member structure](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/CrossL2Inbox.sol#L7-L19) that requires 160 bytes (32 bytes × 5 members).
66
+
Lastly, you need to call a function which requires a 4-byte selector.
67
67
68
-
So the number of bytes required is *164+32t+n*.
68
+
Therefore, the total bytes required is: **164 + 32t + n**
69
+
70
+
Where:
71
+
*`164` = base overhead (160 bytes for the structure + 4 bytes for the function selector)
72
+
*`t` = number of topics in the log entry
73
+
*`n` = number of data bytes in the log entry
69
74
70
75
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.
76
+
In comparison, the hashing operation costs approximately [*30+0.2×\<number of bytes>*](https://www.evm.codes/?fork=cancun#20), which is negligible by comparison.
72
77
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
78
74
79
The cost of using the message is beyond the scope here, because it depends on your application.
75
80
76
-
So the main cost drivers are the 21,000 transaction gas cost has plus the cost of posting a *164+32t+n* byte transaction.
81
+
The main cost drivers are the 21,000 gas transaction cost plus the cost of posting a *164+32t+n* byte transaction.
77
82
78
83
## Cross domain messenger
79
84
@@ -99,7 +104,7 @@ The chain operator will bear the cost.
99
104
100
105
If autorelay is not turned on, the executing message is a call to [`L2ToL2CrossDomainMessenger.relayMessage`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol#L197-L256).
101
106
The only storage operation here is [noting the hash has been used for a message already](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol#L241).
102
-
This is previously unwritten storage, so we can expect to pay the tull*22,100* in gas.
107
+
This is previously unwritten storage, so we can expect to pay the full*22,100* in gas.
103
108
Plus, of course, the *21,000* that any transaction costs.
0 commit comments