Skip to content

Commit b9db585

Browse files
Merge remote-tracking branch 'origin/main' into matthias/update-toolchain
2 parents b7e2070 + 5e7e8c1 commit b9db585

File tree

17 files changed

+2849
-1125
lines changed

17 files changed

+2849
-1125
lines changed

circ_blocks/circ_fields/src/ext_field.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
use serde::{Serialize, Deserialize};
2-
use std::ops::{Neg, Add, AddAssign, Mul, MulAssign, Sub, SubAssign};
3-
use ff::{derive::subtle::{Choice, ConditionallySelectable, ConstantTimeEq}, Field};
1+
use ff::{
2+
derive::subtle::{Choice, ConditionallySelectable, ConstantTimeEq},
3+
Field,
4+
};
45
use rand::RngCore;
6+
use serde::{Deserialize, Serialize};
7+
use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
58

69
use crate::ff_field::FGoldilocks;
710
use ff::derive::subtle::CtOption;
811
use rug::Integer;
912

1013
/// Degree 2 FGoldilocks extension field mod x^2 - 7
11-
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Hash)]
14+
#[derive(
15+
Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Hash,
16+
)]
1217
pub struct FGoldilocksExt2(pub [FGoldilocks; 2]);
1318

1419
impl FGoldilocksExt2 {
@@ -431,4 +436,4 @@ impl std::convert::From<&FGoldilocksExt2> for Integer {
431436
assert_eq!(f.0[1], FGoldilocks::from(0u64));
432437
Integer::from(&f.0[0])
433438
}
434-
}
439+
}

circ_blocks/circ_fields/src/ff_field.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,4 @@ def_field!(
151151
4
152152
);
153153

154-
def_field!(
155-
f_goldilocks,
156-
"18446744069414584321",
157-
"7",
158-
2
159-
);
154+
def_field!(f_goldilocks, "18446744069414584321", "7", 2);

circ_blocks/circ_fields/src/lib.rs

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
#![warn(missing_docs)]
44
#![deny(warnings)]
55

6+
mod ext_field;
67
mod ff_field;
78
mod int_field;
8-
mod ext_field;
99
pub mod size;
1010

1111
/// Exports for moduli defined in this crate, as ARCs
1212
pub mod moduli {
1313
pub use super::ff_field::{F_BLS12381_FMOD_ARC, F_BN254_FMOD_ARC, F_CURVE25519_FMOD_ARC};
1414
}
1515

16-
use ff_field::{FBls12381, FBn254, FCurve25519, FGoldilocks};
1716
use ext_field::FGoldilocksExt2;
17+
use ff_field::{FBls12381, FBn254, FCurve25519, FGoldilocks};
1818
use ff_field::{F_BLS12381_FMOD, F_BN254_FMOD, F_CURVE25519_FMOD, F_GOLDILOCKS_FMOD};
19-
use ff_field::{F_BLS12381_FMOD_ARC, F_BN254_FMOD_ARC, F_CURVE25519_FMOD_ARC, F_GOLDILOCKS_FMOD_ARC};
19+
use ff_field::{
20+
F_BLS12381_FMOD_ARC, F_BN254_FMOD_ARC, F_CURVE25519_FMOD_ARC, F_GOLDILOCKS_FMOD_ARC,
21+
};
2022
use int_field::IntField;
2123

2224
use datasize::DataSize;
@@ -573,10 +575,16 @@ impl FieldV {
573575
match &*self.full_cow() {
574576
FullFieldV::FBls12381(pf) => Self::from(FullFieldV::FBls12381(pf.invert().unwrap())),
575577
FullFieldV::FBn254(pf) => Self::from(FullFieldV::FBn254(pf.invert().unwrap())),
576-
FullFieldV::FCurve25519(pf) => Self::from(FullFieldV::FCurve25519(pf.invert().unwrap())),
578+
FullFieldV::FCurve25519(pf) => {
579+
Self::from(FullFieldV::FCurve25519(pf.invert().unwrap()))
580+
}
577581
FullFieldV::IntField(i) => Self::from(FullFieldV::IntField(i.clone().recip())),
578-
FullFieldV::FGoldilocks(pf) => Self::from(FullFieldV::FGoldilocks(pf.invert().unwrap())),
579-
FullFieldV::FGoldilocksExt2(pf) => Self::from(FullFieldV::FGoldilocksExt2(pf.invert().unwrap())),
582+
FullFieldV::FGoldilocks(pf) => {
583+
Self::from(FullFieldV::FGoldilocks(pf.invert().unwrap()))
584+
}
585+
FullFieldV::FGoldilocksExt2(pf) => {
586+
Self::from(FullFieldV::FGoldilocksExt2(pf.invert().unwrap()))
587+
}
580588
}
581589
}
582590

