Skip to content

Commit

Permalink
chore: lints
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpwang committed Dec 31, 2024
1 parent b841983 commit 36dcaa1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
15 changes: 9 additions & 6 deletions extensions/ecc/tests/programs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"]
6 changes: 3 additions & 3 deletions extensions/ecc/tests/programs/examples/decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
25 changes: 11 additions & 14 deletions extensions/ecc/tests/programs/examples/ec.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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!(
Expand All @@ -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!();
}
}

0 comments on commit 36dcaa1

Please sign in to comment.