You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/src/custom-extensions/ecc.md
+40-10Lines changed: 40 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -15,12 +15,20 @@ The OpenVM Elliptic Curve Cryptography Extension provides support for elliptic c
15
15
-`WeierstrassPoint` trait:
16
16
It represents an affine point on a Weierstrass elliptic curve and it extends `Group`.
17
17
18
-
-`Coordinate` type is the type of the coordinates of the point, and it implements `IntMod`.
19
-
-`x()`, `y()` are used to get the affine coordinates
18
+
-`Coordinate` type is the type of the coordinates of the point, and it implements `Field`.
19
+
-`x()`, `y()` are used to get the affine coordinates.
20
20
-`from_xy` is a constructor for the point, which checks if the point is either identity or on the affine curve.
21
21
- The point supports elliptic curve operations through intrinsic functions `add_ne_nonidentity` and `double_nonidentity`.
22
22
-`decompress`: Sometimes an elliptic curve point is compressed and represented by its `x` coordinate and the odd/even parity of the `y` coordinate. `decompress` is used to decompress the point back to `(x, y)`.
23
23
24
+
-`TwistedEdwardsPoint` trait:
25
+
It represents an affine point on a twisted Edwards elliptic curve and it extends `Group`.
26
+
27
+
-`Coordinate` type is the type of the coordinates of the point, and it implements `Field`.
28
+
-`x()`, `y()` are used to get the affine coordinates.
29
+
-`from_xy` is a constructor for the point, which checks if the point is on the affine curve.
30
+
- The point supports elliptic curve addition through the `add_impl` method.
31
+
24
32
-`msm`: for multi-scalar multiplication.
25
33
26
34
-`ecdsa`: for doing ECDSA signature verification and public key recovery from signature.
@@ -29,37 +37,45 @@ The OpenVM Elliptic Curve Cryptography Extension provides support for elliptic c
29
37
30
38
For elliptic curve cryptography, the `openvm-ecc-guest` crate provides macros similar to those in [`openvm-algebra-guest`](./algebra.md):
31
39
32
-
1.**Declare**: Use `sw_declare!` to define elliptic curvesover the previously declared moduli. For example:
40
+
1.**Declare**: Use `sw_declare!`or `te_declare!`to define weierstrass or twisted edwards elliptic curves, respectively,over the previously declared moduli. For example:
This creates `Bls12_381G1Affine` and `P256Affine` structs which implement the `Group` and `WeierstrassPoint` traits, and the `Edwards25519` struct which implements the `Group` and `TwistedEdwardsPoint` traits. The underlying memory layout of the structs uses the memory layout of the `Bls12_381Fp`, `P256Coord`, and `Edwards25519Coord` structs, respectively.
40
52
41
-
Each declared curve must specify the `mod_type` (implementing `IntMod`) and a constant `b` for the Weierstrass curve equation \\(y^2 = x^3 + ax + b\\). `a` is optional and defaults to 0 for short Weierstrass curves.
42
-
This creates `Bls12_381G1Affine` and `P256Affine` structs which implement the `Group` and `WeierstrassPoint` traits. The underlying memory layout of the structs uses the memory layout of the `Bls12_381Fp` and `P256Coord` structs, respectively.
53
+
Each declared curve must specify the `mod_type` (implementing `Field`) and a constant `b` for the Weierstrass curve equation \\(y^2 = x^3 + ax + b\\) or `a` and `d` for the twisted Edwards curve equation \\(ax^2 + y^2 = 1 + dx^2y^2\\). For short Weierstrass curves, `a` is optional and defaults to 0.
43
54
44
55
2.**Init**: Called once, it enumerates these curves and allows the compiler to produce optimized instructions:
45
56
46
57
```rust
47
58
sw_init! {
48
59
Bls12_381G1Affine, P256Affine,
49
60
}
61
+
te_init! {
62
+
Edwards25519,
63
+
}
50
64
```
51
65
52
66
3.**Setup**: Similar to the moduli and complex extensions, runtime setup instructions ensure that the correct curve parameters are being used, guaranteeing secure operation.
To use elliptic curve operations on a struct defined with `sw_declare!`, it is expected that the struct for the curve's coordinate field was defined using `moduli_declare!`. In particular, the coordinate field needs to be initialized and set up as described in the [algebra extension](./algebra.md) chapter.
76
+
To use elliptic curve operations on a struct defined with `sw_declare!` or `te_declare!`, it is expected that the struct for the curve's coordinate field was defined using `moduli_declare!`. In particular, the coordinate field needs to be initialized and set up as described in the [algebra extension](./algebra.md) chapter.
61
77
62
-
For the basic operations provided by the `WeierstrassPoint`trait, the scalar field is not needed. For the ECDSA functions in the `ecdsa` module, the scalar field must also be declared, initialized, and set up.
78
+
For the basic operations provided by the `WeierstrassPoint`or `TwistedEdwardsPoint` traits, the scalar field is not needed. For the ECDSA functions in the `ecdsa` module, the scalar field must also be declared, initialized, and set up.
a = "57896044618658097711785492504343953926634992332820282019728792003956564819948"
130
+
d = "37095705934669439343138083508754565189542113879843219016388785533085940283555"
103
131
```
104
132
105
133
The `supported_modulus` parameter is a list of moduli that the guest program will use. The `ecc.supported_curves` parameter is a list of supported curves that the guest program will use. They must be provided in decimal format in the `.toml` file. For multiple curves create multiple `[[app_vm_config.ecc.supported_curves]]` sections.
134
+
135
+
The `type` field must be `SwCurve` for short Weierstrass curves and `TeCurve` for twisted Edwards curves.
0 commit comments