Skip to content

Commit a80f55a

Browse files
authored
feat: vm changes from draft-v29 (#4221)
## What ❔ Extracted vm related changes from [draft-v29 #3960](#3960) <!-- What are the changes this PR brings about? --> <!-- Example: This PR adds a PR template to the repo. --> <!-- (For bigger PRs adding more context is appreciated) --> ## Why ❔ Preparation for v29 ## Is this a breaking change? - [ ] Yes - [x] No ## Operational changes None ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`.
1 parent b63282c commit a80f55a

File tree

59 files changed

+541
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+541
-134
lines changed

core/bin/system-constants-generator/src/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ fn default_l1_batch() -> L1BatchEnv {
190190
timestamp: 100,
191191
prev_block_hash: L2BlockHasher::legacy_hash(L2BlockNumber(0)),
192192
max_virtual_blocks_to_create: 100,
193+
interop_roots: vec![],
193194
},
194195
}
195196
}

core/lib/basic_types/src/protocol_version.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub enum ProtocolVersionId {
7373
Version27,
7474
Version28,
7575
Version29,
76+
Version30,
7677
}
7778

7879
impl ProtocolVersionId {
@@ -128,8 +129,10 @@ impl ProtocolVersionId {
128129
ProtocolVersionId::Version26 => VmVersion::VmGateway,
129130
ProtocolVersionId::Version27 => VmVersion::VmEvmEmulator,
130131
ProtocolVersionId::Version28 => VmVersion::VmEcPrecompiles,
132+
ProtocolVersionId::Version29 => VmVersion::VmEcPrecompiles, // TODO: Switch to `VmInterop` after contracts are finalized
133+
131134
// Speculative VM version for the next protocol version to be used in the upgrade integration test etc.
132-
ProtocolVersionId::Version29 => VmVersion::VmEcPrecompiles,
135+
ProtocolVersionId::Version30 => VmVersion::VmInterop,
133136
}
134137
}
135138

@@ -163,6 +166,10 @@ impl ProtocolVersionId {
163166
self >= &Self::Version27
164167
}
165168

169+
pub fn is_pre_interop(&self) -> bool {
170+
self < &Self::Version30
171+
}
172+
166173
pub fn is_1_4_0(&self) -> bool {
167174
self >= &ProtocolVersionId::Version18 && self < &ProtocolVersionId::Version20
168175
}
@@ -314,8 +321,9 @@ impl From<ProtocolVersionId> for VmVersion {
314321
ProtocolVersionId::Version26 => VmVersion::VmGateway,
315322
ProtocolVersionId::Version27 => VmVersion::VmEvmEmulator,
316323
ProtocolVersionId::Version28 => VmVersion::VmEcPrecompiles,
324+
ProtocolVersionId::Version29 => VmVersion::VmEcPrecompiles, // TODO: Switch to `VmInterop` after contracts are finalized
317325
// Speculative VM version for the next protocol version to be used in the upgrade integration test etc.
318-
ProtocolVersionId::Version29 => VmVersion::VmEcPrecompiles,
326+
ProtocolVersionId::Version30 => VmVersion::VmInterop,
319327
}
320328
}
321329
}

core/lib/basic_types/src/vm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub enum VmVersion {
1919
VmGateway,
2020
VmEvmEmulator,
2121
VmEcPrecompiles,
22+
VmInterop,
2223
}
2324

2425
impl VmVersion {

core/lib/constants/src/contracts.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,21 @@ pub const L2_WRAPPED_BASE_TOKEN_IMPL: Address = H160([
191191
0x00, 0x01, 0x00, 0x07,
192192
]);
193193

194+
pub const L2_INTEROP_ROOT_STORAGE_ADDRESS: Address = H160([
195+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
196+
0x00, 0x01, 0x00, 0x08,
197+
]);
198+
199+
pub const L2_MESSAGE_VERIFICATION_ADDRESS: Address = H160([
200+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
201+
0x00, 0x01, 0x00, 0x09,
202+
]);
203+
204+
pub const L2_CHAIN_ASSET_HANDLER_ADDRESS: Address = H160([
205+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
206+
0x00, 0x01, 0x00, 0x0a,
207+
]);
208+
194209
pub const ERC20_TRANSFER_TOPIC: H256 = H256([
195210
221, 242, 82, 173, 27, 226, 200, 155, 105, 194, 176, 104, 252, 55, 141, 170, 149, 43, 167, 241,
196211
99, 196, 161, 22, 40, 245, 90, 77, 245, 35, 179, 239,

core/lib/dal/src/transactions_dal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,6 +2232,7 @@ impl TransactionsDal<'_, '_> {
22322232
prev_block_hash,
22332233
virtual_blocks: l2_block_row.virtual_blocks as u32,
22342234
txs,
2235+
interop_roots: vec![],
22352236
});
22362237
}
22372238
Ok(data)

core/lib/multivm/src/utils/bytecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) fn be_words_to_bytes(words: &[U256]) -> Vec<u8> {
2323
.collect()
2424
}
2525

