mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-02-11 17:55:46 +00:00
Pass CommitmentTreeWitness directly into Builder::add_sapling_spend
This is more likely to be the data that the caller has available, and is all we need now that a CommitmentTreeWitness can compute its root.
This commit is contained in:
parent
8a210ec271
commit
3a3008caf9
@ -13,7 +13,7 @@ use crate::{
|
|||||||
consensus,
|
consensus,
|
||||||
keys::OutgoingViewingKey,
|
keys::OutgoingViewingKey,
|
||||||
legacy::TransparentAddress,
|
legacy::TransparentAddress,
|
||||||
merkle_tree::{CommitmentTreeWitness, IncrementalWitness},
|
merkle_tree::CommitmentTreeWitness,
|
||||||
note_encryption::{generate_esk, Memo, SaplingNoteEncryption},
|
note_encryption::{generate_esk, Memo, SaplingNoteEncryption},
|
||||||
prover::TxProver,
|
prover::TxProver,
|
||||||
redjubjub::PrivateKey,
|
redjubjub::PrivateKey,
|
||||||
@ -44,7 +44,6 @@ pub enum Error {
|
|||||||
ChangeIsNegative(Amount),
|
ChangeIsNegative(Amount),
|
||||||
InvalidAddress,
|
InvalidAddress,
|
||||||
InvalidAmount,
|
InvalidAmount,
|
||||||
InvalidWitness,
|
|
||||||
NoChangeAddress,
|
NoChangeAddress,
|
||||||
SpendProof,
|
SpendProof,
|
||||||
}
|
}
|
||||||
@ -342,18 +341,18 @@ impl<R: RngCore + CryptoRng> Builder<R> {
|
|||||||
extsk: ExtendedSpendingKey,
|
extsk: ExtendedSpendingKey,
|
||||||
diversifier: Diversifier,
|
diversifier: Diversifier,
|
||||||
note: Note<Bls12>,
|
note: Note<Bls12>,
|
||||||
witness: IncrementalWitness<Node>,
|
witness: CommitmentTreeWitness<Node>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
// Consistency check: all anchors must equal the first one
|
// Consistency check: all anchors must equal the first one
|
||||||
|
let cm = Node::new(note.cm(&JUBJUB).into());
|
||||||
if let Some(anchor) = self.anchor {
|
if let Some(anchor) = self.anchor {
|
||||||
let witness_root: Fr = witness.root().into();
|
let witness_root: Fr = witness.root(cm).into();
|
||||||
if witness_root != anchor {
|
if witness_root != anchor {
|
||||||
return Err(Error::AnchorMismatch);
|
return Err(Error::AnchorMismatch);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.anchor = Some(witness.root().into())
|
self.anchor = Some(witness.root(cm).into())
|
||||||
}
|
}
|
||||||
let witness = witness.path().ok_or(Error::InvalidWitness)?;
|
|
||||||
|
|
||||||
let alpha = Fs::random(&mut self.rng);
|
let alpha = Fs::random(&mut self.rng);
|
||||||
|
|
||||||
@ -779,7 +778,7 @@ mod tests {
|
|||||||
extsk.clone(),
|
extsk.clone(),
|
||||||
*to.diversifier(),
|
*to.diversifier(),
|
||||||
note1.clone(),
|
note1.clone(),
|
||||||
witness1.clone(),
|
witness1.path().unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
builder
|
builder
|
||||||
@ -816,10 +815,15 @@ mod tests {
|
|||||||
{
|
{
|
||||||
let mut builder = Builder::new(0);
|
let mut builder = Builder::new(0);
|
||||||
builder
|
builder
|
||||||
.add_sapling_spend(extsk.clone(), *to.diversifier(), note1, witness1)
|
.add_sapling_spend(
|
||||||
|
extsk.clone(),
|
||||||
|
*to.diversifier(),
|
||||||
|
note1,
|
||||||
|
witness1.path().unwrap(),
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
builder
|
builder
|
||||||
.add_sapling_spend(extsk, *to.diversifier(), note2, witness2)
|
.add_sapling_spend(extsk, *to.diversifier(), note2, witness2.path().unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
builder
|
builder
|
||||||
.add_sapling_output(ovk, to, Amount::from_u64(30000).unwrap(), None)
|
.add_sapling_output(ovk, to, Amount::from_u64(30000).unwrap(), None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user