Skip to content

Commit

Permalink
feat: minimize unsigned spend builder requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
jowparks committed Jan 10, 2024
1 parent 9d202ab commit 68ce420
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion ironfish-rust/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ impl ProposedTransaction {
let mut unsigned_spends = Vec::with_capacity(self.spends.len());
for spend in &self.spends {
unsigned_spends.push(spend.build(
&self.spender_key,
&self.spender_key.sapling_proof_generation_key(),
&self.spender_key.view_key(),
&self.public_key_randomness,
&randomized_public_key,
)?);
Expand Down
21 changes: 11 additions & 10 deletions ironfish-rust/src/transaction/spends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
note::Note,
sapling_bls12::SAPLING,
serializing::{read_point, read_scalar},
witness::WitnessTrait,
witness::WitnessTrait, ViewKey,
};

use bellperson::gadgets::multipack;
Expand All @@ -23,7 +23,7 @@ use ironfish_zkp::{
primitives::ValueCommitment,
proofs::Spend,
redjubjub::{self, Signature},
Nullifier,
Nullifier, ProofGenerationKey,
};
use jubjub::ExtendedPoint;
use rand::thread_rng;
Expand Down Expand Up @@ -90,15 +90,16 @@ impl SpendBuilder {
/// transactions
pub(crate) fn build(
&self,
spender_key: &SaplingKey,
proof_generation_key: &ProofGenerationKey,
view_key: &ViewKey,
public_key_randomness: &jubjub::Fr,
randomized_public_key: &redjubjub::PublicKey,
) -> Result<UnsignedSpendDescription, IronfishError> {
let value_commitment_point = self.value_commitment_point();

let circuit = Spend {
value_commitment: Some(self.value_commitment.clone()),
proof_generation_key: Some(spender_key.sapling_proof_generation_key()),
proof_generation_key: Some(proof_generation_key.clone()),
payment_address: Some(self.note.owner.0),
auth_path: self.auth_path.clone(),
commitment_randomness: Some(self.note.randomness),
Expand All @@ -116,7 +117,7 @@ impl SpendBuilder {
// has been previously spent.
let nullifier = self
.note
.nullifier(&spender_key.view_key, self.witness_position);
.nullifier(view_key, self.witness_position);

let blank_signature = {
let buf = [0u8; 64];
Expand Down Expand Up @@ -428,7 +429,7 @@ mod test {
thread_rng().fill(&mut sig_hash[..]);

let unsigned_proof = spend
.build(&key, &public_key_randomness, &randomized_public_key)
.build(&key.sapling_proof_generation_key(), key.view_key(), &public_key_randomness, &randomized_public_key)
.expect("should be able to build proof");

verify_spend_proof(
Expand All @@ -441,17 +442,17 @@ mod test {

// Wrong spender key
assert!(spend
.build(&sender_key, &public_key_randomness, &randomized_public_key)
.build(&sender_key.sapling_proof_generation_key(), &sender_key.view_key(), &public_key_randomness, &randomized_public_key)
.is_err());

// Wrong public key randomness
assert!(spend
.build(&key, &other_public_key_randomness, &randomized_public_key)
.build(&key.sapling_proof_generation_key(), &key.view_key(), &other_public_key_randomness, &randomized_public_key)
.is_err());

// Wrong randomized public key
assert!(spend
.build(&key, &public_key_randomness, &other_randomized_public_key)
.build(&key.sapling_proof_generation_key(), &key.view_key(), &public_key_randomness, &other_randomized_public_key)
.is_err());

assert!(verify_spend_proof(
Expand Down Expand Up @@ -491,7 +492,7 @@ mod test {
thread_rng().fill(&mut sig_hash[..]);

let unsigned_proof = spend
.build(&key, &public_key_randomness, &randomized_public_key)
.build(&key.sapling_proof_generation_key(), &key.view_key(), &public_key_randomness, &randomized_public_key)
.expect("should be able to build proof");
let proof = unsigned_proof
.sign(&key, &sig_hash)
Expand Down

0 comments on commit 68ce420

Please sign in to comment.