26-
pub(crate) fn bytes_to_be_words(bytes: &[u8]) -> Vec<U256> {
26+
pub fn bytes_to_be_words(bytes: &[u8]) -> Vec<U256> {
2727
assert_eq!(
2828
bytes.len() % 32,
2929
0,

core/lib/multivm/src/utils/mod.rs

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
interface::L1BatchEnv,
1111
};
1212

13-
pub(crate) mod bytecode;
13+
pub mod bytecode;
1414
mod deduplicator;
1515
pub(crate) mod events;
1616

@@ -73,7 +73,8 @@ pub fn derive_base_fee_and_gas_per_pubdata(
7373
| VmVersion::Vm1_5_0IncreasedBootloaderMemory
7474
| VmVersion::VmGateway
7575
| VmVersion::VmEvmEmulator
76-
| VmVersion::VmEcPrecompiles => {
76+
| VmVersion::VmEcPrecompiles
77+
| VmVersion::VmInterop => {
7778
crate::vm_latest::utils::fee::derive_base_fee_and_gas_per_pubdata(
7879
batch_fee_input.into_pubdata_independent(),
7980
)
@@ -105,9 +106,8 @@ pub fn get_batch_base_fee(l1_batch_env: &L1BatchEnv, vm_version: VmVersion) -> u
105106
| VmVersion::Vm1_5_0IncreasedBootloaderMemory
106107
| VmVersion::VmGateway
107108
| VmVersion::VmEvmEmulator
108-
| VmVersion::VmEcPrecompiles => {
109-
crate::vm_latest::utils::fee::get_batch_base_fee(l1_batch_env)
110-
}
109+
| VmVersion::VmEcPrecompiles
110+
| VmVersion::VmInterop => crate::vm_latest::utils::fee::get_batch_base_fee(l1_batch_env),
111111
}
112112
}
113113

@@ -241,9 +241,8 @@ pub fn derive_overhead(
241241
| VmVersion::Vm1_5_0IncreasedBootloaderMemory
242242
| VmVersion::VmGateway
243243
| VmVersion::VmEvmEmulator
244-
| VmVersion::VmEcPrecompiles => {
245-
crate::vm_latest::utils::overhead::derive_overhead(encoded_len)
246-
}
244+
| VmVersion::VmEcPrecompiles
245+
| VmVersion::VmInterop => crate::vm_latest::utils::overhead::derive_overhead(encoded_len),
247246
}
248247
}
249248

@@ -288,6 +287,9 @@ pub fn get_bootloader_encoding_space(version: VmVersion) -> u32 {
288287
crate::vm_latest::MultiVmSubversion::EcPrecompiles,
289288
)
290289
}
290+
VmVersion::VmInterop => crate::vm_latest::constants::get_bootloader_tx_encoding_space(
291+
crate::vm_latest::MultiVmSubversion::Interop,
292+
),
291293
}
292294
}
293295

@@ -311,7 +313,29 @@ pub fn get_bootloader_max_txs_in_batch(version: VmVersion) -> usize {
311313
| VmVersion::Vm1_5_0IncreasedBootloaderMemory
312314
| VmVersion::VmGateway
313315
| VmVersion::VmEvmEmulator
314-
| VmVersion::VmEcPrecompiles => crate::vm_latest::constants::MAX_TXS_IN_BATCH,
316+
| VmVersion::VmEcPrecompiles
317+
| VmVersion::VmInterop => crate::vm_latest::constants::MAX_TXS_IN_BATCH,
318+
}
319+
}
320+
321+
pub fn get_bootloader_max_msg_roots_in_batch(version: VmVersion) -> usize {
322+
match version {
323+
VmVersion::M5WithRefunds
324+
| VmVersion::M5WithoutRefunds
325+
| VmVersion::M6Initial
326+
| VmVersion::M6BugWithCompressionFixed
327+
| VmVersion::Vm1_3_2
328+
| VmVersion::VmVirtualBlocks
329+
| VmVersion::VmVirtualBlocksRefundsEnhancement
330+
| VmVersion::VmBoojumIntegration
331+
| VmVersion::Vm1_4_1
332+
| VmVersion::Vm1_4_2
333+
| VmVersion::Vm1_5_0SmallBootloaderMemory
334+
| VmVersion::Vm1_5_0IncreasedBootloaderMemory
335+
| VmVersion::VmGateway
336+
| VmVersion::VmEvmEmulator
337+
| VmVersion::VmEcPrecompiles => 0,
338+
VmVersion::VmInterop => crate::vm_latest::constants::MAX_MSG_ROOTS_IN_BATCH,
315339
}
316340
}
317341

