Skip to content

Commit adc120a

Browse files
committed
Add the ironfish prefix to crates, and use ironfish-jubjub
1 parent c0e1d15 commit adc120a

File tree

33 files changed

+285
-285
lines changed

33 files changed

+285
-285
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ members = [
55
"components/zcash_address",
66
"components/zcash_encoding",
77
"components/zcash_note_encryption",
8-
"zcash_primitives",
9-
"zcash_proofs",
8+
"ironfish-primitives",
9+
"ironfish-proofs",
1010
]
1111

1212
[profile.release]

components/zcash_note_encryption/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ subtle = { version = "2.2.3", default-features = false }
2525

2626
[dev-dependencies]
2727
ff = { version = "0.12", default-features = false }
28-
zcash_primitives = { version = "0.7", path = "../../zcash_primitives" }
29-
jubjub = { git = "https://github.com/iron-fish/jubjub.git", branch = "blstrs" }
28+
ironfish-primitives = { version = "0.1.0", path = "../../ironfish-primitives" }
29+
ironfish-jubjub = { version = "0.1.0" }
3030

3131
[features]
3232
default = ["alloc"]

components/zcash_note_encryption/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,11 @@ pub trait ShieldedOutput<D: Domain, const CIPHERTEXT_SIZE: usize> {
347347
/// ```
348348
/// extern crate ff;
349349
/// extern crate rand_core;
350-
/// extern crate zcash_primitives;
350+
/// extern crate ironfish_primitives;
351351
///
352352
/// use ff::Field;
353353
/// use rand_core::OsRng;
354-
/// use zcash_primitives::{
354+
/// use ironfish_primitives::{
355355
/// keys::{OutgoingViewingKey, prf_expand},
356356
/// consensus::{TEST_NETWORK, TestNetwork, NetworkUpgrade, Parameters},
357357
/// memo::MemoBytes,
@@ -370,7 +370,7 @@ pub trait ShieldedOutput<D: Domain, const CIPHERTEXT_SIZE: usize> {
370370
/// let ovk = Some(OutgoingViewingKey([0; 32]));
371371
///
372372
/// let value = 1000;
373-
/// let rcv = jubjub::Fr::random(&mut rng);
373+
/// let rcv = ironfish_jubjub::Fr::random(&mut rng);
374374
/// let cv = ValueCommitment {
375375
/// value,
376376
/// randomness: rcv.clone(),

ironfish-primitives

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zcash_primitives

ironfish-proofs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zcash_proofs

zcash_extensions/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ zcash_primitives = { version = "0.7", path = "../zcash_primitives", features = [
1414

1515
[dev-dependencies]
1616
ff = "0.12"
17-
jubjub = "0.9"
17+
ironfish-jubjub = { version = "0.1.0", path = "../../jubjub" }
1818
rand_core = "0.6"
1919
zcash_address = { version = "0.1", path = "../components/zcash_address" }
2020
zcash_proofs = { version = "0.7", path = "../zcash_proofs" }

zcash_primitives/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
[package]
2-
name = "zcash_primitives"
2+
name = "ironfish-primitives"
33
description = "Rust implementations of the Zcash primitives"
4-
version = "0.7.0"
4+
version = "0.1.0"
55
authors = [
66
"Jack Grigg <[email protected]>",
77
"Kris Nuttycombe <[email protected]>"
88
]
9-
homepage = "https://github.com/zcash/librustzcash"
10-
repository = "https://github.com/zcash/librustzcash"
9+
repository = "https://github.com/iron-fish/librustzcash"
1110
readme = "README.md"
1211
license = "MIT OR Apache-2.0"
1312
edition = "2018"
@@ -33,7 +32,7 @@ group = "0.12"
3332
hdwallet = { version = "0.3.1", optional = true }
3433
hex = "0.4"
3534
incrementalmerkletree = "0.3"
36-
jubjub = { git = "https://github.com/iron-fish/jubjub.git", branch = "blstrs" }
35+
ironfish-jubjub = { version = "0.1.0" }
3736
lazy_static = "1"
3837
memuse = "0.2"
3938
nonempty = "0.7"

zcash_primitives/src/constants.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use ff::PrimeField;
44
use group::Group;
5-
use jubjub::SubgroupPoint;
5+
use ironfish_jubjub::SubgroupPoint;
66
use lazy_static::lazy_static;
77

88
pub mod mainnet;
@@ -255,7 +255,7 @@ fn generate_pedersen_hash_exp_table() -> Vec<Vec<Vec<SubgroupPoint>>> {
255255
let mut tables = vec![];
256256

257257
let mut num_bits = 0;
258-
while num_bits <= jubjub::Fr::NUM_BITS {
258+
while num_bits <= ironfish_jubjub::Fr::NUM_BITS {
259259
let mut table = Vec::with_capacity(1 << window);
260260
let mut base = SubgroupPoint::identity();
261261

@@ -279,7 +279,7 @@ fn generate_pedersen_hash_exp_table() -> Vec<Vec<Vec<SubgroupPoint>>> {
279279

280280
#[cfg(test)]
281281
mod tests {
282-
use jubjub::SubgroupPoint;
282+
use ironfish_jubjub::SubgroupPoint;
283283

284284
use super::*;
285285
use crate::sapling::group_hash::group_hash;
@@ -391,7 +391,7 @@ mod tests {
391391
/// Check for simple relations between the generators, that make finding collisions easy;
392392
/// far worse than spec inconsistencies!
393393
fn check_consistency_of_pedersen_hash_generators(
394-
pedersen_hash_generators: &[jubjub::SubgroupPoint],
394+
pedersen_hash_generators: &[ironfish_jubjub::SubgroupPoint],
395395
) {
396396
for (i, p1) in pedersen_hash_generators.iter().enumerate() {
397397
if p1.is_identity().into() {

zcash_primitives/src/merkle_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<Node: Hashable> CommitmentTree<Node> {
315315
/// ```
316316
/// use ff::{Field, PrimeField};
317317
/// use rand_core::OsRng;
318-
/// use zcash_primitives::{
318+
/// use ironfish_primitives::{
319319
/// merkle_tree::{CommitmentTree, IncrementalWitness},
320320
/// sapling::Node,
321321
/// };

zcash_primitives/src/sapling.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn merkle_hash(depth: usize, lhs: &[u8; 32], rhs: &[u8; 32]) -> [u8; 32] {
5555
tmp
5656
};
5757

58-
jubjub::ExtendedPoint::from(pedersen_hash(
58+
ironfish_jubjub::ExtendedPoint::from(pedersen_hash(
5959
Personalization::MerkleTree(depth),
6060
lhs.iter()
6161
.copied()
@@ -134,7 +134,7 @@ lazy_static! {
134134
/// Create the spendAuthSig for a Sapling SpendDescription.
135135
pub fn spend_sig<R: RngCore + CryptoRng>(
136136
ask: PrivateKey,
137-
ar: jubjub::Fr,
137+
ar: ironfish_jubjub::Fr,
138138
sighash: &[u8; 32],
139139
rng: &mut R,
140140
) -> Signature {
@@ -143,7 +143,7 @@ pub fn spend_sig<R: RngCore + CryptoRng>(
143143

144144
pub(crate) fn spend_sig_internal<R: RngCore>(
145145
ask: PrivateKey,
146-
ar: jubjub::Fr,
146+
ar: ironfish_jubjub::Fr,
147147
sighash: &[u8; 32],
148148
rng: &mut R,
149149
) -> Signature {
@@ -165,20 +165,20 @@ pub(crate) fn spend_sig_internal<R: RngCore>(
165165
#[derive(Clone)]
166166
pub struct ValueCommitment {
167167
pub value: u64,
168-
pub randomness: jubjub::Fr,
168+
pub randomness: ironfish_jubjub::Fr,
169169
}
170170

171171
impl ValueCommitment {
172-
pub fn commitment(&self) -> jubjub::SubgroupPoint {
173-
(*constants::VALUE_COMMITMENT_VALUE_GENERATOR * jubjub::Fr::from(self.value))
172+
pub fn commitment(&self) -> ironfish_jubjub::SubgroupPoint {
173+
(*constants::VALUE_COMMITMENT_VALUE_GENERATOR * ironfish_jubjub::Fr::from(self.value))
174174
+ (*constants::VALUE_COMMITMENT_RANDOMNESS_GENERATOR * self.randomness)
175175
}
176176
}
177177

178178
#[derive(Clone)]
179179
pub struct ProofGenerationKey {
180-
pub ak: jubjub::SubgroupPoint,
181-
pub nsk: jubjub::Fr,
180+
pub ak: ironfish_jubjub::SubgroupPoint,
181+
pub nsk: ironfish_jubjub::Fr,
182182
}
183183

184184
impl ProofGenerationKey {
@@ -192,12 +192,12 @@ impl ProofGenerationKey {
192192

193193
#[derive(Debug, Clone)]
194194
pub struct ViewingKey {
195-
pub ak: jubjub::SubgroupPoint,
196-
pub nk: jubjub::SubgroupPoint,
195+
pub ak: ironfish_jubjub::SubgroupPoint,
196+
pub nk: ironfish_jubjub::SubgroupPoint,
197197
}
198198

199199
impl ViewingKey {
200-
pub fn rk(&self, ar: jubjub::Fr) -> jubjub::SubgroupPoint {
200+
pub fn rk(&self, ar: ironfish_jubjub::Fr) -> ironfish_jubjub::SubgroupPoint {
201201
self.ak + *constants::SPENDING_KEY_GENERATOR * ar
202202
}
203203

@@ -217,7 +217,7 @@ impl ViewingKey {
217217
// Drop the most significant five bits, so it can be interpreted as a scalar.
218218
h[31] &= 0b0000_0111;
219219

220-
SaplingIvk(jubjub::Fr::from_repr(h).unwrap())
220+
SaplingIvk(ironfish_jubjub::Fr::from_repr(h).unwrap())
221221
}
222222

223223
pub fn to_payment_address(&self, diversifier: Diversifier) -> Option<PaymentAddress> {
@@ -226,7 +226,7 @@ impl ViewingKey {
226226
}
227227

228228
#[derive(Debug, Clone)]
229-
pub struct SaplingIvk(pub jubjub::Fr);
229+
pub struct SaplingIvk(pub ironfish_jubjub::Fr);
230230

231231
impl SaplingIvk {
232232
pub fn to_payment_address(&self, diversifier: Diversifier) -> Option<PaymentAddress> {
@@ -246,7 +246,7 @@ impl SaplingIvk {
246246
pub struct Diversifier(pub [u8; 11]);
247247

248248
impl Diversifier {
249-
pub fn g_d(&self) -> Option<jubjub::SubgroupPoint> {
249+
pub fn g_d(&self) -> Option<ironfish_jubjub::SubgroupPoint> {
250250
group_hash(&self.0, constants::KEY_DIVERSIFICATION_PERSONALIZATION)
251251
}
252252
}
@@ -259,7 +259,7 @@ impl Diversifier {
259259
/// and not the identity).
260260
#[derive(Clone, Debug)]
261261
pub struct PaymentAddress {
262-
pk_d: jubjub::SubgroupPoint,
262+
pk_d: ironfish_jubjub::SubgroupPoint,
263263
diversifier: Diversifier,
264264
}
265265

@@ -273,7 +273,7 @@ impl PaymentAddress {
273273
/// Constructs a PaymentAddress from a diversifier and a Jubjub point.
274274
///
275275
/// Returns None if `pk_d` is the identity.
276-
pub fn from_parts(diversifier: Diversifier, pk_d: jubjub::SubgroupPoint) -> Option<Self> {
276+
pub fn from_parts(diversifier: Diversifier, pk_d: ironfish_jubjub::SubgroupPoint) -> Option<Self> {
277277
if pk_d.is_identity().into() {
278278
None
279279
} else {
@@ -287,7 +287,7 @@ impl PaymentAddress {
287287
#[cfg(test)]
288288
pub(crate) fn from_parts_unchecked(
289289
diversifier: Diversifier,
290-
pk_d: jubjub::SubgroupPoint,
290+
pk_d: ironfish_jubjub::SubgroupPoint,
291291
) -> Self {
292292
PaymentAddress { pk_d, diversifier }
293293
}
@@ -302,7 +302,7 @@ impl PaymentAddress {
302302
// Check that the diversifier is valid
303303
diversifier.g_d()?;
304304

305-
let pk_d = jubjub::SubgroupPoint::from_bytes(bytes[11..43].try_into().unwrap());
305+
let pk_d = ironfish_jubjub::SubgroupPoint::from_bytes(bytes[11..43].try_into().unwrap());
306306
if pk_d.is_some().into() {
307307
PaymentAddress::from_parts(diversifier, pk_d.unwrap())
308308
} else {
@@ -324,11 +324,11 @@ impl PaymentAddress {
324324
}
325325

326326
/// Returns `pk_d` for this `PaymentAddress`.
327-
pub fn pk_d(&self) -> &jubjub::SubgroupPoint {
327+
pub fn pk_d(&self) -> &ironfish_jubjub::SubgroupPoint {
328328
&self.pk_d
329329
}
330330

331-
pub fn g_d(&self) -> Option<jubjub::SubgroupPoint> {
331+
pub fn g_d(&self) -> Option<ironfish_jubjub::SubgroupPoint> {
332332
self.diversifier.g_d()
333333
}
334334

@@ -349,7 +349,7 @@ impl PaymentAddress {
349349
/// both the note commitment trapdoor `rcm` and the ephemeral private key `esk`.
350350
#[derive(Copy, Clone, Debug)]
351351
pub enum Rseed {
352-
BeforeZip212(jubjub::Fr),
352+
BeforeZip212(ironfish_jubjub::Fr),
353353
AfterZip212([u8; 32]),
354354
}
355355

@@ -404,9 +404,9 @@ pub struct Note {
404404
/// The value of the note
405405
pub value: u64,
406406
/// The diversified base of the address, GH(d)
407-
pub g_d: jubjub::SubgroupPoint,
407+
pub g_d: ironfish_jubjub::SubgroupPoint,
408408
/// The public key of the address, g_d^ivk
409-
pub pk_d: jubjub::SubgroupPoint,
409+
pub pk_d: ironfish_jubjub::SubgroupPoint,
410410
/// rseed
411411
pub rseed: Rseed,
412412
}
@@ -428,7 +428,7 @@ impl Note {
428428
}
429429

430430
/// Computes the note commitment, returning the full point.
431-
fn cm_full_point(&self) -> jubjub::SubgroupPoint {
431+
fn cm_full_point(&self) -> ironfish_jubjub::SubgroupPoint {
432432
// Calculate the note contents, as bytes
433433
let mut note_contents = vec![];
434434

@@ -462,7 +462,7 @@ impl Note {
462462
pub fn nf(&self, viewing_key: &ViewingKey, position: u64) -> Nullifier {
463463
// Compute rho = cm + position.G
464464
let rho = self.cm_full_point()
465-
+ (*constants::NULLIFIER_POSITION_GENERATOR * jubjub::Fr::from(position));
465+
+ (*constants::NULLIFIER_POSITION_GENERATOR * ironfish_jubjub::Fr::from(position));
466466

467467
// Compute nf = BLAKE2s(nk | rho)
468468
Nullifier::from_slice(
@@ -482,36 +482,36 @@ impl Note {
482482
pub fn cmu(&self) -> blstrs::Scalar {
483483
// The commitment is in the prime order subgroup, so mapping the
484484
// commitment to the u-coordinate is an injective encoding.
485-
jubjub::ExtendedPoint::from(self.cm_full_point())
485+
ironfish_jubjub::ExtendedPoint::from(self.cm_full_point())
486486
.to_affine()
487487
.get_u()
488488
}
489489

490-
pub fn rcm(&self) -> jubjub::Fr {
490+
pub fn rcm(&self) -> ironfish_jubjub::Fr {
491491
match self.rseed {
492492
Rseed::BeforeZip212(rcm) => rcm,
493493
Rseed::AfterZip212(rseed) => {
494-
jubjub::Fr::from_bytes_wide(prf_expand(&rseed, &[0x04]).as_array())
494+
ironfish_jubjub::Fr::from_bytes_wide(prf_expand(&rseed, &[0x04]).as_array())
495495
}
496496
}
497497
}
498498

499-
pub fn generate_or_derive_esk<R: RngCore + CryptoRng>(&self, rng: &mut R) -> jubjub::Fr {
499+
pub fn generate_or_derive_esk<R: RngCore + CryptoRng>(&self, rng: &mut R) -> ironfish_jubjub::Fr {
500500
self.generate_or_derive_esk_internal(rng)
501501
}
502502

503-
pub(crate) fn generate_or_derive_esk_internal<R: RngCore>(&self, rng: &mut R) -> jubjub::Fr {
503+
pub(crate) fn generate_or_derive_esk_internal<R: RngCore>(&self, rng: &mut R) -> ironfish_jubjub::Fr {
504504
match self.derive_esk() {
505-
None => jubjub::Fr::random(rng),
505+
None => ironfish_jubjub::Fr::random(rng),
506506
Some(esk) => esk,
507507
}
508508
}
509509

510510
/// Returns the derived `esk` if this note was created after ZIP 212 activated.
511-
pub fn derive_esk(&self) -> Option<jubjub::Fr> {
511+
pub fn derive_esk(&self) -> Option<ironfish_jubjub::Fr> {
512512
match self.rseed {
513513
Rseed::BeforeZip212(_) => None,
514-
Rseed::AfterZip212(rseed) => Some(jubjub::Fr::from_bytes_wide(
514+
Rseed::AfterZip212(rseed) => Some(ironfish_jubjub::Fr::from_bytes_wide(
515515
prf_expand(&rseed, &[0x05]).as_array(),
516516
)),
517517
}

0 commit comments

Comments
 (0)