Proof

Build Status License

Proof is library for validating and manipulating merkle proofs of partial objects.

The library conforms with the evolving Ethereum 2.0 specification merkle proof partials. Until version 1.0, expect the API to be unstable.

Getting Started

Add the following to your projects Cargo.toml under [dependencies]:

proof = { git = "https://github.com/c-o-l-o-r/proof" } proof_derive = { git = "https://github.com/c-o-l-o-r/proof" } If you plan to use ssz_types, also add:

ssz_types = { git = "https://github.com/sigp/lighthouse" }

Example

```rust // S's merkle tree representation // // root(0) // / \ // a(1) b(2) -----+ // / \ // +-- data(5) --+ len(6) // / \ // i(11) i(12) // / \ / \ // b0,1 b2,3 b4,5 b6,7

use proof::{Proof, Path, SerializedProof, hash_children};

[derive(Provable)]

struct S { a: u64, b: VariableList, }

fn main() { // Build the 32-byte chunks let one = vec![0u8; 32]; let six = vec![0u8; 32]; let twelve = hashchildren(&[0u8; 32], &[0u8; 32]); let twentythree = vec![1u8; 32]; let twenty_four = vec![2u8; 32];

// Generate the proof
let serialized_proof = SerializedProof {
    indices: vec![1, 6, 12, 23, 24],
    chunks: vec![one, six, twelve, twenty_three, twenty_four].into_iter().flatten().collect(),
};

// Load the proof
let mut proof = Proof::<S>::new(serialized_proof.clone());

// Fill in chunks that can be inferred
assert_eq!(proof.fill(), Ok(()));

// Extract a proof to `S.b[2]`
assert_eq!(
    proof.extract(vec![Path::Ident("b".to_string()), Path::Index(2)]),
    Ok(serialized_proof)
);

} ```

For additional usage examples, see the tests directory.

License

Licensed under Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)