Skip to main content

Blake2bV2Header

Struct Blake2bV2Header 

Source
pub struct Blake2bV2Header {
Show 16 fields pub version: u32, pub prev_block_hash: BlockHash, pub merkle_root: [u8; 32], pub time_on_wire: u32, pub bits: u32, pub nonce: u32, pub nonce2: u32, pub nonce3: u32, pub extranonce: [u8; 16], pub time_offset: u32, pub tx_count: u16, pub flags: u8, pub xor_key_mask_clear_bits: u8, pub xor_key: [u8; 16], pub height: u32, pub mm_rhs: [u8; 32],
}
Expand description

The 164-byte header used from the BLAKE2b fork height — on a sidestr chain beside a BLAKE2b parent, from height 0 (siding/lib/overlay.mjs: blake2bHeight: 0).

The layout below is the kernel’s knots:BlockHeaderV2 struct with its field comments adapted. The first 80 bytes keep the classic layout (version with bit 31 set; the wire time may be offset); proof of work is the BLAKE2b construction over a commitment tree of these fields, not SHA-256d of the bytes.

offsetsizefieldwire
04versionu32le, bit 31 set
432prev_block_hashhash256
3632merkle_roothash256
684time_on_wireu32le
724bitsu32le
764nonceu32le
804nonce2u32le
844nonce3u32le
8816extranoncebytes, wire order
1044time_offsetu32le
1082tx_countu16le
1101flagsu8
1111xor_key_mask_clear_bitsu8
11216xor_keybytes, wire order
1284heighti32le
13232mm_rhshash256

Beside a BLAKE2b parent siding’s buildBlock sets version = 0xa000_0000, every nonce, the extranonce, the XOR key and mm_rhs to zero, flags = 0, tx_count to the block’s transaction count and height to the block’s height; only nonce moves while the block is sealed against powLimit.

use sidestr_header::{Blake2bV2Header, fork};
// txbt4 block 150,308, the fork block: the first v2 / BLAKE2b header.
// Captured from a Knots 29.4.1 node (bitcoin-desktop/schema test vectors).
let bytes = hex::decode(
    "000000a0ccb157caa788400a667f6c19858ee913c701a42c8d1cd85122ec17000000000043d2e57990429ae581621ce01aa5fbf5e4c2723996be18660a4930b91e96d6c871b4946affff001dce0ac801d123881f71b4946a00000000b10cf00d0100000000000000000000008e00000000000000000000000000000000000000244b02000000000000000000000000000000000000000000000000000000000000000000",
).unwrap();
let h = Blake2bV2Header::decode(&bytes).unwrap();
assert_eq!(h.height, fork::TXBT4_FORK_HEIGHT);
assert_eq!(h.hash(), fork::TXBT4_FORK_HASH);
assert_eq!(h.tx_count, 142);
assert_eq!(h.flags, 0); // ASIC profile 0, no time offset
assert_eq!(h.encode().as_slice(), bytes.as_slice());

Fields§

§version: u32

Raw wire version: bit 31 set marks a v2 header; the low bits carry the usual version.

§prev_block_hash: BlockHash

The previous block’s hash.

§merkle_root: [u8; 32]

The transaction merkle root in wire (internal) order.

§time_on_wire: u32

Block time as serialised. The consensus time is time_on_wire + time_offset when flags bit 2 is set; see Self::time.

§bits: u32

Compact proof-of-work target.

§nonce: u32

The first nonce.

§nonce2: u32

The second nonce.

§nonce3: u32

The third nonce.

§extranonce: [u8; 16]

128-bit extranonce, wire order (bitcoind’s RPC shows it byte-reversed).

§time_offset: u32

The offset added to time_on_wire when flags bit 2 is set; also a nonce input to the second BLAKE2b round.

§tx_count: u16

Committed transaction count; must equal the block’s transaction count (knots:rule-block-txcount).

§flags: u8

