Skip to content

feat(wip): Boojum OS initial draft version #1481

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

Draft
wants to merge 3 commits into
base: v29/custom-da-removal
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion l1-contracts/contracts/bridge/L2WrappedBaseToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import {IL2WrappedBaseToken} from "./interfaces/IL2WrappedBaseToken.sol";
import {IBridgedStandardToken} from "./interfaces/IBridgedStandardToken.sol";
import {L2_NATIVE_TOKEN_VAULT_ADDR} from "../common/L2ContractAddresses.sol";
import {L2_NATIVE_TOKEN_VAULT_ADDR, L2_GENESIS_UPGRADE_ADDR} from "../common/L2ContractAddresses.sol";

import {ZeroAddress, Unauthorized, BridgeMintNotImplemented, WithdrawFailed} from "../common/L1ContractErrors.sol";

Expand Down Expand Up @@ -49,6 +49,13 @@
_disableInitializers();
}

// we set deployed code during genesis upgrade and calling this(only) method during the genesis upgrade
function init_boojum() external {
require(msg.sender == L2_GENESIS_UPGRADE_ADDR);

Check failure on line 54 in l1-contracts/contracts/bridge/L2WrappedBaseToken.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 54 in l1-contracts/contracts/bridge/L2WrappedBaseToken.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 54 in l1-contracts/contracts/bridge/L2WrappedBaseToken.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 54 in l1-contracts/contracts/bridge/L2WrappedBaseToken.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 54 in l1-contracts/contracts/bridge/L2WrappedBaseToken.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 54 in l1-contracts/contracts/bridge/L2WrappedBaseToken.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

_disableInitializers();
}

/// @dev Fallback function to allow receiving Ether.
receive() external payable {
depositTo(msg.sender);
Expand Down
13 changes: 10 additions & 3 deletions l1-contracts/contracts/bridge/asset-router/AssetRouterBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ abstract contract AssetRouterBase is IAssetRouterBase, Ownable2StepUpgradeable,
using SafeERC20 for IERC20;

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

/// @dev Chain ID of L1 for bridging reasons
uint256 public immutable L1_CHAIN_ID;
uint256 public L1_CHAIN_ID;

/// @dev Chain ID of Era for legacy reasons
uint256 public immutable ERA_CHAIN_ID;
uint256 public ERA_CHAIN_ID;

/// @dev Maps asset ID to address of corresponding asset handler.
/// @dev Tracks the address of Asset Handler contracts, where bridged funds are locked for each asset.
Expand Down Expand Up @@ -69,6 +69,13 @@ abstract contract AssetRouterBase is IAssetRouterBase, Ownable2StepUpgradeable,
BRIDGE_HUB = _bridgehub;
}

// we set deployed code during genesis upgrade and calling this(only) method during the genesis upgrade
function init_boojum(uint256 _l1ChainId, uint256 _eraChainId, IBridgehub _bridgehub) internal {
L1_CHAIN_ID = _l1ChainId;
ERA_CHAIN_ID = _eraChainId;
BRIDGE_HUB = _bridgehub;
}

