Skip to content

Commit 3e29d4c

Browse files
qbzztkrofax
andauthored
@krofax suggestions
Co-authored-by: Blessing Krofegha <[email protected]>
1 parent 1317a9c commit 3e29d4c

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

pages/interop/estimate-costs.mdx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import { InteropCallout } from '@/components/WipCallout'
2424
# Estimating the cost of interop messages
2525

2626
<Callout type="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.
2929

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.
3131
</Callout>
3232

3333
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
3737
* The transaction type.
3838
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.
3939
* 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.
4141

4242
## CrossL2Inbox
4343

4444
This is the low level protocol used by all interop protocols, including `L2ToL2CrossDomainMessenger`.
4545

4646
### Initiating message
4747

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).
5151

5252
### Executing message
5353

@@ -61,19 +61,24 @@ The executing message cost has several components:
6161
The first and second components depend on the log entry.
6262
`CrossL2Inbox.validateMessage` only requires a 32 byte hash of the log entry, but actually using it typically requires the information that has been hashed.
6363

64-
Additionally, you need to provide the `CrossL2Inbox` with how to find the log entry.
65-
This is encoded in a [five member 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.
6767

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
6974

7075
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.
7277
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.
7378

7479
The cost of using the message is beyond the scope here, because it depends on your application.
7580

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

7883
## Cross domain messenger
7984

@@ -99,7 +104,7 @@ The chain operator will bear the cost.
99104

100105
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).
101106
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.
103108
Plus, of course, the *21,000* that any transaction costs.
104109
All the other gas costs are negligible.
105110

0 commit comments

Comments
 (0)