Skip to content

Commit

Permalink
Merge pull request #2 from noir-lang/mv/update-for-u32-num-gen
Browse files Browse the repository at this point in the history
fix: Switch to use u32 numeric generics and update to 0.3.0 noir-bignum
  • Loading branch information
vezenovm authored Jul 31, 2024
2 parents 8582e61 + a49e924 commit 46b1a89
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ authors = [""]
compiler_version = ">=0.32.0"

[dependencies]
bignum = {tag = "v0.2", git = "https://github.com/noir-lang/noir-bignum"}
bignum = {tag = "v0.3.0", git = "https://github.com/noir-lang/noir-bignum"}
10 changes: 5 additions & 5 deletions src/curve_jac.nr
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ impl<BigNum, CurveParams> CurveJ<BigNum, CurveParams> where BigNum: BigNumTrait,
(accumulator, affine_transcript)
}

unconstrained fn compute_linear_expression_transcript<let NScalarSlices: u64, let NMuls: u64, let NAdds: u64>(
unconstrained fn compute_linear_expression_transcript<let NScalarSlices: u32, let NMuls: u32, let NAdds: u32>(
mul_points: [BigCurve<BigNum, CurveParams>; NMuls],
mul_scalars: [ScalarField<NScalarSlices>; NMuls],
add_points: [BigCurve<BigNum, CurveParams>; NAdds]
Expand Down Expand Up @@ -679,7 +679,7 @@ impl<BigNum, CurveParams> CurveJ<BigNum, CurveParams> where BigNum: BigNumTrait,
}
}

struct LinearExpressionTranscript<BigNum, CurveParams, let NScalarSlices: u64, let NMuls: u64, let NAdds: u64>{
struct LinearExpressionTranscript<BigNum, CurveParams, let NScalarSlices: u32, let NMuls: u32, let NAdds: u32>{
table_transcript: [[JTranscript<BigNum, CurveParams>; 8]; NMuls],
msm_double_transcript: [[JTranscript<BigNum, CurveParams>; 4]; NScalarSlices],
msm_add_transcript: [[JTranscript<BigNum, CurveParams>; NMuls]; NScalarSlices],
Expand All @@ -688,7 +688,7 @@ struct LinearExpressionTranscript<BigNum, CurveParams, let NScalarSlices: u64, l
offset_generator_transcript: JTranscript<BigNum, CurveParams>
}

struct AffineLinearExpressionTranscript<BigNum, CurveParams, let NScalarSlices: u64, let NMuls: u64, let NAdds: u64>{
struct AffineLinearExpressionTranscript<BigNum, CurveParams, let NScalarSlices: u32, let NMuls: u32, let NAdds: u32>{
table_transcript: [[AffineTranscript<BigNum, CurveParams>; 8]; NMuls],
msm_double_transcript: [[AffineTranscript<BigNum, CurveParams>; 4]; NScalarSlices],
msm_add_transcript: [[AffineTranscript<BigNum, CurveParams>; NMuls]; NScalarSlices],
Expand All @@ -697,7 +697,7 @@ struct AffineLinearExpressionTranscript<BigNum, CurveParams, let NScalarSlices:
offset_generator_transcript: AffineTranscript<BigNum, CurveParams>
}

impl<BigNum, CurveParams, let NScalarSlices: u64, let NMuls: u64, let NAdds: u64> AffineLinearExpressionTranscript<BigNum, CurveParams,NScalarSlices,NMuls,NAdds> where BigNum: BigNumTrait, CurveParams: CurveParamsTrait<BigNum> {
impl<BigNum, CurveParams, let NScalarSlices: u32, let NMuls: u32, let NAdds: u32> AffineLinearExpressionTranscript<BigNum, CurveParams,NScalarSlices,NMuls,NAdds> where BigNum: BigNumTrait, CurveParams: CurveParamsTrait<BigNum> {

unconstrained fn from_jtranscript(jtranscript: LinearExpressionTranscript<BigNum, CurveParams, NScalarSlices, NMuls, NAdds>) -> Self {
let mut inverses: [BigNum] = &[];
Expand Down Expand Up @@ -776,7 +776,7 @@ impl<BigNum, CurveParams, let NScalarSlices: u64, let NMuls: u64, let NAdds: u64
result
}
}
impl<BigNum, CurveParams, let NBits: u64, let NScalarSlices: u64, let NMuls: u64, let NAdds: u64> LinearExpressionTranscript<BigNum, CurveParams, NBits, NScalarSlices, NMuls, NAdds> where BigNum: BigNumTrait, CurveParams: CurveParamsTrait<BigNum> {}
impl<BigNum, CurveParams, let NBits: u32, let NScalarSlices: u32, let NMuls: u32, let NAdds: u32> LinearExpressionTranscript<BigNum, CurveParams, NBits, NScalarSlices, NMuls, NAdds> where BigNum: BigNumTrait, CurveParams: CurveParamsTrait<BigNum> {}

// TODO: this should probably be in bignum
unconstrained pub fn batch_invert<BigNum>(x: &mut [BigNum]) where BigNum: BigNumTrait {
Expand Down
6 changes: 3 additions & 3 deletions src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -630,21 +630,21 @@ impl<BigNum, CurveParams> BigCurve<BigNum, CurveParams> where CurveParams: Curve
accumulator
}

unconstrained fn get_mul_transcript<let NScalarSlices: u64>(
unconstrained fn get_mul_transcript<let NScalarSlices: u32>(
P: Self,
scalar: ScalarField<NScalarSlices>
) -> [AffineTranscript<BigNum, CurveParams>; 326] {
CurveJ::from(P).mul(scalar).1.as_array()
}

// Expensive witness generation! Avoid if possible
fn mul<let NScalarSlices: u64>(self, scalar: ScalarField<NScalarSlices>) -> Self {
fn mul<let NScalarSlices: u32>(self, scalar: ScalarField<NScalarSlices>) -> Self {
let transcript: [AffineTranscript<BigNum, CurveParams>; 326] = BigCurve::get_mul_transcript(self, scalar);

self.mul_with_hint(scalar, transcript)
}

fn evaluate_linear_expression<let NScalarSlices: u64, let NMuls: u64, let NAdds: u64>(
fn evaluate_linear_expression<let NScalarSlices: u32, let NMuls: u32, let NAdds: u32>(
mut mul_points: [Self; NMuls],
mut mul_scalars: [ScalarField<NScalarSlices>; NMuls],
add_points: [Self; NAdds]
Expand Down
2 changes: 1 addition & 1 deletion src/scalar_field.nr
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<let N: u32> ScalarField<N> {
}

// Note: I can't propagate ModulusBits or NumLimbs from a generic that satisfies BigNumTrait due to bugs, so we have to pass NumLimbs and Params in directly. disgusting!
fn from_bignum<let NumLimbs: u64, Params>(x: BigNum<NumLimbs, Params>) -> Self where Params: BigNumParamsTrait<NumLimbs> + RuntimeBigNumParamsTrait<NumLimbs> {
fn from_bignum<let NumLimbs: u32, Params>(x: BigNum<NumLimbs, Params>) -> Self where Params: BigNumParamsTrait<NumLimbs> + RuntimeBigNumParamsTrait<NumLimbs> {
x.validate_in_field();
let mut (slices, skew): ([u8; N], bool) = get_wnaf_slices2(x.limbs);

Expand Down

0 comments on commit 46b1a89

Please sign in to comment.