Skip to content
Closed
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
9 changes: 5 additions & 4 deletions common-testing/src/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -86,7 +87,7 @@ pub fn parse_output<T: DeserializeOwned>(
.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.
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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()
),
Expand Down Expand Up @@ -222,7 +223,7 @@ pub fn emulate(
) -> (Vec<usize>, Vec<u8>, Vec<u8>) {
let mut exit_code_bytes: Vec<u8> = Vec::new();
let mut output_bytes: Vec<u8> = 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 {
Expand Down
15 changes: 14 additions & 1 deletion examples/src/bin/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions examples/src/bin/keccak_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ fn ethash_final(c: &mut Sha3) -> Vec<u8> {
fn ethash(bytes: &[u8]) -> Vec<u8> {
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"))]
Expand Down
22 changes: 19 additions & 3 deletions examples/src/bin/long_io.rs
Original file line number Diff line number Diff line change
@@ -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<InputTuple, String> {
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,
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion sdk/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down