Skip to content

Commit baf1784

Browse files
Avaneesh-axiomjonathanpwang
authored andcommitted
Remove blanket Field impl that clashes with guest libs
1 parent 99c3a71 commit baf1784

File tree

1 file changed

+19
-33
lines changed

1 file changed

+19
-33
lines changed

extensions/algebra/guest/src/halo2curves.rs

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use core::ops::{Add, Mul, Sub};
2-
31
use halo2curves_axiom::ff;
42

53
use crate::{field::Field, DivAssignUnsafe, DivUnsafe};
64

7-
macro_rules! div_unsafe_impl {
5+
macro_rules! field_impls {
86
($($t:ty),*) => {
97
$(
108
impl DivUnsafe for $t {
@@ -42,49 +40,37 @@ macro_rules! div_unsafe_impl {
4240
*self *= other.invert().unwrap();
4341
}
4442
}
43+
44+
impl Field for $t {
45+
const ZERO: Self = <$t as ff::Field>::ZERO;
46+
const ONE: Self = <$t as ff::Field>::ONE;
47+
48+
type SelfRef<'a> = &'a Self;
49+
50+
fn double_assign(&mut self) {
51+
*self += *self;
52+
}
53+
54+
fn square_assign(&mut self) {
55+
*self = self.square();
56+
}
57+
}
58+
4559
)*
4660
};
4761
}
4862

49-
div_unsafe_impl!(
63+
field_impls!(
5064
halo2curves_axiom::bls12_381::Fq,
5165
halo2curves_axiom::bls12_381::Fq12,
5266
halo2curves_axiom::bls12_381::Fq2
5367
);
54-
div_unsafe_impl!(
68+
field_impls!(
5569
halo2curves_axiom::bn256::Fq,
5670
halo2curves_axiom::bn256::Fq12,
5771
halo2curves_axiom::bn256::Fq2
5872
);
5973

60-
impl<F: ff::Field> Field for F
61-
where
62-
for<'a> &'a F: Add<&'a F, Output = F>
63-
+ Sub<&'a F, Output = F>
64-
+ Mul<&'a F, Output = F>
65-
+ DivUnsafe<&'a F, Output = F>,
66-
for<'a> F: Add<&'a F, Output = F>
67-
+ Sub<&'a F, Output = F>
68-
+ Mul<&'a F, Output = F>
69-
+ DivAssignUnsafe
70-
+ DivUnsafe
71-
+ DivAssignUnsafe<&'a F>
72-
+ DivUnsafe<&'a F, Output = F>,
73-
{
74-
const ZERO: Self = <F as ff::Field>::ZERO;
75-
const ONE: Self = <F as ff::Field>::ONE;
76-
77-
type SelfRef<'a> = &'a F;
78-
79-
fn double_assign(&mut self) {
80-
*self += *self;
81-
}
82-
83-
fn square_assign(&mut self) {
84-
*self = self.square();
85-
}
86-
}
87-
8874
mod bn254 {
8975
use alloc::vec::Vec;
9076

0 commit comments

Comments
 (0)