diff --git a/crates/bin/prove_block/tests/prove_block.rs b/crates/bin/prove_block/tests/prove_block.rs index c8fa60c2..3e0fc667 100644 --- a/crates/bin/prove_block/tests/prove_block.rs +++ b/crates/bin/prove_block/tests/prove_block.rs @@ -55,6 +55,8 @@ 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(162389)] +#[case::timestamp_rounding_2(167815)] #[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/cairo_types/new_syscalls.rs b/crates/starknet-os/src/cairo_types/new_syscalls.rs index 6a54824a..b0aee505 100644 --- a/crates/starknet-os/src/cairo_types/new_syscalls.rs +++ b/crates/starknet-os/src/cairo_types/new_syscalls.rs @@ -103,3 +103,26 @@ pub struct StorageWriteRequest { pub struct ReplaceClassRequest { pub class_hash: Felt252, } + +#[allow(unused)] +#[derive(FieldOffsetGetters)] +pub struct ExecutionInfo { + block_info: Relocatable, + tx_info: Relocatable, + // Entry-point-specific info. + caller_address: Felt252, + // The execution is done in the context of the contract at this address. + // It controls the storage being used, messages sent to L1, calling contracts, etc. + contract_address: Felt252, + // The entry point selector. + selector: Felt252, +} + +#[allow(unused)] +#[derive(FieldOffsetGetters)] +pub struct BlockInfo { + block_number: Felt252, + block_timestamp: Felt252, + // The address of the sequencer that is creating this block. + sequencer_address: Felt252, +} diff --git a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs index 9e1c7862..6de802ba 100644 --- a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs +++ b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs @@ -8,6 +8,7 @@ use cairo_vm::Felt252; use tokio::sync::RwLock; use super::helper::ExecutionHelperWrapper; +use crate::cairo_types::new_syscalls::{BlockInfo as BlockInfoStruct, ExecutionInfo}; use crate::cairo_types::syscalls::{ CallContract, CallContractResponse, Deploy, DeployResponse, GetBlockNumber, GetBlockNumberResponse, GetBlockTimestamp, GetBlockTimestampResponse, GetContractAddress, GetContractAddressResponse, GetSequencerAddress, @@ -134,11 +135,16 @@ where pub async fn get_block_number(&self, syscall_ptr: Relocatable, vm: &mut VirtualMachine) -> Result<(), HintError> { let syscall_handler = self.deprecated_syscall_handler.read().await; + let execution_helper = syscall_handler.exec_wrapper.execution_helper.read().await; - let block_number = syscall_handler.block_info.block_number; + let execution_info_ptr = execution_helper + .call_execution_info_ptr + .ok_or(HintError::SyscallError("Execution info pointer not set".to_string().into_boxed_str()))?; + let block_info_ptr = vm.get_relocatable((execution_info_ptr + ExecutionInfo::block_info_offset())?)?; + let block_number = vm.get_integer((block_info_ptr + BlockInfoStruct::block_number_offset())?)?.into_owned(); 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)?, block_number)?; Ok(()) } @@ -149,12 +155,18 @@ where vm: &mut VirtualMachine, ) -> Result<(), HintError> { let syscall_handler = self.deprecated_syscall_handler.read().await; + let execution_helper = syscall_handler.exec_wrapper.execution_helper.read().await; - let block_timestamp = syscall_handler.block_info.block_timestamp; + let execution_info_ptr = execution_helper + .call_execution_info_ptr + .ok_or(HintError::SyscallError("Execution info pointer not set".to_string().into_boxed_str()))?; + let block_info_ptr = vm.get_relocatable((execution_info_ptr + ExecutionInfo::block_info_offset())?)?; + let block_timestamp = + vm.get_integer((block_info_ptr + BlockInfoStruct::block_timestamp_offset())?)?.into_owned(); 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)?, block_timestamp)?; Ok(()) } diff --git a/tests/integration/deprecated_syscalls_tests.rs b/tests/integration/deprecated_syscalls_tests.rs index e2835ecb..6770b961 100644 --- a/tests/integration/deprecated_syscalls_tests.rs +++ b/tests/integration/deprecated_syscalls_tests.rs @@ -95,14 +95,14 @@ async fn test_syscall_get_block_number_cairo0( let sender_address = initial_state.deployed_cairo0_contracts.get("account_with_dummy_validate").unwrap().address; let contract_address = initial_state.deployed_cairo0_contracts.get("test_contract").unwrap().address; - let expected_block_number = felt!(block_context.block_info().block_number.0); + let block_number = block_context.block_info().block_number.0; let tx_version = TransactionVersion::ZERO; let mut nonce_manager = NonceManager::default(); let tx = test_utils::account_invoke_tx(invoke_tx_args! { max_fee, sender_address: sender_address, - calldata: create_calldata(contract_address, "test_get_block_number", &[expected_block_number]), + calldata: create_calldata(contract_address, "test_get_block_number", &[felt!(block_number)]), version: tx_version, nonce: nonce_manager.next(sender_address), }); @@ -136,14 +136,14 @@ async fn test_syscall_get_block_timestamp_cairo0( let sender_address = initial_state.deployed_cairo0_contracts.get("account_with_dummy_validate").unwrap().address; let contract_address = initial_state.deployed_cairo0_contracts.get("test_contract").unwrap().address; - let expected_block_timestamp = felt!(block_context.block_info().block_timestamp.0); + let block_timestamp = block_context.block_info().block_timestamp.0; let tx_version = TransactionVersion::ZERO; let mut nonce_manager = NonceManager::default(); let tx = test_utils::account_invoke_tx(invoke_tx_args! { max_fee, sender_address: sender_address, - calldata: create_calldata(contract_address, "test_get_block_timestamp", &[expected_block_timestamp]), + calldata: create_calldata(contract_address, "test_get_block_timestamp", &[felt!(block_timestamp)]), version: tx_version, nonce: nonce_manager.next(sender_address), });