Struct grin_core::pow::Proof

source ·
pub struct Proof {
    pub edge_bits: u8,
    pub nonces: Vec<u64>,
}
Expand description

A Cuck(at)oo Cycle proof of work, consisting of the edge_bits to get the graph size (i.e. the 2-log of the number of edges) and the nonces of the graph solution. While being expressed as u64 for simplicity, nonces a.k.a. edge indices range from 0 to (1 << edge_bits) - 1

The hash of the Proof is the hash of its packed nonces when serializing them at their exact bit size. The resulting bit sequence is padded to be byte-aligned. We form a PROOFSIZE*edge_bits integer by packing the PROOFSIZE edge indices together, with edge index i occupying bits i * edge_bits through (i+1) * edge_bits - 1, padding it with up to 7 0-bits to a multiple of 8 bits, writing as a little endian byte array, and hashing with blake2b using 256 bit digest.

Fields§

§edge_bits: u8

Power of 2 used for the size of the cuckoo graph

§nonces: Vec<u64>

The nonces

Implementations§

source§

impl Proof

source

pub fn new(in_nonces: Vec<u64>) -> Proof

Builds a proof with provided nonces at default edge_bits

source

pub fn zero(proof_size: usize) -> Proof

Builds a proof with all bytes zeroed out

source

pub fn pack_len(bit_width: u8) -> usize

Number of bytes required store a proof of given edge bits

source

pub fn random(proof_size: usize) -> Proof

Builds a proof with random POW data, needed so that tests that ignore POW don’t fail due to duplicate hashes

source

pub fn proof_size(&self) -> usize

Returns the proof size

source

pub fn pack_nonces(&self) -> Vec<u8>

Pack the nonces of the proof to their exact bit size as described above

Trait Implementations§

source§

impl Clone for Proof

source§

fn clone(&self) -> Proof

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Proof

source§

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

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

impl PartialEq for Proof

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Proof

source§

fn partial_cmp(&self, other: &Proof) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Readable for Proof

source§

fn read<R: Reader>(reader: &mut R) -> Result<Proof, Error>

Reads the data necessary to this Readable from the provided reader
source§

impl Serialize for Proof

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Writeable for Proof

source§

fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error>

Write the data held by this Writeable to the provided writer
source§

impl DefaultHashable for Proof

source§

impl Eq for Proof

source§

impl StructuralPartialEq for Proof

Auto Trait Implementations§

§

impl Freeze for Proof

§

impl RefUnwindSafe for Proof

§

impl Send for Proof

§

impl Sync for Proof

§

impl Unpin for Proof

§

impl UnwindSafe for Proof

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> CloneAny for T
where T: Any + Clone,

source§

fn clone_any(&self) -> Box<dyn CloneAny>

source§

fn clone_any_send(&self) -> Box<dyn CloneAny + Send>
where T: Send,

source§

fn clone_any_sync(&self) -> Box<dyn CloneAny + Sync>
where T: Sync,

source§

fn clone_any_send_sync(&self) -> Box<dyn CloneAny + Send + Sync>
where T: Send + Sync,

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<D> Hashed for D
where D: DefaultHashable,

source§

fn hash(&self) -> Hash

Obtain the hash of the object
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> PMMRIndexHashable for T
where T: DefaultHashable,

source§

fn hash_with_index(&self, index: u64) -> Hash

Hash with a given index
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<H> ShortIdentifiable for H
where H: Hashed,

source§

fn short_id(&self, hash: &Hash, nonce: u64) -> ShortId

Generate a short_id via the following -

  • extract k0/k1 from block_hash hashed with the nonce (first two u64 values) * initialize a siphasher24 with k0/k1
    • self.hash() passing in the siphasher24 instance
    • drop the 2 most significant bytes (to return a 6 byte short_id)
source§

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

§

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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

impl<T> DebugAny for T
where T: Any + Debug,

source§

impl<T> UnsafeAny for T
where T: Any,