Skip to content

Commit e3c32a8

Browse files
committed
port transact feature from Passage to Zenith
1 parent 81e9690 commit e3c32a8

File tree

7 files changed

+95
-131
lines changed

7 files changed

+95
-131
lines changed

.gas-snapshot

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@ OrdersTest:test_sweepERC20() (gas: 60402)
1414
OrdersTest:test_sweepETH() (gas: 81940)
1515
OrdersTest:test_underflowETH() (gas: 63528)
1616
PassageTest:test_configureEnter() (gas: 82311)
17-
PassageTest:test_disallowedEnter() (gas: 17916)
18-
PassageTest:test_enter() (gas: 25563)
19-
PassageTest:test_enterToken() (gas: 64332)
20-
PassageTest:test_enterToken_defaultChain() (gas: 62915)
21-
PassageTest:test_enterTransact() (gas: 60890)
22-
PassageTest:test_enter_defaultChain() (gas: 24033)
23-
PassageTest:test_fallback() (gas: 21534)
24-
PassageTest:test_onlyTokenAdmin() (gas: 16926)
25-
PassageTest:test_receive() (gas: 21384)
26-
PassageTest:test_setUp() (gas: 16968)
27-
PassageTest:test_transact() (gas: 58562)
28-
PassageTest:test_transact_defaultChain() (gas: 57475)
29-
PassageTest:test_withdraw() (gas: 59033)
30-
ZenithTest:test_addSequencer() (gas: 88121)
31-
ZenithTest:test_badSignature() (gas: 37241)
32-
ZenithTest:test_incorrectHostBlock() (gas: 35086)
33-
ZenithTest:test_notSequencer() (gas: 34076)
34-
ZenithTest:test_notSequencerAdmin() (gas: 10125)
35-
ZenithTest:test_onePerBlock() (gas: 68193)
36-
ZenithTest:test_removeSequencer() (gas: 39665)
37-
ZenithTest:test_setUp() (gas: 8366)
38-
ZenithTest:test_submitBlock() (gas: 63333)
17+
PassageTest:test_disallowedEnter() (gas: 17938)
18+
PassageTest:test_enter() (gas: 25507)
19+
PassageTest:test_enterToken() (gas: 64354)
20+
PassageTest:test_enterToken_defaultChain() (gas: 62870)
21+
PassageTest:test_enter_defaultChain() (gas: 24011)
22+
PassageTest:test_fallback() (gas: 21445)
23+
PassageTest:test_onlyTokenAdmin() (gas: 16881)
24+
PassageTest:test_receive() (gas: 21339)
25+
PassageTest:test_setUp() (gas: 16901)
26+
PassageTest:test_withdraw() (gas: 59055)
27+
ZenithTest:test_addSequencer() (gas: 88222)
28+
ZenithTest:test_badSignature() (gas: 37320)
29+
ZenithTest:test_incorrectHostBlock() (gas: 35165)
30+
ZenithTest:test_notSequencer() (gas: 34155)
31+
ZenithTest:test_notSequencerAdmin() (gas: 10137)
32+
ZenithTest:test_onePerBlock() (gas: 68351)
33+
ZenithTest:test_removeSequencer() (gas: 39744)
34+
ZenithTest:test_setUp() (gas: 8410)
35+
ZenithTest:test_submitBlock() (gas: 63456)
36+
ZenithTest:test_transact() (gas: 32536)
37+
ZenithTest:test_transact_defaultChain() (gas: 31022)

script/Zenith.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ contract ZenithScript is Script {
1616
address sequencerAdmin
1717
) public returns (Zenith z, Passage p, HostOrders m) {
1818
vm.startBroadcast();
19-
z = new Zenith(sequencerAdmin);
19+
z = new Zenith(defaultRollupChainId, sequencerAdmin);
2020
p = new Passage(defaultRollupChainId, withdrawalAdmin, initialEnterTokens);
2121
m = new HostOrders();
2222
}

src/Passage.sol

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,6 @@ contract Passage {
3636
uint256 indexed rollupChainId, address indexed rollupRecipient, address indexed token, uint256 amount
3737
);
3838

39-
/// @notice Emitted to send a special transaction to the rollup.
40-
event Transact(
41-
uint256 indexed rollupChainId,
42-
address indexed sender,
43-
address indexed to,
44-
bytes data,
45-
uint256 value,
46-
uint256 gas,
47-
uint256 maxFeePerGas
48-
);
49-
5039
/// @notice Emitted when the admin withdraws tokens from the contract.
5140
event Withdrawal(address indexed token, address indexed recipient, uint256 amount);
5241

@@ -106,54 +95,6 @@ contract Passage {
10695
enterToken(defaultRollupChainId, rollupRecipient, token, amount);
10796
}
10897

