pub struct BlockHeader { /* private fields */ }Expand description
The header of a block. It contains metadata about the block, commitments to the current state of the chain and the hash of the proof that attests to the integrity of the chain.
A block header includes the following fields:
versionspecifies the version of the block header itself. It changes when fields are added to or removed from the header, and when the scheme behind one of the header’s commitments changes, for example the structure of the SMTs or of the MMR.timestampis the time when the block was created, in seconds since UNIX epoch. The u32 is sufficient to represent timestamps up to year 2106.block_numis a unique sequential number of the current block.prev_block_commitmentis the hash of the previous block header.chain_commitmentis a commitment to an MMR of the entire chain where each block is a leaf.account_rootis a commitment to account database.nullifier_rootis a commitment to the nullifier database.note_rootis a commitment to all notes created in the current block.tx_commitmentis a commitment to the set of transaction IDs which affected accounts in the block.validator_configis the set of validator public keys authorized to sign the next block, together with the quorum, seeValidatorConfigfor more details.fee_parametersare the parameters defining the base fees, seeFeeParametersfor more details.protocol_config_commitmentis the commitment to the chain’sProtocolConfig.next_protocol_configis the scheduled protocol upgrade, if any, seeNextProtocolConfigfor more details.sub_commitmentis a sequential hash of all fields except the note_root.commitmentis a 2-to-1 hash of the sub_commitment and the note_root.
Implementations§
Source§impl BlockHeader
impl BlockHeader
Sourcepub fn new(
prev_block_commitment: Word,
block_num: BlockNumber,
chain_commitment: Word,
account_root: Word,
nullifier_root: Word,
note_root: Word,
tx_commitment: Word,
validator_config: ValidatorConfig,
fee_parameters: FeeParameters,
protocol_config_commitment: Word,
next_protocol_config: Option<NextProtocolConfig>,
timestamp: u32,
) -> Self
pub fn new( prev_block_commitment: Word, block_num: BlockNumber, chain_commitment: Word, account_root: Word, nullifier_root: Word, note_root: Word, tx_commitment: Word, validator_config: ValidatorConfig, fee_parameters: FeeParameters, protocol_config_commitment: Word, next_protocol_config: Option<NextProtocolConfig>, timestamp: u32, ) -> Self
Creates a new block header.
Sourcepub fn commitment(&self) -> Word
pub fn commitment(&self) -> Word
Returns the commitment of the block header.
Sourcepub fn sub_commitment(&self) -> Word
pub fn sub_commitment(&self) -> Word
Returns the sub commitment of the block header.
The sub commitment is a sequential hash of all block header fields except the note root. This is used in the block commitment computation which is a 2-to-1 hash of the sub commitment and the note root [hash(sub_commitment, note_root)]. This procedure is used to make the note root easily accessible without having to unhash the entire header.
Sourcepub fn prev_block_commitment(&self) -> Word
pub fn prev_block_commitment(&self) -> Word
Returns the commitment to the previous block header.
Sourcepub fn block_num(&self) -> BlockNumber
pub fn block_num(&self) -> BlockNumber
Returns the block number.
Sourcepub fn block_epoch(&self) -> u16
pub fn block_epoch(&self) -> u16
Returns the epoch to which this block belongs.
This is the block number shifted right by BlockNumber::EPOCH_LENGTH_EXPONENT.
Sourcepub fn chain_commitment(&self) -> Word
pub fn chain_commitment(&self) -> Word
Returns the chain commitment.
Sourcepub fn account_root(&self) -> Word
pub fn account_root(&self) -> Word
Returns the account database root.
Sourcepub fn nullifier_root(&self) -> Word
pub fn nullifier_root(&self) -> Word
Returns the nullifier database root.
Sourcepub fn validator_config(&self) -> &ValidatorConfig
pub fn validator_config(&self) -> &ValidatorConfig
Returns the validator configuration authorized to sign the next block.
A block’s signatures are verified against the validator_config committed to by its parent
block, not against this field. See the BlockHeader docs for details.
Sourcepub fn tx_commitment(&self) -> Word
pub fn tx_commitment(&self) -> Word
Returns the commitment to all transactions in this block.
The commitment is computed as sequential hash of (transaction_id, account_id) tuples.
This makes it possible for the verifier to link transaction IDs to the accounts which
they were executed against.
Sourcepub fn fee_parameters(&self) -> &FeeParameters
pub fn fee_parameters(&self) -> &FeeParameters
Returns a reference to the FeeParameters in this header.
Sourcepub fn protocol_config_commitment(&self) -> Word
pub fn protocol_config_commitment(&self) -> Word
Returns the commitment to the chain’s
ProtocolConfig.
Sourcepub fn next_protocol_config(&self) -> Option<&NextProtocolConfig>
pub fn next_protocol_config(&self) -> Option<&NextProtocolConfig>
Returns the protocol upgrade scheduled by this block, if any.
Sourcepub fn next_protocol_config_commitment(&self) -> Word
pub fn next_protocol_config_commitment(&self) -> Word
Returns the commitment to the scheduled protocol upgrade, or Word::empty if no upgrade
is scheduled.
Sourcepub fn timestamp(&self) -> u32
pub fn timestamp(&self) -> u32
Returns the timestamp at which the block was created, in seconds since UNIX epoch.
Sourcepub fn epoch_block_num(&self) -> BlockNumber
pub fn epoch_block_num(&self) -> BlockNumber
Returns the block number of the epoch block to which this block belongs.
Sourcepub fn to_elements(&self) -> Vec<Felt>
pub fn to_elements(&self) -> Vec<Felt>
Returns this header as a sequence of field elements.
The element layout is:
[
[version, block_num, timestamp, 0],
PREV_BLOCK_COMMITMENT,
CHAIN_COMMITMENT,
ACCOUNT_ROOT,
NULLIFIER_ROOT,
TX_COMMITMENT,
PROTOCOL_CONFIG_COMMITMENT,
VALIDATOR_CONFIG_COMMITMENT,
NEXT_PROTOCOL_CONFIG_COMMITMENT,
[verification_base_fee, 0, 0, 0],
NOTE_ROOT,
]This is the canonical encoding of a header. It is the layout of the kernel’s block data
memory section and the order in which the header is provided to the kernel, so keep it in
sync with the kernel’s process_block_data procedure.
Note that BlockHeader::commitment is not the sequential hash of these elements: the
note root is hashed separately so that it stays accessible without unhashing the whole
header. All elements but the trailing note root form the preimage of
BlockHeader::sub_commitment.
Trait Implementations§
Source§impl Clone for BlockHeader
impl Clone for BlockHeader
Source§impl Debug for BlockHeader
impl Debug for BlockHeader
Source§impl Deserializable for BlockHeader
impl Deserializable for BlockHeader
Source§fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>
source, attempts to deserialize these bytes
into Self, and returns the result. Read moreSource§fn min_serialized_size() -> usize
fn min_serialized_size() -> usize
Source§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
Source§fn read_from_bytes_with_budget(
bytes: &[u8],
budget: usize,
) -> Result<Self, DeserializationError>
fn read_from_bytes_with_budget( bytes: &[u8], budget: usize, ) -> Result<Self, DeserializationError>
Self from bytes with a byte budget limit. Read moreimpl Eq for BlockHeader
Source§impl PartialEq for BlockHeader
impl PartialEq for BlockHeader
Source§impl Serializable for BlockHeader
impl Serializable for BlockHeader
Source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
self into bytes and writes these bytes into the target.Source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
impl StructuralPartialEq for BlockHeader
Auto Trait Implementations§
impl Freeze for BlockHeader
impl RefUnwindSafe for BlockHeader
impl Send for BlockHeader
impl Sync for BlockHeader
impl Unpin for BlockHeader
impl UnsafeUnpin for BlockHeader
impl UnwindSafe for BlockHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more