Skip to content

Commit

Permalink
fix: timestamp and block number mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
HermanObst committed Oct 9, 2024
1 parent af74c75 commit 4b85abd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/bin/prove_block/tests/prove_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions crates/starknet-os/src/execution/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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(())
}
Expand All @@ -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(())
}
Expand Down

0 comments on commit 4b85abd

Please sign in to comment.