Skip to content

Commit b321c6d

Browse files
committed
Revert "improve: query shared bridge address dynamically (#944)"
This reverts commit 2727922.
1 parent 4929cc1 commit b321c6d

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

contracts/chain-adapters/ZkStack_Adapter.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ contract ZkStack_Adapter is AdapterInterface {
4949
// Set l1Weth at construction time to make testing easier.
5050
WETH9Interface public immutable L1_WETH;
5151

52+
// SharedBridge address, which is read from the BridgeHub at construction.
53+
address public immutable SHARED_BRIDGE;
54+
5255
// The maximum gas price a transaction sent to this adapter may have. This is set to prevent a block producer from setting an artificially high priority fee
5356
// when calling a hub pool message relay, which would otherwise cause a large amount of ETH to be sent to L2.
5457
uint256 private immutable MAX_TX_GASPRICE;
@@ -84,6 +87,7 @@ contract ZkStack_Adapter is AdapterInterface {
8487
L2_GAS_LIMIT = _l2GasLimit;
8588
MAX_TX_GASPRICE = _maxTxGasprice;
8689
L1_GAS_TO_L2_GAS_PER_PUB_DATA_LIMIT = _l1GasToL2GasPerPubDataLimit;
90+
SHARED_BRIDGE = BRIDGE_HUB.sharedBridge();
8791
address gasToken = BRIDGE_HUB.baseToken(CHAIN_ID);
8892
if (gasToken != ETH_TOKEN_ADDRESS) {
8993
revert ETHGasTokenRequired();
@@ -156,8 +160,7 @@ contract ZkStack_Adapter is AdapterInterface {
156160
);
157161
} else {
158162
// An ERC20 that is not WETH.
159-
address sharedBridge = BRIDGE_HUB.sharedBridge();
160-
IERC20(l1Token).forceApprove(sharedBridge, amount);
163+
IERC20(l1Token).forceApprove(SHARED_BRIDGE, amount);
161164
txHash = BRIDGE_HUB.requestL2TransactionTwoBridges{ value: txBaseCost }(
162165
BridgeHubInterface.L2TransactionRequestTwoBridgesOuter({
163166
chainId: CHAIN_ID,
@@ -166,7 +169,7 @@ contract ZkStack_Adapter is AdapterInterface {
166169
l2GasLimit: L2_GAS_LIMIT,
167170
l2GasPerPubdataByteLimit: L1_GAS_TO_L2_GAS_PER_PUB_DATA_LIMIT,
168171
refundRecipient: L2_REFUND_ADDRESS,
169-
secondBridgeAddress: sharedBridge,
172+
secondBridgeAddress: SHARED_BRIDGE,
170173
secondBridgeValue: 0,
171174
secondBridgeCalldata: _secondBridgeCalldata(to, l1Token, amount)
172175
})

contracts/chain-adapters/ZkStack_CustomGasToken_Adapter.sol

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ contract ZkStack_CustomGasToken_Adapter is AdapterInterface {
6464
// Set l1Weth at construction time to make testing easier.
6565
WETH9Interface public immutable L1_WETH;
6666

67+
// SharedBridge address, which is read from the BridgeHub at construction.
68+
address public immutable SHARED_BRIDGE;
69+
6770
// Custom gas token address, which is read from the BridgeHub at construction.
6871
address public immutable CUSTOM_GAS_TOKEN;
6972

@@ -107,6 +110,7 @@ contract ZkStack_CustomGasToken_Adapter is AdapterInterface {
107110
L2_GAS_LIMIT = _l2GasLimit;
108111
MAX_TX_GASPRICE = _maxTxGasprice;
109112
L1_GAS_TO_L2_GAS_PER_PUB_DATA_LIMIT = _l1GasToL2GasPerPubDataLimit;
113+
SHARED_BRIDGE = BRIDGE_HUB.sharedBridge();
110114
CUSTOM_GAS_TOKEN = BRIDGE_HUB.baseToken(CHAIN_ID);
111115
if (CUSTOM_GAS_TOKEN == ETH_TOKEN_ADDRESS) {
112116
revert ETHGasTokenNotAllowed();
@@ -121,7 +125,7 @@ contract ZkStack_CustomGasToken_Adapter is AdapterInterface {
121125
*/
122126
function relayMessage(address target, bytes memory message) external payable override {
123127
uint256 txBaseCost = _pullCustomGas(L2_GAS_LIMIT);
124-
IERC20(CUSTOM_GAS_TOKEN).forceApprove(BRIDGE_HUB.sharedBridge(), txBaseCost);
128+
IERC20(CUSTOM_GAS_TOKEN).forceApprove(SHARED_BRIDGE, txBaseCost);
125129

126130
// Returns the hash of the requested L2 transaction. This hash can be used to follow the transaction status.
127131
bytes32 canonicalTxHash = BRIDGE_HUB.requestL2TransactionDirect(
@@ -159,14 +163,13 @@ contract ZkStack_CustomGasToken_Adapter is AdapterInterface {
159163
// A bypass proxy seems to no longer be needed to avoid deposit limits. The tracking of these limits seems to be deprecated.
160164
// See: https://github.com/matter-labs/era-contracts/blob/bce4b2d0f34bd87f1aaadd291772935afb1c3bd6/l1-contracts/contracts/bridge/L1ERC20Bridge.sol#L54-L55
161165
uint256 txBaseCost = _pullCustomGas(L2_GAS_LIMIT);
162-
address sharedBridge = BRIDGE_HUB.sharedBridge();
163166

164167
bytes32 txHash;
165168
if (l1Token == address(L1_WETH)) {
166169
// If the l1Token is WETH then unwrap it to ETH then send the ETH to the standard bridge along with the base
167170
// cost of custom gas tokens.
168171
L1_WETH.withdraw(amount);
169-
IERC20(CUSTOM_GAS_TOKEN).forceApprove(sharedBridge, txBaseCost);
172+
IERC20(CUSTOM_GAS_TOKEN).forceApprove(SHARED_BRIDGE, txBaseCost);
170173
// Note: When bridging ETH with `L2TransactionRequestTwoBridgesOuter`, the second bridge must be 0 for the shared bridge call to not revert.
171174
// https://github.com/matter-labs/era-contracts/blob/aafee035db892689df3f7afe4b89fd6467a39313/l1-contracts/contracts/bridge/L1SharedBridge.sol#L328
172175
txHash = BRIDGE_HUB.requestL2TransactionTwoBridges{ value: amount }(
@@ -177,14 +180,14 @@ contract ZkStack_CustomGasToken_Adapter is AdapterInterface {
177180
l2GasLimit: L2_GAS_LIMIT,
178181
l2GasPerPubdataByteLimit: L1_GAS_TO_L2_GAS_PER_PUB_DATA_LIMIT,
179182
refundRecipient: L2_REFUND_ADDRESS,
180-
secondBridgeAddress: sharedBridge,
183+
secondBridgeAddress: SHARED_BRIDGE,
181184
secondBridgeValue: amount,
182185
secondBridgeCalldata: _secondBridgeCalldata(to, ETH_TOKEN_ADDRESS, 0)
183186
})
184187
);
185188
} else if (l1Token == CUSTOM_GAS_TOKEN) {
186189
// The chain's custom gas token.
187-
IERC20(l1Token).forceApprove(sharedBridge, txBaseCost + amount);
190+
IERC20(l1Token).forceApprove(SHARED_BRIDGE, txBaseCost + amount);
188191
txHash = BRIDGE_HUB.requestL2TransactionDirect(
189192
BridgeHubInterface.L2TransactionRequestDirect({
190193
chainId: CHAIN_ID,
@@ -200,8 +203,8 @@ contract ZkStack_CustomGasToken_Adapter is AdapterInterface {
200203
);
201204
} else {
202205
// An ERC20 that is not WETH and not the custom gas token.
203-
IERC20(CUSTOM_GAS_TOKEN).forceApprove(sharedBridge, txBaseCost);
204-
IERC20(l1Token).forceApprove(sharedBridge, amount);
206+
IERC20(CUSTOM_GAS_TOKEN).forceApprove(SHARED_BRIDGE, txBaseCost);
207+
IERC20(l1Token).forceApprove(SHARED_BRIDGE, amount);
205208
txHash = BRIDGE_HUB.requestL2TransactionTwoBridges(
206209
BridgeHubInterface.L2TransactionRequestTwoBridgesOuter({
207210
chainId: CHAIN_ID,
@@ -210,7 +213,7 @@ contract ZkStack_CustomGasToken_Adapter is AdapterInterface {
210213
l2GasLimit: L2_GAS_LIMIT,
211214
l2GasPerPubdataByteLimit: L1_GAS_TO_L2_GAS_PER_PUB_DATA_LIMIT,
212215
refundRecipient: L2_REFUND_ADDRESS,
213-
secondBridgeAddress: sharedBridge,
216+
secondBridgeAddress: SHARED_BRIDGE,
214217
secondBridgeValue: 0,
215218
secondBridgeCalldata: _secondBridgeCalldata(to, l1Token, amount)
216219
})

0 commit comments

Comments
 (0)