Skip to content

Latest commit

 

History

History
57 lines (36 loc) · 2.17 KB

getting-started.md

File metadata and controls

57 lines (36 loc) · 2.17 KB

Getting started

This program hashes three records, checks an inclusion proof for each, then checks that a fourth record is an append. It uses only rfc9162. Storage and signatures are the tutorial.

Install Rust from the installation page, then:

cargo new ct-log
cd ct-log
cargo add rfc9162@0.10.0

Replace src/main.rs with the program below and run cargo run.

The head

leaf_hash hashes each record. Head::over is the size and the hexadecimal root.

{{#rustdoc_include ../examples/src/bin/getting_started.rs:records}}

Inclusion

inclusion_proof returns the sibling hashes for one index, innermost first. verify_inclusion folds that path back to the root. The inclusion page draws the path for beta.

{{#rustdoc_include ../examples/src/bin/getting_started.rs:inclusion}}

Consistency

The second head is the same three records plus delta. consistency_proof returns the nodes that recompute both roots. verify_consistency accepts the pair when the later tree is the earlier tree with entries appended. The consistency page lists the three nodes in this proof.

{{#rustdoc_include ../examples/src/bin/getting_started.rs:consistency}}

Bytes a signature can cover

Head::material is the domain, the size and the root, separated by tabs. The domain names the log. The tile crate signs a C2SP checkpoint over the same size and root.

{{#rustdoc_include ../examples/src/bin/getting_started.rs:material}}

Output

cargo run -q prints:

{{#include output/getting_started.txt}}

The root at size 3 is 385da30f3917282c8939dff851957e519ab1846b1351a14c0adb3b11632742aa. alpha and beta each need two siblings. gamma needs one. The consistency proof from size 3 to size 4 has three nodes, and the check returns true.

Next, build the same log on disk and read the proofs back from the store.