Skip to content

Commit 173af58

Browse files
Update ecc example
1 parent e1f69d0 commit 173af58

File tree

2 files changed

+12
-62
lines changed

2 files changed

+12
-62
lines changed

examples/ecc/openvm.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ a = "0"
1414
b = "7"
1515

1616
[[app_vm_config.ecc.supported_te_curves]]
17+
struct_name = "Edwards25519Point"
1718
modulus = "57896044618658097711785492504343953926634992332820282019728792003956564819949"
1819
scalar = "7237005577332262213973186563042994240857116359379907606001950938285454250989"
1920

examples/ecc/src/main.rs

Lines changed: 11 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,20 @@
22
use hex_literal::hex;
33
use openvm_algebra_guest::{Field, IntMod};
44
use openvm_ecc_guest::{
5-
edwards::TwistedEdwardsPoint,
6-
weierstrass::WeierstrassPoint
7-
Group,
5+
ed25519::Ed25519Point, edwards::TwistedEdwardsPoint, weierstrass::WeierstrassPoint, Group,
86
};
97
use openvm_k256::{Secp256k1Coord, Secp256k1Point};
108
// ANCHOR_END: imports
11-
openvm_algebra_guest::moduli_macros::moduli_declare! {
12-
// The Secp256k1 modulus and scalar field modulus are already declared in the k256 module
13-
Edwards25519Coord { modulus = "57896044618658097711785492504343953926634992332820282019728792003956564819949" },
14-
}
159

1610
// ANCHOR: init
1711
openvm::init!();
1812
/* The init! macro will expand to the following
1913
openvm_algebra_guest::moduli_macros::moduli_init! {
20-
"0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F",
21-
"0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141",
22-
"57896044618658097711785492504343953926634992332820282019728792003956564819949",
23-
}
24-
25-
// have to implement Field for Edwards25519Coord because moduli_declare! only implements IntMod
26-
impl Field for Edwards25519Coord {
27-
const ZERO: Self = <Self as IntMod>::ZERO;
28-
const ONE: Self = <Self as IntMod>::ONE;
29-
30-
type SelfRef<'a> = &'a Self;
31-
32-
fn double_assign(&mut self) {
33-
IntMod::double_assign(self);
34-
}
35-
36-
fn square_assign(&mut self) {
37-
IntMod::square_assign(self);
38-
}
39-
}
40-
41-
// a = 57896044618658097711785492504343953926634992332820282019728792003956564819948
42-
// d = 37095705934669439343138083508754565189542113879843219016388785533085940283555
43-
// encoded in little endian, 32 limbs of 8 bits each
44-
const CURVE_A: Edwards25519Coord = Edwards25519Coord::from_const_bytes([
45-
236, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
46-
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127,
47-
]);
48-
const CURVE_D: Edwards25519Coord = Edwards25519Coord::from_const_bytes([
49-
163, 120, 89, 19, 202, 77, 235, 117, 171, 216, 65, 65, 77, 10, 112, 0, 152, 232, 121, 119, 121,
50-
64, 199, 140, 115, 254, 111, 43, 238, 108, 3, 82,
51-
]);
52-
53-
// Note that we are defining the Edwards25519 curve for illustrative purposes only.
54-
// In practice, we would use the ed25519 module which defines the Edwards25519 curve for us.
55-
openvm_ecc_guest::te_macros::te_declare! {
56-
Edwards25519Point {
57-
mod_type = Edwards25519Coord,
58-
a = CURVE_A,
59-
d = CURVE_D
60-
}
61-
}
62-
63-
openvm_ecc_guest::te_macros::te_init! {
64-
Edwards25519Point,
65-
}
66-
67-
openvm_ecc_guest::sw_macros::sw_init! {
68-
Secp256k1Point,
14+
"115792089237316195423570985008687907853269984665640564039457584007908834671663",
15+
"115792089237316195423570985008687907852837564279074904382605163141518161494337"
6916
}
17+
openvm_ecc_guest::sw_macros::sw_init! { Secp256k1Point }
18+
openvm_ecc_guest::te_macros::te_init! { Ed25519Point }
7019
*/
7120
// ANCHOR_END: init
7221

@@ -87,19 +36,19 @@ pub fn main() {
8736
#[allow(clippy::op_ref)]
8837
let _p3 = &p1 + &p2;
8938

90-
let x1 = Edwards25519Coord::from_be_bytes(&hex!(
39+
let x1 = Ed25519Coord::from_be_bytes(&hex!(
9140
"216936D3CD6E53FEC0A4E231FDD6DC5C692CC7609525A7B2C9562D608F25D51A"
9241
));
93-
let y1 = Edwards25519Coord::from_be_bytes(&hex!(
42+
let y1 = Ed25519Coord::from_be_bytes(&hex!(
9443
"6666666666666666666666666666666666666666666666666666666666666658"
9544
));
96-
let p1 = Edwards25519Point::from_xy(x1, y1).unwrap();
45+
let p1 = Ed25519Point::from_xy(x1, y1).unwrap();
9746

98-
let x2 = Edwards25519Coord::from_u32(2);
99-
let y2 = Edwards25519Coord::from_be_bytes(&hex!(
47+
let x2 = Ed25519Coord::from_u32(2);
48+
let y2 = Ed25519Coord::from_be_bytes(&hex!(
10049
"1A43BF127BDDC4D71FF910403C11DDB5BA2BCDD2815393924657EF111E712631"
10150
));
102-
let p2 = Edwards25519Point::from_xy(x2, y2).unwrap();
51+
let p2 = Ed25519Point::from_xy(x2, y2).unwrap();
10352

10453
#[allow(clippy::op_ref)]
10554
let _p3 = &p1 + &p2;

0 commit comments

Comments
 (0)