Skip to content

Commit

Permalink
N-12: Constant Could be Used to Denote ETH on L2s
Browse files Browse the repository at this point in the history
Signed-off-by: bennett <[email protected]>
  • Loading branch information
bmzig committed Nov 8, 2024
1 parent 3df9450 commit 813bf95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion contracts/chain-adapters/ZkStack_Adapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import { BridgeHubInterface } from "../interfaces/ZkStackBridgeHub.sol";
contract ZkStack_Adapter is AdapterInterface {
using SafeERC20 for IERC20;

// The ZkSync bridgehub contract treats address(1) to represent ETH.
address private constant ETH_TOKEN_ADDRESS = address(1);

// We need to pay a base fee to the operator to include our L1 --> L2 transaction.
// https://docs.zksync.io/build/developer-reference/l1-l2-interoperability#l1-to-l2-gas-estimation-for-transactions

Expand Down Expand Up @@ -73,7 +76,7 @@ contract ZkStack_Adapter is AdapterInterface {
L1_GAS_TO_L2_GAS_PER_PUB_DATA_LIMIT = _l1GasToL2GasPerPubDataLimit;
SHARED_BRIDGE = BRIDGE_HUB.sharedBridge();
address gasToken = BRIDGE_HUB.baseToken(CHAIN_ID);
if (gasToken != address(1)) {
if (gasToken != ETH_TOKEN_ADDRESS) {
revert ETHGasTokenRequired();
}
}
Expand Down
7 changes: 5 additions & 2 deletions contracts/chain-adapters/ZkStack_CustomGasToken_Adapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ interface FunderInterface {
contract ZkStack_CustomGasToken_Adapter is AdapterInterface {
using SafeERC20 for IERC20;

// The ZkSync bridgehub contract treats address(1) to represent ETH.
address private constant ETH_TOKEN_ADDRESS = address(1);

// We need to pay a base fee to the operator to include our L1 --> L2 transaction.
// https://docs.zksync.io/build/developer-reference/l1-l2-interoperability#l1-to-l2-gas-estimation-for-transactions

Expand Down Expand Up @@ -96,7 +99,7 @@ contract ZkStack_CustomGasToken_Adapter is AdapterInterface {
L1_GAS_TO_L2_GAS_PER_PUB_DATA_LIMIT = _l1GasToL2GasPerPubDataLimit;
SHARED_BRIDGE = BRIDGE_HUB.sharedBridge();
CUSTOM_GAS_TOKEN = BRIDGE_HUB.baseToken(CHAIN_ID);
if (CUSTOM_GAS_TOKEN == address(1)) {
if (CUSTOM_GAS_TOKEN == ETH_TOKEN_ADDRESS) {
revert ETHGasTokenNotAllowed();
}
}
Expand Down Expand Up @@ -164,7 +167,7 @@ contract ZkStack_CustomGasToken_Adapter is AdapterInterface {
refundRecipient: L2_REFUND_ADDRESS,
secondBridgeAddress: BRIDGE_HUB.sharedBridge(),
secondBridgeValue: amount,
secondBridgeCalldata: _secondBridgeCalldata(to, address(1), amount)
secondBridgeCalldata: _secondBridgeCalldata(to, ETH_TOKEN_ADDRESS, amount)
})
);
} else if (l1Token == CUSTOM_GAS_TOKEN) {
Expand Down

0 comments on commit 813bf95

Please sign in to comment.