-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: OZ fixes from (GW + Governance audit) + ZK as base token for GW…
… combined (#978) Co-authored-by: Raid Ateir <[email protected]> Co-authored-by: Stanislav Breadless <[email protected]> Co-authored-by: Vlad Bochok <[email protected]> Co-authored-by: vladbochok <[email protected]> Co-authored-by: kelemeno <[email protected]>
- Loading branch information
1 parent
f33bcb7
commit 21ac083
Showing
58 changed files
with
538 additions
and
235 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 |
---|---|---|
|
@@ -9,7 +9,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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,6 @@ | |
|
||
pragma solidity ^0.8.21; | ||
|
||
// 0xe4efb466 | ||
error NotNTV(); | ||
|
||
// 0x6d963f88 | ||
error EthTransferFailed(); | ||
|
||
|
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 |
---|---|---|
|
@@ -29,7 +29,7 @@ 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 {WrongL2Sender, NotNTV, NativeTokenVaultAlreadySet, EthTransferFailed, WrongMsgLength} from "./L1BridgeContractErrors.sol"; | ||
import {WrongL2Sender, NativeTokenVaultAlreadySet, EthTransferFailed, WrongMsgLength} from "./L1BridgeContractErrors.sol"; | ||
|
||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
|
@@ -126,14 +126,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)) { | ||
|
@@ -142,14 +134,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 { | ||
|
@@ -210,10 +194,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 { | ||
if (msg.sender != address(l1NativeTokenVault)) { | ||
revert NotNTV(); | ||
} | ||
function nullifyChainBalanceByNTV(uint256 _chainId, address _token) external onlyL1NTV { | ||
__DEPRECATED_chainBalance[_chainId][_token] = 0; | ||
} | ||
|
||
|
@@ -290,7 +271,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. | ||
|
@@ -431,10 +412,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); | ||
|
@@ -593,8 +573,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) | ||
}); | ||
|
@@ -618,8 +598,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
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 |
---|---|---|
|
@@ -7,9 +7,6 @@ pragma solidity 0.8.24; | |
/// @custom:security-contact [email protected] | ||
/// @notice Used for any asset handler and called by the AssetRouter | ||
interface IAssetHandler { | ||
/// @dev Emitted when a new token is initialized | ||
event BridgeInitialize(address indexed token, string name, string symbol, uint8 decimals); | ||
|
||
/// @dev Emitted when a token is minted | ||
event BridgeMint(uint256 indexed chainId, bytes32 indexed assetId, address receiver, uint256 amount); | ||
|
||
|
@@ -27,7 +24,7 @@ interface IAssetHandler { | |
/// @param _data the actual data specified for the function | ||
function bridgeMint(uint256 _chainId, bytes32 _assetId, bytes calldata _data) external payable; | ||
|
||
/// @notice Burns bridged tokens and returns the calldata for L2 -> L1 message. | ||
/// @notice Burns bridged tokens and returns the calldata for L2 <-> L1 message. | ||
/// @dev In case of native token vault _data is the tuple of _depositAmount and _l2Receiver. | ||
/// @param _chainId the chainId that the message will be sent to | ||
/// @param _msgValue the msg.value of the L2 transaction. For now it is always 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
Oops, something went wrong.