Skip to content

Commit b66eac4

Browse files
committed
Squashed commit of the following:
commit f9aa66e Author: Waylon Jepsen <[email protected]> Date: Tue May 7 09:00:35 2024 -0600 curves in sage (#39) commit 63ce62f Author: Waylon Jepsen <[email protected]> Date: Mon May 6 17:46:22 2024 -0600 fix: lock commit d1c84eb Author: Colin Roberts <[email protected]> Date: Mon May 6 16:39:25 2024 -0700 feat: home-baked `FiniteField` trait (#38) * feat: new `FiniteField` trait Now everything compiles again. Will work to clean this all up and get all the tests to pass. * fix: `GF101` tests pass * fix: reimplement monty optimizations * clean: udeps --------- Co-authored-by: Waylon Jepsen <[email protected]> commit 96c8b66 Merge: fb27e5f 62a9a57 Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon May 6 23:26:56 2024 +0000 Merge pull request #42 from pluto/dependabot/cargo/anyhow-1.0.83 Bump anyhow from 1.0.82 to 1.0.83 commit 62a9a57 Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon May 6 23:26:43 2024 +0000 Bump anyhow from 1.0.82 to 1.0.83 Bumps [anyhow](https://github.com/dtolnay/anyhow) from 1.0.82 to 1.0.83. - [Release notes](https://github.com/dtolnay/anyhow/releases) - [Commits](dtolnay/anyhow@1.0.82...1.0.83) --- updated-dependencies: - dependency-name: anyhow dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]>
1 parent b24e148 commit b66eac4

File tree

3 files changed

+63
-21
lines changed

3 files changed

+63
-21
lines changed

math/curve.sage

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# our prime modulus
2+
F101 = IntegerModRing(101)
3+
4+
# A number 5 in our prime modulus, should be 5
5+
print(IntegerMod(F101, 5))
6+
7+
# Should be 96
8+
print(IntegerMod(F101, -5))
9+
10+
# should be 81
11+
print(IntegerMod(F101, 1/5))
12+
13+
# should be 20
14+
print(IntegerMod(F101, -1/5))
15+
16+
# should be 100
17+
print(IntegerMod(F101, -1))
18+
19+
# Lets make our elliptic curve
20+
E = EllipticCurve(F101, [0, 3])
21+
22+
# lets print out the points, notice they print (x,y,z) the difference between homogenious points and affine points is that to use affine you just divide x,y by z.
23+
# We can see here that for all points in the curve group z = 1 except the zero point at infinity. So for this field they are the same
24+
print(E.points())
25+
26+
# Define polynomial ring
27+
R.<X> = PolynomialRing(F101)
28+
29+
# Lets make an extension field
30+
# niavely: we could pick x^2 + 1 but
31+
# x^2 + 1 = x^2 + 100 = (x+10)(x-10) -> There is a root in the field
32+
# lets pick x^2 + 2 which is irreducible in our field
33+
34+
# Extended polynomial ring
35+
K.<X> = GF(101**2, modulus = x^2 + 2)
36+
37+
# Curve group over polynomial ring
38+
E2 = EllipticCurve(K, [0, 3])
39+
print(E2.points())
40+
41+
# G1 is the generator for E1
42+
G1 = E(1,2)
43+
print(G1)
44+
45+
# N is the order of the group E1
46+
N = 17
47+
48+
# G2 is the generator for E2
49+
G2 = E2([36, 31 *X])
50+
print(G2)
51+
52+
# Now Lets generate the structured refrence string (SRS),
53+
# we will use the "random" number 2 for the example but in practice it should be strong random.
54+
# a circuit with n gates requires an SRS with at least
55+
# n + 5 elements as below
56+
# We will let it be of length 9, pythagorean triple uses 4 gates
57+
g1SRS = [(2**i)*G1 for i in range(7)]
58+
print(g1SRS)
59+
60+
g2SRS = [(2**i)*G2 for i in range(2)]
61+
print(g2SRS)

src/field/gf_101.rs

+2-20
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,8 @@ impl fmt::Display for GF101 {
2626
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.value) }
2727
}
2828

29-
impl From<u32> for GF101 {
30-
fn from(val: u32) -> Self { Self::new(val) }
31-
}
32-
3329
impl GF101 {
34-
// pub const fn new(value: u32) -> Self { Self { value: to_monty(value) } }
35-
pub const fn new(value: u32) -> Self { Self { value: value % Self::ORDER } }
30+
pub const fn new(value: u32) -> Self { Self { value: to_monty(value) } }
3631
}
3732

3833
impl FiniteField for GF101 {
@@ -119,8 +114,7 @@ impl SubAssign for GF101 {
119114
impl Mul for GF101 {
120115
type Output = Self;
121116

122-
// fn mul(self, rhs: Self) -> Self { Self { value: from_monty(self.value * rhs.value) } }
123-
fn mul(self, rhs: Self) -> Self::Output { Self::new(self.value * rhs.value) }
117+
fn mul(self, rhs: Self) -> Self { Self { value: from_monty(self.value * rhs.value) } }
124118
}
125119

126120
impl MulAssign for GF101 {
@@ -428,18 +422,6 @@ mod tests {
428422

429423
#[test]
430424
fn primitive_root_of_unity() {
431-
let n = 2;
432-
let omega = GF101::primitive_root_of_unity(n);
433-
println!("omega: {:?}", omega);
434-
assert_eq!(omega, F::new(95));
435-
let omega_n = omega.pow(n);
436-
for i in 1..n {
437-
let omega_i = omega.pow(i);
438-
println!("omega^{}: {:?}", i, omega_i);
439-
assert_ne!(omega_i, F::new(1));
440-
}
441-
assert_eq!(omega_n, F::new(1));
442-
443425
let n = 5;
444426
let omega = GF101::primitive_root_of_unity(n);
445427
println!("omega: {:?}", omega);

src/field/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub trait FiniteField:
2525
+ DivAssign
2626
+ Neg<Output = Self>
2727
+ Rem<Output = Self>
28-
+ From<u32>
2928
+ Hash
3029
+ 'static {
3130
type Storage: From<u32>

0 commit comments

Comments
 (0)