From 4b85abd595efaca7b2f04bd383a5dee737a4c463 Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Wed, 9 Oct 2024 09:08:35 -0700 Subject: [PATCH 01/11] 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(()) } From 2e89d67f609c41e7accf62771f11c54512cb8278 Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Thu, 10 Oct 2024 19:58:41 -0300 Subject: [PATCH 02/11] experiments --- .../src/execution/deprecated_syscall_handler.rs | 5 +++++ crates/starknet-os/src/execution/mod.rs | 2 +- tests/integration/deprecated_syscalls_tests.rs | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs index c0a52b30..a2671476 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 super::syscall_handler; use crate::cairo_types::syscalls::{ CallContract, CallContractResponse, Deploy, DeployResponse, GetBlockNumber, GetBlockNumberResponse, GetBlockTimestamp, GetBlockTimestampResponse, GetContractAddress, GetContractAddressResponse, GetSequencerAddress, @@ -135,6 +136,10 @@ 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 bla = syscall_handler.exec_wrapper.execution_helper.read().await; + let tx_info = bla.tx_execution_info.clone().unwrap(); + let validate = tx_info.validate_call_info.clone().unwrap(); + let execute = tx_info.execute_call_info.clone().unwrap(); let block_number = syscall_handler.block_info.block_number; let rounded_block_number = (block_number.0 / VALIDATE_BLOCK_NUMBER_ROUNDING ) * VALIDATE_BLOCK_NUMBER_ROUNDING; diff --git a/crates/starknet-os/src/execution/mod.rs b/crates/starknet-os/src/execution/mod.rs index 26faedf1..155381ea 100644 --- a/crates/starknet-os/src/execution/mod.rs +++ b/crates/starknet-os/src/execution/mod.rs @@ -1,4 +1,4 @@ -mod constants; +pub mod constants; pub mod deprecated_syscall_handler; pub mod execute_syscalls; pub mod helper; diff --git a/tests/integration/deprecated_syscalls_tests.rs b/tests/integration/deprecated_syscalls_tests.rs index e2835ecb..e19674ba 100644 --- a/tests/integration/deprecated_syscalls_tests.rs +++ b/tests/integration/deprecated_syscalls_tests.rs @@ -29,6 +29,10 @@ use crate::common::state::{initial_state_cairo0, StarknetTestState}; use crate::common::transaction_utils::execute_txs_and_run_os; use crate::common::utils::check_os_output_read_only_syscall; +use starknet_os::execution::constants::{VALIDATE_BLOCK_NUMBER_ROUNDING, VALIDATE_TIMESTAMP_ROUNDING}; + +// ::{VALIDATE_BLOCK_NUMBER_ROUNDING, VALIDATE_TIMESTAMP_ROUNDING}; + #[rstest] // We need to use the multi_thread runtime to use task::block_in_place for sync -> async calls. #[tokio::test(flavor = "multi_thread", worker_threads = 1)] @@ -95,14 +99,16 @@ 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 rounded_block_number = (block_number / VALIDATE_BLOCK_NUMBER_ROUNDING) * VALIDATE_BLOCK_NUMBER_ROUNDING; + // let expected_block_number = felt!(rounded_block_number); - let tx_version = TransactionVersion::ZERO; + let tx_version = TransactionVersion::THREE; 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,7 +142,9 @@ 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 rounded_block_timestamp = (block_timestamp / VALIDATE_TIMESTAMP_ROUNDING) * VALIDATE_TIMESTAMP_ROUNDING; + let expected_block_timestamp = felt!(rounded_block_timestamp); let tx_version = TransactionVersion::ZERO; let mut nonce_manager = NonceManager::default(); From ea7f3ec4ff8f75220a3006ec21f9b82f142370d2 Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Tue, 15 Oct 2024 14:41:37 -0300 Subject: [PATCH 03/11] fetch Block Timestamp and Block Number from ExecutionInfo --- .../src/cairo_types/new_syscalls.rs | 23 +++++++++++++++++++ .../execution/deprecated_syscall_handler.rs | 22 +++++++++--------- .../integration/deprecated_syscalls_tests.rs | 4 +--- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/crates/starknet-os/src/cairo_types/new_syscalls.rs b/crates/starknet-os/src/cairo_types/new_syscalls.rs index 6a54824a..6775a1be 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, +} \ No newline at end of file diff --git a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs index a2671476..3651632b 100644 --- a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs +++ b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs @@ -8,13 +8,13 @@ use cairo_vm::Felt252; use tokio::sync::RwLock; use super::helper::ExecutionHelperWrapper; -use super::syscall_handler; use crate::cairo_types::syscalls::{ CallContract, CallContractResponse, Deploy, DeployResponse, GetBlockNumber, GetBlockNumberResponse, GetBlockTimestamp, GetBlockTimestampResponse, GetContractAddress, GetContractAddressResponse, GetSequencerAddress, GetSequencerAddressResponse, GetTxInfo, GetTxInfoResponse, GetTxSignature, GetTxSignatureResponse, LibraryCall, TxInfo, }; +use crate::cairo_types::new_syscalls::{ExecutionInfo, BlockInfo as BlockInfoStruct}; use crate::starknet::starknet_storage::PerContractStorage; use crate::execution::constants::{VALIDATE_BLOCK_NUMBER_ROUNDING, VALIDATE_TIMESTAMP_ROUNDING}; @@ -136,17 +136,15 @@ 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 bla = syscall_handler.exec_wrapper.execution_helper.read().await; - let tx_info = bla.tx_execution_info.clone().unwrap(); - let validate = tx_info.validate_call_info.clone().unwrap(); - let execute = tx_info.execute_call_info.clone().unwrap(); + let execution_helper = syscall_handler.exec_wrapper.execution_helper.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 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_pointer = vm.get_relocatable((execution_info_ptr + ExecutionInfo::block_info_offset())?)?; + let block_number= vm.get_integer((block_info_pointer + 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(rounded_block_number))?; + vm.insert_value((syscall_ptr + response_offset)?, Felt252::from(block_number))?; Ok(()) } @@ -157,13 +155,15 @@ 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 rounded_block_timestamp = (block_timestamp.0 / VALIDATE_TIMESTAMP_ROUNDING) * VALIDATE_TIMESTAMP_ROUNDING; + 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_pointer = vm.get_relocatable((execution_info_ptr + ExecutionInfo::block_info_offset())?)?; + let block_timestamp = vm.get_integer((block_info_pointer + 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(rounded_block_timestamp))?; + vm.insert_value((syscall_ptr + response_offset)?, Felt252::from(block_timestamp))?; Ok(()) } diff --git a/tests/integration/deprecated_syscalls_tests.rs b/tests/integration/deprecated_syscalls_tests.rs index e19674ba..5814769a 100644 --- a/tests/integration/deprecated_syscalls_tests.rs +++ b/tests/integration/deprecated_syscalls_tests.rs @@ -143,15 +143,13 @@ async fn test_syscall_get_block_timestamp_cairo0( let contract_address = initial_state.deployed_cairo0_contracts.get("test_contract").unwrap().address; let block_timestamp = block_context.block_info().block_timestamp.0; - let rounded_block_timestamp = (block_timestamp / VALIDATE_TIMESTAMP_ROUNDING) * VALIDATE_TIMESTAMP_ROUNDING; - let expected_block_timestamp = felt!(rounded_block_timestamp); 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), }); From 276fa0d70638334ef4575e4b266b8da5cc178a90 Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Tue, 15 Oct 2024 15:26:57 -0300 Subject: [PATCH 04/11] fmt + clippy --- .../src/cairo_types/new_syscalls.rs | 2 +- .../execution/deprecated_syscall_handler.rs | 21 +++++++++++-------- .../integration/deprecated_syscalls_tests.rs | 3 +-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/starknet-os/src/cairo_types/new_syscalls.rs b/crates/starknet-os/src/cairo_types/new_syscalls.rs index 6775a1be..b0aee505 100644 --- a/crates/starknet-os/src/cairo_types/new_syscalls.rs +++ b/crates/starknet-os/src/cairo_types/new_syscalls.rs @@ -125,4 +125,4 @@ pub struct BlockInfo { block_timestamp: Felt252, // The address of the sequencer that is creating this block. sequencer_address: Felt252, -} \ No newline at end of file +} diff --git a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs index 3651632b..2ac652b8 100644 --- a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs +++ b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs @@ -8,15 +8,14 @@ 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, GetSequencerAddressResponse, GetTxInfo, GetTxInfoResponse, GetTxSignature, GetTxSignatureResponse, LibraryCall, TxInfo, }; -use crate::cairo_types::new_syscalls::{ExecutionInfo, BlockInfo as BlockInfoStruct}; 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)] @@ -138,10 +137,11 @@ where let syscall_handler = self.deprecated_syscall_handler.read().await; let execution_helper = syscall_handler.exec_wrapper.execution_helper.read().await; - 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_pointer = vm.get_relocatable((execution_info_ptr + ExecutionInfo::block_info_offset())?)?; - let block_number= vm.get_integer((block_info_pointer + BlockInfoStruct::block_number_offset())?)?.into_owned(); - + 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_pointer = vm.get_relocatable((execution_info_ptr + ExecutionInfo::block_info_offset())?)?; + let block_number = vm.get_integer((block_info_pointer + 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))?; @@ -157,9 +157,12 @@ where let syscall_handler = self.deprecated_syscall_handler.read().await; let execution_helper = syscall_handler.exec_wrapper.execution_helper.read().await; - 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_pointer = vm.get_relocatable((execution_info_ptr + ExecutionInfo::block_info_offset())?)?; - let block_timestamp = vm.get_integer((block_info_pointer + BlockInfoStruct::block_timestamp_offset())?)?.into_owned(); + 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_pointer = vm.get_relocatable((execution_info_ptr + ExecutionInfo::block_info_offset())?)?; + let block_timestamp = + vm.get_integer((block_info_pointer + BlockInfoStruct::block_timestamp_offset())?)?.into_owned(); let response_offset = GetBlockTimestamp::response_offset() + GetBlockTimestampResponse::block_timestamp_offset(); diff --git a/tests/integration/deprecated_syscalls_tests.rs b/tests/integration/deprecated_syscalls_tests.rs index 5814769a..85c5657a 100644 --- a/tests/integration/deprecated_syscalls_tests.rs +++ b/tests/integration/deprecated_syscalls_tests.rs @@ -22,6 +22,7 @@ use rstest::rstest; use starknet_api::core::calculate_contract_address; use starknet_api::felt; use starknet_api::transaction::{Calldata, ContractAddressSalt, Fee, TransactionHash, TransactionVersion}; +use starknet_os::execution::constants::{VALIDATE_BLOCK_NUMBER_ROUNDING, VALIDATE_TIMESTAMP_ROUNDING}; use starknet_os_types::chain_id::chain_id_to_felt; use crate::common::block_context; @@ -29,8 +30,6 @@ use crate::common::state::{initial_state_cairo0, StarknetTestState}; use crate::common::transaction_utils::execute_txs_and_run_os; use crate::common::utils::check_os_output_read_only_syscall; -use starknet_os::execution::constants::{VALIDATE_BLOCK_NUMBER_ROUNDING, VALIDATE_TIMESTAMP_ROUNDING}; - // ::{VALIDATE_BLOCK_NUMBER_ROUNDING, VALIDATE_TIMESTAMP_ROUNDING}; #[rstest] From 240703b259d5cadcd89f33f31d23e604de018a2d Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Tue, 15 Oct 2024 15:28:09 -0300 Subject: [PATCH 05/11] fmt + clippy --- tests/integration/deprecated_syscalls_tests.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/integration/deprecated_syscalls_tests.rs b/tests/integration/deprecated_syscalls_tests.rs index 85c5657a..0eb37719 100644 --- a/tests/integration/deprecated_syscalls_tests.rs +++ b/tests/integration/deprecated_syscalls_tests.rs @@ -22,7 +22,6 @@ use rstest::rstest; use starknet_api::core::calculate_contract_address; use starknet_api::felt; use starknet_api::transaction::{Calldata, ContractAddressSalt, Fee, TransactionHash, TransactionVersion}; -use starknet_os::execution::constants::{VALIDATE_BLOCK_NUMBER_ROUNDING, VALIDATE_TIMESTAMP_ROUNDING}; use starknet_os_types::chain_id::chain_id_to_felt; use crate::common::block_context; @@ -99,8 +98,6 @@ async fn test_syscall_get_block_number_cairo0( let contract_address = initial_state.deployed_cairo0_contracts.get("test_contract").unwrap().address; let block_number = block_context.block_info().block_number.0; - let rounded_block_number = (block_number / VALIDATE_BLOCK_NUMBER_ROUNDING) * VALIDATE_BLOCK_NUMBER_ROUNDING; - // let expected_block_number = felt!(rounded_block_number); let tx_version = TransactionVersion::THREE; let mut nonce_manager = NonceManager::default(); From 1a40f5c5cea423fcff87c2452af0a8e5cb064b0f Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Tue, 15 Oct 2024 15:30:32 -0300 Subject: [PATCH 06/11] remove unused code --- crates/starknet-os/src/execution/constants.rs | 2 -- crates/starknet-os/src/execution/mod.rs | 2 +- tests/integration/deprecated_syscalls_tests.rs | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/starknet-os/src/execution/constants.rs b/crates/starknet-os/src/execution/constants.rs index 42243df4..ce5f5cd2 100644 --- a/crates/starknet-os/src/execution/constants.rs +++ b/crates/starknet-os/src/execution/constants.rs @@ -77,5 +77,3 @@ 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/mod.rs b/crates/starknet-os/src/execution/mod.rs index 155381ea..26faedf1 100644 --- a/crates/starknet-os/src/execution/mod.rs +++ b/crates/starknet-os/src/execution/mod.rs @@ -1,4 +1,4 @@ -pub mod constants; +mod constants; pub mod deprecated_syscall_handler; pub mod execute_syscalls; pub mod helper; diff --git a/tests/integration/deprecated_syscalls_tests.rs b/tests/integration/deprecated_syscalls_tests.rs index 0eb37719..b9bd5453 100644 --- a/tests/integration/deprecated_syscalls_tests.rs +++ b/tests/integration/deprecated_syscalls_tests.rs @@ -29,8 +29,6 @@ use crate::common::state::{initial_state_cairo0, StarknetTestState}; use crate::common::transaction_utils::execute_txs_and_run_os; use crate::common::utils::check_os_output_read_only_syscall; -// ::{VALIDATE_BLOCK_NUMBER_ROUNDING, VALIDATE_TIMESTAMP_ROUNDING}; - #[rstest] // We need to use the multi_thread runtime to use task::block_in_place for sync -> async calls. #[tokio::test(flavor = "multi_thread", worker_threads = 1)] From 6bcbe9de1ccb741c38253f630bad1e5f8ccc47c4 Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Tue, 15 Oct 2024 15:32:03 -0300 Subject: [PATCH 07/11] add integration tests --- crates/bin/prove_block/tests/prove_block.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/bin/prove_block/tests/prove_block.rs b/crates/bin/prove_block/tests/prove_block.rs index 21b14fa4..7e5a2019 100644 --- a/crates/bin/prove_block/tests/prove_block.rs +++ b/crates/bin/prove_block/tests/prove_block.rs @@ -53,7 +53,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(162388)] +#[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) { From ddd375db7f564f34ba31dbe49d641006b961de8a Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Tue, 15 Oct 2024 15:39:00 -0300 Subject: [PATCH 08/11] fix clippy --- .../starknet-os/src/execution/deprecated_syscall_handler.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs index 2ac652b8..4ddd588f 100644 --- a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs +++ b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs @@ -144,7 +144,7 @@ where let block_number = vm.get_integer((block_info_pointer + 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))?; + vm.insert_value((syscall_ptr + response_offset)?, block_number)?; Ok(()) } @@ -166,7 +166,7 @@ where let response_offset = GetBlockTimestamp::response_offset() + GetBlockTimestampResponse::block_timestamp_offset(); - vm.insert_value((syscall_ptr + response_offset)?, Felt252::from(block_timestamp))?; + vm.insert_value((syscall_ptr + response_offset)?, block_timestamp)?; Ok(()) } From 88eeeb93d8794e622bc85376ccb528f9bbdb1d2b Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri <70286869+HermanObst@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:31:05 -0400 Subject: [PATCH 09/11] Update crates/starknet-os/src/execution/deprecated_syscall_handler.rs Co-authored-by: Stephen Shelton --- .../starknet-os/src/execution/deprecated_syscall_handler.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs index 4ddd588f..0ad045a8 100644 --- a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs +++ b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs @@ -160,9 +160,9 @@ where 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_pointer = vm.get_relocatable((execution_info_ptr + ExecutionInfo::block_info_offset())?)?; + let block_info_ptr = vm.get_relocatable((execution_info_ptr + ExecutionInfo::block_info_offset())?)?; let block_timestamp = - vm.get_integer((block_info_pointer + BlockInfoStruct::block_timestamp_offset())?)?.into_owned(); + vm.get_integer((block_info_ptr + BlockInfoStruct::block_timestamp_offset())?)?.into_owned(); let response_offset = GetBlockTimestamp::response_offset() + GetBlockTimestampResponse::block_timestamp_offset(); From 14d71010ae94a3cfc432b43066f5cdeee8141c28 Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Tue, 15 Oct 2024 18:32:41 -0300 Subject: [PATCH 10/11] ptr instead of pointer --- .../starknet-os/src/execution/deprecated_syscall_handler.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs index 0ad045a8..6de802ba 100644 --- a/crates/starknet-os/src/execution/deprecated_syscall_handler.rs +++ b/crates/starknet-os/src/execution/deprecated_syscall_handler.rs @@ -140,8 +140,8 @@ where 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_pointer = vm.get_relocatable((execution_info_ptr + ExecutionInfo::block_info_offset())?)?; - let block_number = vm.get_integer((block_info_pointer + BlockInfoStruct::block_number_offset())?)?.into_owned(); + 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)?, block_number)?; From 9db1d562278b6c4ffb752eb6d51df1ba0c78f6cf Mon Sep 17 00:00:00 2001 From: Herman Obst Demaestri Date: Tue, 15 Oct 2024 18:33:49 -0300 Subject: [PATCH 11/11] restore tx version to zero --- tests/integration/deprecated_syscalls_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/deprecated_syscalls_tests.rs b/tests/integration/deprecated_syscalls_tests.rs index b9bd5453..6770b961 100644 --- a/tests/integration/deprecated_syscalls_tests.rs +++ b/tests/integration/deprecated_syscalls_tests.rs @@ -97,7 +97,7 @@ async fn test_syscall_get_block_number_cairo0( let block_number = block_context.block_info().block_number.0; - let tx_version = TransactionVersion::THREE; + let tx_version = TransactionVersion::ZERO; let mut nonce_manager = NonceManager::default(); let tx = test_utils::account_invoke_tx(invoke_tx_args! { max_fee,