Add value back to Proof.

This commit is contained in:
Romain Ruetschi
2016-11-21 22:22:08 +01:00
parent b395f224f5
commit 011c10cd81
6 changed files with 135 additions and 63 deletions

View File

@ -4,6 +4,7 @@ syntax = "proto3";
message ProofProto { message ProofProto {
bytes root_hash = 1; bytes root_hash = 1;
LemmaProto lemma = 2; LemmaProto lemma = 2;
bytes value = 3;
} }
message LemmaProto { message LemmaProto {

View File

@ -112,13 +112,13 @@ impl <D, T> MerkleTree<D, T> where D: Digest + Clone, T: Into<Vec<u8>> + Clone {
/// Generate an inclusion proof for the given value. /// Generate an inclusion proof for the given value.
/// Returns `None` if the given value is not found in the tree. /// Returns `None` if the given value is not found in the tree.
pub fn gen_proof(&self, value: &T) -> Option<Proof<D, T>> { pub fn gen_proof(&self, value: T) -> Option<Proof<D, T>> {
let mut digest = self.digest.clone(); let mut digest = self.digest.clone();
let root_hash = self.root_hash().clone(); let root_hash = self.root_hash().clone();
let node_hash = digest.hash_bytes(&value.clone().into()); let node_hash = digest.hash_bytes(&value.clone().into());
Lemma::new(&self.root, &node_hash).map(|lemma| Lemma::new(&self.root, &node_hash).map(|lemma|
Proof::new(digest, root_hash, lemma) Proof::new(digest, root_hash, lemma, value)
) )
} }

View File

@ -1,6 +1,4 @@
use std::marker::PhantomData;
use crypto::digest::Digest; use crypto::digest::Digest;
use tree::Tree; use tree::Tree;
@ -20,18 +18,19 @@ pub struct Proof<D, T> {
/// The first `Lemma` of the `Proof` /// The first `Lemma` of the `Proof`
pub lemma: Lemma, pub lemma: Lemma,
_value_marker: PhantomData<T> /// The value concerned by this `Proof`
pub value: T
} }
impl <D, T> Proof<D, T> { impl <D, T> Proof<D, T> {
/// Constructs a new `Proof` /// Constructs a new `Proof`
pub fn new(digest: D, root_hash: Vec<u8>, lemma: Lemma) -> Self { pub fn new(digest: D, root_hash: Vec<u8>, lemma: Lemma, value: T) -> Self {
Proof { Proof {
digest: digest, digest: digest,
root_hash: root_hash, root_hash: root_hash,
lemma: lemma, lemma: lemma,
_value_marker: PhantomData value: value
} }
} }

View File

@ -11,22 +11,28 @@ use protobuf::core::parse_from_bytes;
impl <D, T> Proof<D, T> { impl <D, T> Proof<D, T> {
/// Constructs a `Proof` struct from its Protobuf representation. /// Constructs a `Proof` struct from its Protobuf representation.
pub fn from_protobuf(digest: D, proto: ProofProto) -> Option<Self> { pub fn from_protobuf(digest: D, proto: ProofProto) -> Option<Self>
where T: From<Vec<u8>>
{
proto.into_proof(digest) proto.into_proof(digest)
} }
/// Encode this `Proof` to its Protobuf representation. /// Encode this `Proof` to its Protobuf representation.
pub fn into_protobuf(self) -> ProofProto { pub fn into_protobuf(self) -> ProofProto
where T: Into<Vec<u8>>
{
ProofProto::from_proof(self) ProofProto::from_proof(self)
} }
/// Parse a `Proof` from its Protobuf binary representation. /// Parse a `Proof` from its Protobuf binary representation.
pub fn parse_from_bytes(bytes: &[u8], digest: D) -> ProtobufResult<Option<Proof<D, T>>> { pub fn parse_from_bytes(bytes: &[u8], digest: D) -> ProtobufResult<Option<Proof<D, T>>>
where T: From<Vec<u8>>
{
parse_from_bytes::<ProofProto>(bytes).map(|proto| proto.into_proof(digest)) parse_from_bytes::<ProofProto>(bytes).map(|proto| proto.into_proof(digest))
} }
/// Serialize this `Proof` with Protobuf. /// Serialize this `Proof` with Protobuf.
pub fn write_to_bytes(self) -> ProtobufResult<Vec<u8>> { pub fn write_to_bytes(self) -> ProtobufResult<Vec<u8>> where T: Into<Vec<u8>> {
self.into_protobuf().write_to_bytes() self.into_protobuf().write_to_bytes()
} }
@ -34,20 +40,25 @@ impl <D, T> Proof<D, T> {
impl ProofProto { impl ProofProto {
pub fn from_proof<D, T>(proof: Proof<D, T>) -> Self { pub fn from_proof<D, T>(proof: Proof<D, T>) -> Self
where T: Into<Vec<u8>>
{
let mut proto = Self::new(); let mut proto = Self::new();
match proof { match proof {
Proof { root_hash, lemma, .. } => { Proof { root_hash, lemma, value, .. } => {
proto.set_root_hash(root_hash); proto.set_root_hash(root_hash);
proto.set_lemma(LemmaProto::from_lemma(lemma)); proto.set_lemma(LemmaProto::from_lemma(lemma));
proto.set_value(value.into());
} }
} }
proto proto
} }
pub fn into_proof<D, T>(mut self, digest: D) -> Option<Proof<D, T>> { pub fn into_proof<D, T>(mut self, digest: D) -> Option<Proof<D, T>>
where T: From<Vec<u8>>
{
if !self.has_root_hash() || !self.has_lemma() { if !self.has_root_hash() || !self.has_lemma() {
return None; return None;
} }
@ -56,7 +67,8 @@ impl ProofProto {
Proof::new( Proof::new(
digest, digest,
self.take_root_hash(), self.take_root_hash(),
lemma lemma,
self.take_value().into()
) )
}) })
} }

View File

@ -25,6 +25,7 @@ pub struct ProofProto {
// message fields // message fields
root_hash: ::protobuf::SingularField<::std::vec::Vec<u8>>, root_hash: ::protobuf::SingularField<::std::vec::Vec<u8>>,
lemma: ::protobuf::SingularPtrField<LemmaProto>, lemma: ::protobuf::SingularPtrField<LemmaProto>,
value: ::protobuf::SingularField<::std::vec::Vec<u8>>,
// special fields // special fields
unknown_fields: ::protobuf::UnknownFields, unknown_fields: ::protobuf::UnknownFields,
cached_size: ::std::cell::Cell<u32>, cached_size: ::std::cell::Cell<u32>,
@ -48,6 +49,7 @@ impl ProofProto {
ProofProto { ProofProto {
root_hash: ::protobuf::SingularField::none(), root_hash: ::protobuf::SingularField::none(),
lemma: ::protobuf::SingularPtrField::none(), lemma: ::protobuf::SingularPtrField::none(),
value: ::protobuf::SingularField::none(),
unknown_fields: ::protobuf::UnknownFields::new(), unknown_fields: ::protobuf::UnknownFields::new(),
cached_size: ::std::cell::Cell::new(0), cached_size: ::std::cell::Cell::new(0),
} }
@ -123,6 +125,42 @@ impl ProofProto {
pub fn get_lemma(&self) -> &LemmaProto { pub fn get_lemma(&self) -> &LemmaProto {
self.lemma.as_ref().unwrap_or_else(|| LemmaProto::default_instance()) self.lemma.as_ref().unwrap_or_else(|| LemmaProto::default_instance())
} }
// optional bytes value = 3;
pub fn clear_value(&mut self) {
self.value.clear();
}
pub fn has_value(&self) -> bool {
self.value.is_some()
}
// Param is passed by value, moved
pub fn set_value(&mut self, v: ::std::vec::Vec<u8>) {
self.value = ::protobuf::SingularField::some(v);
}
// Mutable pointer to the field.
// If field is not initialized, it is initialized with default value first.
pub fn mut_value(&mut self) -> &mut ::std::vec::Vec<u8> {
if self.value.is_none() {
self.value.set_default();
};
self.value.as_mut().unwrap()
}
// Take field
pub fn take_value(&mut self) -> ::std::vec::Vec<u8> {
self.value.take().unwrap_or_else(|| ::std::vec::Vec::new())
}
pub fn get_value(&self) -> &[u8] {
match self.value.as_ref() {
Some(v) => &v,
None => &[],
}
}
} }
impl ::protobuf::Message for ProofProto { impl ::protobuf::Message for ProofProto {
@ -140,6 +178,9 @@ impl ::protobuf::Message for ProofProto {
2 => { 2 => {
try!(::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.lemma)); try!(::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.lemma));
}, },
3 => {
try!(::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.value));
},
_ => { _ => {
try!(::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())); try!(::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields()));
}, },
@ -159,6 +200,9 @@ impl ::protobuf::Message for ProofProto {
let len = value.compute_size(); let len = value.compute_size();
my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len;
}; };
for value in &self.value {
my_size += ::protobuf::rt::bytes_size(3, &value);
};
my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
self.cached_size.set(my_size); self.cached_size.set(my_size);
my_size my_size
@ -173,6 +217,9 @@ impl ::protobuf::Message for ProofProto {
try!(os.write_raw_varint32(v.get_cached_size())); try!(os.write_raw_varint32(v.get_cached_size()));
try!(v.write_to_with_cached_sizes(os)); try!(v.write_to_with_cached_sizes(os));
}; };
if let Some(v) = self.value.as_ref() {
try!(os.write_bytes(3, &v));
};
try!(os.write_unknown_fields(self.get_unknown_fields())); try!(os.write_unknown_fields(self.get_unknown_fields()));
::std::result::Result::Ok(()) ::std::result::Result::Ok(())
} }
@ -225,6 +272,11 @@ impl ::protobuf::MessageStatic for ProofProto {
ProofProto::has_lemma, ProofProto::has_lemma,
ProofProto::get_lemma, ProofProto::get_lemma,
)); ));
fields.push(::protobuf::reflect::accessor::make_singular_bytes_accessor(
"value",
ProofProto::has_value,
ProofProto::get_value,
));
::protobuf::reflect::MessageDescriptor::new::<ProofProto>( ::protobuf::reflect::MessageDescriptor::new::<ProofProto>(
"ProofProto", "ProofProto",
fields, fields,
@ -239,6 +291,7 @@ impl ::protobuf::Clear for ProofProto {
fn clear(&mut self) { fn clear(&mut self) {
self.clear_root_hash(); self.clear_root_hash();
self.clear_lemma(); self.clear_lemma();
self.clear_value();
self.unknown_fields.clear(); self.unknown_fields.clear();
} }
} }
@ -247,6 +300,7 @@ impl ::std::cmp::PartialEq for ProofProto {
fn eq(&self, other: &ProofProto) -> bool { fn eq(&self, other: &ProofProto) -> bool {
self.root_hash == other.root_hash && self.root_hash == other.root_hash &&
self.lemma == other.lemma && self.lemma == other.lemma &&
self.value == other.value &&
self.unknown_fields == other.unknown_fields self.unknown_fields == other.unknown_fields
} }
} }
@ -650,55 +704,61 @@ impl ::std::fmt::Debug for LemmaProto {
static file_descriptor_proto_data: &'static [u8] = &[ static file_descriptor_proto_data: &'static [u8] = &[
0x0a, 0x14, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x0a, 0x14, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x70, 0x72, 0x6f, 0x6f, 0x66,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x4c, 0x0a, 0x0a, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x50, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x62, 0x0a, 0x0a, 0x50, 0x72, 0x6f, 0x6f, 0x66, 0x50,
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x68, 0x61, 0x73,
0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, 0x6f, 0x6f, 0x74, 0x48, 0x61, 0x73,
0x68, 0x12, 0x21, 0x0a, 0x05, 0x6c, 0x65, 0x6d, 0x6d, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x68, 0x12, 0x21, 0x0a, 0x05, 0x6c, 0x65, 0x6d, 0x6d, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x0b, 0x2e, 0x4c, 0x65, 0x6d, 0x6d, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x52, 0x05, 0x6c, 0x32, 0x0b, 0x2e, 0x4c, 0x65, 0x6d, 0x6d, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x52, 0x05, 0x6c,
0x65, 0x6d, 0x6d, 0x61, 0x22, 0xc1, 0x01, 0x0a, 0x0a, 0x4c, 0x65, 0x6d, 0x6d, 0x61, 0x50, 0x72, 0x65, 0x6d, 0x6d, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x03, 0x20,
0x6f, 0x74, 0x6f, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0xc1, 0x01, 0x0a, 0x0a, 0x4c,
0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x6e, 0x6f, 0x64, 0x65, 0x48, 0x61, 0x73, 0x68, 0x65, 0x6d, 0x6d, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x6f, 0x64,
0x12, 0x28, 0x0a, 0x09, 0x73, 0x75, 0x62, 0x5f, 0x6c, 0x65, 0x6d, 0x6d, 0x61, 0x18, 0x02, 0x20, 0x65, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x6e, 0x6f,
0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x4c, 0x65, 0x6d, 0x6d, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x64, 0x65, 0x48, 0x61, 0x73, 0x68, 0x12, 0x28, 0x0a, 0x09, 0x73, 0x75, 0x62, 0x5f, 0x6c, 0x65,
0x52, 0x08, 0x73, 0x75, 0x62, 0x4c, 0x65, 0x6d, 0x6d, 0x61, 0x12, 0x2c, 0x0a, 0x11, 0x6c, 0x65, 0x6d, 0x6d, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x4c, 0x65, 0x6d, 0x6d,
0x66, 0x74, 0x5f, 0x73, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x52, 0x08, 0x73, 0x75, 0x62, 0x4c, 0x65, 0x6d, 0x6d, 0x61,
0x03, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x0f, 0x6c, 0x65, 0x66, 0x74, 0x53, 0x69, 0x62, 0x12, 0x2c, 0x0a, 0x11, 0x6c, 0x65, 0x66, 0x74, 0x5f, 0x73, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67,
0x6c, 0x69, 0x6e, 0x67, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2e, 0x0a, 0x12, 0x72, 0x69, 0x67, 0x68, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x0f, 0x6c,
0x74, 0x5f, 0x73, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x04, 0x65, 0x66, 0x74, 0x53, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x48, 0x61, 0x73, 0x68, 0x12, 0x2e,
0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x10, 0x72, 0x69, 0x67, 0x68, 0x74, 0x53, 0x69, 0x62, 0x0a, 0x12, 0x72, 0x69, 0x67, 0x68, 0x74, 0x5f, 0x73, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x5f,
0x6c, 0x69, 0x6e, 0x67, 0x48, 0x61, 0x73, 0x68, 0x42, 0x0e, 0x0a, 0x0c, 0x73, 0x69, 0x62, 0x6c, 0x68, 0x61, 0x73, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x10, 0x72, 0x69,
0x69, 0x6e, 0x67, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x4a, 0xe4, 0x03, 0x0a, 0x06, 0x12, 0x04, 0x01, 0x67, 0x68, 0x74, 0x53, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x48, 0x61, 0x73, 0x68, 0x42, 0x0e,
0x00, 0x11, 0x01, 0x0a, 0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03, 0x01, 0x00, 0x12, 0x0a, 0x0a, 0x0a, 0x0a, 0x0c, 0x73, 0x69, 0x62, 0x6c, 0x69, 0x6e, 0x67, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x4a, 0xaa,
0x02, 0x04, 0x00, 0x12, 0x04, 0x03, 0x00, 0x06, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, 0x04, 0x0a, 0x06, 0x12, 0x04, 0x01, 0x00, 0x12, 0x01, 0x0a, 0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03,
0x12, 0x03, 0x03, 0x08, 0x12, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x00, 0x12, 0x03, 0x04, 0x01, 0x00, 0x12, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x00, 0x12, 0x04, 0x03, 0x00, 0x07, 0x01, 0x0a,
0x02, 0x16, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x04, 0x12, 0x04, 0x04, 0x02, 0x03, 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, 0x12, 0x03, 0x03, 0x08, 0x12, 0x0a, 0x0b, 0x0a, 0x04, 0x04,
0x14, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x05, 0x12, 0x03, 0x04, 0x02, 0x07, 0x0a, 0x00, 0x02, 0x00, 0x12, 0x03, 0x04, 0x02, 0x16, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00,
0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x01, 0x12, 0x03, 0x04, 0x08, 0x11, 0x0a, 0x0c, 0x0a, 0x04, 0x12, 0x04, 0x04, 0x02, 0x03, 0x14, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x05,
0x05, 0x04, 0x00, 0x02, 0x00, 0x03, 0x12, 0x03, 0x04, 0x14, 0x15, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x12, 0x03, 0x04, 0x02, 0x07, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x01, 0x12, 0x03,
0x00, 0x02, 0x01, 0x12, 0x03, 0x05, 0x02, 0x17, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, 0x04, 0x08, 0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x03, 0x12, 0x03, 0x04, 0x14,
0x04, 0x12, 0x04, 0x05, 0x02, 0x04, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, 0x06, 0x15, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x01, 0x12, 0x03, 0x05, 0x02, 0x17, 0x0a, 0x0d,
0x12, 0x03, 0x05, 0x02, 0x0c, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, 0x01, 0x12, 0x03, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, 0x04, 0x12, 0x04, 0x05, 0x02, 0x04, 0x16, 0x0a, 0x0c, 0x0a,
0x05, 0x0d, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, 0x03, 0x12, 0x03, 0x05, 0x15, 0x05, 0x04, 0x00, 0x02, 0x01, 0x06, 0x12, 0x03, 0x05, 0x02, 0x0c, 0x0a, 0x0c, 0x0a, 0x05, 0x04,
0x16, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x01, 0x12, 0x04, 0x08, 0x00, 0x11, 0x01, 0x0a, 0x0a, 0x0a, 0x00, 0x02, 0x01, 0x01, 0x12, 0x03, 0x05, 0x0d, 0x12, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02,
0x03, 0x04, 0x01, 0x01, 0x12, 0x03, 0x08, 0x08, 0x12, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x01, 0x03, 0x12, 0x03, 0x05, 0x15, 0x16, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x02, 0x12,
0x00, 0x12, 0x03, 0x09, 0x02, 0x16, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x04, 0x12, 0x03, 0x06, 0x02, 0x12, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x04, 0x12, 0x04, 0x06,
0x04, 0x09, 0x02, 0x08, 0x14, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x05, 0x12, 0x03, 0x02, 0x05, 0x17, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x05, 0x12, 0x03, 0x06, 0x02,
0x09, 0x02, 0x07, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x01, 0x12, 0x03, 0x09, 0x08, 0x07, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x01, 0x12, 0x03, 0x06, 0x08, 0x0d, 0x0a,
0x11, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x03, 0x12, 0x03, 0x09, 0x14, 0x15, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x03, 0x12, 0x03, 0x06, 0x10, 0x11, 0x0a, 0x0a, 0x0a,
0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x01, 0x12, 0x03, 0x0a, 0x02, 0x1b, 0x0a, 0x0d, 0x0a, 0x05, 0x02, 0x04, 0x01, 0x12, 0x04, 0x09, 0x00, 0x12, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x01, 0x01,
0x04, 0x01, 0x02, 0x01, 0x04, 0x12, 0x04, 0x0a, 0x02, 0x09, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x12, 0x03, 0x09, 0x08, 0x12, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x00, 0x12, 0x03, 0x0a,
0x01, 0x02, 0x01, 0x06, 0x12, 0x03, 0x0a, 0x02, 0x0c, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x02, 0x16, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x04, 0x12, 0x04, 0x0a, 0x02, 0x09,
0x01, 0x01, 0x12, 0x03, 0x0a, 0x0d, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x03, 0x14, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x05, 0x12, 0x03, 0x0a, 0x02, 0x07, 0x0a,
0x12, 0x03, 0x0a, 0x19, 0x1a, 0x0a, 0x0c, 0x0a, 0x04, 0x04, 0x01, 0x08, 0x00, 0x12, 0x04, 0x0c, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x00, 0x01, 0x12, 0x03, 0x0a, 0x08, 0x11, 0x0a, 0x0c, 0x0a,
0x02, 0x0f, 0x03, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x08, 0x00, 0x01, 0x12, 0x03, 0x0c, 0x08, 0x05, 0x04, 0x01, 0x02, 0x00, 0x03, 0x12, 0x03, 0x0a, 0x14, 0x15, 0x0a, 0x0b, 0x0a, 0x04, 0x04,
0x14, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x02, 0x12, 0x03, 0x0d, 0x04, 0x20, 0x0a, 0x0c, 0x01, 0x02, 0x01, 0x12, 0x03, 0x0b, 0x02, 0x1b, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01,
0x0a, 0x05, 0x04, 0x01, 0x02, 0x02, 0x05, 0x12, 0x03, 0x0d, 0x04, 0x09, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x12, 0x04, 0x0b, 0x02, 0x0a, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x06,
0x04, 0x01, 0x02, 0x02, 0x01, 0x12, 0x03, 0x0d, 0x0a, 0x1b, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x12, 0x03, 0x0b, 0x02, 0x0c, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x01, 0x12, 0x03,
0x02, 0x02, 0x03, 0x12, 0x03, 0x0d, 0x1e, 0x1f, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x03, 0x0b, 0x0d, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x01, 0x03, 0x12, 0x03, 0x0b, 0x19,
0x12, 0x03, 0x0e, 0x04, 0x21, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x05, 0x12, 0x03, 0x1a, 0x0a, 0x0c, 0x0a, 0x04, 0x04, 0x01, 0x08, 0x00, 0x12, 0x04, 0x0d, 0x02, 0x10, 0x03, 0x0a,
0x0e, 0x04, 0x09, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x01, 0x12, 0x03, 0x0e, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x08, 0x00, 0x01, 0x12, 0x03, 0x0d, 0x08, 0x14, 0x0a, 0x0b, 0x0a,
0x1c, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x03, 0x12, 0x03, 0x0e, 0x1f, 0x20, 0x62, 0x04, 0x04, 0x01, 0x02, 0x02, 0x12, 0x03, 0x0e, 0x04, 0x20, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x02, 0x02, 0x05, 0x12, 0x03, 0x0e, 0x04, 0x09, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x02,
0x01, 0x12, 0x03, 0x0e, 0x0a, 0x1b, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x02, 0x03, 0x12,
0x03, 0x0e, 0x1e, 0x1f, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x01, 0x02, 0x03, 0x12, 0x03, 0x0f, 0x04,
0x21, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x05, 0x12, 0x03, 0x0f, 0x04, 0x09, 0x0a,
0x0c, 0x0a, 0x05, 0x04, 0x01, 0x02, 0x03, 0x01, 0x12, 0x03, 0x0f, 0x0a, 0x1c, 0x0a, 0x0c, 0x0a,
0x05, 0x04, 0x01, 0x02, 0x03, 0x03, 0x12, 0x03, 0x0f, 0x1f, 0x20, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
]; ];
static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy {

View File

@ -108,7 +108,7 @@ fn test_valid_proof() {
let tree = MerkleTree::from_vec_unsafe(Sha3::sha3_256(), values.clone()); let tree = MerkleTree::from_vec_unsafe(Sha3::sha3_256(), values.clone());
let root_hash = tree.root_hash(); let root_hash = tree.root_hash();
for value in values.iter() { for value in values {
let proof = tree.gen_proof(value); let proof = tree.gen_proof(value);
let is_valid = proof.map(|p| p.validate(&root_hash)).unwrap_or(false); let is_valid = proof.map(|p| p.validate(&root_hash)).unwrap_or(false);
@ -140,7 +140,7 @@ fn test_wrong_proof() {
let root_hash = tree2.root_hash(); let root_hash = tree2.root_hash();
for value in values1.iter() { for value in values1 {
let proof = tree1.gen_proof(value); let proof = tree1.gen_proof(value);
let is_valid = proof.map(|p| p.validate(root_hash)).unwrap_or(false); let is_valid = proof.map(|p| p.validate(root_hash)).unwrap_or(false);
@ -156,7 +156,7 @@ fn test_mutate_proof_first_lemma() {
let mut i = 0; let mut i = 0;
for value in values.iter() { for value in values {
let mut proof = tree.gen_proof(value).unwrap(); let mut proof = tree.gen_proof(value).unwrap();
match i % 3 { match i % 3 {