|
1 |
| -use core::ops::{Add, Mul, Sub}; |
2 |
| - |
3 | 1 | use halo2curves_axiom::ff;
|
4 | 2 |
|
5 | 3 | use crate::{field::Field, DivAssignUnsafe, DivUnsafe};
|
6 | 4 |
|
7 |
| -macro_rules! div_unsafe_impl { |
| 5 | +macro_rules! field_impls { |
8 | 6 | ($($t:ty),*) => {
|
9 | 7 | $(
|
10 | 8 | impl DivUnsafe for $t {
|
@@ -42,49 +40,37 @@ macro_rules! div_unsafe_impl {
|
42 | 40 | *self *= other.invert().unwrap();
|
43 | 41 | }
|
44 | 42 | }
|
| 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 | + |
45 | 59 | )*
|
46 | 60 | };
|
47 | 61 | }
|
48 | 62 |
|
49 |
| -div_unsafe_impl!( |
| 63 | +field_impls!( |
50 | 64 | halo2curves_axiom::bls12_381::Fq,
|
51 | 65 | halo2curves_axiom::bls12_381::Fq12,
|
52 | 66 | halo2curves_axiom::bls12_381::Fq2
|
53 | 67 | );
|
54 |
| -div_unsafe_impl!( |
| 68 | +field_impls!( |
55 | 69 | halo2curves_axiom::bn256::Fq,
|
56 | 70 | halo2curves_axiom::bn256::Fq12,
|
57 | 71 | halo2curves_axiom::bn256::Fq2
|
58 | 72 | );
|
59 | 73 |
|
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 |
| - |
88 | 74 | mod bn254 {
|
89 | 75 | use alloc::vec::Vec;
|
90 | 76 |
|
|
0 commit comments