From 93c172f128f0e26ffb568b231e57f4847ff07f47 Mon Sep 17 00:00:00 2001 From: lightsing Date: Fri, 21 Nov 2025 13:06:06 +0800 Subject: [PATCH 1/3] add k256 test --- Cargo.lock | 2 ++ ceno_host/tests/test_elf.rs | 12 ++++++++++++ examples/Cargo.toml | 2 ++ 3 files changed, 16 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 41978bb39..0ed5bb269 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2133,11 +2133,13 @@ dependencies = [ "alloy-consensus", "alloy-primitives", "ceno_crypto", + "ceno_crypto_primitives 0.1.0", "ceno_keccak", "ceno_rt", "ceno_sha2", "ceno_syscall 0.1.0", "getrandom 0.3.2", + "k256 0.13.4 (git+https://github.com/scroll-tech/elliptic-curves?branch=ceno%2Fk256-13.4)", "rand 0.8.5", "revm-precompile 28.1.1", "rkyv", diff --git a/ceno_host/tests/test_elf.rs b/ceno_host/tests/test_elf.rs index 434bcf50c..818e7c688 100644 --- a/ceno_host/tests/test_elf.rs +++ b/ceno_host/tests/test_elf.rs @@ -289,6 +289,18 @@ fn bytes_to_words(bytes: [u8; 65]) -> [u32; 16] { std::array::from_fn(|i| u32::from_le_bytes(bytes[4 * i..4 * (i + 1)].try_into().unwrap())) } +#[test] +fn test_secp256k1() -> Result<()> { + let program_elf = ceno_examples::secp256k1; + let mut state = VMState::new_from_elf(unsafe_platform(), program_elf)?; + let steps = run(&mut state)?; + + let syscalls = steps.iter().filter_map(|step| step.syscall()).collect_vec(); + assert!(!syscalls.is_empty()); + + Ok(()) +} + #[test] fn test_secp256k1_add() -> Result<()> { let program_elf = ceno_examples::secp256k1_add_syscall; diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 22b77f436..b4430f926 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -13,6 +13,7 @@ version = "0.1.0" alloy-consensus = { version = "1.0", features = ["crypto-backend"] } alloy-primitives = { version = "1.3", features = ["native-keccak"] } ceno_crypto = { path = "../guest_libs/crypto" } +ceno_crypto_primitives = { path = "../guest_libs/crypto-primitives" } ceno_keccak = { path = "../guest_libs/keccak" } ceno_rt = { path = "../ceno_rt" } ceno_sha2 = { path = "../guest_libs/sha2" } @@ -23,6 +24,7 @@ revm-precompile = { version = "28", default-features = false } tiny-keccak.workspace = true bn = { package = "substrate-bn", git = "https://github.com/scroll-tech/bn", branch = "ceno" } +k256 = { git = "https://github.com/scroll-tech/elliptic-curves", branch = "ceno/k256-13.4", default-features = false, features = ["std", "ecdsa"] } rkyv = { version = "0.8", default-features = false, features = [ "alloc", "bytecheck", From e3afdb256a923e39fa0679818e2b2a2e2d9afd40 Mon Sep 17 00:00:00 2001 From: lightsing Date: Fri, 21 Nov 2025 13:30:10 +0800 Subject: [PATCH 2/3] assert syscall happens --- ceno_host/tests/test_elf.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ceno_host/tests/test_elf.rs b/ceno_host/tests/test_elf.rs index 818e7c688..94229f56a 100644 --- a/ceno_host/tests/test_elf.rs +++ b/ceno_host/tests/test_elf.rs @@ -452,12 +452,12 @@ fn test_secp256k1_decompress() -> Result<()> { #[test] fn test_secp256k1_ecrecover() -> Result<()> { - let _ = ceno_host::run( - CENO_PLATFORM, - ceno_examples::secp256k1_ecrecover, - &CenoStdin::default(), - None, - ); + let program_elf = ceno_examples::secp256k1_ecrecover; + let mut state = VMState::new_from_elf(unsafe_platform(), program_elf)?; + + let steps = run(&mut state)?; + let syscalls = steps.iter().filter_map(|step| step.syscall()).collect_vec(); + assert!(!syscalls.is_empty()); Ok(()) } From fe9c9510767ae88d2f062b33280df9e2e3648921 Mon Sep 17 00:00:00 2001 From: lightsing Date: Fri, 21 Nov 2025 13:34:33 +0800 Subject: [PATCH 3/3] add k256 --- examples/examples/secp256k1.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 examples/examples/secp256k1.rs diff --git a/examples/examples/secp256k1.rs b/examples/examples/secp256k1.rs new file mode 100644 index 000000000..449248f9c --- /dev/null +++ b/examples/examples/secp256k1.rs @@ -0,0 +1,16 @@ + +extern crate ceno_rt; + +use k256::{ProjectivePoint, Scalar}; +use k256::elliptic_curve::Group; +use k256::elliptic_curve::ops::MulByGenerator; + +fn main() { + let scalar = Scalar::from(5u64); + let a = ProjectivePoint::mul_by_generator(&scalar); + let _ = a.double(); // -> syscall_secp256k1_double + + let scalar = Scalar::from(6u64); + let b = ProjectivePoint::mul_by_generator(&scalar); + let _ = a + b; // -> syscall_secp256k1_add +}