diff --git a/common-testing/src/emulator.rs b/common-testing/src/emulator.rs index 401445a40..a498eb0ab 100644 --- a/common-testing/src/emulator.rs +++ b/common-testing/src/emulator.rs @@ -11,6 +11,7 @@ use serde::{de::DeserializeOwned, Serialize}; use std::{path::PathBuf, process::Command}; use tempfile::{tempdir, TempDir}; +use std::path::Path; #[derive(Clone)] pub enum EmulatorType { @@ -86,7 +87,7 @@ pub fn parse_output( .expect("Failed to parse exit code"), ); - if output.len() == 0 { + if output.is_empty() { Ok((exit_code, None)) } else { // Deserialize the rest as the output. @@ -128,7 +129,7 @@ pub fn setup_guest_project(runtime_path: &PathBuf) -> TempDir { } /// Setup project. -pub fn write_guest_source_code(tmp_project_path: &PathBuf, test_path: &str) { +pub fn write_guest_source_code(tmp_project_path: &Path, test_path: &str) { // Overwrite the main.rs file with the test file. let main_file = format!("{}/src/main.rs", tmp_project_path.to_str().unwrap()); @@ -160,7 +161,7 @@ pub fn compile_guest_project( .arg(target) .env( "RUSTFLAGS", - &format!( + format!( "{compile_flags} -C relocation-model=pic -C panic=abort -C link-arg=-T{}", linker_script.display() ), @@ -222,7 +223,7 @@ pub fn emulate( ) -> (Vec, Vec, Vec) { let mut exit_code_bytes: Vec = Vec::new(); let mut output_bytes: Vec = Vec::new(); - let ad = vec![0u8; 0xbeef as usize]; // placeholder ad until we have use for it + let ad = vec![0u8; 0xbeef_usize]; // placeholder ad until we have use for it let mut cycles = Vec::new(); for elf in elfs { diff --git a/examples/src/bin/input_output.rs b/examples/src/bin/input_output.rs index ad53d7385..81df4f022 100644 --- a/examples/src/bin/input_output.rs +++ b/examples/src/bin/input_output.rs @@ -2,8 +2,21 @@ use nexus_rt::println; +#[cfg(not(target_arch = "riscv32"))] +fn read_inputs() -> Result<(u32, u32), String> { + Ok((42, 24)) +} + +#[cfg(not(target_arch = "riscv32"))] +fn result(output: &u32) -> Result<(), String> { + println!("Result: {}", output); + Ok(()) +} + #[nexus_rt::main] -#[nexus_rt::public_input(x)] +#[cfg_attr(not(target_arch = "riscv32"), nexus_rt::custom_input((x, y), read_inputs))] +#[cfg_attr(not(target_arch = "riscv32"), nexus_rt::custom_output(result))] +#[cfg_attr(target_arch = "riscv32", nexus_rt::public_input(x))] fn main(x: u32, y: u32) -> u32 { println!("Read public input: {}", x); println!("Read private input: {}", y); diff --git a/examples/src/bin/keccak_input.rs b/examples/src/bin/keccak_input.rs index 26e06be10..3b4ffc55d 100644 --- a/examples/src/bin/keccak_input.rs +++ b/examples/src/bin/keccak_input.rs @@ -148,8 +148,7 @@ fn ethash_final(c: &mut Sha3) -> Vec { fn ethash(bytes: &[u8]) -> Vec { let mut c = sha3_init(32); sha3_update(&mut c, bytes); - let v = ethash_final(&mut c); - v + ethash_final(&mut c) } #[cfg(not(target_arch = "riscv32"))] diff --git a/examples/src/bin/long_io.rs b/examples/src/bin/long_io.rs index 09c7367c5..ac6154415 100644 --- a/examples/src/bin/long_io.rs +++ b/examples/src/bin/long_io.rs @@ -1,8 +1,24 @@ #![cfg_attr(target_arch = "riscv32", no_std, no_main)] +type InputTuple = (bool, u8, u16, u32, u64, bool, u8, u16, u32, u64); +type OutputTuple = (bool, u8, u16, u32, u64); + +#[cfg(not(target_arch = "riscv32"))] +fn read_inputs() -> Result { + Ok((true, 1, 2, 3, 4, false, 5, 6, 7, 8)) +} + +#[cfg(not(target_arch = "riscv32"))] +fn result(output: &OutputTuple) -> Result<(), String> { + println!("Result: {:?}", output); + Ok(()) +} + #[nexus_rt::main] -#[nexus_rt::public_input(a0, a1, a2, a3, a4)] -#[nexus_rt::private_input(b0, b1, b2, b3, b4)] +#[cfg_attr(not(target_arch = "riscv32"), nexus_rt::custom_input((a0, a1, a2, a3, a4, b0, b1, b2, b3, b4), read_inputs))] +#[cfg_attr(not(target_arch = "riscv32"), nexus_rt::custom_output(result))] +#[cfg_attr(target_arch = "riscv32", nexus_rt::public_input(a0, a1, a2, a3, a4))] +#[cfg_attr(target_arch = "riscv32", nexus_rt::private_input(b0, b1, b2, b3, b4))] fn main( a0: bool, a1: u8, @@ -14,6 +30,6 @@ fn main( b2: u16, b3: u32, b4: u64, -) -> (bool, u8, u16, u32, u64) { +) -> OutputTuple { (a0 & b0, a1 + b1, a2 + b2, a3 + b3, a4 + b4) } diff --git a/sdk/src/traits.rs b/sdk/src/traits.rs index e81817c5f..591905395 100644 --- a/sdk/src/traits.rs +++ b/sdk/src/traits.rs @@ -90,7 +90,7 @@ impl CheckedView for nexus_core::nvm::View { ); let static_memory_size = - (&expected_elf.rom_image.len() + &expected_elf.ram_image.len()) * WORD_SIZE; + (expected_elf.rom_image.len() + expected_elf.ram_image.len()) * WORD_SIZE; Self::new( &Some(*memory_layout),