Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kl/without 1.5.0 merge dev #331

Merged
merged 135 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 97 commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
587fc6f
Use Governance contract as STM owner
ly0va Apr 2, 2024
56cfe4b
Fix deploy script with undefined chainId
ly0va Apr 3, 2024
08fcdc3
updating hyperchain migration tests
kelemeno Mar 21, 2024
fed442f
updating hyperchain migration tests
kelemeno Mar 21, 2024
a975413
modifying hyperchain upgrade
kelemeno Mar 24, 2024
1cc2c80
creating script for hyperchain upgrade
kelemeno Mar 25, 2024
5eaf3fa
updated upgrade scripts
kelemeno Mar 25, 2024
89ebe8e
zk fmt
kelemeno Mar 25, 2024
5cf9582
contracts era chain id fix
kelemeno Mar 26, 2024
34a9cd5
zk fmt and linting
kelemeno Mar 26, 2024
5a32908
small fix in deploy script
kelemeno Mar 26, 2024
a21571b
genesis protocol version from latest p v
kelemeno Mar 28, 2024
30f8956
updated upgrade tests
kelemeno Apr 3, 2024
4befd8a
Ownable2StepUpgradeable
kelemeno Apr 3, 2024
c6be4c7
fixed typo
kelemeno Apr 1, 2024
445bcf7
fixed "changeFeeParams" function
kelemeno Apr 1, 2024
cff36f9
setValidium mode based on storedBatchHashes
kelemeno Apr 1, 2024
8f4c5b0
Fix PR review
vladbochok Apr 1, 2024
ee5ca89
fixed currentPendingAdmin log error
kelemeno Apr 1, 2024
021b1c0
new events
kelemeno Apr 1, 2024
38147a6
gas cost fixes
kelemeno Apr 2, 2024
ee7bd5a
zk lint
kelemeno Apr 2, 2024
db1130f
changed STM -> DP functions
kelemeno Apr 1, 2024
78d4951
zk fmt
kelemeno Apr 1, 2024
622a801
Address review
vladbochok Apr 1, 2024
df9f325
Fix review
vladbochok Apr 1, 2024
488d15b
added onlyOwner
kelemeno Apr 2, 2024
bc02bed
validation issues, OZ L04
kelemeno Apr 1, 2024
0b93956
zk fmt
kelemeno Apr 1, 2024
8a5de19
fixed tests
kelemeno Apr 1, 2024
207d195
Address review
vladbochok Apr 1, 2024
ceb100f
fixed require statement and error message
kelemeno Apr 1, 2024
094f57f
lint
kelemeno Apr 1, 2024
bd9e94d
Fix L-06
vladbochok Apr 1, 2024
a5dfc6a
add extra comments in STM
kelemeno Apr 2, 2024
bbbe9e9
Fix N-02
vladbochok Apr 1, 2024
24c8be7
lints
vladbochok Apr 1, 2024
f360d0e
Fix test
vladbochok Apr 1, 2024
af562bd
Update l1-contracts/contracts/state-transition/StateTransitionManager…
StanislavBreadless Apr 1, 2024
3f92673
Fix N-03
vladbochok Apr 1, 2024
ca34c4b
remove redundancy
StanislavBreadless Apr 1, 2024
ca524ce
fix lint
StanislavBreadless Apr 1, 2024
8cd5184
fix casting bridges
StanislavBreadless Apr 1, 2024
3998cad
added new doc strings
kelemeno Apr 2, 2024
88e3c7c
zk lint
kelemeno Apr 2, 2024
60cf175
fix typographical errors
Apr 1, 2024
39abd6c
add named parameters and improve descriptions
Apr 1, 2024
b2ea1b5
zk lint
kelemeno Apr 1, 2024
72a49c6
add indexed params for validator timelock events
Apr 1, 2024
882e4e7
Fix tests
vladbochok Apr 1, 2024
42bacf9
renaming n09
kelemeno Apr 1, 2024
ced6472
some naming issues
kelemeno Apr 3, 2024
a1bd4cc
removed payable
kelemeno Apr 1, 2024
0c3e2d2
removed payable from interface
kelemeno Apr 1, 2024
4dc74b8
renamed StateTransition to Hyperchain
kelemeno Apr 1, 2024
4ba6bcf
renaming revert messages
kelemeno Apr 3, 2024
46f85d4
Update l1-contracts/contracts/state-transition/StateTransitionManager…
kelemeno Apr 3, 2024
d66e55f
zk fmt
vladbochok Apr 1, 2024
2194747
fixing tests
kelemeno Apr 3, 2024
15293e4
added new SharedBridgeTest file
kelemeno Apr 3, 2024
a19cd47
move nonce to correct location
juan518munoz Apr 5, 2024
dc4d1b6
Merge pull request #319 from lambdaclass/without-1.5.0-fix-nonce
kelemeno Apr 5, 2024
6aef3b7
small renaming
kelemeno Apr 8, 2024
3be4efc
missing import added back
benceharomi Apr 8, 2024
efb9af3
move eraSetFirstUpgradeBatch to its own function
kelemeno Apr 8, 2024
b7b61ef
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Apr 8, 2024
a30ecb6
fix test
kelemeno Apr 8, 2024
b5d7fc5
merging differences, tests
kelemeno Apr 8, 2024
98ee7e5
kelemeno -> zksync-sdk
ly0va Apr 8, 2024
5eb45d2
Fix utils
ly0va Apr 8, 2024
38c1237
Fix config path
ly0va Apr 8, 2024
27e3ba8
fix(deploy-test-process): CONTRACTS_ERA_CHAIN_ID set to 270
benceharomi Apr 8, 2024
7de6499
deploy-preimages fix: zksync-web3 added back
benceharomi Apr 8, 2024
d70e5e0
small chainId changes
kelemeno Apr 8, 2024
97f2a83
config change back
kelemeno Apr 8, 2024
964c1d0
zk fmt
kelemeno Apr 8, 2024
affa83d
linting
kelemeno Apr 9, 2024
45ee4ae
small import change
kelemeno Apr 9, 2024
4844258
zk fmt
kelemeno Apr 9, 2024
d023451
test fix
kelemeno Apr 9, 2024
bc40ba2
zk lint
kelemeno Apr 9, 2024
742c131
renaming file
kelemeno Apr 9, 2024
bf2a357
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Apr 9, 2024
e78c5c3
small fixes
kelemeno Apr 9, 2024
76cd777
l2-contracts deploy utils
kelemeno Apr 9, 2024
17daf4a
zk lint
kelemeno Apr 9, 2024
8c4e10a
system contract fix attempt 1
kelemeno Apr 9, 2024
434ef23
zk fmt
kelemeno Apr 9, 2024
f4e562a
system contract fix attempt 2
kelemeno Apr 9, 2024
2d54bcd
added output
kelemeno Apr 9, 2024
91b657d
package.json attempt
kelemeno Apr 9, 2024
9026685
attempt 4
kelemeno Apr 9, 2024
52d2d46
linting
kelemeno Apr 9, 2024
6770c0b
yarn update
kelemeno Apr 9, 2024
f403e23
small fix
kelemeno Apr 9, 2024
ee2717b
fixes based for Bence's comments
kelemeno Apr 9, 2024
c43cf97
small contract fixes, added extra script
kelemeno Apr 9, 2024
96c9814
Vlad and Stas issues
kelemeno Apr 10, 2024
9a1d6a1
state transition hyperchain renaming
kelemeno Apr 10, 2024
1b42052
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Apr 10, 2024
1fd4cd8
oz upgradable contracts submodule
kelemeno Apr 10, 2024
6c82491
attempt remove from foundry.toml
kelemeno Apr 10, 2024
ae16bd5
address alias helper cleanup
kelemeno Apr 10, 2024
2e21950
Merge branch 'dev' into kl/without-1.5.0-merge-dev
Deniallugo Apr 10, 2024
27fc259
forge install: openzeppelin-contracts-upgradeable
Deniallugo Apr 10, 2024
f33e767
Fix foundry scripts
Deniallugo Apr 10, 2024
c706d00
slither
kelemeno Apr 10, 2024
4b3ea16
slither
kelemeno Apr 10, 2024
95e5571
Merge branch 'dev' into kl/without-1.5.0-merge-dev
Deniallugo Apr 11, 2024
032427b
upgrade fix
kelemeno Apr 11, 2024
6ca20c6
spellcheck
kelemeno Apr 12, 2024
40d0f60
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Apr 12, 2024
c88cb6f
small contract fixes
kelemeno Apr 12, 2024
80d3067
zk fmt && zk lint
kelemeno Apr 12, 2024
6a9a0d0
fix C4 issue related to claimFailedDeposits
kelemeno Apr 12, 2024
da97cae
fixes, linting
kelemeno Apr 12, 2024
dab2a1f
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Apr 12, 2024
d32f4a3
cleaned up hyperchain-upgrade test a bit,
kelemeno Apr 12, 2024
8656a58
rename and add to interface
kelemeno Apr 12, 2024
a2f0167
fixed comparison error
kelemeno Apr 12, 2024
6f8ae38
better name
kelemeno Apr 12, 2024
f168e54
changed the names a bit
kelemeno Apr 12, 2024
a60710d
finalizeWithdrawal check eraPostUpgradeFirstBatch
kelemeno Apr 12, 2024
53a0a21
last deposit time edge case
kelemeno Apr 12, 2024
5e033da
removed wrong check (tx number = 0 is allowed)
kelemeno Apr 12, 2024
857eada
separate eth and token withdrawal batch number
kelemeno Apr 13, 2024
95da499
cleanup
kelemeno Apr 13, 2024
76acbf5
more migration testing
kelemeno Apr 15, 2024
a997ae6
small typo fix
kelemeno Apr 16, 2024
77d1cc8
tokenProxyBytecodeHash now only
kelemeno Apr 16, 2024
77ec2bb
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Apr 16, 2024
74311c2
extra comments
kelemeno Apr 16, 2024
bb39921
yarn update
kelemeno Apr 18, 2024
abe934f
revert yarn update
kelemeno Apr 18, 2024
90c869e
chore(scripts): Get Scripts Working in CI (#376)
koloz193 Apr 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion l1-contracts/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CHAIN_ETH_NETWORK=hardhat
CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT=72000000
CONTRACTS_DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT=10000000
ETH_CLIENT_WEB3_URL=http://127.0.0.1:8545
CHAIN_ETH_ZKSYNC_NETWORK_ID=270
CHAIN_ETH_ZKSYNC_NETWORK_ID=271
CONTRACTS_BRIDGEHUB_PROXY_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHUB_IMPL_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_STATE_TRANSITION_PROXY_ADDR=0x0000000000000000000000000000000000000000
Expand Down
13 changes: 6 additions & 7 deletions l1-contracts/contracts/bridge/L1SharedBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

pragma solidity 0.8.24;

import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand All @@ -27,24 +26,25 @@
/// @custom:security-contact [email protected]
/// @dev Bridges assets between L1 and hyperchains, supporting both ETH and ERC20 tokens.
/// @dev Designed for use with a proxy for upgradability.
contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Initializable, Ownable2Step {
contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgradeable {
using SafeERC20 for IERC20;

/// @dev The address of the WETH token on L1.
address public immutable override l1WethAddress;

Check warning on line 33 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 33 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 33 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @dev Bridgehub smart contract that is used to operate with L2 via asynchronous L2 <-> L1 communication.
IBridgehub public immutable override bridgehub;

Check warning on line 36 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 36 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 36 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @dev Era's chainID
uint256 immutable eraChainId;

Check warning on line 39 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 39 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 39 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @dev The address of zkSync Era diamond proxy contract.
address immutable eraDiamondProxy;

Check warning on line 42 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 42 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 42 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @dev Stores the first batch number on the zkSync Era Diamond Proxy that was settled after Shared Bridge upgrade.
/// This variable is used to differentiate between pre-upgrade and post-upgrade withdrawals. Withdrawals from batches older
/// than this value are considered to have been finalized prior to the upgrade and handled separately.
/// We use this both for Eth and erc20 token withdrawals, so we need to update the diamond and bridge simultaneously.
uint256 internal eraFirstPostUpgradeBatch;

/// @dev Legacy bridge smart contract that used to hold ERC20 tokens.
Expand Down Expand Up @@ -110,13 +110,12 @@
/// @dev Initializes a contract bridge for later use. Expected to be used in the proxy
/// @param _owner Address which can change L2 token implementation and upgrade the bridge
/// implementation. The owner is the Governor and separate from the ProxyAdmin from now on, so that the Governor can call the bridge.
function initialize(
address _owner,
uint256 _eraFirstPostUpgradeBatch
) external reentrancyGuardInitializer initializer {
function initialize(address _owner) external reentrancyGuardInitializer initializer {
require(_owner != address(0), "ShB owner 0");
_transferOwnership(_owner);
}

function setEraFirstPostUpgradeBatch(uint256 _eraFirstPostUpgradeBatch) external onlyOwner {
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
eraFirstPostUpgradeBatch = _eraFirstPostUpgradeBatch;
}

Expand Down Expand Up @@ -606,7 +605,7 @@
address refundRecipient = _refundRecipient;
if (_refundRecipient == address(0)) {
// slither-disable-next-line tx-origin
refundRecipient = _prevMsgSender != tx.origin

Check warning on line 608 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin

Check warning on line 608 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin

Check warning on line 608 in l1-contracts/contracts/bridge/L1SharedBridge.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin
? AddressAliasHelper.applyL1ToL2Alias(_prevMsgSender)
: _prevMsgSender;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ interface IL1SharedBridge {
bytes32[] calldata _merkleProof
) external;

function setEraFirstPostUpgradeBatch(uint256 _eraFirstPostUpgradeBatch) external;

function l1WethAddress() external view returns (address);

function bridgehub() external view returns (IBridgehub);
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/contracts/bridgehub/Bridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity 0.8.24;

import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";

import {L2TransactionRequestDirect, L2TransactionRequestTwoBridgesOuter, L2TransactionRequestTwoBridgesInner} from "./IBridgehub.sol";
import {IBridgehub, IL1SharedBridge} from "../bridge/interfaces/IL1SharedBridge.sol";
Expand All @@ -13,7 +13,7 @@
import {BridgehubL2TransactionRequest, L2Message, L2Log, TxStatus} from "../common/Messaging.sol";
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol";

contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2Step {
contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable {
/// @notice all the ether is held by the weth bridge
IL1SharedBridge public sharedBridge;

Expand Down Expand Up @@ -321,7 +321,7 @@
function _actualRefundRecipient(address _refundRecipient) internal view returns (address _recipient) {
if (_refundRecipient == address(0)) {
// If the `_refundRecipient` is not provided, we use the `msg.sender` as the recipient.
_recipient = msg.sender == tx.origin ? msg.sender : AddressAliasHelper.applyL1ToL2Alias(msg.sender);

Check warning on line 324 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin

Check warning on line 324 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin

Check warning on line 324 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin
} else if (_refundRecipient.code.length > 0) {
// If the `_refundRecipient` is a smart contract, we apply the L1 to L2 alias to prevent foot guns.
_recipient = AddressAliasHelper.applyL1ToL2Alias(_refundRecipient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ contract DummyAdminFacet2 is ZkSyncHyperchainBase {
function test() internal virtual {}

function getName() external pure returns (string memory) {
return "DummyAdminFacet";
return "DummyAdminFacet2";
}

function dummySetValidator(address _validator) external {
s.validators[_validator] = true;
}

function executeUpgrade(Diamond.DiamondCutData calldata _diamondCut) external {
function executeUpgrade2(Diamond.DiamondCutData calldata _diamondCut) external {
Diamond.diamondCut(_diamondCut);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import {FeeParams} from "./chain-deps/ZkSyncHyperchainStorage.sol";
import {L2_SYSTEM_CONTEXT_SYSTEM_CONTRACT_ADDR, L2_FORCE_DEPLOYER_ADDR} from "../common/L2ContractAddresses.sol";
import {L2CanonicalTransaction} from "../common/Messaging.sol";
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import {ProposedUpgrade} from "../upgrades/BaseZkSyncUpgrade.sol";
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol";
import {REQUIRED_L2_GAS_PRICE_PER_PUBDATA, L2_TO_L1_LOG_SERIALIZE_SIZE, DEFAULT_L2_LOGS_TREE_ROOT_HASH, EMPTY_STRING_KECCAK, SYSTEM_UPGRADE_L2_TX_TYPE, PRIORITY_TX_MAX_GAS_LIMIT} from "../common/Config.sol";
Expand All @@ -23,9 +23,9 @@
/// @title StateTransition contract
/// @author Matter Labs
/// @custom:security-contact [email protected]
contract StateTransitionManager is IStateTransitionManager, ReentrancyGuard, Ownable2Step {
contract StateTransitionManager is IStateTransitionManager, ReentrancyGuard, Ownable2StepUpgradeable {
/// @notice Address of the bridgehub
address public immutable bridgehub;

Check warning on line 28 in l1-contracts/contracts/state-transition/StateTransitionManager.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 28 in l1-contracts/contracts/state-transition/StateTransitionManager.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 28 in l1-contracts/contracts/state-transition/StateTransitionManager.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

/// @notice The mapping from chainId => hyperchain contract
mapping(uint256 chainId => address chainContract) public hyperchain;
Expand All @@ -42,7 +42,7 @@
/// @dev The current protocolVersion
uint256 public protocolVersion;

/// @dev timestamp when protocolVersion can be last used
/// @dev The timestamp when protocolVersion can be last used
mapping(uint256 _protocolVersion => uint256) public protocolVersionDeadline;

/// @dev The validatorTimelock contract address, used to setChainId
Expand Down Expand Up @@ -157,10 +157,10 @@
uint256 _newProtocolVersion
) external onlyOwner {
bytes32 newCutHash = keccak256(abi.encode(_cutData));
protocolVersionDeadline[_oldProtocolVersion] = _oldprotocolVersionDeadline;
uint256 previousProtocolVersion = protocolVersion;
upgradeCutHash[_oldProtocolVersion] = newCutHash;
protocolVersionDeadline[_oldProtocolVersion] = _oldprotocolVersionDeadline;
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
protocolVersionDeadline[_newProtocolVersion] = type(uint256).max;
uint256 previousProtocolVersion = protocolVersion;
protocolVersion = _newProtocolVersion;
emit NewProtocolVersion(previousProtocolVersion, _newProtocolVersion);
emit NewUpgradeCutHash(_oldProtocolVersion, newCutHash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
string public constant override getName = "MailboxFacet";

/// @dev Era's chainID
uint256 immutable eraChainId;

Check warning on line 37 in l1-contracts/contracts/state-transition/chain-deps/facets/Mailbox.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 37 in l1-contracts/contracts/state-transition/chain-deps/facets/Mailbox.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

Check warning on line 37 in l1-contracts/contracts/state-transition/chain-deps/facets/Mailbox.sol

View workflow job for this annotation

GitHub Actions / lint

Immutable variables name are set to be in capitalized SNAKE_CASE

constructor(uint256 _eraChainId) {
eraChainId = _eraChainId;
Expand All @@ -42,7 +42,7 @@

/// @inheritdoc IMailbox
function transferEthToSharedBridge() external onlyBaseTokenBridge {
require(s.chainId == eraChainId, "transferEthToSharedBridge only available for Era on mailbox");
require(s.chainId == eraChainId, "Mailbox: transferEthToSharedBridge only available for Era on mailbox");

uint256 amount = address(this).balance;
address baseTokenBridgeAddress = s.baseTokenBridge;
Expand Down Expand Up @@ -191,7 +191,7 @@
bytes calldata _message,
bytes32[] calldata _merkleProof
) external nonReentrant {
require(s.chainId == eraChainId, "finalizeEthWithdrawal only available for Era on mailbox");
require(s.chainId == eraChainId, "Mailbox: finalizeEthWithdrawal only available for Era on mailbox");
IL1SharedBridge(s.baseTokenBridge).finalizeWithdrawal({
_chainId: eraChainId,
_l2BatchNumber: _l2BatchNumber,
Expand All @@ -212,7 +212,7 @@
bytes[] calldata _factoryDeps,
address _refundRecipient
) external payable returns (bytes32 canonicalTxHash) {
require(s.chainId == eraChainId, "legacy interface only available for era token");
require(s.chainId == eraChainId, "Mailbox: legacy interface only available for Era");
canonicalTxHash = _requestL2TransactionSender(
BridgehubL2TransactionRequest({
sender: msg.sender,
Expand Down Expand Up @@ -255,7 +255,7 @@
// Please note, currently zkSync address derivation is different from Ethereum one, but it may be changed in the future.
address l2Sender = _request.sender;
// slither-disable-next-line tx-origin
if (l2Sender != tx.origin) {

Check warning on line 258 in l1-contracts/contracts/state-transition/chain-deps/facets/Mailbox.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin

Check warning on line 258 in l1-contracts/contracts/state-transition/chain-deps/facets/Mailbox.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin

Check warning on line 258 in l1-contracts/contracts/state-transition/chain-deps/facets/Mailbox.sol

View workflow job for this annotation

GitHub Actions / lint

Avoid to use tx.origin
l2Sender = AddressAliasHelper.applyL1ToL2Alias(_request.sender);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract ZkSyncHyperchainBase is ReentrancyGuard {
}

modifier onlyBaseTokenBridge() {
require(msg.sender == s.baseTokenBridge, "Hyperchain: Only shared bridge can call this function");
require(msg.sender == s.baseTokenBridge, "Hyperchain: Only base token bridge can call this function");
_;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ abstract contract BaseZkSyncUpgradeGenesis is BaseZkSyncUpgrade {
function _setNewProtocolVersion(uint256 _newProtocolVersion) internal override {
uint256 previousProtocolVersion = s.protocolVersion;
require(
// !! ONLY CHANGE IS IN THIS LINE !!
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
// Genesis Upgrade difference: Note this is the only thing change > to >=
_newProtocolVersion >= previousProtocolVersion,
"New protocol version is not greater than the current one"
Expand Down
33 changes: 33 additions & 0 deletions l1-contracts/contracts/upgrades/UpgradeHyperchains.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {Diamond} from "../state-transition/libraries/Diamond.sol";
import {BaseZkSyncUpgrade, ProposedUpgrade} from "./BaseZkSyncUpgrade.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
contract UpgradeHyperchains is BaseZkSyncUpgrade {
/// @notice The main function that will be called by the upgrade proxy.
/// @param _proposedUpgrade The upgrade to be executed.
function upgradeWithAdditionalData(
ProposedUpgrade calldata _proposedUpgrade,
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
bytes calldata _additionalData
) public returns (bytes32) {
(uint256 chainId, address bridgehubAddress, address stateTransitionManager, address sharedBridgeAddress) = abi
.decode(_additionalData, (uint256, address, address, address));
// Check to make sure that the new blob versioned hash address is not the zero address.
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
require(sharedBridgeAddress != address(0), "b9");
kelemeno marked this conversation as resolved.
Show resolved Hide resolved

s.chainId = chainId;
s.bridgehub = bridgehubAddress;
s.stateTransitionManager = stateTransitionManager;
s.baseTokenBridge = sharedBridgeAddress;
s.baseToken = 0x0000000000000000000000000000000000000001;
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
s.baseTokenGasPriceMultiplierNominator = 1;
s.baseTokenGasPriceMultiplierDenominator = 1;

super.upgrade(_proposedUpgrade);
return Diamond.DIAMOND_INIT_SUCCESS_RETURN_VALUE;
}
}
7 changes: 5 additions & 2 deletions l1-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"ts-node": "^10.1.0",
"typechain": "^4.0.0",
"typescript": "^4.6.4",
"zksync-ethers": "https://github.com/kelemeno/zksync-ethers#ethers-v5-feat/bridgehub"
"zksync-ethers": "https://github.com/zksync-sdk/zksync-ethers#ethers-v5-feat/bridgehub"
},
"scripts": {
"build": "hardhat compile",
Expand All @@ -74,7 +74,10 @@
"initialize-governance": "ts-node scripts/initialize-governance.ts",
"migrate-governance": "ts-node scripts/migrate-governance.ts",
"display-governance": "ts-node scripts/display-governance.ts",
"upgrade-system": "ts-node upgrade-system/index.ts"
"upgrade-system": "ts-node upgrade-system/index.ts",
"hyperchain-upgrade-1": "ts-node scripts/hyperchain-upgrade-1.ts",
"hyperchain-upgrade-2": "ts-node scripts/hyperchain-upgrade-2.ts",
"upgrade-shared-bridge-era": "ts-node scripts/upgrade-shared-bridge-era.ts"
},
"dependencies": {
"dotenv": "^16.0.3",
Expand Down
10 changes: 1 addition & 9 deletions l1-contracts/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,7 @@ async function main() {
verbose: true,
});

await initialBridgehubDeployment(
deployer,
[],
gasPrice,
cmd.onlyVerifier,
cmd.diamondUpgradeInit,
create2Salt,
nonce
);
await initialBridgehubDeployment(deployer, [], gasPrice, cmd.onlyVerifier, create2Salt, nonce);
});

await program.parseAsync(process.argv);
Expand Down
69 changes: 69 additions & 0 deletions l1-contracts/scripts/hyperchain-upgrade-1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// hardhat import should be the first import in the file
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as hardhat from "hardhat";
import { Command } from "commander";
import { Wallet, ethers } from "ethers";
import { Deployer } from "../src.ts/deploy";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import { web3Provider, GAS_MULTIPLIER } from "./utils";
import { deployedAddressesFromEnv } from "../src.ts/deploy-utils";
import { ethTestConfig } from "../src.ts/utils";
import { upgradeToHyperchains1 } from "../src.ts/hyperchain-upgrade";

const provider = web3Provider();

async function main() {
const program = new Command();

program.version("0.1.0").name("deploy").description("deploy L1 contracts");

program
.option("--private-key <private-key>")
.option("--chain-id <chain-id>")
.option("--gas-price <gas-price>")
.option("--nonce <nonce>")
.option("--owner-address <owner-address>")
.option("--create2-salt <create2-salt>")
.option("--diamond-upgrade-init <version>")
.option("--only-verifier")
.action(async (cmd) => {
const deployWallet = cmd.privateKey
? new Wallet(cmd.privateKey, provider)
: Wallet.fromMnemonic(
process.env.MNEMONIC ? process.env.MNEMONIC : ethTestConfig.mnemonic,
"m/44'/60'/0'/0/1"
).connect(provider);
console.log(`Using deployer wallet: ${deployWallet.address}`);

const ownerAddress = cmd.ownerAddress ? cmd.ownerAddress : deployWallet.address;
console.log(`Using owner address: ${ownerAddress}`);

const gasPrice = cmd.gasPrice
? parseUnits(cmd.gasPrice, "gwei")
: (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const nonce = cmd.nonce ? parseInt(cmd.nonce) : await deployWallet.getTransactionCount();
console.log(`Using nonce: ${nonce}`);

const create2Salt = cmd.create2Salt ? cmd.create2Salt : ethers.utils.hexlify(ethers.utils.randomBytes(32));

const deployer = new Deployer({
deployWallet,
addresses: deployedAddressesFromEnv(),
ownerAddress,
verbose: true,
});

await upgradeToHyperchains1(deployer, gasPrice, create2Salt, nonce);
});

await program.parseAsync(process.argv);
}

main()
.then(() => process.exit(0))
.catch((err) => {
console.error("Error:", err);
process.exit(1);
});
69 changes: 69 additions & 0 deletions l1-contracts/scripts/hyperchain-upgrade-2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// hardhat import should be the first import in the file
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as hardhat from "hardhat";
import { Command } from "commander";
import { Wallet, ethers } from "ethers";
import { Deployer } from "../src.ts/deploy";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import { web3Provider, GAS_MULTIPLIER } from "./utils";
import { deployedAddressesFromEnv } from "../src.ts/deploy-utils";
import { ethTestConfig } from "../src.ts/utils";
import { upgradeToHyperchains2 } from "../src.ts/hyperchain-upgrade";

const provider = web3Provider();

async function main() {
const program = new Command();

program.version("0.1.0").name("deploy").description("deploy L1 contracts");

program
.option("--private-key <private-key>")
.option("--chain-id <chain-id>")
.option("--gas-price <gas-price>")
.option("--nonce <nonce>")
.option("--owner-address <owner-address>")
.option("--create2-salt <create2-salt>")
.option("--diamond-upgrade-init <version>")
.option("--only-verifier")
.action(async (cmd) => {
const deployWallet = cmd.privateKey
? new Wallet(cmd.privateKey, provider)
: Wallet.fromMnemonic(
process.env.MNEMONIC ? process.env.MNEMONIC : ethTestConfig.mnemonic,
"m/44'/60'/0'/0/1"
).connect(provider);
console.log(`Using deployer wallet: ${deployWallet.address}`);

const ownerAddress = cmd.ownerAddress ? cmd.ownerAddress : deployWallet.address;
console.log(`Using owner address: ${ownerAddress}`);

const gasPrice = cmd.gasPrice
? parseUnits(cmd.gasPrice, "gwei")
: (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const nonce = cmd.nonce ? parseInt(cmd.nonce) : await deployWallet.getTransactionCount();
console.log(`Using nonce: ${nonce}`);

const create2Salt = cmd.create2Salt ? cmd.create2Salt : ethers.utils.hexlify(ethers.utils.randomBytes(32));

const deployer = new Deployer({
deployWallet,
addresses: deployedAddressesFromEnv(),
ownerAddress,
verbose: true,
});

await upgradeToHyperchains2(deployer, gasPrice, create2Salt, nonce);
});

await program.parseAsync(process.argv);
}

main()
.then(() => process.exit(0))
.catch((err) => {
console.error("Error:", err);
process.exit(1);
});
Loading
Loading