Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
refactor: move validate_block_number_rounding and validate_timestamp_…
Browse files Browse the repository at this point in the history
…rounding to versioned_constants
  • Loading branch information
OriStarkware committed Feb 14, 2024
1 parent 7abd478 commit 6666ae7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 2 additions & 0 deletions crates/blockifier/resources/versioned_constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,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,
Expand Down
9 changes: 4 additions & 5 deletions crates/blockifier/src/execution/deprecated_syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -403,10 +400,11 @@ pub fn get_block_number(
_vm: &mut VirtualMachine,
syscall_handler: &mut DeprecatedSyscallHintProcessor<'_>,
) -> DeprecatedSyscallResult<GetBlockNumberResponse> {
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,
};
Expand Down Expand Up @@ -434,10 +432,11 @@ pub fn get_block_timestamp(
_vm: &mut VirtualMachine,
syscall_handler: &mut DeprecatedSyscallHintProcessor<'_>,
) -> DeprecatedSyscallResult<GetBlockTimestampResponse> {
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,
};
Expand Down
15 changes: 5 additions & 10 deletions crates/blockifier/src/execution/syscalls/hint_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -507,13 +501,14 @@ 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<StarkFelt> = if self.is_validate_mode() {
// Round down to the nearest multiple of VALIDATE_BLOCK_NUMBER_ROUNDING.
// 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.
(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 / VALIDATE_TIMESTAMP_ROUNDING) * VALIDATE_TIMESTAMP_ROUNDING;
(block_timestamp / versioned_constants.validate_timestamp_rounding) * versioned_constants.validate_timestamp_rounding;

vec![
StarkFelt::from(rounded_block_number),
Expand Down
4 changes: 4 additions & 0 deletions crates/blockifier/src/versioned_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ static DEFAULT_CONSTANTS: Lazy<VersionedConstants> = Lazy::new(|| {
pub struct VersionedConstants {
// Limits.
pub invoke_tx_max_n_steps: u32,
// 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,
pub max_recursion_depth: usize,

// Resources.
Expand Down

0 comments on commit 6666ae7

Please sign in to comment.