From 4b85abd595efaca7b2f04bd383a5dee737a4c463 Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Wed, 9 Oct 2024 09:08:35 -0700 Subject: [PATCH] fix: timestamp and block number mismatch --- crates/bin/prove_block/tests/prove_block.rs | 1 + crates/starknet-os/src/execution/constants.rs | 2 ++ .../src/execution/deprecated_syscall_handler.rs | 8 ++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/bin/prove_block/tests/prove_block.rs b/crates/bin/prove_block/tests/prove_block.rs index a25dea57..21b14fa4 100644 --- a/crates/bin/prove_block/tests/prove_block.rs +++ b/crates/bin/prove_block/tests/prove_block.rs @@ -53,6 +53,7 @@ use rstest::rstest; #[case::key_not_in_proof_0(155087)] #[case::key_not_in_proof_1(162388)] #[case::key_not_in_proof_2(155172)] +#[case::timestamp_rounding_1(162388)] #[ignore = "Requires a running Pathfinder node"] #[tokio::test(flavor = "multi_thread")] async fn test_prove_selected_blocks(#[case] block_number: u64) { diff --git a/crates/starknet-os/src/execution/constants.rs b/crates/starknet-os/src/execution/constants.rs index ce5f5cd2..42243df4 100644 --- a/crates/starknet-os/src/execution/constants.rs +++ b/crates/starknet-os/src/execution/constants.rs @@ -77,3 +77,5 @@ pub const KECCAK_FULL_RATE_IN_U64S: u64 = 17; // The hexadecimal string "0x000000000000000000000000496e76616c696420696e707574206c656e677468" // decodes to "Invalid input length". pub const INVALID_INPUT_LENGTH_ERROR: &str = "0x000000000000000000000000496e76616c696420696e707574206c656e677468"; +pub const VALIDATE_TIMESTAMP_ROUNDING: u64 = 3600; +pub const VALIDATE_BLOCK_NUMBER_ROUNDING: u64 = 100; diff --git a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs index 9e1c7862..c0a52b30 100644 --- a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs +++ b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs @@ -15,6 +15,7 @@ use crate::cairo_types::syscalls::{ TxInfo, }; use crate::starknet::starknet_storage::PerContractStorage; +use crate::execution::constants::{VALIDATE_BLOCK_NUMBER_ROUNDING, VALIDATE_TIMESTAMP_ROUNDING}; /// DeprecatedSyscallHandler implementation for execution of system calls in the StarkNet OS #[derive(Debug)] @@ -136,9 +137,11 @@ where let syscall_handler = self.deprecated_syscall_handler.read().await; let block_number = syscall_handler.block_info.block_number; + let rounded_block_number = (block_number.0 / VALIDATE_BLOCK_NUMBER_ROUNDING ) * VALIDATE_BLOCK_NUMBER_ROUNDING; + let response_offset = GetBlockNumber::response_offset() + GetBlockNumberResponse::block_number_offset(); - vm.insert_value((syscall_ptr + response_offset)?, Felt252::from(block_number.0))?; + vm.insert_value((syscall_ptr + response_offset)?, Felt252::from(rounded_block_number))?; Ok(()) } @@ -151,10 +154,11 @@ where let syscall_handler = self.deprecated_syscall_handler.read().await; let block_timestamp = syscall_handler.block_info.block_timestamp; + let rounded_block_timestamp = (block_timestamp.0 / VALIDATE_TIMESTAMP_ROUNDING) * VALIDATE_TIMESTAMP_ROUNDING; let response_offset = GetBlockTimestamp::response_offset() + GetBlockTimestampResponse::block_timestamp_offset(); - vm.insert_value((syscall_ptr + response_offset)?, Felt252::from(block_timestamp.0))?; + vm.insert_value((syscall_ptr + response_offset)?, Felt252::from(rounded_block_timestamp))?; Ok(()) }