Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: proof system v1 (from v0.1) #309

Merged
merged 35 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a21ae22
potential limit fix
QuantumExplorer Jun 30, 2024
9f64570
removed offset from proofs
QuantumExplorer Jul 1, 2024
b5f37c2
new proof system
QuantumExplorer Jul 3, 2024
414acd7
much more work on new proof system
QuantumExplorer Jul 3, 2024
04ce2b3
more work on new proof system
QuantumExplorer Jul 4, 2024
2317e81
more work on proofs
QuantumExplorer Jul 4, 2024
0482eef
much more work on proofs
QuantumExplorer Jul 4, 2024
b442876
more work on proofs
QuantumExplorer Jul 5, 2024
1e1c97e
more work
QuantumExplorer Jul 5, 2024
40b4cda
more fixes
QuantumExplorer Jul 5, 2024
e3a477d
fmt
QuantumExplorer Jul 6, 2024
89607fe
more work
QuantumExplorer Jul 6, 2024
b7f210c
Merge branch 'develop' into feat/proofV2
QuantumExplorer Jul 6, 2024
099cdd0
fixed tests for merk proofs
QuantumExplorer Jul 6, 2024
fa325e8
more work
QuantumExplorer Jul 7, 2024
f4f8d6a
more work
QuantumExplorer Jul 7, 2024
8cb7e09
more work
QuantumExplorer Jul 7, 2024
d77f865
more work
QuantumExplorer Jul 8, 2024
7beb692
all tests passing
QuantumExplorer Jul 8, 2024
14e3b42
trial
QuantumExplorer Jul 8, 2024
ab8d1e2
more work
QuantumExplorer Jul 8, 2024
8346e26
complex conditional queries
QuantumExplorer Jul 9, 2024
6f2932a
cleanup
QuantumExplorer Jul 9, 2024
c0f6aad
clippy fixes
QuantumExplorer Jul 9, 2024
33c7335
fmt
QuantumExplorer Jul 9, 2024
4f62af2
small fix
QuantumExplorer Jul 9, 2024
9827e2b
fmt
QuantumExplorer Jul 9, 2024
1a28e75
reactivated test
QuantumExplorer Jul 9, 2024
c1442bb
cleaned up merk
QuantumExplorer Jul 9, 2024
ef6f2e6
cleaned up merk
QuantumExplorer Jul 9, 2024
ded5054
small fix
QuantumExplorer Jul 9, 2024
196d9fa
cleaned up verification imports
QuantumExplorer Jul 9, 2024
e426f23
clippy fixes
QuantumExplorer Jul 9, 2024
0b09f9f
clippy fixes
QuantumExplorer Jul 9, 2024
9dba1da
added documentation
QuantumExplorer Jul 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions grovedb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ grovedb-storage = { version = "1.0.0-rc.2", path = "../storage", optional = true
grovedb-visualize = { version = "1.0.0-rc.2", path = "../visualize", optional = true }
hex = { version = "0.4.3"}
itertools = { version = "0.12.1", optional = true }
derive_more = { version = "0.99.18" }
integer-encoding = { version = "4.0.0", optional = true }
grovedb-costs = { version = "1.0.0-rc.2", path = "../costs", optional = true }
nohash-hasher = { version = "0.2.0", optional = true }
indexmap = { version = "2.2.6", optional = true }
indexmap = { version = "2.2.6"}
intmap = { version = "2.0.0", optional = true }
grovedb-path = { version = "1.0.0-rc.2", path = "../path" }
grovedbg-types = { path = "../grovedbg-types", optional = true }
Expand All @@ -45,6 +46,7 @@ harness = false

[features]
default = ["full"]
proof_debug = ["grovedb-merk/proof_debug"]
full = [
"grovedb-merk/full",
"thiserror",
Expand All @@ -55,7 +57,6 @@ full = [
"integer-encoding",
"grovedb-costs",
"nohash-hasher",
"indexmap",
"intmap"
]
visualize = [
Expand Down
6 changes: 3 additions & 3 deletions grovedb/src/batch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@
trait TreeCache<G, SR> {
fn insert(&mut self, op: &GroveDbOp, is_sum_tree: bool) -> CostResult<(), Error>;

fn get_batch_run_mode(&self) -> BatchRunMode;

Check warning on line 686 in grovedb/src/batch/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

method `get_batch_run_mode` is never used

warning: method `get_batch_run_mode` is never used --> grovedb/src/batch/mod.rs:686:8 | 683 | trait TreeCache<G, SR> { | --------- method in this trait ... 686 | fn get_batch_run_mode(&self) -> BatchRunMode; | ^^^^^^^^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default

/// We will also be returning an op mode, this is to be used in propagation
fn execute_ops_on_path(
Expand Down Expand Up @@ -1000,7 +1000,7 @@
let mut merk = cost_return_on_error!(&mut cost, merk_wrapped);
merk.set_base_root_key(root_key)
.add_cost(cost)
.map_err(|_| Error::InternalError("unable to set base root key"))
.map_err(|_| Error::InternalError("unable to set base root key".to_string()))
}

fn execute_ops_on_path(
Expand Down Expand Up @@ -1804,7 +1804,7 @@
.add_cost(cost)
} else {
Err(Error::CorruptedPath(
"cannot open a subtree as parent exists but is not a tree",
"cannot open a subtree as parent exists but is not a tree".to_string(),
))
.wrap_with_cost(OperationCost::default())
}
Expand Down Expand Up @@ -3493,7 +3493,7 @@
reference_key_query.insert_key(b"key1".to_vec());
let path_query = PathQuery::new_unsized(vec![TEST_LEAF.to_vec()], reference_key_query);
let proof = db
.prove_query(&path_query)
.prove_query(&path_query, None)
.unwrap()
.expect("should generate proof");
let verification_result = GroveDb::verify_query_raw(&proof, &path_query);
Expand Down
26 changes: 20 additions & 6 deletions grovedb/src/element/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@
#[cfg(feature = "full")]
use integer_encoding::VarInt;

#[cfg(feature = "full")]
use crate::reference_path::path_from_reference_path_type;
#[cfg(any(feature = "full", feature = "verify"))]
use crate::reference_path::{path_from_reference_path_type, ReferencePathType};
#[cfg(any(feature = "full", feature = "verify"))]
use crate::{element::SUM_ITEM_COST_SIZE, Element, Error};
use crate::reference_path::ReferencePathType;
#[cfg(feature = "full")]
use crate::{
element::{SUM_TREE_COST_SIZE, TREE_COST_SIZE},
element::{SUM_ITEM_COST_SIZE, SUM_TREE_COST_SIZE, TREE_COST_SIZE},
ElementFlags,
};
#[cfg(any(feature = "full", feature = "verify"))]
use crate::{Element, Error};

impl Element {
#[cfg(any(feature = "full", feature = "verify"))]
Expand Down Expand Up @@ -133,9 +135,15 @@
matches!(self, Element::SumTree(..))
}

#[cfg(any(feature = "full", feature = "verify"))]
/// Check if the element is a tree but not a sum tree
pub fn is_basic_tree(&self) -> bool {
matches!(self, Element::Tree(..))
}

#[cfg(any(feature = "full", feature = "verify"))]
/// Check if the element is a tree
pub fn is_tree(&self) -> bool {
pub fn is_any_tree(&self) -> bool {
matches!(self, Element::SumTree(..) | Element::Tree(..))
}

Expand All @@ -147,10 +155,16 @@

#[cfg(any(feature = "full", feature = "verify"))]
/// Check if the element is an item
pub fn is_item(&self) -> bool {
pub fn is_any_item(&self) -> bool {
matches!(self, Element::Item(..) | Element::SumItem(..))
}

#[cfg(any(feature = "full", feature = "verify"))]
/// Check if the element is an item
pub fn is_basic_item(&self) -> bool {
matches!(self, Element::Item(..))
}

#[cfg(any(feature = "full", feature = "verify"))]
/// Check if the element is a sum item
pub fn is_sum_item(&self) -> bool {
Expand Down Expand Up @@ -287,7 +301,7 @@
#[cfg(feature = "full")]
/// Get tree costs for a key value
pub fn specialized_costs_for_key_value(
key: &Vec<u8>,

Check warning on line 304 in grovedb/src/element/helpers.rs

View workflow job for this annotation

GitHub Actions / clippy

writing `&Vec` instead of `&[_]` involves a new object where a slice will do

warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do --> grovedb/src/element/helpers.rs:304:14 | 304 | key: &Vec<u8>, | ^^^^^^^^ help: change this to: `&[u8]` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg = note: `#[warn(clippy::ptr_arg)]` on by default
value: &[u8],
is_sum_node: bool,
) -> Result<u32, Error> {
Expand Down Expand Up @@ -358,9 +372,9 @@
#[cfg(feature = "full")]
/// Get the value defined cost for a serialized value
pub fn value_defined_cost(&self) -> Option<ValueDefinedCostType> {
let Some(value_cost) = self.get_specialized_cost().ok() else {
return None;
};

Check warning on line 377 in grovedb/src/element/helpers.rs

View workflow job for this annotation

GitHub Actions / clippy

this `let...else` may be rewritten with the `?` operator

warning: this `let...else` may be rewritten with the `?` operator --> grovedb/src/element/helpers.rs:375:9 | 375 | / let Some(value_cost) = self.get_specialized_cost().ok() else { 376 | | return None; 377 | | }; | |__________^ help: replace it with: `let value_cost = self.get_specialized_cost().ok()?;` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark = note: `#[warn(clippy::question_mark)]` on by default

let cost = value_cost
+ self.get_flags().as_ref().map_or(0, |flags| {
Expand Down
92 changes: 62 additions & 30 deletions grovedb/src/element/mod.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
// MIT LICENSE
//
// Copyright (c) 2021 Dash Core Group
//
// Permission is hereby granted, free of charge, to any
// person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the
// Software without restriction, including without
// limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice
// shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

//! Module for subtrees handling.
//! Subtrees handling is isolated so basically this module is about adapting
//! Merk API to GroveDB needs.
Expand All @@ -48,8 +20,8 @@ mod query;
pub use query::QueryOptions;
#[cfg(any(feature = "full", feature = "verify"))]
mod serialize;
#[cfg(feature = "full")]
use core::fmt;
#[cfg(any(feature = "full", feature = "verify"))]
use std::fmt;

use bincode::{Decode, Encode};
#[cfg(any(feature = "full", feature = "verify"))]
Expand All @@ -59,6 +31,7 @@ use grovedb_merk::estimated_costs::{LAYER_COST_SIZE, SUM_LAYER_COST_SIZE};
#[cfg(feature = "full")]
use grovedb_visualize::visualize_to_vec;

use crate::operations::proof::util::hex_to_ascii;
#[cfg(any(feature = "full", feature = "verify"))]
use crate::reference_path::ReferencePathType;

Expand Down Expand Up @@ -111,6 +84,65 @@ pub enum Element {
SumTree(Option<Vec<u8>>, SumValue, Option<ElementFlags>),
}

impl fmt::Display for Element {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Element::Item(data, flags) => {
write!(
f,
"Item({}{})",
hex_to_ascii(data),
flags
.as_ref()
.map_or(String::new(), |f| format!(", flags: {:?}", f))
)
}
Element::Reference(path, max_hop, flags) => {
write!(
f,
"Reference({}, max_hop: {}{})",
path,
max_hop.map_or("None".to_string(), |h| h.to_string()),
flags
.as_ref()
.map_or(String::new(), |f| format!(", flags: {:?}", f))
)
}
Element::Tree(root_key, flags) => {
write!(
f,
"Tree({}{})",
root_key.as_ref().map_or("None".to_string(), hex::encode),
flags
.as_ref()
.map_or(String::new(), |f| format!(", flags: {:?}", f))
)
}
Element::SumItem(sum_value, flags) => {
write!(
f,
"SumItem({}{}",
sum_value,
flags
.as_ref()
.map_or(String::new(), |f| format!(", flags: {:?}", f))
)
}
Element::SumTree(root_key, sum_value, flags) => {
write!(
f,
"SumTree({}, {}{}",
root_key.as_ref().map_or("None".to_string(), hex::encode),
sum_value,
flags
.as_ref()
.map_or(String::new(), |f| format!(", flags: {:?}", f))
)
}
}
}
}

impl Element {
pub fn type_str(&self) -> &str {
match self {
Expand Down
Loading
Loading