@@ -336,7 +360,8 @@ pub fn gas_bootloader_batch_tip_overhead(version: VmVersion) -> u32 {
336360
| VmVersion::Vm1_5_0IncreasedBootloaderMemory
337361
| VmVersion::VmGateway
338362
| VmVersion::VmEvmEmulator
339-
| VmVersion::VmEcPrecompiles => crate::vm_latest::constants::BOOTLOADER_BATCH_TIP_OVERHEAD,
363+
| VmVersion::VmEcPrecompiles
364+
| VmVersion::VmInterop => crate::vm_latest::constants::BOOTLOADER_BATCH_TIP_OVERHEAD,
340365
}
341366
}
342367

@@ -361,7 +386,8 @@ pub fn circuit_statistics_bootloader_batch_tip_overhead(version: VmVersion) -> u
361386
| VmVersion::Vm1_5_0IncreasedBootloaderMemory
362387
| VmVersion::VmGateway
363388
| VmVersion::VmEvmEmulator
364-
| VmVersion::VmEcPrecompiles => {
389+
| VmVersion::VmEcPrecompiles
390+
| VmVersion::VmInterop => {
365391
crate::vm_latest::constants::BOOTLOADER_BATCH_TIP_CIRCUIT_STATISTICS_OVERHEAD as usize
366392
}
367393
}
@@ -388,7 +414,8 @@ pub fn execution_metrics_bootloader_batch_tip_overhead(version: VmVersion) -> us
388414
| VmVersion::Vm1_5_0IncreasedBootloaderMemory
389415
| VmVersion::VmGateway
390416
| VmVersion::VmEvmEmulator
391-
| VmVersion::VmEcPrecompiles => {
417+
| VmVersion::VmEcPrecompiles
418+
| VmVersion::VmInterop => {
392419
crate::vm_latest::constants::BOOTLOADER_BATCH_TIP_METRICS_SIZE_OVERHEAD as usize
393420
}
394421
}
@@ -416,7 +443,8 @@ pub fn get_max_gas_per_pubdata_byte(version: VmVersion) -> u64 {
416443
| VmVersion::Vm1_5_0IncreasedBootloaderMemory
417444
| VmVersion::VmGateway
418445
| VmVersion::VmEvmEmulator
419-
| VmVersion::VmEcPrecompiles => crate::vm_latest::constants::MAX_GAS_PER_PUBDATA_BYTE,
446+
| VmVersion::VmEcPrecompiles
447+
| VmVersion::VmInterop => crate::vm_latest::constants::MAX_GAS_PER_PUBDATA_BYTE,
420448
}
421449
}
422450

@@ -461,6 +489,9 @@ pub fn get_used_bootloader_memory_bytes(version: VmVersion) -> usize {
461489
crate::vm_latest::MultiVmSubversion::EcPrecompiles,
462490
)
463491
}
492+
VmVersion::VmInterop => crate::vm_latest::constants::get_used_bootloader_memory_bytes(
493+
crate::vm_latest::MultiVmSubversion::Interop,
494+
),
464495
}
465496
}
466497

@@ -505,6 +536,9 @@ pub fn get_used_bootloader_memory_words(version: VmVersion) -> usize {
505536
crate::vm_latest::MultiVmSubversion::EcPrecompiles,
506537
)
507538
}
539+
VmVersion::VmInterop => crate::vm_latest::constants::get_used_bootloader_memory_words(
540+
crate::vm_latest::MultiVmSubversion::Interop,
541+
),
508542
}
509543
}
510544

@@ -530,7 +564,8 @@ pub fn get_max_batch_gas_limit(version: VmVersion) -> u64 {
530564
| VmVersion::Vm1_5_0IncreasedBootloaderMemory
531565
| VmVersion::VmGateway
532566
| VmVersion::VmEvmEmulator
533-
| VmVersion::VmEcPrecompiles => crate::vm_latest::constants::BATCH_GAS_LIMIT,
567+
| VmVersion::VmEcPrecompiles
568+
| VmVersion::VmInterop => crate::vm_latest::constants::BATCH_GAS_LIMIT,
534569
}
535570
}
536571

