Skip to content

Commit

Permalink
wip 2: just change runtime behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Oppen committed Jan 15, 2024
1 parent 573975a commit 0ea1067
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 55 deletions.
12 changes: 3 additions & 9 deletions core/lib/multivm/src/versions/vm_latest/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pub use zk_evm_1_4_0::zkevm_opcode_defs::system_params::{
ERGS_PER_CIRCUIT, INITIAL_STORAGE_WRITE_PUBDATA_BYTES, MAX_PUBDATA_PER_BLOCK,
};
use zksync_system_constants::{
MAX_L2_TX_GAS_LIMIT, MAX_NEW_FACTORY_DEPS, MAX_TXS_IN_BLOCK, USED_BOOTLOADER_MEMORY_WORDS,
L1_GAS_PER_PUBDATA_BYTE, MAX_L2_TX_GAS_LIMIT, MAX_NEW_FACTORY_DEPS, MAX_TXS_IN_BLOCK,
USED_BOOTLOADER_MEMORY_WORDS,
};

use crate::vm_latest::old_vm::utils::heap_page_from_base;
Expand Down Expand Up @@ -86,14 +87,7 @@ const INITIAL_BASE_PAGE: u32 = 8;
pub const BOOTLOADER_HEAP_PAGE: u32 = heap_page_from_base(MemoryPage(INITIAL_BASE_PAGE)).0;
pub const BLOCK_OVERHEAD_GAS: u32 = 1200000;
pub const BLOCK_OVERHEAD_L1_GAS: u32 = 1000000;
pub const L1_GAS_PER_PUBDATA_BYTE: u32 = match core::option_env!("VALIDIUM_MODE") {
Some(_) => 0,
_ => zksync_system_constants::L1_GAS_PER_PUBDATA_BYTE,
};
pub const BLOCK_OVERHEAD_PUBDATA: u32 = match core::option_env!("VALIDIUM_MODE") {
Some(_) => 0,
_ => BLOCK_OVERHEAD_L1_GAS / L1_GAS_PER_PUBDATA_BYTE,
};
pub const BLOCK_OVERHEAD_PUBDATA: u32 = BLOCK_OVERHEAD_L1_GAS / L1_GAS_PER_PUBDATA_BYTE;

/// VM Hooks are used for communication between bootloader and tracers.
/// The 'type' / 'opcode' is put into VM_HOOK_POSITION slot,
Expand Down
8 changes: 4 additions & 4 deletions core/lib/multivm/src/versions/vm_latest/utils/fee.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Utility functions for vm
use zksync_system_constants::MAX_GAS_PER_PUBDATA_BYTE;
use zksync_system_constants::{L1_GAS_PER_PUBDATA_BYTE, MAX_GAS_PER_PUBDATA_BYTE};
use zksync_utils::ceil_div;

use crate::vm_latest::constants::L1_GAS_PER_PUBDATA_BYTE;

pub(crate) fn eth_price_per_pubdata_byte(l1_gas_price: u64) -> u64 {
// This value will typically be a lot less than u64
// unless the gas price on L1 goes beyond tens of millions of gwei
l1_gas_price * (L1_GAS_PER_PUBDATA_BYTE as u64)
// TODO: make this check only once
let validium_mode = std::env::var("ETH_SENDER_SENDER_VALIDIUM_MODE") == Ok("true".to_string());
l1_gas_price * (L1_GAS_PER_PUBDATA_BYTE as u64) * (!validium_mode as u64)
}

/// Calculates the amount of gas required to publish one byte of pubdata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pub use zk_evm_1_3_3::zkevm_opcode_defs::system_params::{
ERGS_PER_CIRCUIT, INITIAL_STORAGE_WRITE_PUBDATA_BYTES, MAX_PUBDATA_PER_BLOCK,
};
use zksync_system_constants::{
MAX_L2_TX_GAS_LIMIT, MAX_NEW_FACTORY_DEPS, MAX_TXS_IN_BLOCK, USED_BOOTLOADER_MEMORY_WORDS,
L1_GAS_PER_PUBDATA_BYTE, MAX_L2_TX_GAS_LIMIT, MAX_NEW_FACTORY_DEPS, MAX_TXS_IN_BLOCK,
USED_BOOTLOADER_MEMORY_WORDS,
};

