pub struct Pollard {
    pub leaves: u64,
    /* private fields */
}
Expand description

The actual Pollard accumulator, it implements all methods required to update the forest and to prove/verify membership.

Fields§

§leaves: u64

The number of leaves in the forest. Actually, this is the number of leaves we ever added to the forest.

Implementations§

source§

impl Pollard

source

pub fn new() -> Pollard

Creates a new empty Pollard.

Example
use rustreexo::accumulator::pollard::Pollard;
let mut pollard = Pollard::new();
source

pub fn serialize<W: Write>(&self, writer: W) -> Result<()>

Writes the Pollard to a writer. Used to send the accumulator over the wire or to disk.

Example
use rustreexo::accumulator::pollard::Pollard;

let mut pollard = Pollard::new();
let mut serialized = Vec::new();
pollard.serialize(&mut serialized).unwrap();

assert_eq!(
    serialized,
    vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
);
source

pub fn deserialize<R: Read>(reader: R) -> Result<Pollard>

Deserializes a pollard from a reader.

Example
use std::io::Cursor;

use rustreexo::accumulator::pollard::Pollard;
let mut serialized = Cursor::new(vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
let pollard = Pollard::deserialize(&mut serialized).unwrap();
assert_eq!(pollard.leaves, 0);
assert_eq!(pollard.get_roots().len(), 0);
source

pub fn prove(&self, targets: &[NodeHash]) -> Result<Proof, String>

Proves that a given set of hashes is in the accumulator. It returns a proof and the hashes that we what to prove, but sorted by position in the tree.

Example
use rustreexo::accumulator::node_hash::NodeHash;
use rustreexo::accumulator::pollard::Pollard;
let mut pollard = Pollard::new();
let hashes = vec![0, 1, 2, 3, 4, 5, 6, 7]
    .iter()
    .map(|n| NodeHash::from([*n; 32]))
    .collect::<Vec<_>>();
pollard.modify(&hashes, &[]).unwrap();
// We want to prove that the first two hashes are in the accumulator.
let proof = pollard.prove(&[hashes[1], hashes[0]]).unwrap();
//TODO: Verify the proof
source

pub fn get_roots(&self) -> &[Rc<Node>]

Returns a reference to the roots in this Pollard.

source

pub fn modify( &mut self, add: &[NodeHash], del: &[NodeHash] ) -> Result<(), String>

Modify is the main API to a Pollard. Because order matters, you can only modify a Pollard, and internally it’ll add and delete, in the correct order.

This method accepts two vectors as parameter, a vec of Hash and a vec of u64. The first one is a vec of leaf hashes for the newly created UTXOs. The second one is the position for the UTXOs being spent in this block as inputs.

Example
use bitcoin_hashes::sha256::Hash as Data;
use bitcoin_hashes::Hash;
use bitcoin_hashes::HashEngine;
use rustreexo::accumulator::node_hash::NodeHash;
use rustreexo::accumulator::pollard::Pollard;
let values = vec![0, 1, 2, 3, 4, 5, 6, 7];
let hashes = values
    .into_iter()
    .map(|val| {
        let mut engine = Data::engine();
        engine.input(&[val]);
        NodeHash::from(Data::from_engine(engine).as_byte_array())
    })
    .collect::<Vec<_>>();
// Add 8 leaves to the pollard
let mut p = Pollard::new();
p.modify(&hashes, &[]).expect("Pollard should not fail");

assert_eq!(
    p.get_roots()[0].get_data().to_string(),
    String::from("b151a956139bb821d4effa34ea95c17560e0135d1e4661fc23cedc3af49dac42")
);
source

pub fn grab_node( &self, pos: u64 ) -> Result<(Rc<Node>, Rc<Node>, Rc<Node>), String>

source

pub fn verify( &self, proof: &Proof, del_hashes: &[NodeHash] ) -> Result<bool, String>

Trait Implementations§

source§

impl Clone for Pollard

source§

fn clone(&self) -> Pollard

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 Pollard

source§

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

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

impl Default for Pollard

source§

fn default() -> Pollard

Returns the “default value” for a type. Read more
source§

impl Display for Pollard

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Pollard

§

impl !Send for Pollard

§

impl !Sync for Pollard

§

impl Unpin for Pollard

§

impl !UnwindSafe for Pollard

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.