Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timestamp and block number mismatch #401

Merged
merged 12 commits into from
Oct 16, 2024
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};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already discussed this, but these should be able to come from the constants in cairo-lang. We should do that if at all possible, but if not we should leave a comment about that here.


/// 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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use prev_multiple_of instead?



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
Loading