use crate::vm_refunds_enhancement::old_vm::utils::heap_page_from_base;
Expand Down Expand Up @@ -69,14 +70,7 @@ const INITIAL_BASE_PAGE: u32 = 8;
pub const BOOTLOADER_HEAP_PAGE: u32 = heap_page_from_base(MemoryPage(INITIAL_BASE_PAGE)).0;
pub const BLOCK_OVERHEAD_GAS: u32 = 1200000;
pub const BLOCK_OVERHEAD_L1_GAS: u32 = 1000000;
pub const L1_GAS_PER_PUBDATA_BYTE: u32 = match core::option_env!("VALIDIUM_MODE") {
Some(_) => 0,
_ => zksync_system_constants::L1_GAS_PER_PUBDATA_BYTE,
};
pub const BLOCK_OVERHEAD_PUBDATA: u32 = match core::option_env!("VALIDIUM_MODE") {
Some(_) => 0,
_ => BLOCK_OVERHEAD_L1_GAS / L1_GAS_PER_PUBDATA_BYTE,
};
pub const BLOCK_OVERHEAD_PUBDATA: u32 = BLOCK_OVERHEAD_L1_GAS / L1_GAS_PER_PUBDATA_BYTE;
/// VM Hooks are used for communication between bootloader and tracers.
/// The 'type' / 'opcode' is put into VM_HOOK_POSITION slot,
/// and VM_HOOKS_PARAMS_COUNT parameters (each 32 bytes) are put in the slots before.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use zk_evm_1_3_3::{
},
};
use zksync_state::WriteStorage;
use zksync_system_constants::L1_GAS_PER_PUBDATA_BYTE;
use zksync_types::{Address, U256};

