-
Notifications
You must be signed in to change notification settings - Fork 990
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
Improved (more compact) Merkle Proofs #1015
Improved (more compact) Merkle Proofs #1015
Conversation
77026a6
to
35e97df
Compare
0de5421
to
6b676fe
Compare
* block sums and reworked block validation read and write block_sums refactor validate on both block and txhashset write block_sum on fast sync we store the kernel_sum (need to account for the offset) * block_sums * rustfmt * cleanup
* txhashset now implements committed for consistency * rustfmt and cleanup
* make kernel offsets commitments, they used to be blinding factors * cleanup various zero_commit inits * cleanup api and wallet to reflect offsets as commitments
verify maturity via merkle proofs TODO - how to check validity of txs?
627ebfd
to
529b72f
Compare
so we know the features are accurate and honest
This I think is ready for review.
/cc @ignopeverell @tromp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, also seems slightly cleaner.
core/src/core/pmmr.rs
Outdated
} | ||
|
||
/// A Merkle proof that proves a particular element exists in the MMR. | ||
#[derive(Debug, Eq, PartialEq, Clone, PartialOrd, Ord)] | ||
pub struct MerkleProof { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/src/core/pmmr.rs
Outdated
@@ -309,6 +297,52 @@ where | |||
.collect() | |||
} | |||
|
|||
fn peak_path(&self, peak_pos: u64) -> Vec<Hash> { | |||
let rhs = self.bag_the_rhs(peak_pos); | |||
println!("rhs bagged - {:?}", rhs); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@tromp - want to take a look over this before I merge onto |
will review |
core/src/core/merkle_proof.rs
Outdated
return Err(MerkleProofError::RootMismatch); | ||
} | ||
} else if self.mmr_size == 1 { | ||
if self.path.len() == 1 && root == node_hash && vec![root] == self.path { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/src/core/merkle_proof.rs
Outdated
let sibling = self.path.remove(0); | ||
let (parent_pos, sibling_pos) = pmmr::family(node_pos); | ||
|
||
let peaks_pos = pmmr::peaks(self.mmr_size); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/src/core/pmmr.rs
Outdated
if mmr_size == 1 { | ||
return Ok(MerkleProof { | ||
mmr_size, | ||
path: vec![node], |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
.iter() | ||
.map(|x| (self.get_from_file(x.1).unwrap_or(Hash::default()), x.1)) | ||
.filter_map(|x| self.get_from_file(x.1)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -940,6 +811,9 @@ pub fn bintree_postorder_height(num: u64) -> u64 { | |||
/// We know the positions of all leaves based on the postorder height of an MMR of any size | |||
/// (somewhat unintuitively but this is how the PMMR is "append only"). | |||
pub fn is_leaf(pos: u64) -> bool { | |||
if pos == 0 { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/tests/merkle_proof.rs
Outdated
assert_eq!(pmmr.get_hash(1).unwrap(), pos_0); | ||
|
||
let proof = pmmr.merkle_proof(1).unwrap(); | ||
assert_eq!(proof.path, [pos_0]); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok except for non empty merkle proof paths when there are no siblings
Addressed feedback, will merge once all tests pass. |
Reworking Merkle proofs so we only store a
path
and the underlyingmmr_size
.The path includes the full sibling path and the necessary hashes derived from the peaks.
We need the
mmr_size
as we cannot rely on this being available when we come to verify the proof.The
mmr_size
is used to determine the pos of the various entries in the path.For siblings in the path we hash the node and the sibling together using the index of the parent.
For peak derived hashes we hash with the
mmr_size
(as a substitute for the non-existent pos).Everything should hash up to the
root
itself.TODO -
verify()
working forImproveMerkleProof
ImprovedMerkleProof
->MerkleProof
println!
all over Merkle Proofs...