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

Port the gateway release candidate + use forge #3212

Open
wants to merge 74 commits into
base: sync-layer-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
af9359c
basic integration of new upgrade system
StanislavBreadless Oct 3, 2024
5231331
latest contracts
StanislavBreadless Oct 3, 2024
1b0514f
sync with base
StanislavBreadless Oct 3, 2024
192e994
expand the max factory deps
StanislavBreadless Oct 3, 2024
1ad8ec7
rust fmt
StanislavBreadless Oct 3, 2024
1cf35b0
use latest contracts
StanislavBreadless Oct 4, 2024
e4941f0
upd contracts
StanislavBreadless Oct 5, 2024
55b3062
upgrade preparation
StanislavBreadless Oct 8, 2024
d5d4b43
sync with main
StanislavBreadless Oct 8, 2024
ce3e22e
fix lint
StanislavBreadless Oct 8, 2024
c1d3743
new contracts
StanislavBreadless Oct 8, 2024
534051e
sync with base
StanislavBreadless Oct 8, 2024
9296f70
fmt
StanislavBreadless Oct 8, 2024
b5015c7
fix compile
StanislavBreadless Oct 8, 2024
68f0968
tmp
StanislavBreadless Oct 8, 2024
5045a06
running ecosystem upgrade works
StanislavBreadless Oct 9, 2024
d24d99c
admin functions
StanislavBreadless Oct 9, 2024
96278af
fix admin finalize stage1
StanislavBreadless Oct 9, 2024
1fa9179
fmt
StanislavBreadless Oct 10, 2024
48656c0
better scripts
StanislavBreadless Oct 10, 2024
9c2236d
debug info + upd contracts
StanislavBreadless Oct 10, 2024
a9ea468
more debug
StanislavBreadless Oct 10, 2024
03158a1
fix bug in deploy scripts
StanislavBreadless Oct 10, 2024
2e8a724
impl setting data for the upgrade
StanislavBreadless Oct 11, 2024
7ab6beb
fmt
StanislavBreadless Oct 11, 2024
041f5e6
fix decode
StanislavBreadless Oct 11, 2024
d2248a7
fix more things
StanislavBreadless Oct 11, 2024
09e50e8
upd contracts
StanislavBreadless Oct 11, 2024
e39a680
correctly update config
StanislavBreadless Oct 11, 2024
1c91ac0
add validators to init
StanislavBreadless Oct 11, 2024
3847361
upd validator timelock
StanislavBreadless Oct 11, 2024
3ba1f31
comit
StanislavBreadless Oct 11, 2024
5de2764
set da validator pair
StanislavBreadless Oct 11, 2024
1647af8
separate schedule step
StanislavBreadless Oct 12, 2024
698b82d
upd contracts
StanislavBreadless Oct 12, 2024
18ccc7b
upd default aa hash
StanislavBreadless Oct 12, 2024
fc29072
set priority queue index on the server
StanislavBreadless Oct 12, 2024
811521e
toolbox
StanislavBreadless Oct 12, 2024
f5db970
fmt
StanislavBreadless Oct 13, 2024
9ce168b
better contracts
StanislavBreadless Oct 13, 2024
6b9a83f
finalize upgrade no governance
StanislavBreadless Oct 14, 2024
008679b
use better contracts
StanislavBreadless Oct 14, 2024
109a01c
new contracts
StanislavBreadless Oct 15, 2024
798e607
ecosystem upgrade
StanislavBreadless Oct 15, 2024
0a2a496
upgrade fully working
StanislavBreadless Oct 15, 2024
426c57d
upgrade flow works
StanislavBreadless Oct 15, 2024
d2179f4
upd contracts
StanislavBreadless Oct 15, 2024
4529de0
upd contracts
StanislavBreadless Oct 15, 2024
b59dd1c
new upgrade system contracts
StanislavBreadless Oct 16, 2024
e11dbd8
works with newer contracts
StanislavBreadless Oct 23, 2024
1a66622
deleted unneeded files
StanislavBreadless Oct 23, 2024
b48a9ab
support weth upon genesis
StanislavBreadless Oct 23, 2024
9893a4b
finalize upgradeable beacon approach
StanislavBreadless Oct 23, 2024
5979586
upd contracts
StanislavBreadless Oct 23, 2024
db9b886
gateway ctm logic closer to actual upgrade
StanislavBreadless Oct 23, 2024
44583ca
remove unsupplied field
StanislavBreadless Oct 23, 2024
7aa97d9
works with new upgrade
StanislavBreadless Oct 24, 2024
8ac89c3
wip porting scripts to stable
StanislavBreadless Oct 30, 2024
6dd3504
sync with base
StanislavBreadless Oct 30, 2024
fde4692
l1/l2 contracts compile via foundry
StanislavBreadless Oct 31, 2024
9db129e
sc wip
StanislavBreadless Oct 31, 2024
d2ad020
make genesis work
StanislavBreadless Oct 31, 2024
b4cc252
upd submodules
StanislavBreadless Oct 31, 2024
2810c78
fix lint/fmt
StanislavBreadless Oct 31, 2024
4d1dc88
use new contracts
StanislavBreadless Oct 31, 2024
fc36271
self review
StanislavBreadless Oct 31, 2024
55f1202
fixes
StanislavBreadless Oct 31, 2024
dcc334c
upd contracts
StanislavBreadless Oct 31, 2024
3c2721e
Update core/lib/types/src/abi.rs
StanislavBreadless Nov 1, 2024
08d4811
solve some comments
StanislavBreadless Nov 1, 2024
85fc646
Merge remote-tracking branch 'origin/sb-forge-for-contracts' into sb-…
StanislavBreadless Nov 1, 2024
d77e027
more comments
StanislavBreadless Nov 1, 2024
cb4d6ad
sync with base
StanislavBreadless Nov 1, 2024
d814f6a
refactor dal
StanislavBreadless Nov 1, 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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "contracts"]
path = contracts
url = https://github.com/matter-labs/era-contracts.git
url = https://github.com/matter-labs/era-contracts-private.git
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts
6 changes: 6 additions & 0 deletions core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub(crate) struct RemoteENConfig {
pub bridgehub_proxy_addr: Option<Address>,
pub state_transition_proxy_addr: Option<Address>,
pub transparent_proxy_admin_addr: Option<Address>,
pub l1_bytecodes_supplier_addr: Option<Address>,
/// Should not be accessed directly. Use [`ExternalNodeConfig::diamond_proxy_address`] instead.
pub user_facing_diamond_proxy: Address,
// While on L1 shared bridge and legacy bridge are different contracts with different addresses,
Expand Down Expand Up @@ -196,6 +197,9 @@ impl RemoteENConfig {
transparent_proxy_admin_addr: ecosystem_contracts
.as_ref()
.map(|a| a.transparent_proxy_admin_addr),
l1_bytecodes_supplier_addr: ecosystem_contracts
.as_ref()
.and_then(|a| a.l1_bytecodes_supplier_addr),
user_facing_diamond_proxy,
user_facing_bridgehub,
l2_testnet_paymaster_addr,
Expand Down Expand Up @@ -224,6 +228,7 @@ impl RemoteENConfig {
bridgehub_proxy_addr: None,
state_transition_proxy_addr: None,
transparent_proxy_admin_addr: None,
l1_bytecodes_supplier_addr: None,
user_facing_diamond_proxy: Address::repeat_byte(1),
user_facing_bridgehub: None,
l1_erc20_bridge_proxy_addr: Some(Address::repeat_byte(2)),
Expand Down Expand Up @@ -1428,6 +1433,7 @@ impl From<&ExternalNodeConfig> for InternalApiConfig {
l1_weth_bridge: config.remote.l1_weth_bridge_addr,
l2_weth_bridge: config.remote.l2_weth_bridge_addr,
},
l1_bytecodes_supplier_addr: config.remote.l1_bytecodes_supplier_addr,
bridgehub_proxy_addr: config.remote.bridgehub_proxy_addr,
state_transition_proxy_addr: config.remote.state_transition_proxy_addr,
transparent_proxy_admin_addr: config.remote.transparent_proxy_admin_addr,
Expand Down
8 changes: 5 additions & 3 deletions core/bin/system-constants-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::fs;
use codegen::{Block, Scope};
use serde::{Deserialize, Serialize};
use zksync_multivm::{
utils::{get_bootloader_encoding_space, get_bootloader_max_txs_in_batch},
utils::{
get_bootloader_encoding_space, get_bootloader_max_txs_in_batch, get_max_new_factory_deps,
},
vm_latest::constants::MAX_VM_PUBDATA_PER_BATCH,
zk_evm_latest::zkevm_opcode_defs::{
circuit_prices::{
Expand All @@ -15,7 +17,7 @@ use zksync_multivm::{
};
use zksync_types::{
IntrinsicSystemGasConstants, ProtocolVersionId, GUARANTEED_PUBDATA_IN_TX,
L1_GAS_PER_PUBDATA_BYTE, MAX_NEW_FACTORY_DEPS, REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE,
L1_GAS_PER_PUBDATA_BYTE, REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE,
};
use zksync_utils::env::Workspace;

Expand Down Expand Up @@ -73,7 +75,7 @@ pub fn generate_l1_contracts_system_config(gas_constants: &IntrinsicSystemGasCon
l1_tx_delta_544_encoding_bytes: gas_constants.l1_tx_delta_544_encoding_bytes,
l1_tx_delta_factory_deps_l2_gas: gas_constants.l1_tx_delta_factory_dep_gas,
l1_tx_delta_factory_deps_pubdata: gas_constants.l1_tx_delta_factory_dep_pubdata,
max_new_factory_deps: MAX_NEW_FACTORY_DEPS as u32,
max_new_factory_deps: get_max_new_factory_deps(ProtocolVersionId::latest().into()) as u32,
required_l2_gas_price_per_pubdata: REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE,
};

Expand Down
10 changes: 9 additions & 1 deletion core/lib/basic_types/src/protocol_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ impl ProtocolVersionId {
}

pub fn is_pre_gateway(&self) -> bool {
self <= &Self::Version26
self < &Self::gateway_upgrade()
}

pub fn is_post_gateway(&self) -> bool {
self >= &Self::gateway_upgrade()
}

pub fn is_1_4_0(&self) -> bool {
Expand Down Expand Up @@ -182,6 +186,10 @@ impl ProtocolVersionId {
pub fn is_post_1_5_0(&self) -> bool {
self >= &ProtocolVersionId::Version23
}

pub const fn gateway_upgrade() -> Self {
ProtocolVersionId::Version26
}
}

impl Default for ProtocolVersionId {
Expand Down
10 changes: 9 additions & 1 deletion core/lib/config/src/configs/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// External uses
use serde::{Deserialize, Serialize};
// Workspace uses
use zksync_basic_types::Address;
use zksync_basic_types::{Address, H256};

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct EcosystemContracts {
pub bridgehub_proxy_addr: Address,
pub state_transition_proxy_addr: Address,
pub transparent_proxy_admin_addr: Address,
pub l1_bytecodes_supplier_addr: Option<Address>,
}

impl EcosystemContracts {
Expand All @@ -16,6 +17,7 @@ impl EcosystemContracts {
bridgehub_proxy_addr: Address::repeat_byte(0x14),
state_transition_proxy_addr: Address::repeat_byte(0x15),
transparent_proxy_admin_addr: Address::repeat_byte(0x15),
l1_bytecodes_supplier_addr: Some(Address::repeat_byte(0x16)),
}
}
}
Expand Down Expand Up @@ -45,6 +47,10 @@ pub struct ContractsConfig {
pub ecosystem_contracts: Option<EcosystemContracts>,
// Used by the RPC API and by the node builder in wiring the BaseTokenRatioProvider layer.
pub base_token_addr: Option<Address>,
pub base_token_asset_id: Option<H256>,

pub predeployed_l2_wrapped_base_token_address: Option<Address>,

// FIXME: maybe refactor
pub user_facing_bridgehub_proxy_addr: Option<Address>,
pub user_facing_diamond_proxy_addr: Option<Address>,
Expand All @@ -71,6 +77,8 @@ impl ContractsConfig {
l1_multicall3_addr: Address::repeat_byte(0x12),
governance_addr: Address::repeat_byte(0x13),
base_token_addr: Some(Address::repeat_byte(0x14)),
base_token_asset_id: Some(H256::repeat_byte(0x15)),
predeployed_l2_wrapped_base_token_address: Some(Address::repeat_byte(0x1b)),
ecosystem_contracts: Some(EcosystemContracts::for_tests()),
user_facing_bridgehub_proxy_addr: Some(Address::repeat_byte(0x15)),
user_facing_diamond_proxy_addr: Some(Address::repeat_byte(0x16)),
Expand Down
3 changes: 3 additions & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ impl Distribution<configs::ContractsConfig> for EncodeDist {
user_facing_bridgehub_proxy_addr: rng.gen(),
user_facing_diamond_proxy_addr: rng.gen(),
base_token_addr: self.sample_opt(|| rng.gen()),
base_token_asset_id: self.sample_opt(|| rng.gen()),
predeployed_l2_wrapped_base_token_address: self.sample_opt(|| rng.gen()),
chain_admin_addr: self.sample_opt(|| rng.gen()),
settlement_layer: self.sample_opt(|| rng.gen()),
l2_da_validator_addr: self.sample_opt(|| rng.gen()),
Expand Down Expand Up @@ -763,6 +765,7 @@ impl Distribution<configs::EcosystemContracts> for EncodeDist {
bridgehub_proxy_addr: rng.gen(),
state_transition_proxy_addr: rng.gen(),
transparent_proxy_admin_addr: rng.gen(),
l1_bytecodes_supplier_addr: rng.gen(),
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions core/lib/constants/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ pub const L2_MESSAGE_ROOT_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x05,
]);
pub const SLOAD_CONTRACT_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x06,
]);
pub const L2_WRAPPED_BASE_TOKEN_IMPL: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x07,
]);

pub const ERC20_TRANSFER_TOPIC: H256 = H256([
221, 242, 82, 173, 27, 226, 200, 155, 105, 194, 176, 104, 252, 55, 141, 170, 149, 43, 167, 241,
Expand Down
2 changes: 0 additions & 2 deletions core/lib/constants/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ pub const ZKPORTER_IS_AVAILABLE: bool = false;
/// Depth of the account tree.
pub const ROOT_TREE_DEPTH: usize = 256;

pub const MAX_NEW_FACTORY_DEPS: usize = 32;

/// To avoid DDoS we limit the size of the transactions size.
/// TODO(X): remove this as a constant and introduce a config.
pub const MAX_ENCODED_TX_SIZE: usize = 1 << 24;
43 changes: 16 additions & 27 deletions core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const STATE_TRANSITION_CONTRACT_FILE: (&str, &str) = (
"state-transition",
"IChainTypeManager.sol/IChainTypeManager.json",
);
const BYTECODE_SUPPLIER_CONTRACT_FILE: (&str, &str) =
("upgrades", "BytecodesSupplier.sol/BytecodesSupplier.json");
const ZKSYNC_HYPERCHAIN_CONTRACT_FILE: (&str, &str) = (
"state-transition/chain-interfaces",
"IZKChain.sol/IZKChain.json",
Expand Down Expand Up @@ -157,6 +159,10 @@ pub fn state_transition_manager_contract() -> Contract {
load_contract_for_both_compilers(STATE_TRANSITION_CONTRACT_FILE)
}

pub fn bytecode_supplier_contract() -> Contract {
load_contract_for_both_compilers(BYTECODE_SUPPLIER_CONTRACT_FILE)
}

pub fn hyperchain_contract() -> Contract {
load_contract_for_both_compilers(ZKSYNC_HYPERCHAIN_CONTRACT_FILE)
}
Expand Down Expand Up @@ -209,13 +215,11 @@ pub fn l1_messenger_contract() -> Contract {
}

pub fn l2_message_root() -> Contract {
load_contract(
"contracts/l1-contracts/artifacts-zk/contracts/bridgehub/MessageRoot.sol/MessageRoot.json",
)
load_contract("contracts/l1-contracts/zkout/MessageRoot.sol/MessageRoot.json")
}

pub fn l2_rollup_da_validator_bytecode() -> Vec<u8> {
read_bytecode("contracts/l2-contracts/artifacts-zk/contracts/data-availability/RollupL2DAValidator.sol/RollupL2DAValidator.json")
read_bytecode("contracts/l2-contracts/zkout/RollupL2DAValidator.sol/RollupL2DAValidator.json")
}

/// Reads bytecode from the path RELATIVE to the Cargo workspace location.
Expand Down Expand Up @@ -326,21 +330,10 @@ pub fn read_bootloader_code(bootloader_type: &str) -> Vec<u8> {
{
return contract;
};

let artifacts_path =
Path::new(&home_path()).join("contracts/system-contracts/bootloader/build/artifacts");
let bytecode_path = artifacts_path.join(format!("{bootloader_type}.yul.zbin"));
if fs::exists(bytecode_path).unwrap_or_default() {
read_yul_bytecode(
"contracts/system-contracts/bootloader/build/artifacts",
bootloader_type,
)
} else {
read_yul_bytecode(
"contracts/system-contracts/bootloader/tests/artifacts",
bootloader_type,
)
}
read_yul_bytecode(
"contracts/system-contracts/bootloader/build/artifacts",
bootloader_type,
)
}

fn read_proved_batch_bootloader_bytecode() -> Vec<u8> {
Expand Down Expand Up @@ -540,10 +533,8 @@ impl BaseSystemContracts {
}

pub fn playground_gateway() -> Self {
let bootloader_bytecode = read_zbin_bytecode(
"contracts/system-contracts/bootloader/build/artifacts/playground_batch.yul.zbin",
// "etc/multivm_bootloaders/vm_gateway/playground_batch.yul/playground_batch.yul.zbin",
);
// TODO: the value should be taken from the `multivm_bootloaders` folder
let bootloader_bytecode = read_bootloader_code("playground_batch");
StanislavBreadless marked this conversation as resolved.
Show resolved Hide resolved
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

Expand Down Expand Up @@ -618,10 +609,8 @@ impl BaseSystemContracts {
}

pub fn estimate_gas_gateway() -> Self {
let bootloader_bytecode = read_zbin_bytecode(
"contracts/system-contracts/bootloader/build/artifacts/fee_estimate.yul.zbin",
// "etc/multivm_bootloaders/vm_gateway/fee_estimate.yul/fee_estimate.yul.zbin",
);
// TODO: the value should be taken from the `multivm_bootloaders` folder
let bootloader_bytecode = read_bootloader_code("fee_estimate");
StanislavBreadless marked this conversation as resolved.
Show resolved Hide resolved
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

Expand Down
40 changes: 22 additions & 18 deletions core/lib/dal/src/factory_deps_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::collections::{HashMap, HashSet};
use anyhow::Context as _;
use zksync_contracts::{BaseSystemContracts, SystemContractCode};
use zksync_db_connection::{connection::Connection, error::DalResult, instrument::InstrumentExt};
use zksync_types::{L2BlockNumber, H256, U256};
use zksync_utils::{bytes_to_be_words, bytes_to_chunks};
use zksync_types::{L2BlockNumber, ProtocolVersionId, H256, U256};
use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, bytes_to_chunks};

use crate::Core;
use crate::{Core, CoreDal};

/// DAL methods related to factory dependencies.
#[derive(Debug)]
Expand Down Expand Up @@ -90,31 +90,26 @@ impl FactoryDepsDal<'_, '_> {
.map(|row| row.bytecode))
}

pub async fn get_base_system_contracts(
pub async fn get_base_system_contracts_from_factory_deps(
&mut self,
bootloader_hash: H256,
default_aa_hash: H256,
evm_emulator_hash: Option<H256>,
) -> anyhow::Result<BaseSystemContracts> {
) -> anyhow::Result<Option<BaseSystemContracts>> {
let bootloader_bytecode = self
.get_sealed_factory_dep(bootloader_hash)
.await
.context("failed loading bootloader code")?
.with_context(|| format!("bootloader code with hash {bootloader_hash:?} should be present in the database"))?;
let bootloader_code = SystemContractCode {
code: bytes_to_be_words(bootloader_bytecode),
hash: bootloader_hash,
};
.context("failed loading bootloader code")?;

let default_aa_bytecode = self
.get_sealed_factory_dep(default_aa_hash)
.await
.context("failed loading default account code")?
.with_context(|| format!("default account code with hash {default_aa_hash:?} should be present in the database"))?;
.context("failed loading default account code")?;

let default_aa_code = SystemContractCode {
code: bytes_to_be_words(default_aa_bytecode),
hash: default_aa_hash,
let (Some(bootloader_bytecode), Some(default_aa_bytecode)) =
(bootloader_bytecode, default_aa_bytecode)
else {
return Ok(None);
};

let evm_emulator_code = if let Some(evm_emulator_hash) = evm_emulator_hash {
Expand All @@ -132,11 +127,20 @@ impl FactoryDepsDal<'_, '_> {
None
};

Ok(BaseSystemContracts {
let bootloader_code = SystemContractCode {
code: bytes_to_be_words(bootloader_bytecode),
hash: bootloader_hash,
};

let default_aa_code = SystemContractCode {
code: bytes_to_be_words(default_aa_bytecode),
hash: default_aa_hash,
};
Ok(Some(BaseSystemContracts {
bootloader: bootloader_code,
default_aa: default_aa_code,
evm_emulator: evm_emulator_code,
})
}))
}

/// Returns bytecodes for factory deps with the specified `hashes`.
Expand Down
Loading
Loading