Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions ceno_host/tests/test_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -440,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(())
}
Expand Down
2 changes: 2 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions examples/examples/secp256k1.rs
Original file line number Diff line number Diff line change
@@ -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
}
Loading