Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the Rust depdendencies to use our newly published crates #5590

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
288 changes: 128 additions & 160 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ironfish-rust-nodejs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ workspace = true
crate-type = ["cdylib"]

[features]
stats = ["ironfish/note-encryption-stats", "jubjub/stats", "dep:signal-hook"]
stats = ["ironfish/note-encryption-stats", "ironfish-jubjub/stats", "dep:signal-hook"]

[dependencies]
base64 = "0.13.0"
Expand All @@ -33,7 +33,7 @@ ironfish = { path = "../ironfish-rust" }
ironfish-frost = { version = "0.1.0" }
napi = { version = "2.14.4", features = ["napi6"] }
napi-derive = "2.14.6"
jubjub = { git = "https://github.com/iron-fish/jubjub.git", branch = "blstrs", features = ["multiply-many"] }
ironfish-jubjub = { version = "0.1.0", features = ["multiply-many"] }
rand = "0.8.5"
num_cpus = "1.16.0"
signal-hook = { version = "0.3.17", optional = true, default-features = false, features = ["iterator"] }
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub fn randomize_pk(
let view_key = ViewKey::from_hex(&view_key_string).map_err(to_napi_err)?;

let public_key_randomness =
jubjub::Fr::from_hex(&public_key_randomness_string).map_err(to_napi_err)?;
ironfish_jubjub::Fr::from_hex(&public_key_randomness_string).map_err(to_napi_err)?;

let public_key =
generate_randomized_public_key(view_key, public_key_randomness).map_err(to_napi_err)?;
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/src/structs/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl NativeTransaction {
let view_key = ViewKey::from_hex(&view_key_str).map_err(to_napi_err)?;
let outgoing_view_key =
OutgoingViewKey::from_hex(&outgoing_view_key_str).map_err(to_napi_err)?;
let proof_authorizing_key = jubjub::Fr::from_hex(&proof_authorizing_key_str)
let proof_authorizing_key = ironfish_jubjub::Fr::from_hex(&proof_authorizing_key_str)
.map_err(|_| to_napi_err("PublicKeyPackage authorizing key hex to bytes failed"))?;

let change_address = match change_goes_to {
Expand Down
4 changes: 2 additions & 2 deletions ironfish-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ name = "ironfish"
path = "src/lib.rs"

[dependencies]
bellperson = { git = "https://github.com/iron-fish/bellperson.git", branch = "blstrs", features = ["groth16"] }
ironfish-bellperson = { version = "0.1.0", features = ["groth16"] }
blake2b_simd = "1.0.0"
blake2s_simd = "1.0.0"
blake3 = "1.5.0"
Expand All @@ -46,7 +46,7 @@ group = "0.12.0"
ironfish-frost = { version = "0.1.0" }
fish_hash = "0.3.0"
ironfish_zkp = { version = "0.2.0", path = "../ironfish-zkp" }
jubjub = { git = "https://github.com/iron-fish/jubjub.git", branch = "blstrs", features = ["multiply-many"] }
ironfish-jubjub = { version = "0.1.0", features = ["multiply-many"] }
lazy_static = "1.4.0"
libc = "0.2.126" # sub-dependency that needs a pinned version until a new release of cpufeatures: https://github.com/RustCrypto/utils/pull/789
rand = "0.8.5"
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust/src/assets/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{
PublicAddress,
};
use byteorder::{ReadBytesExt, WriteBytesExt};
use ironfish_jubjub::{ExtendedPoint, SubgroupPoint};
use ironfish_zkp::constants::{ASSET_ID_LENGTH, ASSET_ID_PERSONALIZATION, GH_FIRST_BLOCK};
use jubjub::{ExtendedPoint, SubgroupPoint};
use std::io;

use super::asset_identifier::AssetIdentifier;
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust/src/assets/asset_identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::errors::{IronfishError, IronfishErrorKind};
use group::cofactor::CofactorGroup;
use ironfish_jubjub::{ExtendedPoint, SubgroupPoint};
use ironfish_zkp::{constants::ASSET_ID_LENGTH, util::asset_hash_to_point};
use jubjub::{ExtendedPoint, SubgroupPoint};
use std::io;

pub const NATIVE_ASSET: AssetIdentifier = AssetIdentifier([
Expand Down
4 changes: 2 additions & 2 deletions ironfish-rust/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ impl From<string::FromUtf8Error> for IronfishError {
}
}

impl From<bellperson::SynthesisError> for IronfishError {
fn from(e: bellperson::SynthesisError) -> IronfishError {
impl From<ironfish_bellperson::SynthesisError> for IronfishError {
fn from(e: ironfish_bellperson::SynthesisError) -> IronfishError {
IronfishError::new_with_source(IronfishErrorKind::BellpersonSynthesis, e)
}
}
Expand Down
4 changes: 2 additions & 2 deletions ironfish-rust/src/frost_utils/account_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use crate::{
};
use group::GroupEncoding;
use ironfish_frost::frost::VerifyingKey;
use ironfish_jubjub::SubgroupPoint;
use ironfish_zkp::constants::PROOF_GENERATION_KEY_GENERATOR;
use jubjub::SubgroupPoint;

pub struct MultisigAccountKeys {
/// Equivalent to [`crate::keys::SaplingKey::proof_authorizing_key`]
pub proof_authorizing_key: jubjub::Fr,
pub proof_authorizing_key: ironfish_jubjub::Fr,
/// Equivalent to [`crate::keys::SaplingKey::outgoing_viewing_key`]
pub outgoing_viewing_key: OutgoingViewKey,
/// Equivalent to [`crate::keys::SaplingKey::view_key`]
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust/src/frost_utils/split_spender_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct TrustedDealerKeyPackages {
pub view_key: ViewKey,
pub incoming_view_key: IncomingViewKey,
pub outgoing_view_key: OutgoingViewKey,
pub proof_authorizing_key: jubjub::Fr,
pub proof_authorizing_key: ironfish_jubjub::Fr,
pub key_packages: HashMap<Identity, KeyPackage>,
}

Expand Down
10 changes: 5 additions & 5 deletions ironfish-rust/src/keys/ephemeral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ use rand::thread_rng;
/// [`crate::keys::shared_secret`]
#[derive(Default)]
pub struct EphemeralKeyPair {
secret: jubjub::Fr,
public: jubjub::SubgroupPoint,
secret: ironfish_jubjub::Fr,
public: ironfish_jubjub::SubgroupPoint,
}

impl EphemeralKeyPair {
pub fn new() -> Self {
let secret = jubjub::Fr::random(thread_rng());
let secret = ironfish_jubjub::Fr::random(thread_rng());

Self {
secret,
public: *PUBLIC_KEY_GENERATOR * secret,
}
}

pub fn secret(&self) -> &jubjub::Fr {
pub fn secret(&self) -> &ironfish_jubjub::Fr {
&self.secret
}

pub fn public(&self) -> &jubjub::SubgroupPoint {
pub fn public(&self) -> &ironfish_jubjub::SubgroupPoint {
&self.public
}
}
Expand Down
14 changes: 7 additions & 7 deletions ironfish-rust/src/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use bip39::Mnemonic;
use blake2b_simd::Params as Blake2b;
use blake2s_simd::Params as Blake2s;
use group::GroupEncoding;
use ironfish_jubjub::SubgroupPoint;
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::*;

use std::io;
Expand Down Expand Up @@ -50,12 +50,12 @@ pub struct SaplingKey {
/// Part of the expanded form of the spending key, generally referred to as
/// `ask` in the literature. Derived from spending key using a seeded
/// pseudorandom hash function. Used to construct authorizing_key.
pub(crate) spend_authorizing_key: jubjub::Fr,
pub(crate) spend_authorizing_key: ironfish_jubjub::Fr,

/// Part of the expanded form of the spending key, generally referred to as
/// `nsk` in the literature. Derived from spending key using a seeded
/// pseudorandom hash function. Used to construct nullifier_deriving_key
pub(crate) proof_authorizing_key: jubjub::Fr,
pub(crate) proof_authorizing_key: ironfish_jubjub::Fr,

/// Part of the expanded form of the spending key, as well as being used
/// directly in the full viewing key. Generally referred to as
Expand All @@ -80,14 +80,14 @@ impl SaplingKey {
/// Construct a new key from an array of bytes
pub fn new(spending_key: [u8; SPEND_KEY_SIZE]) -> Result<Self, IronfishError> {
let spend_authorizing_key =
jubjub::Fr::from_bytes_wide(&Self::convert_key(spending_key, 0));
ironfish_jubjub::Fr::from_bytes_wide(&Self::convert_key(spending_key, 0));

if spend_authorizing_key == jubjub::Fr::zero() {
if spend_authorizing_key == ironfish_jubjub::Fr::zero() {
return Err(IronfishError::new(IronfishErrorKind::IllegalValue));
}

let proof_authorizing_key =
jubjub::Fr::from_bytes_wide(&Self::convert_key(spending_key, 1));
ironfish_jubjub::Fr::from_bytes_wide(&Self::convert_key(spending_key, 1));

let mut outgoing_viewing_key = [0; SPEND_KEY_SIZE];
outgoing_viewing_key[0..SPEND_KEY_SIZE]
Expand Down Expand Up @@ -243,7 +243,7 @@ impl SaplingKey {
pub fn hash_viewing_key(
authorizing_key: &SubgroupPoint,
nullifier_deriving_key: &SubgroupPoint,
) -> Result<jubjub::Fr, IronfishError> {
) -> Result<ironfish_jubjub::Fr, IronfishError> {
let mut view_key_contents = [0; 64];
view_key_contents[0..32].copy_from_slice(&authorizing_key.to_bytes());
view_key_contents[32..64].copy_from_slice(&nullifier_deriving_key.to_bytes());
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust/src/keys/public_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
serializing::{bytes_to_hex, hex_to_bytes},
};
use group::GroupEncoding;
use ironfish_jubjub::SubgroupPoint;
use ironfish_zkp::constants::PUBLIC_KEY_GENERATOR;
use jubjub::SubgroupPoint;

use std::io;

Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust/src/keys/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::keys::{ephemeral::EphemeralKeyPair, PUBLIC_ADDRESS_SIZE};

use super::{shared_secret, PublicAddress, SaplingKey};
use group::Curve;
use jubjub::ExtendedPoint;
use ironfish_jubjub::ExtendedPoint;

#[test]
fn test_key_generation_and_construction() {
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust/src/keys/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use group::GroupEncoding;
use ironfish_jubjub::Fr;
use ironfish_zkp::{constants::SPENDING_KEY_GENERATOR, redjubjub};
use jubjub::Fr;

use crate::{errors::IronfishError, ViewKey};

Expand Down
10 changes: 5 additions & 5 deletions ironfish-rust/src/keys/view_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
use bip39::{Language, Mnemonic};
use blake2b_simd::Params as Blake2b;
use group::GroupEncoding;
use jubjub::SubgroupPoint;
use ironfish_jubjub::SubgroupPoint;

use std::io;

Expand All @@ -32,7 +32,7 @@ const DIFFIE_HELLMAN_PERSONALIZATION: &[u8; 16] = b"Iron Fish shared";
/// Referred to as `ivk` in the literature.
#[derive(Clone)]
pub struct IncomingViewKey {
pub(crate) view_key: jubjub::Fr,
pub(crate) view_key: ironfish_jubjub::Fr,
}

impl IncomingViewKey {
Expand Down Expand Up @@ -110,11 +110,11 @@ pub struct ViewKey {
/// Part of the full viewing key. Generally referred to as
/// `ak` in the literature. Derived from spend_authorizing_key using scalar
/// multiplication in Sapling. Used to construct incoming viewing key.
pub authorizing_key: jubjub::SubgroupPoint,
pub authorizing_key: ironfish_jubjub::SubgroupPoint,
/// Part of the full viewing key. Generally referred to as
/// `nk` in the literature. Derived from proof_authorizing_key using scalar
/// multiplication. Used to construct incoming viewing key.
pub nullifier_deriving_key: jubjub::SubgroupPoint,
pub nullifier_deriving_key: ironfish_jubjub::SubgroupPoint,
}

impl ViewKey {
Expand Down Expand Up @@ -241,7 +241,7 @@ impl OutgoingViewKey {
/// The resulting key can be used in any symmetric cipher
#[must_use]
pub(crate) fn shared_secret(
secret_key: &jubjub::Fr,
secret_key: &ironfish_jubjub::Fr,
other_public_key: &SubgroupPoint,
reference_public_key: &SubgroupPoint,
) -> [u8; 32] {
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use bellperson::groth16;
use blstrs::Bls12;
use ironfish_bellperson::groth16;

pub mod assets;
pub mod errors;
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust/src/merkle_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use blake2b_simd::Params as Blake2b;
use blstrs::Scalar;
use ff::PrimeField;
use group::GroupEncoding;
use ironfish_jubjub::{ExtendedPoint, SubgroupPoint};
use ironfish_zkp::primitives::ValueCommitment;
use jubjub::{ExtendedPoint, SubgroupPoint};

use std::{convert::TryInto, io};

Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust/src/merkle_note_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use super::serializing::read_scalar;
use blstrs::Scalar;
use ff::{PrimeField, PrimeFieldBits};
use group::Curve;
use ironfish_jubjub::ExtendedPoint;
use ironfish_zkp::pedersen_hash::{pedersen_hash, Personalization};
use jubjub::ExtendedPoint;

use std::io;

Expand Down
27 changes: 18 additions & 9 deletions ironfish-rust/src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use blstrs::Scalar;
use byteorder::{ByteOrder, LittleEndian, ReadBytesExt, WriteBytesExt};
use ff::{Field, PrimeField};
use group::{Curve, GroupEncoding};
use ironfish_jubjub::SubgroupPoint;
use ironfish_zkp::{
constants::{ASSET_ID_LENGTH, NULLIFIER_POSITION_GENERATOR, PRF_NF_PERSONALIZATION},
util::commitment_full_point,
Nullifier,
};
use jubjub::SubgroupPoint;
use rand::thread_rng;
use std::{fmt, io, io::Read};
pub const ENCRYPTED_NOTE_SIZE: usize =
Expand Down Expand Up @@ -99,7 +99,7 @@ pub struct Note {
/// This helps create zero knowledge around the note,
/// allowing the owner to prove they have the note without revealing
/// anything else about it.
pub(crate) randomness: jubjub::Fr,
pub(crate) randomness: ironfish_jubjub::Fr,

/// Arbitrary note the spender can supply when constructing a spend so the
/// receiver has some record from whence it came.
Expand All @@ -120,7 +120,7 @@ impl Note {
asset_id: AssetIdentifier,
sender: PublicAddress,
) -> Self {
let randomness: jubjub::Fr = jubjub::Fr::random(thread_rng());
let randomness: ironfish_jubjub::Fr = ironfish_jubjub::Fr::random(thread_rng());

Self {
owner,
Expand All @@ -142,7 +142,7 @@ impl Note {
let asset_id = AssetIdentifier::read(&mut reader)?;

let value = reader.read_u64::<LittleEndian>()?;
let randomness: jubjub::Fr = read_scalar(&mut reader)?;
let randomness: ironfish_jubjub::Fr = read_scalar(&mut reader)?;

let mut memo = Memo::default();
reader.read_exact(&mut memo.0)?;
Expand Down Expand Up @@ -244,7 +244,7 @@ impl Note {
self.owner
}

pub fn asset_generator(&self) -> jubjub::ExtendedPoint {
pub fn asset_generator(&self) -> ironfish_jubjub::ExtendedPoint {
self.asset_id.asset_generator()
}

Expand Down Expand Up @@ -286,7 +286,7 @@ impl Note {
}

/// Computes the note commitment, returning the full point.
fn commitment_full_point(&self) -> jubjub::SubgroupPoint {
fn commitment_full_point(&self) -> ironfish_jubjub::SubgroupPoint {
commitment_full_point(
self.asset_generator(),
self.value,
Expand All @@ -304,7 +304,7 @@ impl Note {
pub fn nullifier(&self, view_key: &ViewKey, position: u64) -> Nullifier {
// Compute rho = cm + position.G
let rho = self.commitment_full_point()
+ (*NULLIFIER_POSITION_GENERATOR * jubjub::Fr::from(position));
+ (*NULLIFIER_POSITION_GENERATOR * ironfish_jubjub::Fr::from(position));

// Compute nf = BLAKE2s(nk | rho)
Nullifier::from_slice(
Expand Down Expand Up @@ -335,7 +335,7 @@ impl Note {
pub(crate) fn commitment_point(&self) -> Scalar {
// The commitment is in the prime order subgroup, so mapping the
// commitment to the u-coordinate is an injective encoding.
jubjub::ExtendedPoint::from(self.commitment_full_point())
ironfish_jubjub::ExtendedPoint::from(self.commitment_full_point())
.to_affine()
.get_u()
}
Expand All @@ -352,7 +352,16 @@ impl Note {
fn decrypt_note_parts(
shared_secret: &[u8; 32],
encrypted_bytes: &[u8; ENCRYPTED_NOTE_SIZE + aead::MAC_SIZE],
) -> Result<(jubjub::Fr, AssetIdentifier, u64, Memo, PublicAddress), IronfishError> {
) -> Result<
(
ironfish_jubjub::Fr,
AssetIdentifier,
u64,
Memo,
PublicAddress,
),
IronfishError,
> {
let plaintext_bytes: [u8; ENCRYPTED_NOTE_SIZE] =
aead::decrypt(shared_secret, encrypted_bytes)?;
let mut reader = &plaintext_bytes[..];
Expand Down
Loading