@@ -558,7 +593,8 @@ pub fn get_eth_call_gas_limit(version: VmVersion) -> u64 {
558593
| VmVersion::Vm1_5_0IncreasedBootloaderMemory
559594
| VmVersion::VmGateway
560595
| VmVersion::VmEvmEmulator
561-
| VmVersion::VmEcPrecompiles => crate::vm_latest::constants::ETH_CALL_GAS_LIMIT,
596+
| VmVersion::VmEcPrecompiles
597+
| VmVersion::VmInterop => crate::vm_latest::constants::ETH_CALL_GAS_LIMIT,
562598
}
563599
}
564600

@@ -583,7 +619,8 @@ pub fn get_max_batch_base_layer_circuits(version: VmVersion) -> usize {
583619
| VmVersion::Vm1_5_0IncreasedBootloaderMemory
584620
| VmVersion::VmGateway
585621
| VmVersion::VmEvmEmulator
586-
| VmVersion::VmEcPrecompiles => crate::vm_latest::constants::MAX_BASE_LAYER_CIRCUITS,
622+
| VmVersion::VmEcPrecompiles
623+
| VmVersion::VmInterop => crate::vm_latest::constants::MAX_BASE_LAYER_CIRCUITS,
587624
}
588625
}
589626

@@ -609,7 +646,8 @@ pub fn get_max_new_factory_deps(version: VmVersion) -> usize {
609646
| VmVersion::Vm1_5_0IncreasedBootloaderMemory
610647
| VmVersion::VmGateway
611648
| VmVersion::VmEvmEmulator
612-
| VmVersion::VmEcPrecompiles) => {
649+
| VmVersion::VmEcPrecompiles
650+
| VmVersion::VmInterop) => {
613651
crate::vm_latest::constants::get_max_new_factory_deps(version.try_into().unwrap())
614652
}
615653
}

core/lib/multivm/src/versions/shadow/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type ReferenceVm<S = InMemoryStorage> = vm_latest::Vm<StorageView<S>, HistoryEna
3030
type ShadowedFastVm<S = InMemoryStorage, Tr = ()> =
3131
crate::vm_instance::ShadowedFastVm<S, Tr, FastValidationTracer>;
3232

33-
fn hash_block(block_env: L2BlockEnv, tx_hashes: &[H256]) -> H256 {
33+
fn hash_block(block_env: &L2BlockEnv, tx_hashes: &[H256]) -> H256 {
3434
let mut hasher = L2BlockHasher::new(
3535
L2BlockNumber(block_env.number),
3636
block_env.timestamp,
@@ -74,7 +74,7 @@ impl Harness {
7474
Self::STORAGE_CONTRACT_ADDRESS,
7575
),
7676
storage_contract_abi: &TestContract::storage_test().abi,
77-
current_block: l1_batch_env.first_l2_block,
77+
current_block: l1_batch_env.first_l2_block.clone(),
7878
}
7979
}
8080

@@ -114,10 +114,11 @@ impl Harness {
114114
self.current_block = L2BlockEnv {
115115
number: self.current_block.number + 1,
116116
timestamp: self.current_block.timestamp + 1,
117-
prev_block_hash: hash_block(self.current_block, tx_hashes),
117+
prev_block_hash: hash_block(&self.current_block, tx_hashes),
118118
max_virtual_blocks_to_create: self.current_block.max_virtual_blocks_to_create,
119+
interop_roots: vec![],
119120
};
120-
vm.start_new_l2_block(self.current_block);
121+
vm.start_new_l2_block(self.current_block.clone());
121122
}
122123

123124
fn execute_on_vm(&mut self, vm: &mut impl VmInterface) {

core/lib/multivm/src/versions/shadow/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ where
125125

126126
fn push_l2_block_unchecked(&mut self, block: L2BlockEnv) {
127127
self.get_mut("push_l2_block_unchecked", |r| match r {
128-
ShadowMut::Main(vm) => vm.push_l2_block_unchecked(block),
129-
ShadowMut::Shadow(vm) => vm.push_l2_block_unchecked(block),
128+
ShadowMut::Main(vm) => vm.push_l2_block_unchecked(block.clone()),
129+
ShadowMut::Shadow(vm) => vm.push_l2_block_unchecked(block.clone()),
130130
});
131131
}
132132

core/lib/multivm/src/versions/testonly/evm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,9 @@ pub(crate) fn test_real_emulator_block_info<VM: TestedVm>() {
254254
timestamp: first_block.timestamp + 5,
255255
prev_block_hash: block_hasher.finalize(ProtocolVersionId::latest()),
256256
max_virtual_blocks_to_create: 1,
257+
interop_roots: vec![],
257258
};
258-
vm.vm.start_new_l2_block(second_block);
259+
vm.vm.start_new_l2_block(second_block.clone());
259260

260261
let tx = account.get_l2_tx_for_execute(create_test_block_execute(evm_abi, &second_block), None);
261262
let (_, vm_result) = vm

0 commit comments

Comments
 (0)