diff --git a/crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/block_hash.cairo b/crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/block_hash.cairo index e33a226eb42..547ef7320f8 100644 --- a/crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/block_hash.cairo +++ b/crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/block_hash.cairo @@ -3,7 +3,7 @@ from starkware.cairo.common.hash_state_poseidon import hash_finalize, hash_init, from starkware.starknet.common.new_syscalls import BlockInfo // The latest block hash version. -const BLOCK_HASH_VERSION = 'STARKNET_BLOCK_HASH1'; +const BLOCK_HASH_VERSION = 'STARKNET_BLOCK_HASH2'; struct BlockHeaderCommitments { transaction_commitment: felt, diff --git a/crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/constants.cairo b/crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/constants.cairo index 99ab76f07b8..3c36a6fab36 100644 --- a/crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/constants.cairo +++ b/crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/constants.cairo @@ -68,7 +68,10 @@ const STORED_BLOCK_HASH_BUFFER = 10; const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_0 = ( 0x03e98c2d7703b03a7edb73ed7f075f97f1dcbaa8f717cdf6e1a57bf058265473 ); -const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_LEN = 1; +const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_1 = ( + 0x046328da2901e5ccd1585a82de99fd97d0e757a876d6b66f29d8ca94bb5ba27b +); +const ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_LEN = 2; // Gas constants. diff --git a/crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/execution/execution_constraints.cairo b/crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/execution/execution_constraints.cairo index aa3b6f2769a..d4bdcca02aa 100644 --- a/crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/execution/execution_constraints.cairo +++ b/crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/execution/execution_constraints.cairo @@ -23,10 +23,13 @@ func check_is_reverted(is_reverted: felt) { // Returns TRUE if the given virtual OS program hash is allowed, FALSE otherwise. func is_program_hash_allowed(program_hash: felt) -> felt { - static_assert ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_LEN == 1; + static_assert ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_LEN == 2; if (program_hash == ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_0) { return TRUE; } + if (program_hash == ALLOWED_VIRTUAL_OS_PROGRAM_HASHES_1) { + return TRUE; + } return FALSE; } diff --git a/crates/apollo_starknet_os_program/src/program_hash.json b/crates/apollo_starknet_os_program/src/program_hash.json index 1f1d6006096..a1e199b10d9 100644 --- a/crates/apollo_starknet_os_program/src/program_hash.json +++ b/crates/apollo_starknet_os_program/src/program_hash.json @@ -1,6 +1,6 @@ { - "os": "0xb0134eed363da4094afca019a74939b4c17f238a4f7411798813f55905cd7", - "virtual_os": "0x3e98c2d7703b03a7edb73ed7f075f97f1dcbaa8f717cdf6e1a57bf058265473", + "os": "0xc2ef94f4f0ad828490194c4a652dbbb71dbf1c6bccd122135383b3c9c5fbd", + "virtual_os": "0x46328da2901e5ccd1585a82de99fd97d0e757a876d6b66f29d8ca94bb5ba27b", "aggregator": "0x43666b81f964bcdedf0098d2791b061d61f3098ff1429a754d0b97eeeae9489", "aggregator_with_prefix": "0x68072c8f5ff5ae133060e12cfad3a38362dbb6d667abd4f7e1fac6f37febe46" } \ No newline at end of file diff --git a/crates/blockifier/resources/blockifier_versioned_constants_0_14_3.json b/crates/blockifier/resources/blockifier_versioned_constants_0_14_3.json index daa28fce299..460571e1c6a 100644 --- a/crates/blockifier/resources/blockifier_versioned_constants_0_14_3.json +++ b/crates/blockifier/resources/blockifier_versioned_constants_0_14_3.json @@ -67,7 +67,8 @@ "segment_arena_cells": false, "os_constants": { "allowed_virtual_os_program_hashes": [ - "0x3e98c2d7703b03a7edb73ed7f075f97f1dcbaa8f717cdf6e1a57bf058265473" + "0x3e98c2d7703b03a7edb73ed7f075f97f1dcbaa8f717cdf6e1a57bf058265473", + "0x46328da2901e5ccd1585a82de99fd97d0e757a876d6b66f29d8ca94bb5ba27b" ], "constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194", "default_entry_point_selector": "0x0", diff --git a/crates/blockifier/resources/versioned_constants_diff_regression/0.14.2_0.14.3.txt b/crates/blockifier/resources/versioned_constants_diff_regression/0.14.2_0.14.3.txt index 8b137891791..7b3c042420b 100644 --- a/crates/blockifier/resources/versioned_constants_diff_regression/0.14.2_0.14.3.txt +++ b/crates/blockifier/resources/versioned_constants_diff_regression/0.14.2_0.14.3.txt @@ -1 +1 @@ - ++ /os_constants/allowed_virtual_os_program_hashes/1: "0x46328da2901e5ccd1585a82de99fd97d0e757a876d6b66f29d8ca94bb5ba27b" diff --git a/crates/starknet_api/src/block_hash/block_hash_calculator.rs b/crates/starknet_api/src/block_hash/block_hash_calculator.rs index 437472bcba3..8891f054cec 100644 --- a/crates/starknet_api/src/block_hash/block_hash_calculator.rs +++ b/crates/starknet_api/src/block_hash/block_hash_calculator.rs @@ -41,12 +41,18 @@ use crate::{StarknetApiError, StarknetApiResult}; #[path = "block_hash_calculator_test.rs"] mod block_hash_calculator_test; -static STARKNET_BLOCK_HASH0: LazyLock = LazyLock::new(|| { +// The prefix constant for the block hash calculation. +type BlockHashConstant = Felt; + +static STARKNET_BLOCK_HASH0: LazyLock = LazyLock::new(|| { ascii_as_felt("STARKNET_BLOCK_HASH0").expect("ascii_as_felt failed for 'STARKNET_BLOCK_HASH0'") }); -pub static STARKNET_BLOCK_HASH1: LazyLock = LazyLock::new(|| { +pub static STARKNET_BLOCK_HASH1: LazyLock = LazyLock::new(|| { ascii_as_felt("STARKNET_BLOCK_HASH1").expect("ascii_as_felt failed for 'STARKNET_BLOCK_HASH1'") }); +pub static STARKNET_BLOCK_HASH2: LazyLock = LazyLock::new(|| { + ascii_as_felt("STARKNET_BLOCK_HASH2").expect("ascii_as_felt failed for 'STARKNET_BLOCK_HASH2'") +}); pub static STARKNET_GAS_PRICES0: LazyLock = LazyLock::new(|| { ascii_as_felt("STARKNET_GAS_PRICES0").expect("ascii_as_felt failed for 'STARKNET_GAS_PRICES0'") }); @@ -56,6 +62,7 @@ pub static STARKNET_GAS_PRICES0: LazyLock = LazyLock::new(|| { pub enum BlockHashVersion { V0_13_2, V0_13_4, + V0_14_3, } impl From for StarknetVersion { @@ -63,6 +70,7 @@ impl From for StarknetVersion { match value { BlockHashVersion::V0_13_2 => StarknetVersion::V0_13_2, BlockHashVersion::V0_13_4 => StarknetVersion::V0_13_4, + BlockHashVersion::V0_14_3 => StarknetVersion::V0_14_3, } } } @@ -76,20 +84,20 @@ impl TryFrom for BlockHashVersion { } else if value < Self::V0_13_4.into() { // Starknet versions 0.13.2 and 0.13.3 both have the same block hash mechanism. Ok(Self::V0_13_2) - } else { + } else if value < Self::V0_14_3.into() { Ok(Self::V0_13_4) + } else { + Ok(Self::V0_14_3) } } } -// The prefix constant for the block hash calculation. -type BlockHashConstant = Felt; - impl From for BlockHashConstant { fn from(block_hash_version: BlockHashVersion) -> Self { match block_hash_version { BlockHashVersion::V0_13_2 => *STARKNET_BLOCK_HASH0, BlockHashVersion::V0_13_4 => *STARKNET_BLOCK_HASH1, + BlockHashVersion::V0_14_3 => *STARKNET_BLOCK_HASH2, } } } diff --git a/crates/starknet_api/src/block_hash/block_hash_calculator_test.rs b/crates/starknet_api/src/block_hash/block_hash_calculator_test.rs index 080c14793fc..638d0f92e58 100644 --- a/crates/starknet_api/src/block_hash/block_hash_calculator_test.rs +++ b/crates/starknet_api/src/block_hash/block_hash_calculator_test.rs @@ -39,7 +39,7 @@ macro_rules! test_hash_changes { ) => { { let partial_block_hash_components = PartialBlockHashComponents { - starknet_version: BlockHashVersion::V0_13_4.into(), + starknet_version: BlockHashVersion::V0_14_3.into(), $( $partial_block_hash_components_field: $partial_block_hash_components_value, )* @@ -68,7 +68,7 @@ macro_rules! test_hash_changes { #[rstest] #[tokio::test] async fn test_block_hash_regression( - #[values(BlockHashVersion::V0_13_2, BlockHashVersion::V0_13_4)] + #[values(BlockHashVersion::V0_13_2, BlockHashVersion::V0_13_4, BlockHashVersion::V0_14_3)] block_hash_version: BlockHashVersion, ) { let state_root = GlobalRoot(Felt::from(2_u8)); @@ -110,6 +110,9 @@ async fn test_block_hash_regression( BlockHashVersion::V0_13_4 => { felt!("0x3d6174623c812f5dc03fa3faa07c42c06fd90ad425629ee5f39e149df65c3ca") } + BlockHashVersion::V0_14_3 => { + felt!("0x477e98ed084a0274e4510ab27327f08235d8e4fdb7506e46e92e9ab0c5ea459") + } }; assert_eq!( @@ -222,6 +225,7 @@ fn extract_event_count_from_concatenated_counts_test( } /// Test that if one of the input to block hash changes, the hash changes. +// TODO(AndrewL): add fee_proposal to the test. #[test] fn change_field_of_hash_input() { // Set non-default values for the header and the commitments fields. Test that changing any of diff --git a/crates/starknet_os/src/hints/hint_implementation/block_hash/test.rs b/crates/starknet_os/src/hints/hint_implementation/block_hash/test.rs index eaca2d0ea4e..56d1f9ceee6 100644 --- a/crates/starknet_os/src/hints/hint_implementation/block_hash/test.rs +++ b/crates/starknet_os/src/hints/hint_implementation/block_hash/test.rs @@ -19,7 +19,7 @@ use starknet_api::block_hash::block_hash_calculator::{ BlockHashVersion, BlockHeaderCommitments, PartialBlockHashComponents, - STARKNET_BLOCK_HASH1, + STARKNET_BLOCK_HASH2, }; use starknet_api::core::{ EventCommitment, @@ -161,7 +161,7 @@ fn test_block_hash_version() { // NOTE: if these checks fail, it means the block hash version in the OS program is not the // latest, and a backward-compatibility flow must be added for the transition. assert_eq!( - *STARKNET_BLOCK_HASH1, latest_block_hash_version, + *STARKNET_BLOCK_HASH2, latest_block_hash_version, "Latest block hash version constant mismatch" ); assert_eq!(