Skip to content

Commit

Permalink
feat: add members of block header
Browse files Browse the repository at this point in the history
  • Loading branch information
yair-starkware committed Feb 5, 2024
1 parent b70d655 commit 766d822
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ mod block_test;
use derive_more::Display;
use serde::{Deserialize, Serialize};

use crate::core::{ContractAddress, GlobalRoot, SequencerPublicKey};
use crate::core::{
EventCommitment, GlobalRoot, SequencerContractAddress, SequencerPublicKey,
TransactionCommitment,
};
use crate::crypto::{verify_message_hash_signature, CryptoError, Signature};
use crate::data_availability::L1DataAvailabilityMode;
use crate::hash::{poseidon_hash_array, StarkHash};
use crate::serde_utils::{BytesAsHex, PrefixedBytesAsHex};
use crate::transaction::{Transaction, TransactionHash, TransactionOutput};
Expand All @@ -26,12 +30,18 @@ pub struct BlockHeader {
pub block_hash: BlockHash,
pub parent_hash: BlockHash,
pub block_number: BlockNumber,
pub eth_l1_gas_price: GasPrice,
pub strk_l1_gas_price: GasPrice,
pub l1_gas_price: GasPricePerToken,
pub l1_data_gas_price: GasPricePerToken,
pub state_root: GlobalRoot,
pub sequencer: ContractAddress,
pub sequencer: SequencerContractAddress,
pub timestamp: BlockTimestamp,
// TODO: add missing commitments.
pub l1_da_mode: L1DataAvailabilityMode,
pub transaction_commitment: TransactionCommitment,
pub event_commitment: EventCommitment,
pub n_transactions: usize,
pub n_events: usize,
// TODO: add missing state diff commitment.
// TODO: add protocol version (starknet version).
}

/// The [transactions](`crate::transaction::Transaction`) and their
Expand Down Expand Up @@ -112,6 +122,16 @@ impl BlockNumber {
}
}

// TODO(yair): Consider moving GasPricePerToken and GasPrice to core.
/// The gas price per token.
#[derive(
Debug, Copy, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord,
)]
pub struct GasPricePerToken {
pub price_in_fri: GasPrice,
pub price_in_wei: GasPrice,
}

/// The gas price at a [Block](`crate::block::Block`).
#[derive(
Debug, Copy, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord,
Expand Down
37 changes: 37 additions & 0 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,40 @@ pub struct EntryPointSelector(pub StarkHash);
)]
pub struct GlobalRoot(pub StarkHash);

/// The commitment on the transactions in a [Block](`crate::block::Block`).
#[derive(
Debug,
Copy,
Clone,
Default,
Eq,
PartialEq,
Hash,
Deserialize,
Serialize,
PartialOrd,
Ord,
Display,
)]
pub struct TransactionCommitment(pub StarkHash);

/// The commitment on the events in a [Block](`crate::block::Block`).
#[derive(
Debug,
Copy,
Clone,
Default,
Eq,
PartialEq,
Hash,
Deserialize,
Serialize,
PartialOrd,
Ord,
Display,
)]
pub struct EventCommitment(pub StarkHash);

/// A key for nodes of a Patricia tree.
// Invariant: key is in range.
#[derive(
Expand Down Expand Up @@ -321,3 +355,6 @@ impl From<EthAddress> for PrefixedBytesAsHex<20_usize> {
Debug, Copy, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord,
)]
pub struct SequencerPublicKey(pub PublicKey);

#[derive(Debug, Default, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
pub struct SequencerContractAddress(pub ContractAddress);
10 changes: 10 additions & 0 deletions src/data_availability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ impl From<DataAvailabilityMode> for StarkFelt {
}
}
}

#[derive(
Clone, Default, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum L1DataAvailabilityMode {
#[default]
Calldata,
Blob,
}

0 comments on commit 766d822

Please sign in to comment.