mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-07-30 20:11:23 +00:00
Rename CommitmentTreeWitness -> MerklePath
This commit is contained in:
@@ -375,11 +375,11 @@ impl<Node: Hashable> IncrementalWitness<Node> {
|
||||
}
|
||||
|
||||
/// Returns the current witness, or None if the tree is empty.
|
||||
pub fn path(&self) -> Option<CommitmentTreeWitness<Node>> {
|
||||
pub fn path(&self) -> Option<MerklePath<Node>> {
|
||||
self.path_inner(SAPLING_COMMITMENT_TREE_DEPTH)
|
||||
}
|
||||
|
||||
fn path_inner(&self, depth: usize) -> Option<CommitmentTreeWitness<Node>> {
|
||||
fn path_inner(&self, depth: usize) -> Option<MerklePath<Node>> {
|
||||
let mut filler = self.filler();
|
||||
let mut auth_path = Vec::new();
|
||||
|
||||
@@ -406,31 +406,27 @@ impl<Node: Hashable> IncrementalWitness<Node> {
|
||||
}
|
||||
assert_eq!(auth_path.len(), depth);
|
||||
|
||||
Some(CommitmentTreeWitness::from_path(
|
||||
auth_path,
|
||||
self.position() as u64,
|
||||
))
|
||||
Some(MerklePath::from_path(auth_path, self.position() as u64))
|
||||
}
|
||||
}
|
||||
|
||||
/// A witness to a path from a position in a particular commitment tree to the root of
|
||||
/// that tree.
|
||||
/// A path from a position in a particular commitment tree to the root of that tree.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct CommitmentTreeWitness<Node: Hashable> {
|
||||
pub struct MerklePath<Node: Hashable> {
|
||||
pub auth_path: Vec<(Node, bool)>,
|
||||
pub position: u64,
|
||||
}
|
||||
|
||||
impl<Node: Hashable> CommitmentTreeWitness<Node> {
|
||||
/// Constructs a witness directly from its path and position.
|
||||
impl<Node: Hashable> MerklePath<Node> {
|
||||
/// Constructs a Merkle path directly from a path and position.
|
||||
pub fn from_path(auth_path: Vec<(Node, bool)>, position: u64) -> Self {
|
||||
CommitmentTreeWitness {
|
||||
MerklePath {
|
||||
auth_path,
|
||||
position,
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads a witness from its serialized form.
|
||||
/// Reads a Merkle path from its serialized form.
|
||||
pub fn from_slice(witness: &[u8]) -> Result<Self, ()> {
|
||||
Self::from_slice_with_depth(witness, SAPLING_COMMITMENT_TREE_DEPTH)
|
||||
}
|
||||
@@ -486,7 +482,7 @@ impl<Node: Hashable> CommitmentTreeWitness<Node> {
|
||||
// have provided more information than they should have, indicating
|
||||
// a bug downstream
|
||||
if witness.is_empty() {
|
||||
Ok(CommitmentTreeWitness {
|
||||
Ok(MerklePath {
|
||||
auth_path,
|
||||
position,
|
||||
})
|
||||
@@ -495,7 +491,7 @@ impl<Node: Hashable> CommitmentTreeWitness<Node> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the root of the tree corresponding to the witness.
|
||||
/// Returns the root of the tree corresponding to this path applied to `leaf`.
|
||||
pub fn root(&self, leaf: Node) -> Node {
|
||||
self.auth_path
|
||||
.iter()
|
||||
@@ -512,7 +508,7 @@ impl<Node: Hashable> CommitmentTreeWitness<Node> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{CommitmentTree, CommitmentTreeWitness, Hashable, IncrementalWitness, PathFiller};
|
||||
use super::{CommitmentTree, Hashable, IncrementalWitness, MerklePath, PathFiller};
|
||||
use crate::sapling::Node;
|
||||
|
||||
use ff::PrimeFieldRepr;
|
||||
@@ -611,7 +607,7 @@ mod tests {
|
||||
self.0.root_inner(TESTING_DEPTH)
|
||||
}
|
||||
|
||||
fn path(&self) -> Option<CommitmentTreeWitness<Node>> {
|
||||
fn path(&self) -> Option<MerklePath<Node>> {
|
||||
self.0.path_inner(TESTING_DEPTH)
|
||||
}
|
||||
}
|
||||
@@ -1047,7 +1043,7 @@ mod tests {
|
||||
|
||||
if let Some(leaf) = leaf {
|
||||
let path = witness.path().expect("should be able to create a path");
|
||||
let expected = CommitmentTreeWitness::from_slice_with_depth(
|
||||
let expected = MerklePath::from_slice_with_depth(
|
||||
&mut hex::decode(paths[paths_i]).unwrap(),
|
||||
TESTING_DEPTH,
|
||||
)
|
||||
|
@@ -7,7 +7,7 @@ use crate::{
|
||||
use pairing::bls12_381::{Bls12, Fr};
|
||||
|
||||
use crate::{
|
||||
merkle_tree::CommitmentTreeWitness,
|
||||
merkle_tree::MerklePath,
|
||||
redjubjub::{PublicKey, Signature},
|
||||
sapling::Node,
|
||||
transaction::components::{Amount, GROTH_PROOF_SIZE},
|
||||
@@ -35,7 +35,7 @@ pub trait TxProver {
|
||||
ar: Fs,
|
||||
value: u64,
|
||||
anchor: Fr,
|
||||
witness: CommitmentTreeWitness<Node>,
|
||||
merkle_path: MerklePath<Node>,
|
||||
) -> Result<
|
||||
(
|
||||
[u8; GROTH_PROOF_SIZE],
|
||||
@@ -82,7 +82,7 @@ pub(crate) mod mock {
|
||||
};
|
||||
|
||||
use crate::{
|
||||
merkle_tree::CommitmentTreeWitness,
|
||||
merkle_tree::MerklePath,
|
||||
redjubjub::{PublicKey, Signature},
|
||||
sapling::Node,
|
||||
transaction::components::{Amount, GROTH_PROOF_SIZE},
|
||||
@@ -108,7 +108,7 @@ pub(crate) mod mock {
|
||||
ar: Fs,
|
||||
value: u64,
|
||||
_anchor: Fr,
|
||||
_witness: CommitmentTreeWitness<Node>,
|
||||
_merkle_path: MerklePath<Node>,
|
||||
) -> Result<
|
||||
(
|
||||
[u8; GROTH_PROOF_SIZE],
|
||||
|
@@ -13,7 +13,7 @@ use crate::{
|
||||
consensus,
|
||||
keys::OutgoingViewingKey,
|
||||
legacy::TransparentAddress,
|
||||
merkle_tree::CommitmentTreeWitness,
|
||||
merkle_tree::MerklePath,
|
||||
note_encryption::{generate_esk, Memo, SaplingNoteEncryption},
|
||||
prover::TxProver,
|
||||
redjubjub::PrivateKey,
|
||||
@@ -53,7 +53,7 @@ struct SpendDescriptionInfo {
|
||||
diversifier: Diversifier,
|
||||
note: Note<Bls12>,
|
||||
alpha: Fs,
|
||||
witness: CommitmentTreeWitness<Node>,
|
||||
merkle_path: MerklePath<Node>,
|
||||
}
|
||||
|
||||
pub struct SaplingOutput {
|
||||
@@ -334,24 +334,24 @@ impl<R: RngCore + CryptoRng> Builder<R> {
|
||||
|
||||
/// Adds a Sapling note to be spent in this transaction.
|
||||
///
|
||||
/// Returns an error if the given witness does not have the same anchor as previous
|
||||
/// witnesses, or has no path.
|
||||
/// Returns an error if the given Merkle path does not have the same anchor as the
|
||||
/// paths for previous Sapling notes.
|
||||
pub fn add_sapling_spend(
|
||||
&mut self,
|
||||
extsk: ExtendedSpendingKey,
|
||||
diversifier: Diversifier,
|
||||
note: Note<Bls12>,
|
||||
witness: CommitmentTreeWitness<Node>,
|
||||
merkle_path: MerklePath<Node>,
|
||||
) -> Result<(), Error> {
|
||||
// Consistency check: all anchors must equal the first one
|
||||
let cm = Node::new(note.cm(&JUBJUB).into());
|
||||
if let Some(anchor) = self.anchor {
|
||||
let witness_root: Fr = witness.root(cm).into();
|
||||
if witness_root != anchor {
|
||||
let path_root: Fr = merkle_path.root(cm).into();
|
||||
if path_root != anchor {
|
||||
return Err(Error::AnchorMismatch);
|
||||
}
|
||||
} else {
|
||||
self.anchor = Some(witness.root(cm).into())
|
||||
self.anchor = Some(merkle_path.root(cm).into())
|
||||
}
|
||||
|
||||
let alpha = Fs::random(&mut self.rng);
|
||||
@@ -363,7 +363,7 @@ impl<R: RngCore + CryptoRng> Builder<R> {
|
||||
diversifier,
|
||||
note,
|
||||
alpha,
|
||||
witness,
|
||||
merkle_path,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
@@ -521,7 +521,7 @@ impl<R: RngCore + CryptoRng> Builder<R> {
|
||||
let mut nullifier = [0u8; 32];
|
||||
nullifier.copy_from_slice(&spend.note.nf(
|
||||
&proof_generation_key.to_viewing_key(&JUBJUB),
|
||||
spend.witness.position,
|
||||
spend.merkle_path.position,
|
||||
&JUBJUB,
|
||||
));
|
||||
|
||||
@@ -534,7 +534,7 @@ impl<R: RngCore + CryptoRng> Builder<R> {
|
||||
spend.alpha,
|
||||
spend.note.value,
|
||||
anchor,
|
||||
spend.witness.clone(),
|
||||
spend.merkle_path.clone(),
|
||||
)
|
||||
.map_err(|()| Error::SpendProof)?;
|
||||
|
||||
|
Reference in New Issue
Block a user