Skip to content

Commit 2fbe8e7

Browse files
Add decompression hints for ed25519 and rewrite curve config
A bug involving opcode collisions between short Weierstrass and twisted Edwards curves was found. To fix this, CurveConfig was rewritten and separate opcodes were given to the two types of curves.
1 parent 4710379 commit 2fbe8e7

File tree

22 files changed

+515
-301
lines changed

22 files changed

+515
-301
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/ecc/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ openvm = { path = "../../crates/toolchain/openvm" }
1111
openvm-platform = { path = "../../crates/toolchain/platform" }
1212
openvm-algebra-guest = { path = "../../extensions/algebra/guest" }
1313
openvm-ecc-guest = { path = "../../extensions/ecc/guest", features = ["k256"] }
14+
openvm-rv32im-guest = { path = "../../extensions/rv32im/guest" }
15+
1416
hex-literal = { version = "0.4.1", default-features = false }
1517
serde = { version = "1.0", default-features = false, features = [ "derive" ] }
1618

examples/ecc/openvm.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22
[app_vm_config.rv32m]
33
[app_vm_config.io]
44
[app_vm_config.modular]
5-
supported_modulus = ["115792089237316195423570985008687907853269984665640564039457584007908834671663", "115792089237316195423570985008687907852837564279074904382605163141518161494337"]
5+
supported_modulus = ["115792089237316195423570985008687907853269984665640564039457584007908834671663", "115792089237316195423570985008687907852837564279074904382605163141518161494337", "57896044618658097711785492504343953926634992332820282019728792003956564819949"]
66

7-
[[app_vm_config.ecc.supported_curves]]
7+
[[app_vm_config.ecc.supported_sw_curves]]
88
modulus = "115792089237316195423570985008687907853269984665640564039457584007908834671663"
99
scalar = "115792089237316195423570985008687907852837564279074904382605163141518161494337"
1010

11-
[app_vm_config.ecc.supported_curves.coeffs]
12-
type = "SwCurve"
11+
[app_vm_config.ecc.supported_sw_curves.coeffs]
1312
a = "0"
1413
b = "7"
1514

16-
[[app_vm_config.ecc.supported_curves]]
15+
[[app_vm_config.ecc.supported_te_curves]]
1716
modulus = "57896044618658097711785492504343953926634992332820282019728792003956564819949"
1817
scalar = "7237005577332262213973186563042994240857116359379907606001950938285454250989"
1918

20-
[app_vm_config.ecc.supported_curves.coeffs]
21-
type = "TeCurve"
19+
[app_vm_config.ecc.supported_te_curves.coeffs]
2220
a = "57896044618658097711785492504343953926634992332820282019728792003956564819948"
2321
d = "37095705934669439343138083508754565189542113879843219016388785533085940283555"

examples/ecc/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ pub fn main() {
9292

9393
let _p3 = &p1 + &p2;
9494

95-
let x1 = Edwards25519Coord::from_le_bytes(&hex!(
95+
let x1 = Edwards25519Coord::from_be_bytes(&hex!(
9696
"216936D3CD6E53FEC0A4E231FDD6DC5C692CC7609525A7B2C9562D608F25D51A"
9797
));
98-
let y1 = Edwards25519Coord::from_le_bytes(&hex!(
98+
let y1 = Edwards25519Coord::from_be_bytes(&hex!(
9999
"6666666666666666666666666666666666666666666666666666666666666658"
100100
));
101101
let p1 = Edwards25519Point::from_xy(x1, y1).unwrap();
102102

103103
let x2 = Edwards25519Coord::from_u32(2);
104-
let y2 = Edwards25519Coord::from_le_bytes(&hex!(
104+
let y2 = Edwards25519Coord::from_be_bytes(&hex!(
105105
"1A43BF127BDDC4D71FF910403C11DDB5BA2BCDD2815393924657EF111E712631"
106106
));
107107
let p2 = Edwards25519Point::from_xy(x2, y2).unwrap();

extensions/ecc/circuit/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ openvm-ecc-guest = { workspace = true, features = [
4444
"halo2curves",
4545
"k256",
4646
"p256",
47+
"ed25519",
4748
] }
4849
openvm-algebra-guest = { workspace = true }

extensions/ecc/circuit/src/config.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,26 @@ pub struct Rv32EccConfig {
2828
}
2929

3030
impl Rv32EccConfig {
31-
pub fn new(curves: Vec<CurveConfig>) -> Self {
32-
let primes: Vec<_> = curves
31+
pub fn new(
32+
sw_curves: Vec<CurveConfig<SwCurveCoeffs>>,
33+
te_curves: Vec<CurveConfig<TeCurveCoeffs>>,
34+
) -> Self {
35+
let sw_primes: Vec<_> = sw_curves
3336
.iter()
3437
.flat_map(|c| [c.modulus.clone(), c.scalar.clone()])
3538
.collect();
39+
let te_primes: Vec<_> = te_curves
40+
.iter()
41+
.flat_map(|c| [c.modulus.clone(), c.scalar.clone()])
42+
.collect();
43+
let primes = sw_primes.into_iter().chain(te_primes).collect();
3644
Self {
3745
system: SystemConfig::default().with_continuations(),
3846
base: Default::default(),
3947
mul: Default::default(),
4048
io: Default::default(),
4149
modular: ModularExtension::new(primes),
42-
ecc: EccExtension::new(curves),
50+
ecc: EccExtension::new(sw_curves, te_curves),
4351
}
4452
}
4553
}

0 commit comments

Comments
 (0)