Skip to content

Commit ab45237

Browse files
authored
move proof generation key extension to ironfish-zkp (#5559)
1 parent 3ae48e2 commit ab45237

File tree

9 files changed

+237
-204
lines changed

9 files changed

+237
-204
lines changed

ironfish-rust/src/keys/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use group::GroupEncoding;
1313
use ironfish_zkp::constants::{
1414
CRH_IVK_PERSONALIZATION, PROOF_GENERATION_KEY_GENERATOR, SPENDING_KEY_GENERATOR,
1515
};
16+
pub use ironfish_zkp::ProofGenerationKey;
1617
use jubjub::SubgroupPoint;
1718
use rand::prelude::*;
1819

@@ -26,8 +27,6 @@ mod view_keys;
2627
pub use view_keys::*;
2728
mod util;
2829
pub use util::*;
29-
pub mod proof_generation_key;
30-
pub use proof_generation_key::*;
3130

3231
#[cfg(test)]
3332
mod test;
@@ -210,10 +209,7 @@ impl SaplingKey {
210209
/// Adapter to convert this key to a proof generation key for use in
211210
/// sapling functions
212211
pub fn sapling_proof_generation_key(&self) -> ProofGenerationKey {
213-
ProofGenerationKey {
214-
ak: self.view_key.authorizing_key,
215-
nsk: self.proof_authorizing_key,
216-
}
212+
ProofGenerationKey::new(self.view_key.authorizing_key, self.proof_authorizing_key)
217213
}
218214

219215
/// Convert the spending key to another value using a pseudorandom hash

ironfish-rust/src/keys/proof_generation_key.rs

Lines changed: 0 additions & 170 deletions
This file was deleted.

ironfish-rust/src/transaction/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,8 @@ impl ProposedTransaction {
239239
) -> Result<UnsignedTransaction, IronfishError> {
240240
let public_address = view_key.public_address()?;
241241

242-
let proof_generation_key = ProofGenerationKey {
243-
ak: view_key.authorizing_key,
244-
nsk: proof_authorizing_key,
245-
};
242+
let proof_generation_key =
243+
ProofGenerationKey::new(view_key.authorizing_key, proof_authorizing_key);
246244

247245
// skip adding change notes if this is special case of a miners fee transaction
248246
let is_miners_fee = self.outputs.iter().any(|output| output.get_is_miners_fee());

ironfish-zkp/src/circuits/mint_asset.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ use bellperson::{
33
Circuit,
44
};
55
use ff::PrimeField;
6-
use zcash_primitives::sapling::ProofGenerationKey;
76
use zcash_proofs::{
87
circuit::ecc,
98
constants::{PROOF_GENERATION_KEY_GENERATOR, SPENDING_KEY_GENERATOR},
109
};
1110

12-
use crate::constants::{proof::PUBLIC_KEY_GENERATOR, CRH_IVK_PERSONALIZATION};
11+
use crate::{
12+
constants::{proof::PUBLIC_KEY_GENERATOR, CRH_IVK_PERSONALIZATION},
13+
ProofGenerationKey,
14+
};
1315

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

127-
use crate::constants::PUBLIC_KEY_GENERATOR;
128+
use crate::{constants::PUBLIC_KEY_GENERATOR, ProofGenerationKey};
128129

129130
use super::MintAsset;
130131

@@ -135,10 +136,10 @@ mod test {
135136

136137
let mut cs = TestConstraintSystem::new();
137138

138-
let proof_generation_key = ProofGenerationKey {
139-
ak: jubjub::SubgroupPoint::random(&mut rng),
140-
nsk: jubjub::Fr::random(&mut rng),
141-
};
139+
let proof_generation_key = ProofGenerationKey::new(
140+
jubjub::SubgroupPoint::random(&mut rng),
141+
jubjub::Fr::random(&mut rng),
142+
);
142143
let incoming_view_key = proof_generation_key.to_viewing_key();
143144
let public_address = *PUBLIC_KEY_GENERATOR * incoming_view_key.ivk().0;
144145
let public_address_point = ExtendedPoint::from(public_address).to_affine();

ironfish-zkp/src/circuits/output.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use bellperson::{gadgets::blake2s, Circuit, ConstraintSystem, SynthesisError};
55
use group::Curve;
66
use jubjub::SubgroupPoint;
77

8-
use zcash_primitives::sapling::ProofGenerationKey;
98
use zcash_proofs::{
109
circuit::{ecc, pedersen_hash},
1110
constants::{
@@ -18,6 +17,7 @@ use crate::{
1817
circuits::util::assert_valid_asset_generator,
1918
constants::{proof::PUBLIC_KEY_GENERATOR, ASSET_ID_LENGTH, CRH_IVK_PERSONALIZATION},
2019
primitives::ValueCommitment,
20+
ProofGenerationKey,
2121
};
2222

2323
use super::util::expose_value_commitment;
@@ -260,9 +260,9 @@ mod test {
260260
use group::{Curve, Group};
261261
use rand::rngs::StdRng;
262262
use rand::{Rng, RngCore, SeedableRng};
263-
use zcash_primitives::sapling::ProofGenerationKey;
264263

265264
use crate::util::asset_hash_to_point;
265+
use crate::ProofGenerationKey;
266266
use crate::{
267267
circuits::output::Output, constants::PUBLIC_KEY_GENERATOR, primitives::ValueCommitment,
268268
util::commitment_full_point,
@@ -296,7 +296,7 @@ mod test {
296296
let esk = jubjub::Fr::random(&mut rng);
297297
let ar = jubjub::Fr::random(&mut rng);
298298

299-
let proof_generation_key = ProofGenerationKey { ak, nsk };
299+
let proof_generation_key = ProofGenerationKey::new(ak, nsk);
300300

301301
let viewing_key = proof_generation_key.to_viewing_key();
302302

ironfish-zkp/src/circuits/spend.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use ff::{Field, PrimeField};
33
use jubjub::SubgroupPoint;
44

55
use crate::constants::{CRH_IVK_PERSONALIZATION, PRF_NF_PERSONALIZATION};
6+
use crate::ProofGenerationKey;
67
use crate::{constants::proof::PUBLIC_KEY_GENERATOR, primitives::ValueCommitment};
78

89
use super::util::expose_value_commitment;
@@ -11,7 +12,6 @@ use bellperson::gadgets::boolean;
1112
use bellperson::gadgets::multipack;
1213
use bellperson::gadgets::num;
1314
use bellperson::gadgets::Assignment;
14-
use zcash_primitives::sapling::ProofGenerationKey;
1515
use zcash_proofs::{
1616
circuit::{ecc, pedersen_hash},
1717
constants::{
@@ -342,15 +342,17 @@ mod test {
342342
use ff::{Field, PrimeField, PrimeFieldBits};
343343
use group::{Curve, Group, GroupEncoding};
344344
use rand::{rngs::StdRng, RngCore, SeedableRng};
345-
use zcash_primitives::sapling::{pedersen_hash, Note, ProofGenerationKey, Rseed};
345+
use zcash_primitives::sapling::{pedersen_hash, Note, Rseed};
346346
use zcash_primitives::{constants::NULLIFIER_POSITION_GENERATOR, sapling::Nullifier};
347347

348348
use crate::{
349349
circuits::spend::Spend,
350-
constants::PUBLIC_KEY_GENERATOR,
351-
constants::{PRF_NF_PERSONALIZATION, VALUE_COMMITMENT_VALUE_GENERATOR},
350+
constants::{
351+
PRF_NF_PERSONALIZATION, PUBLIC_KEY_GENERATOR, VALUE_COMMITMENT_VALUE_GENERATOR,
352+
},
352353
primitives::ValueCommitment,
353354
util::commitment_full_point,
355+
ProofGenerationKey,
354356
};
355357

356358
#[test]
@@ -367,10 +369,10 @@ mod test {
367369
asset_generator: (*VALUE_COMMITMENT_VALUE_GENERATOR).into(),
368370
};
369371

370-
let proof_generation_key = ProofGenerationKey {
371-
ak: jubjub::SubgroupPoint::random(&mut rng),
372-
nsk: jubjub::Fr::random(&mut rng),
373-
};
372+
let proof_generation_key = ProofGenerationKey::new(
373+
jubjub::SubgroupPoint::random(&mut rng),
374+
jubjub::Fr::random(&mut rng),
375+
);
374376

375377
let viewing_key = proof_generation_key.to_viewing_key();
376378

@@ -524,10 +526,10 @@ mod test {
524526
asset_generator: (*VALUE_COMMITMENT_VALUE_GENERATOR).into(),
525527
};
526528

527-
let proof_generation_key = ProofGenerationKey {
528-
ak: jubjub::SubgroupPoint::random(&mut rng),
529-
nsk: jubjub::Fr::random(&mut rng),
530-
};
529+
let proof_generation_key = ProofGenerationKey::new(
530+
jubjub::SubgroupPoint::random(&mut rng),
531+
jubjub::Fr::random(&mut rng),
532+
);
531533

532534
let viewing_key = proof_generation_key.to_viewing_key();
533535

ironfish-zkp/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ pub mod util;
66

77
pub use zcash_primitives::sapling::{
88
group_hash::group_hash, pedersen_hash, redjubjub, Diversifier, Note as SaplingNote, Nullifier,
9-
PaymentAddress, ProofGenerationKey, Rseed, ViewingKey,
9+
PaymentAddress, Rseed, ViewingKey,
1010
};
1111

12+
pub use primitives::proof_generation_key::ProofGenerationKey;
1213
pub mod proofs {
1314
pub use crate::circuits::mint_asset::MintAsset;
1415
pub use crate::circuits::{output::Output, spend::Spend};

ironfish-zkp/src/primitives/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
pub mod proof_generation_key;
12
mod value_commitment;
23
pub use value_commitment::ValueCommitment;

0 commit comments

Comments
 (0)