Bits 0–1: ASIC layout profile; bit 2: time offset in use; bits 6–7 reserved for future hardforks (must be 0).

§xor_key_mask_clear_bits: u8

How many leading bits of the PoW XOR mask are cleared.

§xor_key: [u8; 16]

128-bit PoW XOR key, wire order.

§height: u32

Committed height; must equal the previous header’s height + 1 (knots:rule-header-height). Serialised i32le; held unsigned.

§mm_rhs: [u8; 32]

Merge-mining hook right-hand side, wire order (reserved; all zeros so far).

Implementations§

Source§

impl Blake2bV2Header

Source

pub const WIRE_SIZE: usize = 164

Wire size in bytes.

Source

pub fn decode(bytes: &[u8]) -> Result<Self, Error>

Decodes exactly 164 bytes. Rejects any other length (Error::WrongLength) and a version with bit 31 clear (Error::VersionBit31Clear). Reserved flag bits are not checked here — the kernel decodes them and its rule rejects them — see Self::check_flags.

Source

pub fn encode(&self) -> [u8; 164]

The 164 wire bytes.

Source

pub fn time(&self) -> u32

The consensus block time: time_on_wire + time_offset (wrapping) when flags bit 2 is set, else time_on_wire (headerTime in the kernel).

Source

pub fn uses_time_offset(&self) -> bool

Whether flags bit 2 is set.

Source

pub fn asic_profile(&self) -> u8

flags & 3: which ASIC input layout the second BLAKE2b round uses.

Source

pub fn check_flags(&self) -> Result<(), Error>

knots:rule-header-flags-reserved: bits 6–7 of flags must be zero.

Source

pub fn hash(&self) -> BlockHash

The block hash, which is the proof-of-work hash (hashHeaderV2):

h1   = tagged("Bitcoin block header 1",
              version ‖ prev(display) ‖ height ‖ merkle(wire) ‖ time_on_wire ‖ 0x00
              ‖ bits ‖ tx_count as u32 ‖ flags ‖ clear_bits ‖ tagged("…XOR key", xor_key))
h2   = tagged("Merge-mining hook", h1 ‖ 0¹⁶ ‖ 0¹⁶ ‖ mm_rhs(wire))
b1   = blake2b-256(0u32 ‖ h2 ‖ extranonce)
b2   = blake2b-256(profile-dependent layout of prev_hidden / h2, nonces, b1)
hash = b2 XOR mask(xor_key, clear_bits)          (display-order bytes)

Note the two byte orders inside round one: prev_block_hash enters in display order (Knots’ hashPrevBlock.ReversedBytes()) while the merkle root enters in wire order.

Source

pub fn hash_stages(&self) -> V2HashStages

The pipeline with every intermediate exposed.

Source

pub fn target(&self) -> Result<Target, Error>

The target bits encodes.

Source

pub fn meets_target(&self) -> bool

hash ≤ target(bits): the kernel’s checkProofOfWork. False when bits does not decode.

Source

pub fn check_pow(&self, pow_limit: &Target) -> Result<(), Error>

SPEC 4 step 1 as siding applies it: bits must be the compact form of pow_limit and the hash must meet it.

Source

pub fn signet_preimage(&self, stripped_merkle_root: [u8; 32]) -> [u8; 72]

The first 72 header bytes — version ‖ prev ‖ merkle_root ‖ time_on_wire — with merkle_root replaced by stripped_merkle_root. Same shape as the stock family’s, which is what makes the BIP-325 block data family-agnostic (siding/lib/block.mjs blockData).

Source

pub fn block_data(&self, stripped_merkle_root: [u8; 32]) -> [u8; 32]

The BIP-325 block data, SHA256(signet_preimage) (SPEC 4 step 2).

Trait Implementations§

Source§

impl Clone for Blake2bV2Header

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Blake2bV2Header

Source§

impl Debug for Blake2bV2Header

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Blake2bV2Header

Source§

impl PartialEq for Blake2bV2Header

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Blake2bV2Header

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.