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 134 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
1 change: 0 additions & 1 deletion l1-contracts-foundry/script-config/config-deploy-l1.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ recursion_node_level_vk_hash = "0x0000000000000000000000000000000000000000000000
recursion_leaf_level_vk_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
recursion_circuits_set_vks_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
priority_tx_max_gas_limit = 80000000
shared_bridge_upgrade_storage_switch = 0
diamond_init_pubdata_pricing_mode = 0
diamond_init_batch_overhead_l1_gas = 1000000
diamond_init_max_pubdata_per_batch = 120000
Expand Down
7 changes: 1 addition & 6 deletions l1-contracts-foundry/script/DeployL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ contract DeployL1Script is Script {
bytes32 recursionLeafLevelVkHash;
bytes32 recursionCircuitsSetVksHash;
uint256 priorityTxMaxGasLimit;
uint256 sharedBridgeUpgradeStorageSwitch;
PubdataPricingMode diamondInitPubdataPricingMode;
uint256 diamondInitBatchOverheadL1Gas;
uint256 diamondInitMaxPubdataPerBatch;
Expand Down Expand Up @@ -181,9 +180,6 @@ contract DeployL1Script is Script {
config.contracts.recursionLeafLevelVkHash = toml.readBytes32("$.contracts.recursion_leaf_level_vk_hash");
config.contracts.recursionCircuitsSetVksHash = toml.readBytes32("$.contracts.recursion_circuits_set_vks_hash");
config.contracts.priorityTxMaxGasLimit = toml.readUint("$.contracts.priority_tx_max_gas_limit");
config.contracts.sharedBridgeUpgradeStorageSwitch = toml.readUint(
"$.contracts.shared_bridge_upgrade_storage_switch"
);
config.contracts.diamondInitPubdataPricingMode = PubdataPricingMode(
toml.readUint("$.contracts.diamond_init_pubdata_pricing_mode")
);
Expand Down Expand Up @@ -499,8 +495,7 @@ contract DeployL1Script is Script {
}

function deploySharedBridgeProxy() internal {
uint256 storageSwitch = config.contracts.sharedBridgeUpgradeStorageSwitch;
bytes memory initCalldata = abi.encodeCall(L1SharedBridge.initialize, (config.deployerAddress, storageSwitch));
bytes memory initCalldata = abi.encodeCall(L1SharedBridge.initialize, (config.deployerAddress));
bytes memory bytecode = abi.encodePacked(
type(TransparentUpgradeableProxy).creationCode,
abi.encode(addresses.bridges.sharedBridgeImplementation, addresses.transparentProxyAdmin, initCalldata)
Expand Down
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
117 changes: 91 additions & 26 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,25 +26,42 @@
/// @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
/// @dev Stores the first batch number on the zkSync Era Diamond Proxy that was settled after Diamond proxy upgrade.
/// This variable is used to differentiate between pre-upgrade and post-upgrade Eth withdrawals. Withdrawals from batches older
/// than this value are considered to have been finalized prior to the upgrade and handled separately.
uint256 internal eraFirstPostUpgradeBatch;
uint256 internal eraPostDiamondUpgradeFirstBatch;

/// @dev Stores the first batch number on the zkSync Era Diamond Proxy that was settled after L1ERC20 Bridge upgrade.
/// This variable is used to differentiate between pre-upgrade and post-upgrade ERC20 withdrawals. Withdrawals from batches older
/// than this value are considered to have been finalized prior to the upgrade and handled separately.
uint256 internal eraPostLegacyBridgeUpgradeFirstBatch;

/// @dev Stores the zkSync Era batch number that processes the last deposit tx initiated by the legacy bridge
/// This variable (together with eraLegacyBridgeLastDepositTxNumber) is used to differentiate between pre-upgrade and post-upgrade deposits. Deposits processed in older batches
/// than this value are considered to have been processed prior to the upgrade and handled separately.
/// We use this both for Eth and erc20 token deposits, so we need to update the diamond and bridge simultaneously.
uint256 internal eraLegacyBridgeLastDepositBatch;

/// @dev The tx number in the _eraLegacyBridgeLastDepositBatch of the last deposit tx initiated by the legacy bridge
/// This variable (together with eraLegacyBridgeLastDepositBatch) is used to differentiate between pre-upgrade and post-upgrade deposits. Deposits processed in older txs
/// than this value are considered to have been processed prior to the upgrade and handled separately.
/// We use this both for Eth and erc20 token deposits, so we need to update the diamond and bridge simultaneously.
uint256 internal eraLegacyBridgeLastDepositTxNumber;

/// @dev Legacy bridge smart contract that used to hold ERC20 tokens.
IL1ERC20Bridge public override legacyBridge;
Expand Down Expand Up @@ -110,14 +126,36 @@
/// @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);
}

/// @dev This sets the first post diamond upgrade batch for era, used to check old eth withdrawals
/// @param _eraPostDiamondUpgradeFirstBatch The first batch number on the zkSync Era Diamond Proxy that was settled after diamond proxy upgrade.
function setEraPostDiamondUpgradeFirstBatch(uint256 _eraPostDiamondUpgradeFirstBatch) external onlyOwner {
require(eraPostDiamondUpgradeFirstBatch == 0, "ShB: eFPUB already set");
eraPostDiamondUpgradeFirstBatch = _eraPostDiamondUpgradeFirstBatch;
}

/// @dev This sets the first post upgrade batch for era, used to check old token withdrawals
/// @param _eraPostLegacyBridgeUpgradeFirstBatch The first batch number on the zkSync Era Diamond Proxy that was settled after legacy bridge upgrade.
function setEraPostLegacyBridgeUpgradeFirstBatch(uint256 _eraPostLegacyBridgeUpgradeFirstBatch) external onlyOwner {
require(eraPostLegacyBridgeUpgradeFirstBatch == 0, "ShB: eFPUB already set");
eraPostLegacyBridgeUpgradeFirstBatch = _eraPostLegacyBridgeUpgradeFirstBatch;
}

eraFirstPostUpgradeBatch = _eraFirstPostUpgradeBatch;
/// @dev This sets the first post upgrade batch for era, used to check old withdrawals
/// @param _eraLegacyBridgeLastDepositBatch The the zkSync Era batch number that processes the last deposit tx initiated by the legacy bridge
/// @param _eraLegacyBridgeLastDepositTxNumber The tx number in the _eraLegacyBridgeLastDepositBatch of the last deposit tx initiated by the legacy bridge
function setEraLegacyBridgeLastDepositTime(
uint256 _eraLegacyBridgeLastDepositBatch,
uint256 _eraLegacyBridgeLastDepositTxNumber
) external onlyOwner {
require(eraLegacyBridgeLastDepositBatch == 0, "ShB: eLOBDB already set");
require(eraLegacyBridgeLastDepositTxNumber == 0, "ShB: eLOBDTN already set");
eraLegacyBridgeLastDepositBatch = _eraLegacyBridgeLastDepositBatch;
eraLegacyBridgeLastDepositTxNumber = _eraLegacyBridgeLastDepositTxNumber;
}

/// @dev transfer tokens from legacy erc20 bridge or mailbox and set chainBalance as part of migration process
Expand Down Expand Up @@ -261,7 +299,6 @@
require(address(legacyBridge) == address(0), "ShB: legacy bridge already set");
require(_legacyBridge != address(0), "ShB: legacy bridge 0");
legacyBridge = IL1ERC20Bridge(_legacyBridge);
l2BridgeAddress[eraChainId] = address(legacyBridge);
}

/// @dev Generate a calldata for calling the deposit finalization on the L2 bridge contract
Expand Down Expand Up @@ -355,7 +392,7 @@
bool notCheckedInLegacyBridgeOrWeCanCheckDeposit;
{
// Deposits that happened before the upgrade cannot be checked here, they have to be claimed and checked in the legacyBridge
bool weCanCheckDepositHere = !_isEraLegacyWithdrawal(_chainId, _l2BatchNumber);
bool weCanCheckDepositHere = !_isEraLegacyDeposit(_chainId, _l2BatchNumber, _l2TxNumberInBatch);
// Double claims are not possible, as we this check except for legacy bridge withdrawals
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in the comments: as we this check

// Funds claimed before the update will still be recorded in the legacy bridge
// Note we double check NEW deposits if they are called from the legacy bridge
Expand Down Expand Up @@ -392,12 +429,46 @@
emit ClaimedFailedDepositSharedBridge(_chainId, _depositSender, _l1Token, _amount);
}

/// @dev Determines if a withdrawal was initiated on zkSync Era before the upgrade to the Shared Bridge.
/// @dev Determines if an eth withdrawal was initiated on zkSync Era before the upgrade to the Shared Bridge.
/// @param _chainId The chain ID of the transaction to check.
/// @param _l2BatchNumber The L2 batch number for the withdrawal.
/// @return Whether withdrawal was initiated on zkSync Era before Shared Bridge upgrade.
function _isEraLegacyWithdrawal(uint256 _chainId, uint256 _l2BatchNumber) internal view returns (bool) {
return (_chainId == eraChainId) && (_l2BatchNumber < eraFirstPostUpgradeBatch);
/// @return Whether withdrawal was initiated on zkSync Era before diamond proxy upgrade.
function _isEraLegacyEthWithdrawal(uint256 _chainId, uint256 _l2BatchNumber) internal view returns (bool) {
require((_chainId != eraChainId) || eraPostDiamondUpgradeFirstBatch != 0, "ShB: diamondUFB not set for Era");
return (_chainId == eraChainId) && (_l2BatchNumber < eraPostDiamondUpgradeFirstBatch);
}

/// @dev Determines if a token withdrawal was initiated on zkSync Era before the upgrade to the Shared Bridge.
/// @param _chainId The chain ID of the transaction to check.
/// @param _l2BatchNumber The L2 batch number for the withdrawal.
/// @return Whether withdrawal was initiated on zkSync Era before Legacy Bridge upgrade.
function _isEraLegacyTokenWithdrawal(uint256 _chainId, uint256 _l2BatchNumber) internal view returns (bool) {
require(
(_chainId != eraChainId) || eraPostLegacyBridgeUpgradeFirstBatch != 0,
"ShB: LegacyUFB not set for Era"
);
return (_chainId == eraChainId) && (_l2BatchNumber < eraPostLegacyBridgeUpgradeFirstBatch);
}

/// @dev Determines if a deposit was initiated on zkSync Era before the upgrade to the Shared Bridge.
/// @param _chainId The chain ID of the transaction to check.
/// @param _l2BatchNumber The L2 batch number for the deposit where it was processed.
/// @param _l2TxNumberInBatch The L2 transaction number in the batch, in which the deposit was processed.
/// @return Whether deposit was initiated on zkSync Era before Shared Bridge upgrade.
function _isEraLegacyDeposit(
uint256 _chainId,
uint256 _l2BatchNumber,
uint256 _l2TxNumberInBatch
) internal view returns (bool) {
require(
(_chainId != eraChainId) || (eraLegacyBridgeLastDepositBatch != 0),
"ShB: last deposit time not set for Era"
);
return
(_chainId == eraChainId) &&
(_l2BatchNumber < eraLegacyBridgeLastDepositBatch ||
(_l2TxNumberInBatch < eraLegacyBridgeLastDepositTxNumber &&
_l2BatchNumber == eraLegacyBridgeLastDepositBatch));
}

/// @notice Finalize the withdrawal and release funds
Expand All @@ -417,7 +488,7 @@
) external override {
// To avoid rewithdrawing txs that have already happened on the legacy bridge.
// Note: new withdraws are all recorded here, so double withdrawing them is not possible.
if (_isEraLegacyWithdrawal(_chainId, _l2BatchNumber)) {
if (_isEraLegacyTokenWithdrawal(_chainId, _l2BatchNumber)) {
require(!legacyBridge.isWithdrawalFinalized(_l2BatchNumber, _l2MessageIndex), "ShB: legacy withdrawal");
}
_finalizeWithdrawal({
Expand Down Expand Up @@ -450,7 +521,7 @@
isWithdrawalFinalized[_chainId][_l2BatchNumber][_l2MessageIndex] = true;

// Handling special case for withdrawal from zkSync Era initiated before Shared Bridge.
if (_isEraLegacyWithdrawal(_chainId, _l2BatchNumber)) {
if (_isEraLegacyEthWithdrawal(_chainId, _l2BatchNumber)) {
// Checks that the withdrawal wasn't finalized already.
bool alreadyFinalized = IGetters(eraDiamondProxy).isEthWithdrawalFinalized(_l2BatchNumber, _l2MessageIndex);
require(!alreadyFinalized, "Withdrawal is already finalized 2");
Expand Down Expand Up @@ -603,13 +674,7 @@
// If the refund recipient is not specified, the refund will be sent to the sender of the transaction.
// Otherwise, the refund will be sent to the specified address.
// If the recipient is a contract on L1, the address alias will be applied.
address refundRecipient = _refundRecipient;
if (_refundRecipient == address(0)) {
// slither-disable-next-line tx-origin
refundRecipient = _prevMsgSender != tx.origin
? AddressAliasHelper.applyL1ToL2Alias(_prevMsgSender)
: _prevMsgSender;
}
address refundRecipient = AddressAliasHelper.actualRefundRecipient(_refundRecipient, _prevMsgSender);

L2TransactionRequestDirect memory request = L2TransactionRequestDirect({
chainId: eraChainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ interface IL1SharedBridge {
bytes32[] calldata _merkleProof
) external;

function setEraPostDiamondUpgradeFirstBatch(uint256 _eraPostDiamondUpgradeFirstBatch) external;

function setEraPostLegacyBridgeUpgradeFirstBatch(uint256 _eraPostLegacyBridgeUpgradeFirstBatch) external;

function setEraLegacyBridgeLastDepositTime(
uint256 _eraLegacyBridgeLastDepositBatch,
uint256 _eraLegacyBridgeLastDepositTxNumber
) external;

function l1WethAddress() external view returns (address);

function bridgehub() external view returns (IBridgehub);
Expand Down
Loading
Loading