-
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.
Merge pull request #60 from matter-labs/sb-codehawks-batch
Codehawks batch
- Loading branch information
Showing
40 changed files
with
120 additions
and
92 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
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
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 |
---|---|---|
|
@@ -8,7 +8,6 @@ import {IBridgehub, L2TransactionRequestTwoBridgesInner} from "./IBridgehub.sol" | |
import {ICTMDeploymentTracker} from "./ICTMDeploymentTracker.sol"; | ||
|
||
import {IAssetRouterBase} from "../bridge/asset-router/IAssetRouterBase.sol"; | ||
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol"; | ||
import {TWO_BRIDGES_MAGIC_VALUE} from "../common/Config.sol"; | ||
import {L2_BRIDGEHUB_ADDR} from "../common/L2ContractAddresses.sol"; | ||
import {OnlyBridgehub, CTMNotRegistered, NotOwnerViaRouter, NoEthAllowed, NotOwner, WrongCounterPart} from "./L1BridgehubErrors.sol"; | ||
|
@@ -20,7 +19,7 @@ bytes1 constant CTM_DEPLOYMENT_TRACKER_ENCODING_VERSION = 0x01; | |
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
/// @dev Contract to be deployed on L1, can link together other contracts based on AssetInfo. | ||
contract CTMDeploymentTracker is ICTMDeploymentTracker, ReentrancyGuard, Ownable2StepUpgradeable { | ||
contract CTMDeploymentTracker is ICTMDeploymentTracker, Ownable2StepUpgradeable { | ||
/// @dev Bridgehub smart contract that is used to operate with L2 via asynchronous L2 <-> L1 communication. | ||
IBridgehub public immutable override BRIDGE_HUB; | ||
|
||
|
@@ -45,15 +44,15 @@ contract CTMDeploymentTracker is ICTMDeploymentTracker, ReentrancyGuard, Ownable | |
|
||
/// @dev Contract is expected to be used as proxy implementation on L1. | ||
/// @dev Initialize the implementation to prevent Parity hack. | ||
constructor(IBridgehub _bridgehub, IAssetRouterBase _l1AssetRouter) reentrancyGuardInitializer { | ||
constructor(IBridgehub _bridgehub, IAssetRouterBase _l1AssetRouter) { | ||
_disableInitializers(); | ||
BRIDGE_HUB = _bridgehub; | ||
L1_ASSET_ROUTER = _l1AssetRouter; | ||
} | ||
|
||
/// @notice used to initialize the contract | ||
/// @param _owner the owner of the contract | ||
function initialize(address _owner) external reentrancyGuardInitializer { | ||
function initialize(address _owner) external { | ||
_transferOwnership(_owner); | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -6,14 +6,11 @@ import {DynamicIncrementalMerkle} from "../common/libraries/DynamicIncrementalMe | |
|
||
import {IBridgehub} from "./IBridgehub.sol"; | ||
import {IMessageRoot} from "./IMessageRoot.sol"; | ||
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol"; | ||
import {OnlyBridgehub, OnlyChain, ChainExists, MessageRootNotRegistered, TooManyChains} from "./L1BridgehubErrors.sol"; | ||
import {OnlyBridgehub, OnlyChain, ChainExists, MessageRootNotRegistered} from "./L1BridgehubErrors.sol"; | ||
import {FullMerkle} from "../common/libraries/FullMerkle.sol"; | ||
|
||
import {MessageHashing} from "../common/libraries/MessageHashing.sol"; | ||
|
||
import {MAX_NUMBER_OF_ZK_CHAINS} from "../common/Config.sol"; | ||
|
||
// Chain tree consists of batch commitments as their leaves. We use hash of "new bytes(96)" as the hash of an empty leaf. | ||
bytes32 constant CHAIN_TREE_EMPTY_ENTRY_HASH = bytes32( | ||
0x46700b4d40ac5c35af2c22dda2787a91eb567b06c924a8fb8ae9a05b20c08c21 | ||
|
@@ -27,7 +24,7 @@ bytes32 constant SHARED_ROOT_TREE_EMPTY_HASH = bytes32( | |
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
/// @dev The MessageRoot contract is responsible for storing the cross message roots of the chains and the aggregated root of all chains. | ||
contract MessageRoot is IMessageRoot, ReentrancyGuard { | ||
contract MessageRoot is IMessageRoot { | ||
using FullMerkle for FullMerkle.FullTree; | ||
using DynamicIncrementalMerkle for DynamicIncrementalMerkle.Bytes32PushTree; | ||
|
||
|
@@ -75,13 +72,13 @@ contract MessageRoot is IMessageRoot, ReentrancyGuard { | |
/// @dev Contract is expected to be used as proxy implementation on L1, but as a system contract on L2. | ||
/// This means we call the _initialize in both the constructor and the initialize functions. | ||
/// @dev Initialize the implementation to prevent Parity hack. | ||
constructor(IBridgehub _bridgehub) reentrancyGuardInitializer { | ||
constructor(IBridgehub _bridgehub) { | ||
BRIDGE_HUB = _bridgehub; | ||
_initialize(); | ||
} | ||
|
||
/// @dev Initializes a contract for later use. Expected to be used in the proxy on L1, on L2 it is a system contract without a proxy. | ||
function initialize() external reentrancyGuardInitializer { | ||
function initialize() external { | ||
_initialize(); | ||
} | ||
|
||
|
@@ -151,10 +148,9 @@ contract MessageRoot is IMessageRoot, ReentrancyGuard { | |
/// @param _chainId the chainId of the chain | ||
function _addNewChain(uint256 _chainId) internal { | ||
uint256 cachedChainCount = chainCount; | ||
if (cachedChainCount >= MAX_NUMBER_OF_ZK_CHAINS) { | ||
revert TooManyChains(cachedChainCount, MAX_NUMBER_OF_ZK_CHAINS); | ||
} | ||
|
||
// Since only the bridgehub can add new chains to the message root, it is expected that | ||
// it will be responsible for ensuring that the number of chains does not exceed the limit. | ||
++chainCount; | ||
chainIndex[_chainId] = cachedChainCount; | ||
chainIndexToId[cachedChainCount] = _chainId; | ||
|
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 |
---|---|---|
|
@@ -14,17 +14,16 @@ import {IChainTypeManager, ChainTypeManagerInitializeData, ChainCreationParams} | |
import {IZKChain} from "./chain-interfaces/IZKChain.sol"; | ||
import {FeeParams} from "./chain-deps/ZKChainStorage.sol"; | ||
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable-v4/access/Ownable2StepUpgradeable.sol"; | ||
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol"; | ||
import {L2_TO_L1_LOG_SERIALIZE_SIZE, DEFAULT_L2_LOGS_TREE_ROOT_HASH, EMPTY_STRING_KECCAK} from "../common/Config.sol"; | ||
import {InitialForceDeploymentMismatch, AdminZero, OutdatedProtocolVersion} from "./L1StateTransitionErrors.sol"; | ||
import {ChainAlreadyLive, Unauthorized, ZeroAddress, HashMismatch, GenesisUpgradeZero, GenesisBatchHashZero, GenesisIndexStorageZero, GenesisBatchCommitmentZero} from "../common/L1ContractErrors.sol"; | ||
import {ChainAlreadyLive, Unauthorized, ZeroAddress, HashMismatch, GenesisUpgradeZero, GenesisBatchHashZero, GenesisIndexStorageZero, GenesisBatchCommitmentZero, MigrationsNotPaused} from "../common/L1ContractErrors.sol"; | ||
import {SemVer} from "../common/libraries/SemVer.sol"; | ||
import {IBridgehub} from "../bridgehub/IBridgehub.sol"; | ||
|
||
/// @title State Transition Manager contract | ||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
contract ChainTypeManager is IChainTypeManager, ReentrancyGuard, Ownable2StepUpgradeable { | ||
contract ChainTypeManager is IChainTypeManager, Ownable2StepUpgradeable { | ||
using EnumerableMap for EnumerableMap.UintToAddressMap; | ||
|
||
/// @notice Address of the bridgehub | ||
|
@@ -65,12 +64,14 @@ contract ChainTypeManager is IChainTypeManager, ReentrancyGuard, Ownable2StepUpg | |
|
||
/// @dev Contract is expected to be used as proxy implementation. | ||
/// @dev Initialize the implementation to prevent Parity hack. | ||
constructor(address _bridgehub) reentrancyGuardInitializer { | ||
constructor(address _bridgehub) { | ||
BRIDGE_HUB = _bridgehub; | ||
|
||
// While this does not provide a protection in the production, it is needed for local testing | ||
// Length of the L2Log encoding should not be equal to the length of other L2Logs' tree nodes preimages | ||
assert(L2_TO_L1_LOG_SERIALIZE_SIZE != 2 * 32); | ||
|
||
_disableInitializers(); | ||
} | ||
|
||
/// @notice only the bridgehub can call | ||
|
@@ -115,7 +116,7 @@ contract ChainTypeManager is IChainTypeManager, ReentrancyGuard, Ownable2StepUpg | |
} | ||
|
||
/// @dev initialize | ||
function initialize(ChainTypeManagerInitializeData calldata _initializeData) external reentrancyGuardInitializer { | ||
function initialize(ChainTypeManagerInitializeData calldata _initializeData) external { | ||
if (_initializeData.owner == address(0)) { | ||
revert ZeroAddress(); | ||
} | ||
|
@@ -227,6 +228,10 @@ contract ChainTypeManager is IChainTypeManager, ReentrancyGuard, Ownable2StepUpg | |
uint256 _oldProtocolVersionDeadline, | ||
uint256 _newProtocolVersion | ||
) external onlyOwner { | ||
if (!IBridgehub(BRIDGE_HUB).migrationPaused()) { | ||
revert MigrationsNotPaused(); | ||
} | ||
|
||
bytes32 newCutHash = keccak256(abi.encode(_cutData)); | ||
uint256 previousProtocolVersion = protocolVersion; | ||
upgradeCutHash[_oldProtocolVersion] = newCutHash; | ||
|
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.