109-
/// @notice Allows a special transaction to be sent to the rollup with sender == L1 msg.sender.
110-
/// @dev Transaction is processed after normal rollup block execution.
111-
/// @dev See `enterTransact` for docs.
112-
function transact(
113-
uint256 rollupChainId,
114-
address to,
115-
bytes calldata data,
116-
uint256 value,
117-
uint256 gas,
118-
uint256 maxFeePerGas
119-
) public payable {
120-
enterTransact(rollupChainId, msg.sender, to, data, value, gas, maxFeePerGas);
121-
}
122-
123-
/// @dev See `transact` for docs.
124-
function transact(address to, bytes calldata data, uint256 value, uint256 gas, uint256 maxFeePerGas)
125-
external
126-
payable
127-
{
128-
enterTransact(defaultRollupChainId, msg.sender, to, data, value, gas, maxFeePerGas);
129-
}
130-
131-
/// @notice Send Ether on the rollup, send a special transaction to be sent to the rollup with sender == L1 msg.sender.
132-
/// @dev Enter and Transact are processed after normal rollup block execution.
133-
/// @dev See `enter` for Enter docs.
134-
/// @param rollupChainId - The rollup chain to send the transaction to.
135-
/// @param etherRecipient - The recipient of the ether.
136-
/// @param to - The address to call on the rollup.
137-
/// @param data - The data to send to the rollup.
138-
/// @param value - The amount of Ether to send on the rollup.
139-
/// @param gas - The gas limit for the transaction.
140-
/// @param maxFeePerGas - The maximum fee per gas for the transaction (per EIP-1559).
141-
/// @custom:emits Transact indicating the transaction to mine on the rollup.
142-
function enterTransact(
143-
uint256 rollupChainId,
144-
address etherRecipient,
145-
address to,
146-
bytes calldata data,
147-
uint256 value,
148-
uint256 gas,
149-
uint256 maxFeePerGas
150-
) public payable {
151-
// if msg.value is attached, Enter
152-
enter(rollupChainId, etherRecipient);
153-
// emit Transact event
154-
emit Transact(rollupChainId, msg.sender, to, data, value, gas, maxFeePerGas);
155-
}
156-
15798
/// @notice Alow/Disallow a given ERC20 token to enter the rollup.
15899
function configureEnter(address token, bool _canEnter) external {
159100
if (msg.sender != tokenAdmin) revert OnlyTokenAdmin();

src/Zenith.sol

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ pragma solidity ^0.8.24;
44
import {Passage} from "./Passage.sol";
55

66
contract Zenith {
7+
/// @notice The chainId of rollup that Ether will be sent to by default when entering the rollup via fallback() or receive().
8+
uint256 public immutable defaultRollupChainId;
9+
710
/// @notice The address that is allowed to set/remove sequencers.
811
address public immutable sequencerAdmin;
912

@@ -63,10 +66,22 @@ contract Zenith {
6366
bytes32 blockDataHash
6467
);
6568

69+
/// @notice Emitted to send a special transaction to the rollup.
70+
event Transact(
71+
uint256 indexed rollupChainId,
72+
address indexed sender,
73+
address indexed to,
74+
bytes data,
75+
uint256 value,
76+
uint256 gas,
77+
uint256 maxFeePerGas
78+
);
79+
6680
/// @notice Emitted when a sequencer is added or removed.
6781
event SequencerSet(address indexed sequencer, bool indexed permissioned);
6882

69-
constructor(address _sequencerAdmin) {
83+
constructor(uint256 _defaultRollupChainId, address _sequencerAdmin) {
84+
defaultRollupChainId = _defaultRollupChainId;
7085
sequencerAdmin = _sequencerAdmin;
7186
deployBlockNumber = block.number;
7287
}
@@ -125,6 +140,32 @@ contract Zenith {
125140
);
126141
}
127142

143+
/// @notice Send a special transaction to be sent to the rollup with sender == L1 msg.sender.
144+
/// @dev Transact is processed after normal rollup block execution.
145+
/// @param rollupChainId - The rollup chain to send the transaction to.
146+
/// @param to - The address to call on the rollup.
147+
/// @param data - The data to send to the rollup.
148+
/// @param value - The amount of Ether to send on the rollup.
149+
/// @param gas - The gas limit for the transaction.
150+
/// @param maxFeePerGas - The maximum fee per gas for the transaction (per EIP-1559).
151+
/// @custom:emits Transact indicating the transaction to mine on the rollup.
152+
function transact(
153+
uint256 rollupChainId,
154+
address to,
155+
bytes calldata data,
156+
uint256 value,
157+
uint256 gas,
158+
uint256 maxFeePerGas
159+
) public {
160+
// emit Transact event
161+
emit Transact(rollupChainId, msg.sender, to, data, value, gas, maxFeePerGas);
162+
}
163+
164+
/// @dev See `transact` for docs.
165+
function transact(address to, bytes calldata data, uint256 value, uint256 gas, uint256 maxFeePerGas) external {
166+
transact(defaultRollupChainId, to, data, value, gas, maxFeePerGas);
167+
}
168+
128169
/// @notice Construct hash of block details that the sequencer signs.
129170
/// @param header - the header information for the rollup block.
130171
/// @return commit - the hash of the encoded block details.

test/Helpers.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ contract HelpersTest is Test {
1818

1919
function setUp() public {
2020
vm.createSelectFork("https://rpc.holesky.ethpandaops.io");
21-
target = new Zenith(0x29403F107781ea45Bf93710abf8df13F67f2008f);
21+
target = new Zenith(block.number + 1, 0x29403F107781ea45Bf93710abf8df13F67f2008f);
2222
}
2323

2424
function check_signature() public {

test/Passage.t.sol

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ contract PassageTest is Test {
1414
address recipient = address(0x123);
1515
uint256 amount = 200;
1616

17-
address to = address(0x01);
18-
bytes data = abi.encodeWithSelector(ERC20.transfer.selector, recipient, amount);
19-
uint256 value = 100;
20-
uint256 gas = 10_000_000;
21-
uint256 maxFeePerGas = 50;
22-
2317
uint256 tokenAdminKey = 123;
2418

2519
event Enter(uint256 indexed rollupChainId, address indexed rollupRecipient, uint256 amount);
@@ -28,16 +22,6 @@ contract PassageTest is Test {
2822
uint256 indexed rollupChainId, address indexed rollupRecipient, address indexed token, uint256 amount
2923
);
3024

31-
event Transact(
32-
uint256 indexed rollupChainId,
33-
address indexed sender,
34-
address indexed to,
35-
bytes data,
36-
uint256 value,
37-
uint256 gas,
38-
uint256 maxFeePerGas
39-
);
40-
4125
event Withdrawal(address indexed token, address indexed recipient, uint256 amount);
4226

4327
event EnterConfigured(address indexed token, bool indexed canEnter);
@@ -150,36 +134,6 @@ contract PassageTest is Test {
150134
target.enterToken(recipient, token, amount);
151135
}
152136

153-
function test_transact() public {
154-
vm.expectEmit();
155-
emit Transact(chainId, address(this), to, data, value, gas, maxFeePerGas);
156-
target.transact(chainId, to, data, value, gas, maxFeePerGas);
157-
158-
vm.expectEmit();
159-
emit Enter(chainId, address(this), amount);
160-
target.transact{value: amount}(chainId, to, data, value, gas, maxFeePerGas);
161-
}
162-
163-
function test_transact_defaultChain() public {
164-
vm.expectEmit();
165-
emit Transact(target.defaultRollupChainId(), address(this), to, data, value, gas, maxFeePerGas);
166-
target.transact(to, data, value, gas, maxFeePerGas);
167-
168-
vm.expectEmit();
169-
emit Enter(target.defaultRollupChainId(), address(this), amount);
170-
target.transact{value: amount}(to, data, value, gas, maxFeePerGas);
171-
}
172-
173-
function test_enterTransact() public {
174-
vm.expectEmit();
175-
emit Transact(chainId, address(this), to, data, value, gas, maxFeePerGas);
176-
target.enterTransact(chainId, recipient, to, data, value, gas, maxFeePerGas);
177-
178-
vm.expectEmit();
179-
emit Enter(chainId, recipient, amount);
180-
target.enterTransact{value: amount}(chainId, recipient, to, data, value, gas, maxFeePerGas);
181-
}
182-
183137
function test_withdraw() public {
184138
TestERC20(token).mint(address(target), amount);
185139

test/Zenith.t.sol

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ contract ZenithTest is Test {
1515
uint256 sequencerKey = 123;
1616
uint256 notSequencerKey = 300;
1717

18+
uint256 chainId = 3;
19+
address to = address(0x01);
20+
bytes data = abi.encode(0xbeef);
21+
uint256 value = 100;
22+
uint256 gas = 10_000_000;
23+
uint256 maxFeePerGas = 50;
24+
1825
event BlockSubmitted(
1926
address indexed sequencer,
2027
uint256 indexed rollupChainId,
@@ -25,8 +32,18 @@ contract ZenithTest is Test {
2532

2633
event SequencerSet(address indexed sequencer, bool indexed permissioned);
2734

35+
event Transact(
36+
uint256 indexed rollupChainId,
37+
address indexed sender,
38+
address indexed to,
39+
bytes data,
40+
uint256 value,
41+
uint256 gas,
42+
uint256 maxFeePerGas
43+
);
44+
2845
function setUp() public {
29-
target = new Zenith(address(this));
46+
target = new Zenith(block.number + 1, address(this));
3047
target.addSequencer(vm.addr(sequencerKey));
3148

3249
// set default block values
@@ -159,4 +176,16 @@ contract ZenithTest is Test {
159176
vm.expectRevert(Zenith.OnlySequencerAdmin.selector);
160177
target.removeSequencer(address(0x02));
161178
}
179+
180+
function test_transact() public {
181+
vm.expectEmit();
182+
emit Transact(chainId, address(this), to, data, value, gas, maxFeePerGas);
183+
target.transact(chainId, to, data, value, gas, maxFeePerGas);
184+
}
185+
186+
function test_transact_defaultChain() public {
187+
vm.expectEmit();
188+
emit Transact(target.defaultRollupChainId(), address(this), to, data, value, gas, maxFeePerGas);
189+
target.transact(to, data, value, gas, maxFeePerGas);
190+
}
162191
}

0 commit comments

Comments
 (0)