From 36dcaa121554bf4f5cdec2cf42bb73540fe3b56b Mon Sep 17 00:00:00 2001 From: Jonathan Wang <31040440+jonathanpwang@users.noreply.github.com> Date: Tue, 31 Dec 2024 14:23:26 -0500 Subject: [PATCH] chore: lints --- .../programs/examples/complex-two-modulos.rs | 2 +- extensions/ecc/tests/programs/Cargo.toml | 15 ++++++----- .../ecc/tests/programs/examples/decompress.rs | 6 ++--- extensions/ecc/tests/programs/examples/ec.rs | 25 ++++++++----------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/extensions/algebra/tests/programs/examples/complex-two-modulos.rs b/extensions/algebra/tests/programs/examples/complex-two-modulos.rs index 0b9f20d03b..a44dc9517d 100644 --- a/extensions/algebra/tests/programs/examples/complex-two-modulos.rs +++ b/extensions/algebra/tests/programs/examples/complex-two-modulos.rs @@ -1,7 +1,7 @@ #![cfg_attr(not(feature = "std"), no_main)] #![cfg_attr(not(feature = "std"), no_std)] -use openvm_algebra_guest::{DivUnsafe, IntMod}; +use openvm_algebra_guest::IntMod; openvm::entry!(main); diff --git a/extensions/ecc/tests/programs/Cargo.toml b/extensions/ecc/tests/programs/Cargo.toml index ef91d26479..3f31bfd372 100644 --- a/extensions/ecc/tests/programs/Cargo.toml +++ b/extensions/ecc/tests/programs/Cargo.toml @@ -27,12 +27,7 @@ k256 = { version = "0.13.3", default-features = false, features = [ [features] default = [] -std = [ - "serde/std", - "openvm/std", - "openvm-ecc-guest/std", -] - +std = ["serde/std", "openvm/std", "openvm-ecc-guest/std"] k256 = ["openvm-ecc-guest/k256", "dep:k256"] [profile.release] @@ -43,3 +38,11 @@ lto = "thin" # turn on lto = fat to decrease binary size, but this optimizes [[example]] name = "ec" required-features = ["k256"] + +[[example]] +name = "decompress" +required-features = ["k256"] + +[[example]] +name = "ecdsa" +required-features = ["k256"] diff --git a/extensions/ecc/tests/programs/examples/decompress.rs b/extensions/ecc/tests/programs/examples/decompress.rs index 39fca6727c..b89716e1e4 100644 --- a/extensions/ecc/tests/programs/examples/decompress.rs +++ b/extensions/ecc/tests/programs/examples/decompress.rs @@ -5,7 +5,7 @@ use openvm::io::read_vec; use openvm_ecc_guest::{ algebra::IntMod, k256::{Secp256k1Coord, Secp256k1Point}, - weierstrass::FromCompressed, + weierstrass::{FromCompressed, WeierstrassPoint}, }; openvm::entry!(main); @@ -31,6 +31,6 @@ pub fn main() { assert_eq!(y, hint_y); let p = Secp256k1Point::decompress(x.clone(), &rec_id); - assert_eq!(p.x, x); - assert_eq!(p.y, y); + assert_eq!(p.x(), &x); + assert_eq!(p.y(), &y); } diff --git a/extensions/ecc/tests/programs/examples/ec.rs b/extensions/ecc/tests/programs/examples/ec.rs index 4b766af430..ee111991a9 100644 --- a/extensions/ecc/tests/programs/examples/ec.rs +++ b/extensions/ecc/tests/programs/examples/ec.rs @@ -1,13 +1,13 @@ #![cfg_attr(not(feature = "std"), no_main)] #![cfg_attr(not(feature = "std"), no_std)] -use core::hint::black_box; - use hex_literal::hex; use openvm_algebra_guest::IntMod; use openvm_ecc_guest::{ k256::{Secp256k1Coord, Secp256k1Point, Secp256k1Scalar}, - msm, Group, + msm, + weierstrass::WeierstrassPoint, + Group, }; openvm::entry!(main); @@ -50,34 +50,31 @@ pub fn main() { "AC54ECC4254A4EDCAB10CC557A9811ED1EF7CB8AFDC64820C6803D2C5F481639" )); - let mut p1 = black_box(Secp256k1Point { - x: x1.clone(), - y: y1.clone(), - }); - let mut p2 = black_box(Secp256k1Point { x: x2, y: y2 }); + let mut p1 = Secp256k1Point::from_xy(x1.clone(), y1.clone()).unwrap(); + let mut p2 = Secp256k1Point::from_xy(x2, y2).unwrap(); // Generic add can handle equal or unequal points. let p3 = &p1 + &p2; - if p3.x != x3 || p3.y != y3 { + if p3.x() != &x3 || p3.y() != &y3 { panic!(); } let p4 = &p2 + &p2; - if p4.x != x4 || p4.y != y4 { + if p4.x() != &x4 || p4.y() != &y4 { panic!(); } // Add assign and double assign p1 += &p2; - if p1.x != x3 || p1.y != y3 { + if p1.x() != &x3 || p1.y() != &y3 { panic!(); } p2.double_assign(); - if p2.x != x4 || p2.y != y4 { + if p2.x() != &x4 || p2.y() != &y4 { panic!(); } // Ec Mul - let p1 = black_box(Secp256k1Point { x: x1, y: y1 }); + let p1 = Secp256k1Point::from_xy(x1, y1).unwrap(); let scalar = Secp256k1Scalar::from_u32(12345678); // Calculated with https://learnmeabitcoin.com/technical/cryptography/elliptic-curve/#ec-multiply-tool let x5 = Secp256k1Coord::from_le_bytes(&hex!( @@ -87,7 +84,7 @@ pub fn main() { "9E272F746DA7BED171E522610212B6AEEAAFDB2AD9F4B530B8E1B27293B19B2C" )); let result = msm(&[scalar], &[p1]); - if result.x != x5 || result.y != y5 { + if result.x() != &x5 || result.y() != &y5 { panic!(); } }