Skip to content

Commit

Permalink
refactor(vm): removes redundant hashmaps introduced in #251 (#254)
Browse files Browse the repository at this point in the history
A followup to #251
  • Loading branch information
montekki authored Oct 18, 2023
1 parent 885ced6 commit 7705c6f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
20 changes: 8 additions & 12 deletions core/lib/multivm/src/versions/vm_latest/types/l1_batch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::interface::L1BatchEnv;
use std::collections::HashMap;
use zksync_types::U256;
use zksync_utils::{address_to_u256, h256_to_u256};

Expand All @@ -14,12 +13,17 @@ const SHOULD_SET_NEW_BLOCK_SLOT: usize = 7;

/// Returns the initial memory for the bootloader based on the current batch environment.
pub(crate) fn bootloader_initial_memory(l1_batch: &L1BatchEnv) -> Vec<(usize, U256)> {
let mut base_params: HashMap<usize, U256> = vec![
let (prev_block_hash, should_set_new_block) = l1_batch
.previous_batch_hash
.map(|prev_block_hash| (h256_to_u256(prev_block_hash), U256::one()))
.unwrap_or_default();

vec![
(
OPERATOR_ADDRESS_SLOT,
address_to_u256(&l1_batch.fee_account),
),
(PREV_BLOCK_HASH_SLOT, Default::default()),
(PREV_BLOCK_HASH_SLOT, prev_block_hash),
(NEW_BLOCK_TIMESTAMP_SLOT, U256::from(l1_batch.timestamp)),
(NEW_BLOCK_NUMBER_SLOT, U256::from(l1_batch.number.0)),
(L1_GAS_PRICE_SLOT, U256::from(l1_batch.l1_gas_price)),
Expand All @@ -28,14 +32,6 @@ pub(crate) fn bootloader_initial_memory(l1_batch: &L1BatchEnv) -> Vec<(usize, U2
U256::from(l1_batch.fair_l2_gas_price),
),
(EXPECTED_BASE_FEE_SLOT, U256::from(l1_batch.base_fee())),
(SHOULD_SET_NEW_BLOCK_SLOT, U256::from(0u32)),
(SHOULD_SET_NEW_BLOCK_SLOT, should_set_new_block),
]
.into_iter()
.collect();

if let Some(prev_block_hash) = l1_batch.previous_batch_hash {
base_params.insert(PREV_BLOCK_HASH_SLOT, h256_to_u256(prev_block_hash));
base_params.insert(SHOULD_SET_NEW_BLOCK_SLOT, U256::from(1u32));
}
base_params.into_iter().collect()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::interface::L1BatchEnv;
use std::collections::HashMap;
use zksync_types::U256;
use zksync_utils::{address_to_u256, h256_to_u256};

Expand All @@ -14,12 +13,17 @@ const SHOULD_SET_NEW_BLOCK_SLOT: usize = 7;

/// Returns the initial memory for the bootloader based on the current batch environment.
pub(crate) fn bootloader_initial_memory(l1_batch_env: &L1BatchEnv) -> Vec<(usize, U256)> {
let mut base_params: HashMap<usize, U256> = vec![
let (prev_block_hash, should_set_new_block) = l1_batch_env
.previous_batch_hash
.map(|prev_block_hash| (h256_to_u256(prev_block_hash), U256::one()))
.unwrap_or_default();

vec![
(
OPERATOR_ADDRESS_SLOT,
address_to_u256(&l1_batch_env.fee_account),
),
(PREV_BLOCK_HASH_SLOT, Default::default()),
(PREV_BLOCK_HASH_SLOT, prev_block_hash),
(NEW_BLOCK_TIMESTAMP_SLOT, U256::from(l1_batch_env.timestamp)),
(NEW_BLOCK_NUMBER_SLOT, U256::from(l1_batch_env.number.0)),
(L1_GAS_PRICE_SLOT, U256::from(l1_batch_env.l1_gas_price)),
Expand All @@ -28,14 +32,6 @@ pub(crate) fn bootloader_initial_memory(l1_batch_env: &L1BatchEnv) -> Vec<(usize
U256::from(l1_batch_env.fair_l2_gas_price),
),
(EXPECTED_BASE_FEE_SLOT, U256::from(l1_batch_env.base_fee())),
(SHOULD_SET_NEW_BLOCK_SLOT, U256::from(0u32)),
(SHOULD_SET_NEW_BLOCK_SLOT, should_set_new_block),
]
.into_iter()
.collect();

if let Some(prev_block_hash) = l1_batch_env.previous_batch_hash {
base_params.insert(PREV_BLOCK_HASH_SLOT, h256_to_u256(prev_block_hash));
base_params.insert(SHOULD_SET_NEW_BLOCK_SLOT, U256::from(1u32));
}
base_params.into_iter().collect()
}

0 comments on commit 7705c6f

Please sign in to comment.