Skip to content

Commit a1b54bf

Browse files
committed
claimId to ensure claims can only happen once
1 parent 1fd10ae commit a1b54bf

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ecosystem/incentivized-relays-mvp.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,25 @@ Relayers that delivered messages can compensate themselves by pushing through th
7575
```solidity
7676
contract L2ToL2CrossDomainGasTank {
7777
78+
mapping(bytes32 => bool) claimed;
79+
7880
function claim(Identifier calldata id, bytes calldata payload) nonReentrant external {
7981
require(id.origin == address(messenger));
8082
ICrossL2Inbox(Predeploys.CROSS_L2_INBOX).validateMessage(id, keccak256(payload));
8183
8284
// parse the receipt
8385
require(payload[:32] == RelayedMessageGasReceipt.selector);
84-
(bytes32 rootMsgHash, address txOrigin, address relayer, uint256 relayCost) = _decode(payload);
86+
(bytes32 rootMsgHash, address txOrigin, uint256 callDepth, address relayer, uint256 relayCost) = _decode(payload);
8587
8688
// ensure message was sent from this chain
8789
require(messenger.sentMessages[rootMsgHash]);
8890
91+
// ensure unclaimed, and mark the claim
92+
bytes32 claimId = keccak256(abi.encode(rootMsgHash, callDepth));
93+
require(!claimed[claimId]);
94+
95+
claimed[claimId] = true
96+
8997
// compute total cost
9098
uint256 claimCost = CLAIM_OVERHEAD * block.basefee;
9199
uint256 cost = relayCost + claimCost;
@@ -98,6 +106,8 @@ contract L2ToL2CrossDomainGasTank {
98106
}
99107
```
100108

109+
A claim is uniquely identified by the `(rootMsgHash, callDepth)` tuple.
110+
101111
As relayers deliver messages, they can claim the cost against the original tx sender deposit with the gas tank. This design introduces some off-chain complexity for the relayer.
102112

103113
1. The relayer must simulate the call and ensure the emitted tx origin has a deposit that will cover the cost on the originating chain.

0 commit comments

Comments
 (0)