Skip to content

Commit

Permalink
Reuse Goldilocks random
Browse files Browse the repository at this point in the history
  • Loading branch information
darth-cy committed Dec 2, 2024
1 parent 8aa5d6f commit 223e359
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
8 changes: 2 additions & 6 deletions spartan_parallel/src/scalar/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::borrow::Borrow;
use core::iter::{Product, Sum};
use core::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign};
use ff::{Field, FromUniformBytes};
use goldilocks::{Goldilocks, MODULUS as P};
use goldilocks::Goldilocks;
use rand::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};
use std::ops::Neg;
Expand All @@ -31,11 +31,7 @@ impl SpartanExtensionField for Scalar {
}

fn random<Rng: RngCore + CryptoRng>(rng: &mut Rng) -> Self {
let mut res = rng.next_u64();
while res >= P {
res = rng.next_u64();
}
Goldilocks(res).into()
Goldilocks::random(rng).into()
}

/// Attempts to convert a little-endian byte representation of
Expand Down
3 changes: 1 addition & 2 deletions spartan_parallel/src/scalar/fp2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use super::Scalar;
use super::SpartanExtensionField;
use crate::{AppendToTranscript, ProofTranscript, Transcript};
use core::borrow::Borrow;
Expand Down Expand Up @@ -37,7 +36,7 @@ impl SpartanExtensionField for ScalarExt2 {
}

fn random<Rng: RngCore + CryptoRng>(rng: &mut Rng) -> Self {
GoldilocksExt2([*Scalar::random(rng).inner(), *Scalar::random(rng).inner()]).into()
GoldilocksExt2::random(rng).into()
}

/// Attempts to convert a little-endian byte representation of
Expand Down

0 comments on commit 223e359

Please sign in to comment.