Skip to content

Commit 137b319

Browse files
starknet_api: add BlockHashVersion::V0_14_3 variant
1 parent ea0f7c1 commit 137b319

7 files changed

Lines changed: 28 additions & 15 deletions

File tree

crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/block_hash.cairo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from starkware.cairo.common.hash_state_poseidon import hash_finalize, hash_init,
33
from starkware.starknet.common.new_syscalls import BlockInfo
44

55
// The latest block hash version.
6-
const BLOCK_HASH_VERSION = 'STARKNET_BLOCK_HASH1';
6+
const BLOCK_HASH_VERSION = 'STARKNET_BLOCK_HASH2';
77

88
struct BlockHeaderCommitments {
99
transaction_commitment: felt,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"os": "0xb0134eed363da4094afca019a74939b4c17f238a4f7411798813f55905cd7",
3-
"virtual_os": "0x3e98c2d7703b03a7edb73ed7f075f97f1dcbaa8f717cdf6e1a57bf058265473",
2+
"os": "0xc2ef94f4f0ad828490194c4a652dbbb71dbf1c6bccd122135383b3c9c5fbd",
3+
"virtual_os": "0x46328da2901e5ccd1585a82de99fd97d0e757a876d6b66f29d8ca94bb5ba27b",
44
"aggregator": "0x43666b81f964bcdedf0098d2791b061d61f3098ff1429a754d0b97eeeae9489",
55
"aggregator_with_prefix": "0x68072c8f5ff5ae133060e12cfad3a38362dbb6d667abd4f7e1fac6f37febe46"
66
}