@@ -587,10 +595,16 @@ impl FieldV {
587595
match &*self.full_cow() {
588596
FullFieldV::FBls12381(pf) => Self::from(FullFieldV::FBls12381(pf.invert().unwrap())),
589597
FullFieldV::FBn254(pf) => Self::from(FullFieldV::FBn254(pf.invert().unwrap())),
590-
FullFieldV::FCurve25519(pf) => Self::from(FullFieldV::FCurve25519(pf.invert().unwrap())),
598+
FullFieldV::FCurve25519(pf) => {
599+
Self::from(FullFieldV::FCurve25519(pf.invert().unwrap()))
600+
}
591601
FullFieldV::IntField(i) => Self::from(FullFieldV::IntField(i.clone().recip())),
592-
FullFieldV::FGoldilocks(pf) => Self::from(FullFieldV::FGoldilocks(pf.invert().unwrap())),
593-
FullFieldV::FGoldilocksExt2(pf) => Self::from(FullFieldV::FGoldilocksExt2(pf.invert().unwrap())),
602+
FullFieldV::FGoldilocks(pf) => {
603+
Self::from(FullFieldV::FGoldilocks(pf.invert().unwrap()))
604+
}
605+
FullFieldV::FGoldilocksExt2(pf) => {
606+
Self::from(FullFieldV::FGoldilocksExt2(pf.invert().unwrap()))
607+
}
594608
}
595609
}
596610

@@ -625,7 +639,7 @@ impl FieldV {
625639
Err(FullFieldV::FCurve25519(pf)) => bool::from(pf.is_one()),
626640
Err(FullFieldV::IntField(i)) => i.i == 1,
627641
Err(FullFieldV::FGoldilocks(pf)) => bool::from(pf.is_one()),
628-
Err(FullFieldV::FGoldilocksExt2(pf)) => { pf == &FGoldilocksExt2::one() },
642+
Err(FullFieldV::FGoldilocksExt2(pf)) => pf == &FGoldilocksExt2::one(),
629643
}
630644
}
631645