use crate::vm_refunds_enhancement::{
Expand Down Expand Up @@ -96,12 +95,6 @@ pub(crate) fn precompile_calls_count_after_timestamp(
sorted_timestamps.len() - sorted_timestamps.partition_point(|t| *t < from_timestamp)
}

pub(crate) fn eth_price_per_pubdata_byte(l1_gas_price: u64) -> u64 {
// This value will typically be a lot less than u64
// unless the gas price on L1 goes beyond tens of millions of gwei
l1_gas_price * (L1_GAS_PER_PUBDATA_BYTE as u64)
}

pub(crate) fn vm_may_have_ended_inner<S: WriteStorage, H: HistoryMode>(
vm: &ZkSyncVmState<S, H>,
) -> Option<VmExecutionResult> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ use crate::{
vm_refunds_enhancement::{
bootloader_state::BootloaderState,
constants::{BOOTLOADER_HEAP_PAGE, OPERATOR_REFUNDS_OFFSET, TX_GAS_LIMIT_OFFSET},
old_vm::{
events::merge_events, history_recorder::HistoryMode, memory::SimpleMemory,
utils::eth_price_per_pubdata_byte,
},
old_vm::{events::merge_events, history_recorder::HistoryMode, memory::SimpleMemory},
tracers::{
traits::VmTracer,
utils::{
gas_spent_on_bytecodes_and_long_messages_this_opcode, get_vm_hook_params, VmHook,
},
},
types::internals::ZkSyncVmState,
utils::fee::eth_price_per_pubdata_byte,
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
//! Utility functions for vm
use zksync_system_constants::MAX_GAS_PER_PUBDATA_BYTE;
use zksync_system_constants::{L1_GAS_PER_PUBDATA_BYTE, MAX_GAS_PER_PUBDATA_BYTE};
use zksync_utils::ceil_div;

use crate::vm_refunds_enhancement::old_vm::utils::eth_price_per_pubdata_byte;
pub(crate) fn eth_price_per_pubdata_byte(l1_gas_price: u64) -> u64 {
// This value will typically be a lot less than u64
// unless the gas price on L1 goes beyond tens of millions of gwei
// TODO: make this check only once
let validium_mode = std::env::var("ETH_SENDER_SENDER_VALIDIUM_MODE") == Ok("true".to_string());
l1_gas_price * (L1_GAS_PER_PUBDATA_BYTE as u64) * (!validium_mode as u64)
}

/// Calculates the amount of gas required to publish one byte of pubdata
pub fn base_fee_to_gas_per_pubdata(l1_gas_price: u64, base_fee: u64) -> u64 {
Expand Down
12 changes: 3 additions & 9 deletions core/lib/multivm/src/versions/vm_virtual_blocks/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pub use zk_evm_1_3_3::zkevm_opcode_defs::system_params::{
ERGS_PER_CIRCUIT, INITIAL_STORAGE_WRITE_PUBDATA_BYTES, MAX_PUBDATA_PER_BLOCK,
};
use zksync_system_constants::{
MAX_L2_TX_GAS_LIMIT, MAX_NEW_FACTORY_DEPS, MAX_TXS_IN_BLOCK, USED_BOOTLOADER_MEMORY_WORDS,
L1_GAS_PER_PUBDATA_BYTE, MAX_L2_TX_GAS_LIMIT, MAX_NEW_FACTORY_DEPS, MAX_TXS_IN_BLOCK,
USED_BOOTLOADER_MEMORY_WORDS,
};

use crate::vm_virtual_blocks::old_vm::utils::heap_page_from_base;
Expand Down Expand Up @@ -69,14 +70,7 @@ const INITIAL_BASE_PAGE: u32 = 8;
pub const BOOTLOADER_HEAP_PAGE: u32 = heap_page_from_base(MemoryPage(INITIAL_BASE_PAGE)).0;
pub(crate) const BLOCK_OVERHEAD_GAS: u32 = 1200000;
pub(crate) const BLOCK_OVERHEAD_L1_GAS: u32 = 1000000;
pub const L1_GAS_PER_PUBDATA_BYTE: u32 = match core::option_env!("VALIDIUM_MODE") {
Some(_) => 0,
_ => zksync_system_constants::L1_GAS_PER_PUBDATA_BYTE,
};
pub const BLOCK_OVERHEAD_PUBDATA: u32 = match core::option_env!("VALIDIUM_MODE") {
Some(_) => 0,
_ => BLOCK_OVERHEAD_L1_GAS / L1_GAS_PER_PUBDATA_BYTE,
};
pub const BLOCK_OVERHEAD_PUBDATA: u32 = BLOCK_OVERHEAD_L1_GAS / L1_GAS_PER_PUBDATA_BYTE;
/// VM Hooks are used for communication between bootloader and tracers.
/// The 'type' / 'opcode' is put into VM_HOOK_POSITION slot,
/// and VM_HOOKS_PARAMS_COUNT parameters (each 32 bytes) are put in the slots before.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use zk_evm_1_3_3::{
},
};
use zksync_state::WriteStorage;
use zksync_system_constants::L1_GAS_PER_PUBDATA_BYTE;
use zksync_types::{Address, U256};

use crate::vm_virtual_blocks::{
Expand Down Expand Up @@ -96,12 +95,6 @@ pub(crate) fn precompile_calls_count_after_timestamp(
sorted_timestamps.len() - sorted_timestamps.partition_point(|t| *t < from_timestamp)
}

pub(crate) fn eth_price_per_pubdata_byte(l1_gas_price: u64) -> u64 {
// This value will typically be a lot less than u64
// unless the gas price on L1 goes beyond tens of millions of gwei
l1_gas_price * (L1_GAS_PER_PUBDATA_BYTE as u64)
}

pub(crate) fn vm_may_have_ended_inner<S: WriteStorage, H: HistoryMode>(
vm: &ZkSyncVmState<S, H>,
) -> Option<VmExecutionResult> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
constants::{BOOTLOADER_HEAP_PAGE, OPERATOR_REFUNDS_OFFSET, TX_GAS_LIMIT_OFFSET},
old_vm::{
events::merge_events, history_recorder::HistoryMode, memory::SimpleMemory,
oracles::storage::storage_key_of_log, utils::eth_price_per_pubdata_byte,
oracles::storage::storage_key_of_log,
},
tracers::{
traits::{ExecutionEndTracer, ExecutionProcessing, VmTracer},
Expand All @@ -32,6 +32,7 @@ use crate::{
},
},
types::internals::ZkSyncVmState,
utils::fee::eth_price_per_pubdata_byte,
},
};

Expand Down
10 changes: 8 additions & 2 deletions core/lib/multivm/src/versions/vm_virtual_blocks/utils/fee.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
//! Utility functions for vm
use zksync_system_constants::MAX_GAS_PER_PUBDATA_BYTE;
use zksync_system_constants::{L1_GAS_PER_PUBDATA_BYTE, MAX_GAS_PER_PUBDATA_BYTE};
use zksync_utils::ceil_div;

use crate::vm_virtual_blocks::old_vm::utils::eth_price_per_pubdata_byte;
pub(crate) fn eth_price_per_pubdata_byte(l1_gas_price: u64) -> u64 {
// This value will typically be a lot less than u64
// unless the gas price on L1 goes beyond tens of millions of gwei
// TODO: make this check only once
let validium_mode = std::env::var("ETH_SENDER_SENDER_VALIDIUM_MODE") == Ok("true".to_string());
l1_gas_price * (L1_GAS_PER_PUBDATA_BYTE as u64) * (!validium_mode as u64)
}

/// Calculates the amount of gas required to publish one byte of pubdata
pub fn base_fee_to_gas_per_pubdata(l1_gas_price: u64, base_fee: u64) -> u64 {
Expand Down
1 change: 0 additions & 1 deletion infrastructure/zk/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export async function init(initArgs: InitArgs = DEFAULT_ARGS) {
if (validiumMode) {
await announced('Setting up validium mode to true');
process.env.ETH_SENDER_SENDER_VALIDIUM_MODE = 'true';
process.env.VALIDIUM_MODE = 'true';
} else {
await announced('Setting up validium mode to false');
process.env.ETH_SENDER_SENDER_VALIDIUM_MODE = 'false';
Expand Down

0 comments on commit 0ea1067

Please sign in to comment.