/// @inheritdoc IAssetRouterBase
function setAssetHandlerAddressThisChain(
bytes32 _assetRegistrationData,
Expand Down
32 changes: 28 additions & 4 deletions l1-contracts/contracts/bridge/asset-router/L2AssetRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import {AddressAliasHelper} from "../../vendor/AddressAliasHelper.sol";
import {ReentrancyGuard} from "../../common/ReentrancyGuard.sol";

import {L2_NATIVE_TOKEN_VAULT_ADDR, L2_BRIDGEHUB_ADDR} from "../../common/L2ContractAddresses.sol";
import {L2_NATIVE_TOKEN_VAULT_ADDR, L2_BRIDGEHUB_ADDR, L2_GENESIS_UPGRADE_ADDR} from "../../common/L2ContractAddresses.sol";
import {L2ContractHelper} from "../../common/libraries/L2ContractHelper.sol";
import {DataEncoding} from "../../common/libraries/DataEncoding.sol";
import {TokenNotLegacy, EmptyAddress, InvalidCaller, AmountMustBeGreaterThanZero, AssetIdNotSupported} from "../../common/L1ContractErrors.sol";
Expand All @@ -26,13 +26,13 @@
/// support any custom token logic, i.e. rebase tokens' functionality is not supported.
contract L2AssetRouter is AssetRouterBase, IL2AssetRouter, ReentrancyGuard {
/// @dev The address of the L2 legacy shared bridge.
address public immutable L2_LEGACY_SHARED_BRIDGE;
address public L2_LEGACY_SHARED_BRIDGE;

/// @dev The asset id of the base token.
bytes32 public immutable BASE_TOKEN_ASSET_ID;
bytes32 public BASE_TOKEN_ASSET_ID;

/// @dev The address of the L1 asset router counterpart.
address public immutable override L1_ASSET_ROUTER;
address public override L1_ASSET_ROUTER;

/// @notice Checks that the message sender is the L1 Asset Router.
modifier onlyAssetRouterCounterpart(uint256 _originChainId) {
Expand Down Expand Up @@ -97,6 +97,30 @@
_transferOwnership(_aliasedOwner);
}

// we set deployed code during genesis upgrade and calling this(only) method during the genesis upgrade
function init_boojum(
uint256 _l1ChainId,
uint256 _eraChainId,
address _l1AssetRouter,
address _legacySharedBridge,
bytes32 _baseTokenAssetId,
address _aliasedOwner
) external {
require(msg.sender == L2_GENESIS_UPGRADE_ADDR);

Check failure on line 109 in l1-contracts/contracts/bridge/asset-router/L2AssetRouter.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 109 in l1-contracts/contracts/bridge/asset-router/L2AssetRouter.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 109 in l1-contracts/contracts/bridge/asset-router/L2AssetRouter.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 109 in l1-contracts/contracts/bridge/asset-router/L2AssetRouter.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 109 in l1-contracts/contracts/bridge/asset-router/L2AssetRouter.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 109 in l1-contracts/contracts/bridge/asset-router/L2AssetRouter.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

init_boojum(_l1ChainId, _eraChainId, IBridgehub(L2_BRIDGEHUB_ADDR));

L2_LEGACY_SHARED_BRIDGE = _legacySharedBridge;
if (_l1AssetRouter == address(0)) {
revert EmptyAddress();
}
L1_ASSET_ROUTER = _l1AssetRouter;
_setAssetHandler(_baseTokenAssetId, L2_NATIVE_TOKEN_VAULT_ADDR);
BASE_TOKEN_ASSET_ID = _baseTokenAssetId;
_disableInitializers();
_transferOwnership(_aliasedOwner);
}

/// @inheritdoc IL2AssetRouter
function setAssetHandlerAddress(
uint256 _originChainId,
Expand Down
49 changes: 46 additions & 3 deletions l1-contracts/contracts/bridge/ntv/L2NativeTokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {BridgedStandardERC20} from "../BridgedStandardERC20.sol";
import {IL2AssetRouter} from "../asset-router/IL2AssetRouter.sol";

import {L2_DEPLOYER_SYSTEM_CONTRACT_ADDR, L2_ASSET_ROUTER_ADDR} from "../../common/L2ContractAddresses.sol";
import {L2_DEPLOYER_SYSTEM_CONTRACT_ADDR, L2_ASSET_ROUTER_ADDR, L2_GENESIS_UPGRADE_ADDR} from "../../common/L2ContractAddresses.sol";
import {L2ContractHelper, IContractDeployer} from "../../common/libraries/L2ContractHelper.sol";

import {SystemContractsCaller} from "../../common/libraries/SystemContractsCaller.sol";
Expand All @@ -32,10 +32,10 @@
contract L2NativeTokenVault is IL2NativeTokenVault, NativeTokenVault {
using SafeERC20 for IERC20;

IL2SharedBridgeLegacy public immutable L2_LEGACY_SHARED_BRIDGE;
IL2SharedBridgeLegacy public L2_LEGACY_SHARED_BRIDGE;

/// @dev Bytecode hash of the proxy for tokens deployed by the bridge.
bytes32 internal immutable L2_TOKEN_PROXY_BYTECODE_HASH;
bytes32 internal L2_TOKEN_PROXY_BYTECODE_HASH;

/// @notice Initializes the bridge contract for later use.
/// @dev this contract is deployed in the L2GenesisUpgrade, and is meant as direct deployment without a proxy.
Expand Down Expand Up @@ -84,6 +84,49 @@
}
}

// we set deployed code during genesis upgrade and calling this(only) method during the genesis upgrade
function init_boojum(
uint256 _l1ChainId,
address _aliasedOwner,
bytes32 _l2TokenProxyBytecodeHash,
address _legacySharedBridge,
address _bridgedTokenBeacon,
bool _contractsDeployedAlready,
address _wethToken,
bytes32 _baseTokenAssetId
) external {
require(msg.sender == L2_GENESIS_UPGRADE_ADDR);

Check failure on line 98 in l1-contracts/contracts/bridge/ntv/L2NativeTokenVault.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 98 in l1-contracts/contracts/bridge/ntv/L2NativeTokenVault.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 98 in l1-contracts/contracts/bridge/ntv/L2NativeTokenVault.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 98 in l1-contracts/contracts/bridge/ntv/L2NativeTokenVault.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 98 in l1-contracts/contracts/bridge/ntv/L2NativeTokenVault.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 98 in l1-contracts/contracts/bridge/ntv/L2NativeTokenVault.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

init_boojum(_wethToken, L2_ASSET_ROUTER_ADDR, _baseTokenAssetId, _l1ChainId);

L2_LEGACY_SHARED_BRIDGE = IL2SharedBridgeLegacy(_legacySharedBridge);

if (_l2TokenProxyBytecodeHash == bytes32(0)) {
revert EmptyBytes32();
}
if (_aliasedOwner == address(0)) {
revert EmptyAddress();
}

L2_TOKEN_PROXY_BYTECODE_HASH = _l2TokenProxyBytecodeHash;
_transferOwnership(_aliasedOwner);

if (_contractsDeployedAlready) {
if (_bridgedTokenBeacon == address(0)) {
revert EmptyAddress();
}
bridgedTokenBeacon = IBeacon(_bridgedTokenBeacon);
} else {
address l2StandardToken = address(new BridgedStandardERC20{salt: bytes32(0)}());

UpgradeableBeacon tokenBeacon = new UpgradeableBeacon{salt: bytes32(0)}(l2StandardToken);

tokenBeacon.transferOwnership(owner());
bridgedTokenBeacon = IBeacon(address(tokenBeacon));
emit L2TokenBeaconUpdated(address(bridgedTokenBeacon), _l2TokenProxyBytecodeHash);
}
}

function _registerTokenIfBridgedLegacy(address _tokenAddress) internal override returns (bytes32) {
// In zkEVM immutables are stored in a storage of a system contract,
// so it makes sense to cache them for efficiency.
Expand Down
17 changes: 13 additions & 4 deletions l1-contracts/contracts/bridge/ntv/NativeTokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ abstract contract NativeTokenVault is
using SafeERC20 for IERC20;

/// @dev The address of the WETH token.
address public immutable override WETH_TOKEN;
address public override WETH_TOKEN;

/// @dev L1 Shared Bridge smart contract that handles communication with its counterparts on L2s
IAssetRouterBase public immutable override ASSET_ROUTER;
IAssetRouterBase public override ASSET_ROUTER;

/// @dev The assetId of the base token.
bytes32 public immutable BASE_TOKEN_ASSET_ID;
bytes32 public BASE_TOKEN_ASSET_ID;

/// @dev Chain ID of L1 for bridging reasons.
uint256 public immutable L1_CHAIN_ID;
uint256 public L1_CHAIN_ID;

/// @dev Contract that stores the implementation address for token.
/// @dev For more details see https://docs.openzeppelin.com/contracts/3.x/api/proxy#UpgradeableBeacon.
Expand Down Expand Up @@ -88,6 +88,15 @@ abstract contract NativeTokenVault is
BASE_TOKEN_ASSET_ID = _baseTokenAssetId;
}

// we set deployed code during genesis upgrade and calling this(only) method during the genesis upgrade
function init_boojum(address _wethToken, address _assetRouter, bytes32 _baseTokenAssetId, uint256 _l1ChainId) internal {
_disableInitializers();
L1_CHAIN_ID = _l1ChainId;
ASSET_ROUTER = IAssetRouterBase(_assetRouter);
WETH_TOKEN = _wethToken;
BASE_TOKEN_ASSET_ID = _baseTokenAssetId;
}

/// @inheritdoc INativeTokenVault
function registerToken(address _nativeToken) external virtual {
_registerToken(_nativeToken);
Expand Down
34 changes: 31 additions & 3 deletions l1-contracts/contracts/bridgehub/Bridgehub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import {ETH_TOKEN_ADDRESS, TWO_BRIDGES_MAGIC_VALUE, BRIDGEHUB_MIN_SECOND_BRIDGE_ADDRESS, SETTLEMENT_LAYER_RELAY_SENDER, L1_SETTLEMENT_LAYER_VIRTUAL_ADDRESS} from "../common/Config.sol";
import {BridgehubL2TransactionRequest, L2Message, L2Log, TxStatus} from "../common/Messaging.sol";
import {L2_GENESIS_UPGRADE_ADDR} from "../common/L2ContractAddresses.sol";
import {AddressAliasHelper} from "../vendor/AddressAliasHelper.sol";
import {IMessageRoot} from "./IMessageRoot.sol";
import {ICTMDeploymentTracker} from "./ICTMDeploymentTracker.sol";
Expand All @@ -37,15 +38,15 @@
using EnumerableMap for EnumerableMap.UintToAddressMap;

/// @notice the asset id of Eth. This is only used on L1.
bytes32 internal immutable ETH_TOKEN_ASSET_ID;
bytes32 internal ETH_TOKEN_ASSET_ID;

/// @notice The chain id of L1. This contract can be deployed on multiple layers, but this value is still equal to the
/// L1 that is at the most base layer.
uint256 public immutable L1_CHAIN_ID;
uint256 public L1_CHAIN_ID;

/// @notice The total number of ZK chains can be created/connected to this CTM.
/// This is the temporary security measure.
uint256 public immutable MAX_NUMBER_OF_ZK_CHAINS;
uint256 public MAX_NUMBER_OF_ZK_CHAINS;

/// @notice all the ether and ERC20 tokens are held by NativeVaultToken managed by the asset router.
address public assetRouter;
Expand Down Expand Up @@ -154,6 +155,33 @@
_initializeInner();
}

// we set deployed code during genesis upgrade and calling this(only) method during the genesis upgrade
function init_boojum(
uint256 _l1ChainId,
address _owner,
uint256 _maxNumberOfZKChains,
address _assetRouter,
ICTMDeploymentTracker _l1CtmDeployer,
IMessageRoot _messageRoot
) external {
require(msg.sender == L2_GENESIS_UPGRADE_ADDR);

Check failure on line 167 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 167 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 167 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 167 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 167 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 167 in l1-contracts/contracts/bridgehub/Bridgehub.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

_disableInitializers();
L1_CHAIN_ID = _l1ChainId;
MAX_NUMBER_OF_ZK_CHAINS = _maxNumberOfZKChains;

// Note that this assumes that the bridgehub only accepts transactions on chains with ETH base token only.
// This is indeed true, since the only methods where this immutable is used are the ones with `onlyL1` modifier.
// We will change this with interop.
ETH_TOKEN_ASSET_ID = DataEncoding.encodeNTVAssetId(L1_CHAIN_ID, ETH_TOKEN_ADDRESS);
_transferOwnership(_owner);
_initializeInner();

assetRouter = _assetRouter;
l1CtmDeployer = _l1CtmDeployer;
messageRoot = _messageRoot;
}

/// @notice used to initialize the contract
/// @notice this contract is also deployed on L2 as a system contract there the owner and the related functions will not be used
/// @param _owner the owner of the contract
Expand Down
12 changes: 11 additions & 1 deletion l1-contracts/contracts/bridgehub/MessageRoot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {IMessageRoot} from "./IMessageRoot.sol";
import {OnlyBridgehub, OnlyChain, ChainExists, MessageRootNotRegistered} from "./L1BridgehubErrors.sol";
import {FullMerkle} from "../common/libraries/FullMerkle.sol";
import {L2_GENESIS_UPGRADE_ADDR} from "../common/L2ContractAddresses.sol";

import {MessageHashing} from "../common/libraries/MessageHashing.sol";

Expand Down Expand Up @@ -36,7 +37,7 @@
event Preimage(bytes32 one, bytes32 two);

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

/// @notice The number of chains that are registered.
uint256 public chainCount;
Expand Down Expand Up @@ -79,6 +80,15 @@
_disableInitializers();
}

// we set deployed code during genesis upgrade and calling this(only) method during the genesis upgrade
function init_boojum(IBridgehub _bridgehub) external {
require(msg.sender == L2_GENESIS_UPGRADE_ADDR);

Check failure on line 85 in l1-contracts/contracts/bridgehub/MessageRoot.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 85 in l1-contracts/contracts/bridgehub/MessageRoot.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 85 in l1-contracts/contracts/bridgehub/MessageRoot.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 85 in l1-contracts/contracts/bridgehub/MessageRoot.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

Check failure on line 85 in l1-contracts/contracts/bridgehub/MessageRoot.sol

View workflow job for this annotation

GitHub Actions / lint

Provide an error message for require

Check failure on line 85 in l1-contracts/contracts/bridgehub/MessageRoot.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

BRIDGE_HUB = _bridgehub;
_initialize();
_disableInitializers();
}

/// @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 initializer {
_initialize();
Expand Down
2 changes: 2 additions & 0 deletions l1-contracts/contracts/common/L1ContractErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ error InvalidSelector(bytes4 func);
error InvalidUpgradeTxn(UpgradeTxVerifyParam);
// 0xfb5c22e6
error L2TimestampTooBig();
// 0x55bde247
error IncorrectBatchChainId();
// 0x97e1359e
error L2WithdrawalMessageWrongLength(uint256 messageLen);
// 0xe37d2c02
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ contract ChainTypeManager is IChainTypeManager, ReentrancyGuard, Ownable2StepUpg
address public validatorTimelock;

/// @dev The stored cutData for upgrade diamond cut. protocolVersion => cutHash
/// @notice it doesn't store cutData for protocolVersion upgrade, it stores cutData to upgrade from protocolVersion
mapping(uint256 protocolVersion => bytes32 cutHash) public upgradeCutHash;

/// @dev The address used to manage non critical updates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,6 @@ struct ZKChainStorage {
bytes32 l2EvmEmulatorBytecodeHash;
/// @dev The scheme of L2 DA commitment. Different L1 validators may use different schemes.
L2DACommitmentScheme l2DACommitmentScheme;
/// @dev Boojum OS flag, if `true` settlement done using Boojum OS state transition, otherwise Era VM
bool boojumOS;
}
Loading
Loading