@@ -910,9 +924,15 @@ impl Neg for FieldV {
910924
match self.full_mut() {
911925
FullFieldV::FBls12381(pf) => Self::from(FullFieldV::FBls12381(pf.clone().neg())),
912926
FullFieldV::FBn254(pf) => Self::from(FullFieldV::FBn254(pf.clone().neg())),
913-
FullFieldV::FCurve25519(pf) => Self::from(FullFieldV::FCurve25519(pf.clone().neg())),
914-
FullFieldV::FGoldilocks(pf) => Self::from(FullFieldV::FGoldilocks(pf.clone().neg())),
915-
FullFieldV::FGoldilocksExt2(pf) => Self::from(FullFieldV::FGoldilocksExt2(pf.clone().neg())),
927+
FullFieldV::FCurve25519(pf) => {
928+
Self::from(FullFieldV::FCurve25519(pf.clone().neg()))
929+
}
930+
FullFieldV::FGoldilocks(pf) => {
931+
Self::from(FullFieldV::FGoldilocks(pf.clone().neg()))
932+
}
933+
FullFieldV::FGoldilocksExt2(pf) => {
934+
Self::from(FullFieldV::FGoldilocksExt2(pf.clone().neg()))
935+
}
916936
FullFieldV::IntField(i) => Self::from(FullFieldV::IntField(i.clone().neg())),
917937
}
918938
} else {

circ_blocks/third_party/ZoKrates/zokrates_pest_ast/src/lib.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@ extern crate lazy_static;
99

1010
pub use ast::{
1111
Access, AnyString, Arguments, ArrayAccess, ArrayCommitted, ArrayDeclStatement,
12-
ArrayInitializerExpression, ArrayParamMetadata, ArrayTranscript, ArrayType,
13-
AssertionStatement, Assignee, AssigneeAccess, BasicOrStructType, BasicType, BinaryExpression,
14-
BinaryOperator, BooleanLiteralExpression, BooleanType, CallAccess, ConditionalStatement,
15-
CondStoreStatement, ConstantDefinition, ConstantGenericValue, Curve, DecimalLiteralExpression,
16-
DecimalNumber, DecimalSuffix, DefinitionStatement, DimRO, ExplicitGenerics, Expression, FieldSuffix,
17-
FieldType, File, FromExpression, FromImportDirective, FuncInline, FunctionDefinition, HexLiteralExpression,
18-
HexNumberExpression, IdentifierExpression, ImportDirective, ImportSymbol,
12+
ArrayInitializerExpression, ArrayParamMetadata, ArrayTranscript, ArrayType, AssertionStatement,
13+
Assignee, AssigneeAccess, BasicOrStructType, BasicType, BinaryExpression, BinaryOperator,
14+
BooleanLiteralExpression, BooleanType, CallAccess, CondStoreStatement, ConditionalStatement,
15+
ConstantDefinition, ConstantGenericValue, Curve, DecimalLiteralExpression, DecimalNumber,
16+
DecimalSuffix, DefinitionStatement, DimRO, ExplicitGenerics, Expression, FieldSuffix,
17+
FieldType, File, FromExpression, FromImportDirective, FuncInline, FunctionDefinition,
18+
HexLiteralExpression, HexNumberExpression, IdentifierExpression, ImportDirective, ImportSymbol,
1919
InlineArrayExpression, InlineStructExpression, InlineStructMember, IterationStatement,
2020
LiteralExpression, MainImportDirective, MemberAccess, NegOperator, NotOperator, Parameter,
2121
PosOperator, PostfixExpression, Pragma, PrivateNumber, PrivateVisibility, PublicVisibility,
2222
Range, RangeOrExpression, ReturnStatement, Span, Spread, SpreadOrExpression, Statement,
2323
StrOperator, StructDefinition, StructField, StructType, SymbolDeclaration, TernaryExpression,
24-
ToExpression, ToFieldOperator, Type, TypeDefinition, TypedIdentifier, TypedIdentifierOrAssignee,
25-
U16NumberExpression, U16Suffix, U16Type, U32NumberExpression, U32Suffix, U32Type,
26-
U64NumberExpression, U64Suffix, U64Type, U8NumberExpression, U8Suffix, U8Type, UnaryExpression,
27-
UnaryOperator, Underscore, Visibility, WhileLoopStatement, WitnessStatement, EOI,
24+
ToExpression, ToFieldOperator, Type, TypeDefinition, TypedIdentifier,
25+
TypedIdentifierOrAssignee, U16NumberExpression, U16Suffix, U16Type, U32NumberExpression,
26+
U32Suffix, U32Type, U64NumberExpression, U64Suffix, U64Type, U8NumberExpression, U8Suffix,
27+
U8Type, UnaryExpression, UnaryOperator, Underscore, Visibility, WhileLoopStatement,
28+
WitnessStatement, EOI,
2829
};
2930

3031
mod ast {
@@ -428,7 +429,7 @@ mod ast {
428429
Iteration(IterationStatement<'ast>),
429430
WhileLoop(WhileLoopStatement<'ast>),
430431
Conditional(ConditionalStatement<'ast>),
431-
ArrayDecl(ArrayDeclStatement<'ast>)
432+
ArrayDecl(ArrayDeclStatement<'ast>),
432433
}
433434

434435
impl<'ast> Statement<'ast> {

circ_blocks/third_party/ZoKrates/zokrates_stdlib/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::env;
55
fn main() {
66
// export stdlib folder to OUT_DIR
77
export_stdlib();
8-
98
}
109

1110
fn export_stdlib() {

ff/ff_derive/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ fn validate_struct(ast: &syn::DeriveInput, limbs: usize) -> Option<proc_macro2::
257257
syn::Expr::Group(expr_group) => match &*expr_group.expr {
258258
syn::Expr::Lit(expr_lit) => Some(&expr_lit.lit),
259259
_ => None,
260-
}
261-
_ => None
260+
},
261+
_ => None,
262262
};
263263
let lit_int = match match expr_lit {
264264
Some(syn::Lit::Int(lit_int)) => Some(lit_int),
@@ -576,7 +576,9 @@ fn prime_field_constants_and_sqrt(
576576
);
577577
let field_name = name;
578578
// sqrt(-1)
579-
let sqrt_minus_1 = (modulus - BigUint::from_str("1").unwrap()).sqrt().to_string();
579+
let sqrt_minus_1 = (modulus - BigUint::from_str("1").unwrap())
580+
.sqrt()
581+
.to_string();
580582
quote! {
581583
use ::ff::derive::subtle::{ConditionallySelectable, ConstantTimeEq};
582584
let c1 = #field_name::from_str_vartime(#sqrt_minus_1).unwrap();

0 commit comments

Comments
 (0)