diff --git a/crates/blockifier/resources/versioned_constants.json b/crates/blockifier/resources/versioned_constants.json index 1228b825ed..135a148773 100644 --- a/crates/blockifier/resources/versioned_constants.json +++ b/crates/blockifier/resources/versioned_constants.json @@ -449,7 +449,9 @@ } } }, + "validate_block_number_rounding": 100, "validate_max_n_steps": 1000000, + "validate_timestamp_rounding": 3600, "vm_resource_fee_cost": { "bitwise_builtin": 0.16, "ec_op_builtin": 2.56, diff --git a/crates/blockifier/src/execution/deprecated_syscalls/mod.rs b/crates/blockifier/src/execution/deprecated_syscalls/mod.rs index 35645593f0..4304f45601 100644 --- a/crates/blockifier/src/execution/deprecated_syscalls/mod.rs +++ b/crates/blockifier/src/execution/deprecated_syscalls/mod.rs @@ -26,9 +26,6 @@ use crate::execution::execution_utils::{ execute_deployment, stark_felt_from_ptr, write_maybe_relocatable, write_stark_felt, ReadOnlySegment, }; -use crate::execution::syscalls::hint_processor::{ - VALIDATE_BLOCK_NUMBER_ROUNDING, VALIDATE_TIMESTAMP_ROUNDING, -}; #[cfg(test)] #[path = "deprecated_syscalls_test.rs"] @@ -407,10 +404,12 @@ pub fn get_block_number( _vm: &mut VirtualMachine, syscall_handler: &mut DeprecatedSyscallHintProcessor<'_>, ) -> DeprecatedSyscallResult { + let versioned_constants = syscall_handler.context.versioned_constants(); let block_number = syscall_handler.get_block_info().block_number; let block_number = match syscall_handler.execution_mode() { ExecutionMode::Validate => BlockNumber( - (block_number.0 / VALIDATE_BLOCK_NUMBER_ROUNDING) * VALIDATE_BLOCK_NUMBER_ROUNDING, + (block_number.0 / versioned_constants.validate_block_number_rounding) + * versioned_constants.validate_block_number_rounding, ), ExecutionMode::Execute => block_number, }; @@ -438,10 +437,12 @@ pub fn get_block_timestamp( _vm: &mut VirtualMachine, syscall_handler: &mut DeprecatedSyscallHintProcessor<'_>, ) -> DeprecatedSyscallResult { + let versioned_constants = syscall_handler.context.versioned_constants(); let block_timestamp = syscall_handler.get_block_info().block_timestamp; let block_timestamp = match syscall_handler.execution_mode() { ExecutionMode::Validate => BlockTimestamp( - (block_timestamp.0 / VALIDATE_TIMESTAMP_ROUNDING) * VALIDATE_TIMESTAMP_ROUNDING, + (block_timestamp.0 / versioned_constants.validate_timestamp_rounding) + * versioned_constants.validate_timestamp_rounding, ), ExecutionMode::Execute => block_timestamp, }; diff --git a/crates/blockifier/src/execution/syscalls/hint_processor.rs b/crates/blockifier/src/execution/syscalls/hint_processor.rs index 910cb4ba3c..8af903d3d1 100644 --- a/crates/blockifier/src/execution/syscalls/hint_processor.rs +++ b/crates/blockifier/src/execution/syscalls/hint_processor.rs @@ -160,12 +160,6 @@ pub const L1_GAS: &str = "0x0000000000000000000000000000000000000000000000000000 // "L2_GAS"; pub const L2_GAS: &str = "0x00000000000000000000000000000000000000000000000000004c325f474153"; -// TODO(Tzahi, 1/4/2024): Move to an appropriate constants file. -// Flooring factor for block number in validate mode. -pub const VALIDATE_BLOCK_NUMBER_ROUNDING: u64 = 100; -// Flooring factor for timestamp in validate mode. -pub const VALIDATE_TIMESTAMP_ROUNDING: u64 = 3600; - /// Executes Starknet syscalls (stateful protocol hints) during the execution of an entry point /// call. pub struct SyscallHintProcessor<'a> { @@ -507,13 +501,16 @@ impl<'a> SyscallHintProcessor<'a> { let block_info = &self.context.tx_context.block_context.block_info; let block_timestamp = block_info.block_timestamp.0; let block_number = block_info.block_number.0; + let versioned_constants = self.context.versioned_constants(); let block_data: Vec = if self.is_validate_mode() { - // Round down to the nearest multiple of VALIDATE_BLOCK_NUMBER_ROUNDING. - let rounded_block_number = - (block_number / VALIDATE_BLOCK_NUMBER_ROUNDING) * VALIDATE_BLOCK_NUMBER_ROUNDING; - // Round down to the nearest multiple of VALIDATE_TIMESTAMP_ROUNDING. - let rounded_timestamp = - (block_timestamp / VALIDATE_TIMESTAMP_ROUNDING) * VALIDATE_TIMESTAMP_ROUNDING; + // Round down to the nearest multiple of validate_block_number_rounding. + let rounded_block_number = (block_number + / versioned_constants.validate_block_number_rounding) + * versioned_constants.validate_block_number_rounding; + // Round down to the nearest multiple of validate_timestamp_rounding. + let rounded_timestamp = (block_timestamp + / versioned_constants.validate_timestamp_rounding) + * versioned_constants.validate_timestamp_rounding; vec![ StarkFelt::from(rounded_block_number), diff --git a/crates/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index 1b64d9f6cd..008c8f5931 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -39,7 +39,11 @@ pub struct VersionedConstants { pub invoke_tx_max_n_steps: u32, pub l2_resource_gas_costs: L2ResourceGasCosts, pub max_recursion_depth: usize, + // Flooring factor for block number in validate mode. + pub validate_block_number_rounding: u64, pub validate_max_n_steps: u32, + // Flooring factor for timestamp in validate mode. + pub validate_timestamp_rounding: u64, // Cairo OS constants. // Note: if loaded from a json file, there are some assumptions made on its structure.