Skip to content

Commit 391fa4d

Browse files
kelemenoneotheprogramisttommysrsaxenismartmakh
authored
fix: script fixes (#726)
Signed-off-by: Danil <[email protected]> Co-authored-by: Neo <[email protected]> Co-authored-by: tommysr <[email protected]> Co-authored-by: Rahul Saxena <[email protected]> Co-authored-by: Artem Makhortov <[email protected]> Co-authored-by: Bence Haromi <[email protected]> Co-authored-by: Zach Kolodny <[email protected]> Co-authored-by: Stanislav Bezkorovainyi <[email protected]> Co-authored-by: Vlad Bochok <[email protected]> Co-authored-by: perekopskiy <[email protected]> Co-authored-by: perekopskiy <[email protected]> Co-authored-by: Danil <[email protected]> Co-authored-by: Ivan Schasny <[email protected]> Co-authored-by: Raid5594 <[email protected]> Co-authored-by: Raid Ateir <[email protected]>
1 parent a91bc7a commit 391fa4d

File tree

70 files changed

+2096
-444
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2096
-444
lines changed

.github/workflows/l1-contracts-ci.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ name: L1 contracts CI
33
on:
44
pull_request:
55

6+
# We need this permissions for this CI to work with external contributions
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
611
jobs:
712
build:
813
runs-on: ubuntu-latest

gas-bound-caller/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"ts-node": "^10.1.0",
3939
"typechain": "^4.0.0",
4040
"typescript": "^4.6.4",
41-
"zksync-ethers": "5.8.0-beta.5"
41+
"zksync-ethers": "^5.9.0"
4242
},
4343
"mocha": {
4444
"timeout": 240000,

l1-contracts/contracts/bridge/L1NativeTokenVault.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
1212

1313
import {IL1NativeTokenVault} from "./interfaces/IL1NativeTokenVault.sol";
1414
import {IL1AssetHandler} from "./interfaces/IL1AssetHandler.sol";
15-
1615
import {IL1AssetRouter} from "./interfaces/IL1AssetRouter.sol";
1716
import {ETH_TOKEN_ADDRESS} from "../common/Config.sol";
1817
import {DataEncoding} from "../common/libraries/DataEncoding.sol";
@@ -23,7 +22,7 @@ import {BridgeHelper} from "./BridgeHelper.sol";
2322
/// @custom:security-contact [email protected]
2423
/// @dev Vault holding L1 native ETH and ERC20 tokens bridged into the ZK chains.
2524
/// @dev Designed for use with a proxy for upgradability.
26-
contract L1NativeTokenVault is IL1NativeTokenVault, IL1AssetHandler, Ownable2StepUpgradeable, PausableUpgradeable {
25+
contract L1NativeTokenVault is IL1NativeTokenVault, Ownable2StepUpgradeable, PausableUpgradeable {
2726
using SafeERC20 for IERC20;
2827

2928
/// @dev The address of the WETH token on L1.
@@ -220,10 +219,15 @@ contract L1NativeTokenVault is IL1NativeTokenVault, IL1AssetHandler, Ownable2Ste
220219
}
221220

222221
/// @dev Receives and parses (name, symbol, decimals) from the token contract
223-
function getERC20Getters(address _token) public view returns (bytes memory) {
222+
function getERC20Getters(address _token) public view override returns (bytes memory) {
224223
return BridgeHelper.getERC20Getters(_token, ETH_TOKEN_ADDRESS);
225224
}
226225

226+
/// @dev Shows the assetId for a given chain and token address
227+
function getAssetId(uint256 _chainId, address _l1Token) external pure override returns (bytes32) {
228+
return DataEncoding.encodeNTVAssetId(_chainId, _l1Token);
229+
}
230+
227231
/// @dev Transfers tokens from the depositor address to the smart contract address.
228232
/// @return The difference between the contract balance before and after the transferring of funds.
229233
function _depositFunds(address _from, IERC20 _token, uint256 _amount) internal returns (uint256) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity 0.8.24;
4+
5+
/// @title L1 Base Token Asset Handler contract interface
6+
/// @author Matter Labs
7+
/// @custom:security-contact [email protected]
8+
/// @notice Used for any asset handler and called by the L1AssetRouter
9+
interface IL1BaseTokenAssetHandler {
10+
/// @notice Used to get the token address of an assetId
11+
function tokenAddress(bytes32 _assetId) external view returns (address);
12+
}

l1-contracts/contracts/bridge/interfaces/IL1NativeTokenVault.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
pragma solidity 0.8.24;
44

55
import {IL1AssetRouter} from "./IL1AssetRouter.sol";
6+
import {IL1AssetHandler} from "./IL1AssetHandler.sol";
7+
import {IL1BaseTokenAssetHandler} from "./IL1BaseTokenAssetHandler.sol";
68

79
/// @title L1 Native token vault contract interface
810
/// @author Matter Labs
911
/// @custom:security-contact [email protected]
1012
/// @notice The NTV is an Asset Handler for the L1AssetRouter to handle native tokens
11-
interface IL1NativeTokenVault {
13+
interface IL1NativeTokenVault is IL1AssetHandler, IL1BaseTokenAssetHandler {
1214
/// @notice The L1AssetRouter contract
1315
function L1_SHARED_BRIDGE() external view returns (IL1AssetRouter);
1416

@@ -24,6 +26,6 @@ interface IL1NativeTokenVault {
2426
/// @notice Used the get token balance for specific ZK chain in shared bridge
2527
function chainBalance(uint256 _chainId, address _l1Token) external view returns (uint256);
2628

27-
/// @notice Used to get the token address of an assetId
28-
function tokenAddress(bytes32 _assetId) external view returns (address);
29+
/// @dev Shows the assetId for a given chain and token address
30+
function getAssetId(uint256 _chainId, address _l1Token) external pure returns (bytes32);
2931
}

l1-contracts/contracts/bridgehub/Bridgehub.sol

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/
1111

1212
import {IBridgehub, L2TransactionRequestDirect, L2TransactionRequestTwoBridgesOuter, L2TransactionRequestTwoBridgesInner} from "./IBridgehub.sol";
1313
import {IL1AssetRouter} from "../bridge/interfaces/IL1AssetRouter.sol";
14+
import {IL1BaseTokenAssetHandler} from "../bridge/interfaces/IL1BaseTokenAssetHandler.sol";
1415
import {IStateTransitionManager} from "../state-transition/IStateTransitionManager.sol";
1516
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol";
1617
import {DataEncoding} from "../common/libraries/DataEncoding.sol";
@@ -48,15 +49,17 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
4849
IL1AssetRouter public sharedBridge;
4950

5051
/// @notice StateTransitionManagers that are registered, and ZKchains that use these STMs can use this bridgehub as settlement layer.
51-
mapping(address _stateTransitionManager => bool) public stateTransitionManagerIsRegistered;
52+
mapping(address stateTransitionManager => bool) public stateTransitionManagerIsRegistered;
53+
5254
/// @notice we store registered tokens (for arbitrary base token)
53-
mapping(address _baseToken => bool) public tokenIsRegistered;
55+
mapping(address baseToken => bool) public __DEPRECATED_tokenIsRegistered;
5456

5557
/// @notice chainID => StateTransitionManager contract address, STM that is managing rules for a given ZKchain.
56-
mapping(uint256 _chainId => address) public stateTransitionManager;
58+
mapping(uint256 chainId => address) public stateTransitionManager;
5759

5860
/// @notice chainID => baseToken contract address, token that is used as 'base token' by a given child chain.
59-
mapping(uint256 _chainId => address) public baseToken;
61+
// slither-disable-next-line uninitialized-state
62+
mapping(uint256 chainId => address) public __DEPRECATED_baseToken;
6063

6164
/// @dev used to manage non critical updates
6265
address public admin;
@@ -73,7 +76,7 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
7376
IMessageRoot public override messageRoot;
7477

7578
/// @notice Mapping from chain id to encoding of the base token used for deposits / withdrawals
76-
mapping(uint256 _chainId => bytes32) public baseTokenAssetId;
79+
mapping(uint256 chainId => bytes32) public baseTokenAssetId;
7780

7881
/// @notice The deployment tracker for the state transition managers.
7982
ISTMDeploymentTracker public stmDeployer;
@@ -89,6 +92,9 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
8992
/// @dev Sync layer chain is expected to have .. as the base token.
9093
mapping(uint256 chainId => bool isWhitelistedSettlementLayer) public whitelistedSettlementLayers;
9194

95+
/// @notice we store registered assetIds (for arbitrary base token)
96+
mapping(bytes32 baseTokenAssetId => bool) public assetIdIsRegistered;
97+
9298
modifier onlyOwnerOrAdmin() {
9399
require(msg.sender == admin || msg.sender == owner(), "BH: not owner or admin");
94100
_;
@@ -181,7 +187,7 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
181187
if (baseTokenAssetId[_chainId] == bytes32(0)) {
182188
return;
183189
}
184-
address token = baseToken[_chainId];
190+
address token = __DEPRECATED_baseToken[_chainId];
185191
require(token != address(0), "BH: token not set");
186192
baseTokenAssetId[_chainId] = DataEncoding.encodeNTVAssetId(block.chainid, token);
187193
}
@@ -222,13 +228,13 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
222228
emit StateTransitionManagerRemoved(_stateTransitionManager);
223229
}
224230

225-
/// @notice token can be any contract with the appropriate interface/functionality
226-
/// @param _token address of base token to be registered
227-
function addToken(address _token) external onlyOwner {
228-
require(!tokenIsRegistered[_token], "BH: token already registered");
229-
tokenIsRegistered[_token] = true;
231+
/// @notice asset id can represent any token contract with the appropriate interface/functionality
232+
/// @param _baseTokenAssetId asset id of base token to be registered
233+
function addTokenAssetId(bytes32 _baseTokenAssetId) external onlyOwner {
234+
require(!assetIdIsRegistered[_baseTokenAssetId], "BH: asset id already registered");
235+
assetIdIsRegistered[_baseTokenAssetId] = true;
230236

231-
emit TokenRegistered(_token);
237+
emit BaseTokenAssetIdRegistered(_baseTokenAssetId);
232238
}
233239

234240
/// @notice Used to register a chain as a settlement layer.
@@ -274,15 +280,15 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
274280
/// @notice for Eth the baseToken address is 1
275281
/// @param _chainId the chainId of the chain
276282
/// @param _stateTransitionManager the state transition manager address
277-
/// @param _baseToken the base token of the chain
283+
/// @param _baseTokenAssetId the base token asset id of the chain
278284
/// @param _salt the salt for the chainId, currently not used
279285
/// @param _admin the admin of the chain
280286
/// @param _initData the fixed initialization data for the chain
281287
/// @param _factoryDeps the factory dependencies for the chain's deployment
282288
function createNewChain(
283289
uint256 _chainId,
284290
address _stateTransitionManager,
285-
address _baseToken,
291+
bytes32 _baseTokenAssetId,
286292
// solhint-disable-next-line no-unused-vars
287293
uint256 _salt,
288294
address _admin,
@@ -294,21 +300,19 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
294300
require(_chainId != block.chainid, "BH: chain id must not match current chainid");
295301

296302
require(stateTransitionManagerIsRegistered[_stateTransitionManager], "BH: state transition not registered");
297-
require(tokenIsRegistered[_baseToken], "BH: token not registered");
303+
require(assetIdIsRegistered[_baseTokenAssetId], "BH: asset id not registered");
298304
require(address(sharedBridge) != address(0), "BH: shared bridge not set");
299305

300306
require(stateTransitionManager[_chainId] == address(0), "BH: chainId already registered");
301307

302308
stateTransitionManager[_chainId] = _stateTransitionManager;
303-
baseToken[_chainId] = _baseToken;
304309

305-
/// For now all base tokens have to use the NTV.
306-
baseTokenAssetId[_chainId] = DataEncoding.encodeNTVAssetId(block.chainid, _baseToken);
310+
baseTokenAssetId[_chainId] = _baseTokenAssetId;
307311
settlementLayer[_chainId] = block.chainid;
308312

309313
address chainAddress = IStateTransitionManager(_stateTransitionManager).createNewChain({
310314
_chainId: _chainId,
311-
_baseToken: _baseToken,
315+
_baseTokenAssetId: _baseTokenAssetId,
312316
_sharedBridge: address(sharedBridge),
313317
_admin: _admin,
314318
_initData: _initData,
@@ -332,6 +336,15 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
332336
Getters
333337
//////////////////////////////////////////////////////////////*/
334338

339+
/// @notice baseToken function, which takes assetId as input, reads assetHandler from AR, and tokenAddress from AH
340+
function baseToken(uint256 _chainId) public view returns (address) {
341+
bytes32 baseTokenAssetId = baseTokenAssetId[_chainId];
342+
IL1BaseTokenAssetHandler assetHandlerAddress = IL1BaseTokenAssetHandler(
343+
sharedBridge.assetHandlerAddress(baseTokenAssetId)
344+
);
345+
return assetHandlerAddress.tokenAddress(baseTokenAssetId);
346+
}
347+
335348
/// @notice Returns all the registered hyperchain addresses
336349
function getAllHyperchains() public view override returns (address[] memory chainAddresses) {
337350
uint256[] memory keys = hyperchainMap.keys();

l1-contracts/contracts/bridgehub/IBridgehub.sol

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ interface IBridgehub is IL1AssetHandler {
7373

7474
function stateTransitionManager(uint256 _chainId) external view returns (address);
7575

76-
function tokenIsRegistered(address _baseToken) external view returns (bool);
76+
function assetIdIsRegistered(bytes32 _baseTokenAssetId) external view returns (bool);
7777

7878
function baseToken(uint256 _chainId) external view returns (address);
7979

@@ -137,7 +137,7 @@ interface IBridgehub is IL1AssetHandler {
137137
function createNewChain(
138138
uint256 _chainId,
139139
address _stateTransitionManager,
140-
address _baseToken,
140+
bytes32 _baseTokenAssetId,
141141
uint256 _salt,
142142
address _admin,
143143
bytes calldata _initData,
@@ -148,7 +148,7 @@ interface IBridgehub is IL1AssetHandler {
148148

149149
function removeStateTransitionManager(address _stateTransitionManager) external;
150150

151-
function addToken(address _token) external;
151+
function addTokenAssetId(bytes32 _baseTokenAssetId) external;
152152

153153
function setAddresses(
154154
address _sharedBridge,
@@ -162,9 +162,7 @@ interface IBridgehub is IL1AssetHandler {
162162

163163
event StateTransitionManagerRemoved(address indexed stateTransitionManager);
164164

165-
event TokenRegistered(address indexed token);
166-
167-
event SharedBridgeUpdated(address indexed sharedBridge);
165+
event BaseTokenAssetIdRegistered(bytes32 indexed assetId);
168166

169167
function whitelistedSettlementLayers(uint256 _chainId) external view returns (bool);
170168

l1-contracts/contracts/dev-contracts/test/DummyAdminFacetNoOverlap.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ contract DummyAdminFacetNoOverlap is ZkSyncHyperchainBase {
1818

1919
function executeUpgradeNoOverlap(Diamond.DiamondCutData calldata _diamondCut) external {
2020
Diamond.diamondCut(_diamondCut);
21-
s.baseTokenAssetId = DataEncoding.encodeNTVAssetId(block.chainid, s.baseToken);
2221
}
2322

2423
function receiveEther() external payable {}

l1-contracts/contracts/dev-contracts/test/DummyBridgehub.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {IMessageRoot} from "../../bridgehub/IMessageRoot.sol";
88

99
import {IGetters} from "../../state-transition/chain-interfaces/IGetters.sol";
1010

11+
/// @title DummyBridgehub
12+
/// @notice A test smart contract that allows to set State Transition Manager for a given chain
1113
contract DummyBridgehub {
1214
IMessageRoot public messageRoot;
1315

l1-contracts/contracts/dev-contracts/test/DummyHyperchain.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ contract DummyHyperchain is MailboxFacet {
1313
s.bridgehub = bridgeHubAddress;
1414
}
1515

16+
function getEraChainId() public view returns (uint256) {
17+
return ERA_CHAIN_ID;
18+
}
19+
1620
function setBridgeHubAddress(address bridgeHubAddress) public {
1721
s.bridgehub = bridgeHubAddress;
1822
}

0 commit comments

Comments
 (0)