-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ZKChain and Gateway Upgrade Audit (#1052)
Co-authored-by: kelemeno <[email protected]> Co-authored-by: kelemeno <[email protected]> Co-authored-by: Vlad Bochok <[email protected]> Co-authored-by: Raid Ateir <[email protected]>
- Loading branch information
1 parent
8208402
commit f72d206
Showing
52 changed files
with
366 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import {DataEncoding} from "../common/libraries/DataEncoding.sol"; | |
/** | ||
* @author Matter Labs | ||
* @custom:security-contact [email protected] | ||
* @notice Helper library for working with L2 contracts on L1. | ||
* @notice Helper library for working with native tokens on both L1 and L2. | ||
*/ | ||
library BridgeHelper { | ||
/// @dev Receives and parses (name, symbol, decimals) from the token contract | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,7 @@ import {DataEncoding} from "../common/libraries/DataEncoding.sol"; | |
|
||
import {IBridgehub} from "../bridgehub/IBridgehub.sol"; | ||
import {L2_BASE_TOKEN_SYSTEM_CONTRACT_ADDR, L2_ASSET_ROUTER_ADDR} from "../common/L2ContractAddresses.sol"; | ||
import {DataEncoding} from "../common/libraries/DataEncoding.sol"; | ||
import {Unauthorized, SharedBridgeKey, DepositExists, AddressAlreadySet, InvalidProof, DepositDoesNotExist, SharedBridgeValueNotSet, WithdrawalAlreadyFinalized, L2WithdrawalMessageWrongLength, InvalidSelector, SharedBridgeValueNotSet, ZeroAddress} from "../common/L1ContractErrors.sol"; | ||
import {Unauthorized, SharedBridgeKey, DepositExists, AddressAlreadySet, InvalidProof, DepositDoesNotExist, SharedBridgeValueNotSet, WithdrawalAlreadyFinalized, L2WithdrawalMessageWrongLength, InvalidSelector, ZeroAddress} from "../common/L1ContractErrors.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
|
@@ -122,14 +121,6 @@ contract L1Nullifier is IL1Nullifier, ReentrancyGuard, Ownable2StepUpgradeable, | |
_; | ||
} | ||
|
||
/// @notice Checks that the message sender is the bridgehub or ZKsync Era Diamond Proxy. | ||
modifier onlyBridgehubOrEra(uint256 _chainId) { | ||
if (msg.sender != address(BRIDGE_HUB) && (_chainId != ERA_CHAIN_ID || msg.sender != ERA_DIAMOND_PROXY)) { | ||
revert Unauthorized(msg.sender); | ||
} | ||
_; | ||
} | ||
|
||
/// @notice Checks that the message sender is the legacy bridge. | ||
modifier onlyLegacyBridge() { | ||
if (msg.sender != address(legacyBridge)) { | ||
|
@@ -138,14 +129,6 @@ contract L1Nullifier is IL1Nullifier, ReentrancyGuard, Ownable2StepUpgradeable, | |
_; | ||
} | ||
|
||
/// @notice Checks that the message sender is the legacy bridge. | ||
modifier onlyAssetRouterOrErc20Bridge() { | ||
if (msg.sender != address(l1AssetRouter) && msg.sender != address(legacyBridge)) { | ||
revert Unauthorized(msg.sender); | ||
} | ||
_; | ||
} | ||
|
||
/// @dev Contract is expected to be used as proxy implementation. | ||
/// @dev Initialize the implementation to prevent Parity hack. | ||
constructor(IBridgehub _bridgehub, uint256 _eraChainId, address _eraDiamondProxy) reentrancyGuardInitializer { | ||
|
@@ -204,8 +187,7 @@ contract L1Nullifier is IL1Nullifier, ReentrancyGuard, Ownable2StepUpgradeable, | |
/// @dev This function is part of the upgrade process used to nullify chain balances once they are credited to NTV. | ||
/// @param _chainId The ID of the ZK chain. | ||
/// @param _token The address of the token which was previously deposit to shared bridge. | ||
function nullifyChainBalanceByNTV(uint256 _chainId, address _token) external { | ||
require(msg.sender == address(l1NativeTokenVault), "L1N: not NTV"); | ||
function nullifyChainBalanceByNTV(uint256 _chainId, address _token) external onlyL1NTV { | ||
__DEPRECATED_chainBalance[_chainId][_token] = 0; | ||
} | ||
|
||
|
@@ -267,7 +249,7 @@ contract L1Nullifier is IL1Nullifier, ReentrancyGuard, Ownable2StepUpgradeable, | |
emit BridgehubDepositFinalized(_chainId, _txDataHash, _txHash); | ||
} | ||
|
||
/// @dev Calls the internal `_encodeTxDataHash`. Used as a wrapped for try / catch case. | ||
/// @dev Calls the library `encodeTxDataHash`. Used as a wrapped for try / catch case. | ||
/// @dev Encodes the transaction data hash using either the latest encoding standard or the legacy standard. | ||
/// @param _encodingVersion EncodingVersion. | ||
/// @param _originalCaller The address of the entity that initiated the deposit. | ||
|
@@ -408,10 +390,9 @@ contract L1Nullifier is IL1Nullifier, ReentrancyGuard, Ownable2StepUpgradeable, | |
} | ||
isWithdrawalFinalized[chainId][l2BatchNumber][l2MessageIndex] = true; | ||
|
||
// Handling special case for withdrawal from ZKsync Era initiated before Shared Bridge. | ||
(bytes32 assetId, bytes memory transferData) = _verifyWithdrawal(_finalizeWithdrawalParams); | ||
|
||
// Handling special case for withdrawal from zkSync Era initiated before Shared Bridge. | ||
// Handling special case for withdrawal from ZKsync Era initiated before Shared Bridge. | ||
if (_isPreSharedBridgeEraEthWithdrawal(chainId, l2BatchNumber)) { | ||
// Checks that the withdrawal wasn't finalized already. | ||
bool alreadyFinalized = IGetters(ERA_DIAMOND_PROXY).isEthWithdrawalFinalized(l2BatchNumber, l2MessageIndex); | ||
|
@@ -568,8 +549,8 @@ contract L1Nullifier is IL1Nullifier, ReentrancyGuard, Ownable2StepUpgradeable, | |
address baseToken = BRIDGE_HUB.baseToken(_chainId); | ||
transferData = DataEncoding.encodeBridgeMintData({ | ||
_originalCaller: address(0), | ||
_l2Receiver: l1Receiver, | ||
_l1Token: baseToken, | ||
_remoteReceiver: l1Receiver, | ||
_originToken: baseToken, | ||
_amount: amount, | ||
_erc20Metadata: new bytes(0) | ||
}); | ||
|
@@ -592,8 +573,8 @@ contract L1Nullifier is IL1Nullifier, ReentrancyGuard, Ownable2StepUpgradeable, | |
assetId = DataEncoding.encodeNTVAssetId(block.chainid, l1Token); | ||
transferData = DataEncoding.encodeBridgeMintData({ | ||
_originalCaller: address(0), | ||
_l2Receiver: l1Receiver, | ||
_l1Token: l1Token, | ||
_remoteReceiver: l1Receiver, | ||
_originToken: l1Token, | ||
_amount: amount, | ||
_erc20Metadata: new bytes(0) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.