2
2
use hex_literal:: hex;
3
3
use openvm_algebra_guest:: { Field , IntMod } ;
4
4
use openvm_ecc_guest:: {
5
- edwards:: TwistedEdwardsPoint ,
6
- weierstrass:: WeierstrassPoint
7
- Group ,
5
+ ed25519:: Ed25519Point , edwards:: TwistedEdwardsPoint , weierstrass:: WeierstrassPoint , Group ,
8
6
} ;
9
7
use openvm_k256:: { Secp256k1Coord , Secp256k1Point } ;
10
8
// 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
- }
15
9
16
10
// ANCHOR: init
17
11
openvm:: init!( ) ;
18
12
/* The init! macro will expand to the following
19
13
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"
69
16
}
17
+ openvm_ecc_guest::sw_macros::sw_init! { Secp256k1Point }
18
+ openvm_ecc_guest::te_macros::te_init! { Ed25519Point }
70
19
*/
71
20
// ANCHOR_END: init
72
21
@@ -87,19 +36,19 @@ pub fn main() {
87
36
#[ allow( clippy:: op_ref) ]
88
37
let _p3 = & p1 + & p2;
89
38
90
- let x1 = Edwards25519Coord :: from_be_bytes ( & hex ! (
39
+ let x1 = Ed25519Coord :: from_be_bytes ( & hex ! (
91
40
"216936D3CD6E53FEC0A4E231FDD6DC5C692CC7609525A7B2C9562D608F25D51A"
92
41
) ) ;
93
- let y1 = Edwards25519Coord :: from_be_bytes ( & hex ! (
42
+ let y1 = Ed25519Coord :: from_be_bytes ( & hex ! (
94
43
"6666666666666666666666666666666666666666666666666666666666666658"
95
44
) ) ;
96
- let p1 = Edwards25519Point :: from_xy ( x1, y1) . unwrap ( ) ;
45
+ let p1 = Ed25519Point :: from_xy ( x1, y1) . unwrap ( ) ;
97
46
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 ! (
100
49
"1A43BF127BDDC4D71FF910403C11DDB5BA2BCDD2815393924657EF111E712631"
101
50
) ) ;
102
- let p2 = Edwards25519Point :: from_xy ( x2, y2) . unwrap ( ) ;
51
+ let p2 = Ed25519Point :: from_xy ( x2, y2) . unwrap ( ) ;
103
52
104
53
#[ allow( clippy:: op_ref) ]
105
54
let _p3 = & p1 + & p2;
0 commit comments