11// ANCHOR: imports
22use hex_literal:: hex;
3- use openvm_algebra_guest:: { Field , IntMod } ;
43use openvm_ecc_guest:: {
4+ algebra:: IntMod ,
5+ ed25519:: { Ed25519Coord , Ed25519Point } ,
56 edwards:: TwistedEdwardsPoint ,
6- weierstrass:: WeierstrassPoint
7- Group ,
7+ weierstrass:: WeierstrassPoint ,
88} ;
99use openvm_k256:: { Secp256k1Coord , Secp256k1Point } ;
1010// 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- }
1511
1612// ANCHOR: init
1713openvm:: init!( ) ;
1814/* The init! macro will expand to the following
1915openvm_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,
16+ "115792089237316195423570985008687907853269984665640564039457584007908834671663",
17+ "115792089237316195423570985008687907852837564279074904382605163141518161494337"
6918}
19+ openvm_ecc_guest::sw_macros::sw_init! { Secp256k1Point }
20+ openvm_ecc_guest::te_macros::te_init! { Ed25519Point }
7021*/
7122// ANCHOR_END: init
7223
@@ -87,19 +38,19 @@ pub fn main() {
8738 #[ allow( clippy:: op_ref) ]
8839 let _p3 = & p1 + & p2;
8940
90- let x1 = Edwards25519Coord :: from_be_bytes ( & hex ! (
41+ let x1 = Ed25519Coord :: from_be_bytes ( & hex ! (
9142 "216936D3CD6E53FEC0A4E231FDD6DC5C692CC7609525A7B2C9562D608F25D51A"
9243 ) ) ;
93- let y1 = Edwards25519Coord :: from_be_bytes ( & hex ! (
44+ let y1 = Ed25519Coord :: from_be_bytes ( & hex ! (
9445 "6666666666666666666666666666666666666666666666666666666666666658"
9546 ) ) ;
96- let p1 = Edwards25519Point :: from_xy ( x1, y1) . unwrap ( ) ;
47+ let p1 = Ed25519Point :: from_xy ( x1, y1) . unwrap ( ) ;
9748
98- let x2 = Edwards25519Coord :: from_u32 ( 2 ) ;
99- let y2 = Edwards25519Coord :: from_be_bytes ( & hex ! (
49+ let x2 = Ed25519Coord :: from_u32 ( 2 ) ;
50+ let y2 = Ed25519Coord :: from_be_bytes ( & hex ! (
10051 "1A43BF127BDDC4D71FF910403C11DDB5BA2BCDD2815393924657EF111E712631"
10152 ) ) ;
102- let p2 = Edwards25519Point :: from_xy ( x2, y2) . unwrap ( ) ;
53+ let p2 = Ed25519Point :: from_xy ( x2, y2) . unwrap ( ) ;
10354
10455 #[ allow( clippy:: op_ref) ]
10556 let _p3 = & p1 + & p2;
0 commit comments