Skip to content

Commit

Permalink
move proof generation key extension to ironfish-zkp
Browse files Browse the repository at this point in the history
  • Loading branch information
jowparks committed Oct 18, 2024
1 parent 3ae48e2 commit d4d405a
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 204 deletions.
8 changes: 2 additions & 6 deletions ironfish-rust/src/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use group::GroupEncoding;
use ironfish_zkp::constants::{
CRH_IVK_PERSONALIZATION, PROOF_GENERATION_KEY_GENERATOR, SPENDING_KEY_GENERATOR,
};
pub use ironfish_zkp::ProofGenerationKey;
use jubjub::SubgroupPoint;
use rand::prelude::*;

Expand All @@ -26,8 +27,6 @@ mod view_keys;
pub use view_keys::*;
mod util;
pub use util::*;
pub mod proof_generation_key;
pub use proof_generation_key::*;

#[cfg(test)]
mod test;
Expand Down Expand Up @@ -210,10 +209,7 @@ impl SaplingKey {
/// Adapter to convert this key to a proof generation key for use in
/// sapling functions
pub fn sapling_proof_generation_key(&self) -> ProofGenerationKey {
ProofGenerationKey {
ak: self.view_key.authorizing_key,
nsk: self.proof_authorizing_key,
}
ProofGenerationKey::new(self.view_key.authorizing_key, self.proof_authorizing_key)
}

/// Convert the spending key to another value using a pseudorandom hash
Expand Down
170 changes: 0 additions & 170 deletions ironfish-rust/src/keys/proof_generation_key.rs

This file was deleted.

6 changes: 2 additions & 4 deletions ironfish-rust/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,8 @@ impl ProposedTransaction {
) -> Result<UnsignedTransaction, IronfishError> {
let public_address = view_key.public_address()?;

let proof_generation_key = ProofGenerationKey {
ak: view_key.authorizing_key,
nsk: proof_authorizing_key,
};
let proof_generation_key =
ProofGenerationKey::new(view_key.authorizing_key, proof_authorizing_key);

// skip adding change notes if this is special case of a miners fee transaction
let is_miners_fee = self.outputs.iter().any(|output| output.get_is_miners_fee());
Expand Down
17 changes: 9 additions & 8 deletions ironfish-zkp/src/circuits/mint_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ use bellperson::{
Circuit,
};
use ff::PrimeField;
use zcash_primitives::sapling::ProofGenerationKey;
use zcash_proofs::{
circuit::ecc,
constants::{PROOF_GENERATION_KEY_GENERATOR, SPENDING_KEY_GENERATOR},
};

use crate::constants::{proof::PUBLIC_KEY_GENERATOR, CRH_IVK_PERSONALIZATION};
use crate::{
constants::{proof::PUBLIC_KEY_GENERATOR, CRH_IVK_PERSONALIZATION},
ProofGenerationKey,
};

pub struct MintAsset {
/// Key required to construct proofs for a particular spending key
Expand Down Expand Up @@ -122,9 +124,8 @@ mod test {
use group::{Curve, Group};
use jubjub::ExtendedPoint;
use rand::{rngs::StdRng, SeedableRng};
use zcash_primitives::sapling::ProofGenerationKey;

use crate::constants::PUBLIC_KEY_GENERATOR;
use crate::{constants::PUBLIC_KEY_GENERATOR, ProofGenerationKey};

use super::MintAsset;

Expand All @@ -135,10 +136,10 @@ mod test {

let mut cs = TestConstraintSystem::new();

let proof_generation_key = ProofGenerationKey {
ak: jubjub::SubgroupPoint::random(&mut rng),
nsk: jubjub::Fr::random(&mut rng),
};
let proof_generation_key = ProofGenerationKey::new(
jubjub::SubgroupPoint::random(&mut rng),
jubjub::Fr::random(&mut rng),
);
let incoming_view_key = proof_generation_key.to_viewing_key();
let public_address = *PUBLIC_KEY_GENERATOR * incoming_view_key.ivk().0;
let public_address_point = ExtendedPoint::from(public_address).to_affine();
Expand Down
6 changes: 3 additions & 3 deletions ironfish-zkp/src/circuits/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use bellperson::{gadgets::blake2s, Circuit, ConstraintSystem, SynthesisError};
use group::Curve;
use jubjub::SubgroupPoint;

use zcash_primitives::sapling::ProofGenerationKey;
use zcash_proofs::{
circuit::{ecc, pedersen_hash},
constants::{
Expand All @@ -18,6 +17,7 @@ use crate::{
circuits::util::assert_valid_asset_generator,
constants::{proof::PUBLIC_KEY_GENERATOR, ASSET_ID_LENGTH, CRH_IVK_PERSONALIZATION},
primitives::ValueCommitment,
ProofGenerationKey,
};

use super::util::expose_value_commitment;
Expand Down Expand Up @@ -260,9 +260,9 @@ mod test {
use group::{Curve, Group};
use rand::rngs::StdRng;
use rand::{Rng, RngCore, SeedableRng};
use zcash_primitives::sapling::ProofGenerationKey;

use crate::util::asset_hash_to_point;
use crate::ProofGenerationKey;
use crate::{
circuits::output::Output, constants::PUBLIC_KEY_GENERATOR, primitives::ValueCommitment,
util::commitment_full_point,
Expand Down Expand Up @@ -296,7 +296,7 @@ mod test {
let esk = jubjub::Fr::random(&mut rng);
let ar = jubjub::Fr::random(&mut rng);

let proof_generation_key = ProofGenerationKey { ak, nsk };
let proof_generation_key = ProofGenerationKey::new(ak, nsk);

let viewing_key = proof_generation_key.to_viewing_key();

Expand Down
26 changes: 14 additions & 12 deletions ironfish-zkp/src/circuits/spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use ff::{Field, PrimeField};
use jubjub::SubgroupPoint;

use crate::constants::{CRH_IVK_PERSONALIZATION, PRF_NF_PERSONALIZATION};
use crate::ProofGenerationKey;
use crate::{constants::proof::PUBLIC_KEY_GENERATOR, primitives::ValueCommitment};

use super::util::expose_value_commitment;
Expand All @@ -11,7 +12,6 @@ use bellperson::gadgets::boolean;
use bellperson::gadgets::multipack;
use bellperson::gadgets::num;
use bellperson::gadgets::Assignment;
use zcash_primitives::sapling::ProofGenerationKey;
use zcash_proofs::{
circuit::{ecc, pedersen_hash},
constants::{
Expand Down Expand Up @@ -342,15 +342,17 @@ mod test {
use ff::{Field, PrimeField, PrimeFieldBits};
use group::{Curve, Group, GroupEncoding};
use rand::{rngs::StdRng, RngCore, SeedableRng};
use zcash_primitives::sapling::{pedersen_hash, Note, ProofGenerationKey, Rseed};
use zcash_primitives::sapling::{pedersen_hash, Note, Rseed};
use zcash_primitives::{constants::NULLIFIER_POSITION_GENERATOR, sapling::Nullifier};

use crate::{
circuits::spend::Spend,
constants::PUBLIC_KEY_GENERATOR,
constants::{PRF_NF_PERSONALIZATION, VALUE_COMMITMENT_VALUE_GENERATOR},
constants::{
PRF_NF_PERSONALIZATION, PUBLIC_KEY_GENERATOR, VALUE_COMMITMENT_VALUE_GENERATOR,
},
primitives::ValueCommitment,
util::commitment_full_point,
ProofGenerationKey,
};

#[test]
Expand All @@ -367,10 +369,10 @@ mod test {
asset_generator: (*VALUE_COMMITMENT_VALUE_GENERATOR).into(),
};

let proof_generation_key = ProofGenerationKey {
ak: jubjub::SubgroupPoint::random(&mut rng),
nsk: jubjub::Fr::random(&mut rng),
};
let proof_generation_key = ProofGenerationKey::new(
jubjub::SubgroupPoint::random(&mut rng),
jubjub::Fr::random(&mut rng),
);

let viewing_key = proof_generation_key.to_viewing_key();

Expand Down Expand Up @@ -524,10 +526,10 @@ mod test {
asset_generator: (*VALUE_COMMITMENT_VALUE_GENERATOR).into(),
};

let proof_generation_key = ProofGenerationKey {
ak: jubjub::SubgroupPoint::random(&mut rng),
nsk: jubjub::Fr::random(&mut rng),
};
let proof_generation_key = ProofGenerationKey::new(
jubjub::SubgroupPoint::random(&mut rng),
jubjub::Fr::random(&mut rng),
);

let viewing_key = proof_generation_key.to_viewing_key();

Expand Down
3 changes: 2 additions & 1 deletion ironfish-zkp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ pub mod util;

pub use zcash_primitives::sapling::{
group_hash::group_hash, pedersen_hash, redjubjub, Diversifier, Note as SaplingNote, Nullifier,
PaymentAddress, ProofGenerationKey, Rseed, ViewingKey,
PaymentAddress, Rseed, ViewingKey,
};

pub use primitives::proof_generation_key::ProofGenerationKey;
pub mod proofs {
pub use crate::circuits::mint_asset::MintAsset;
pub use crate::circuits::{output::Output, spend::Spend};
Expand Down
1 change: 1 addition & 0 deletions ironfish-zkp/src/primitives/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod proof_generation_key;
mod value_commitment;
pub use value_commitment::ValueCommitment;
Loading

0 comments on commit d4d405a

Please sign in to comment.