Skip to content

Commit 9d1db12

Browse files
committed
starknet_api: define partial block hash
1 parent 84831ef commit 9d1db12

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

crates/starknet_api/src/block_hash/block_hash_calculator.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::core::{
3030
use crate::crypto::utils::HashChain;
3131
use crate::data_availability::L1DataAvailabilityMode;
3232
use crate::execution_resources::GasVector;
33+
use crate::hash::StarkHash;
3334
use crate::state::ThinStateDiff;
3435
use crate::transaction::fields::{Fee, TransactionSignature};
3536
use crate::transaction::{Event, MessageToL1, TransactionExecutionStatus, TransactionHash};
@@ -165,6 +166,29 @@ impl TryFrom<&BlockHeader> for Option<BlockHeaderCommitments> {
165166
}
166167
}
167168

169+
/// Hash of [`PartialBlockHashComponents`] only (no state root or parent hash).
170+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
171+
pub struct PartialBlockHash(pub StarkHash);
172+
173+
impl PartialBlockHash {
174+
const GLOBAL_ROOT_FOR_PARTIAL_BLOCK_HASH: GlobalRoot = GlobalRoot(Felt::ZERO);
175+
const PARENT_HASH_FOR_PARTIAL_BLOCK_HASH: BlockHash = BlockHash(Felt::ZERO);
176+
177+
/// Hash of [`PartialBlockHashComponents`].
178+
/// Uses the same formula as [`calculate_block_hash`] with the fixed constants above for the
179+
/// state root and parent hash..
180+
fn from_partial_block_hash_components(
181+
partial_block_hash_components: &PartialBlockHashComponents,
182+
) -> StarknetApiResult<Self> {
183+
let block_hash = calculate_block_hash(
184+
partial_block_hash_components,
185+
Self::GLOBAL_ROOT_FOR_PARTIAL_BLOCK_HASH,
186+
Self::PARENT_HASH_FOR_PARTIAL_BLOCK_HASH,
187+
)?;
188+
Ok(PartialBlockHash(block_hash.0))
189+
}
190+
}
191+
168192
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
169193
/// All information required to calculate a block hash except for the state root and the parent
170194
/// block hash.

0 commit comments

Comments
 (0)