crates/blockifier/resources/blockifier_versioned_constants_0_14_3.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"segment_arena_cells": false,
6868
"os_constants": {
6969
"allowed_virtual_os_program_hashes": [
70-
"0x3e98c2d7703b03a7edb73ed7f075f97f1dcbaa8f717cdf6e1a57bf058265473"
70+
"0x3e98c2d7703b03a7edb73ed7f075f97f1dcbaa8f717cdf6e1a57bf058265473",
71+
"0x46328da2901e5ccd1585a82de99fd97d0e757a876d6b66f29d8ca94bb5ba27b"
7172
],
7273
"constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194",
7374
"default_entry_point_selector": "0x0",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
+ /os_constants/allowed_virtual_os_program_hashes/1: "0x46328da2901e5ccd1585a82de99fd97d0e757a876d6b66f29d8ca94bb5ba27b"

crates/starknet_api/src/block_hash/block_hash_calculator.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@ use crate::{StarknetApiError, StarknetApiResult};
4141
#[path = "block_hash_calculator_test.rs"]
4242
mod block_hash_calculator_test;
4343

44-
static STARKNET_BLOCK_HASH0: LazyLock<Felt> = LazyLock::new(|| {
44+
// The prefix constant for the block hash calculation.
45+
type BlockHashConstant = Felt;
46+
47+
static STARKNET_BLOCK_HASH0: LazyLock<BlockHashConstant> = LazyLock::new(|| {
4548
ascii_as_felt("STARKNET_BLOCK_HASH0").expect("ascii_as_felt failed for 'STARKNET_BLOCK_HASH0'")
4649
});
47-
pub static STARKNET_BLOCK_HASH1: LazyLock<Felt> = LazyLock::new(|| {
50+
pub static STARKNET_BLOCK_HASH1: LazyLock<BlockHashConstant> = LazyLock::new(|| {
4851
ascii_as_felt("STARKNET_BLOCK_HASH1").expect("ascii_as_felt failed for 'STARKNET_BLOCK_HASH1'")
4952
});
53+
pub static STARKNET_BLOCK_HASH2: LazyLock<BlockHashConstant> = LazyLock::new(|| {
54+
ascii_as_felt("STARKNET_BLOCK_HASH2").expect("ascii_as_felt failed for 'STARKNET_BLOCK_HASH2'")
55+
});
5056
pub static STARKNET_GAS_PRICES0: LazyLock<Felt> = LazyLock::new(|| {
5157
ascii_as_felt("STARKNET_GAS_PRICES0").expect("ascii_as_felt failed for 'STARKNET_GAS_PRICES0'")
5258
});
@@ -56,13 +62,15 @@ pub static STARKNET_GAS_PRICES0: LazyLock<Felt> = LazyLock::new(|| {
5662
pub enum BlockHashVersion {
5763
V0_13_2,
5864
V0_13_4,
65+
V0_14_3,
5966
}
6067

6168
impl From<BlockHashVersion> for StarknetVersion {
6269
fn from(value: BlockHashVersion) -> Self {
6370
match value {
6471
BlockHashVersion::V0_13_2 => StarknetVersion::V0_13_2,
6572
BlockHashVersion::V0_13_4 => StarknetVersion::V0_13_4,
73+
BlockHashVersion::V0_14_3 => StarknetVersion::V0_14_3,
6674
}
6775
}
6876
}
@@ -76,20 +84,20 @@ impl TryFrom<StarknetVersion> for BlockHashVersion {
7684
} else if value < Self::V0_13_4.into() {
7785
// Starknet versions 0.13.2 and 0.13.3 both have the same block hash mechanism.
7886
Ok(Self::V0_13_2)
79-
} else {
87+
} else if value < Self::V0_14_3.into() {
8088
Ok(Self::V0_13_4)
89+
} else {
90+
Ok(Self::V0_14_3)
8191
}
8292
}
8393
}
8494

85-
// The prefix constant for the block hash calculation.
86-
type BlockHashConstant = Felt;
87-
8895
impl From<BlockHashVersion> for BlockHashConstant {
8996
fn from(block_hash_version: BlockHashVersion) -> Self {
9097
match block_hash_version {
9198
BlockHashVersion::V0_13_2 => *STARKNET_BLOCK_HASH0,
9299
BlockHashVersion::V0_13_4 => *STARKNET_BLOCK_HASH1,
100+
BlockHashVersion::V0_14_3 => *STARKNET_BLOCK_HASH2,
93101
}
94102
}
95103
}

crates/starknet_api/src/block_hash/block_hash_calculator_test.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ macro_rules! test_hash_changes {
3939
) => {
4040
{
4141
let partial_block_hash_components = PartialBlockHashComponents {
42-
starknet_version: BlockHashVersion::V0_13_4.into(),
42+
starknet_version: BlockHashVersion::V0_14_3.into(),
4343
$(
4444
$partial_block_hash_components_field: $partial_block_hash_components_value,
4545
)*
@@ -68,7 +68,7 @@ macro_rules! test_hash_changes {
6868
#[rstest]
6969
#[tokio::test]
7070
async fn test_block_hash_regression(
71-
#[values(BlockHashVersion::V0_13_2, BlockHashVersion::V0_13_4)]
71+
#[values(BlockHashVersion::V0_13_2, BlockHashVersion::V0_13_4, BlockHashVersion::V0_14_3)]
7272
block_hash_version: BlockHashVersion,
7373
) {
7474
let state_root = GlobalRoot(Felt::from(2_u8));
@@ -110,6 +110,9 @@ async fn test_block_hash_regression(
110110
BlockHashVersion::V0_13_4 => {
111111
felt!("0x3d6174623c812f5dc03fa3faa07c42c06fd90ad425629ee5f39e149df65c3ca")
112112
}
113+
BlockHashVersion::V0_14_3 => {
114+
felt!("0x477e98ed084a0274e4510ab27327f08235d8e4fdb7506e46e92e9ab0c5ea459")
115+
}
113116
};
114117

115118
assert_eq!(
@@ -222,6 +225,7 @@ fn extract_event_count_from_concatenated_counts_test(
222225
}
223226

224227
/// Test that if one of the input to block hash changes, the hash changes.
228+
// TODO(AndrewL): add fee_proposal to the test.
225229
#[test]
226230
fn change_field_of_hash_input() {
227231
// Set non-default values for the header and the commitments fields. Test that changing any of

crates/starknet_os/src/hints/hint_implementation/block_hash/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use starknet_api::block_hash::block_hash_calculator::{
1919
BlockHashVersion,
2020
BlockHeaderCommitments,
2121
PartialBlockHashComponents,
22-
STARKNET_BLOCK_HASH1,
22+
STARKNET_BLOCK_HASH2,
2323
};
2424
use starknet_api::core::{
2525
EventCommitment,
@@ -161,7 +161,7 @@ fn test_block_hash_version() {
161161
// NOTE: if these checks fail, it means the block hash version in the OS program is not the
162162
// latest, and a backward-compatibility flow must be added for the transition.
163163
assert_eq!(
164-
*STARKNET_BLOCK_HASH1, latest_block_hash_version,
164+
*STARKNET_BLOCK_HASH2, latest_block_hash_version,
165165
"Latest block hash version constant mismatch"
166166
);
167167
assert_eq!(

0 commit comments

Comments
 (0)