diff --git a/.github/workflows/mips-build.yml b/.github/workflows/mips-build.yml new file mode 100644 index 0000000000..264a485ee4 --- /dev/null +++ b/.github/workflows/mips-build.yml @@ -0,0 +1,51 @@ +name: MIPS Build and Package + +on: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + rust_toolchain_version: ["1.74"] + + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Cache apt packages + id: apt-cache + uses: actions/cache@v4 + with: + path: | + /var/cache/apt/archives/*.deb + key: ${{ runner.os }}-apt-${{ hashFiles('.github/workflows/mips-build.yml') }} + + - name: Install MIPS tools + run: | + sudo apt-get update + sudo apt-get install -y binutils-mips-linux-gnu + + - name: Build MIPS programs + run: make build-mips-programs + + - name: Use shared Rust toolchain setting up steps + uses: ./.github/actions/toolchain-shared + with: + rust_toolchain_version: ${{ matrix.rust_toolchain_version }} + + - name: Test elf_loader against mips programs + run: ./o1vm/test-gen-state-json.sh + + - name: Create tar archive + run: | + cd o1vm/resources/programs/mips + tar -czf mips-binaries.tar.gz bin/ + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: mips-binaries + path: o1vm/resources/programs/mips/mips-binaries.tar.gz diff --git a/.gitignore b/.gitignore index 75a56fa0f0..4cdc7c90ff 100644 --- a/.gitignore +++ b/.gitignore @@ -39,8 +39,13 @@ o1vm/op-program-db* o1vm/state.json meta.json state.json +o1vm/meta_test.json # Directory for the RISC-V 32bits toolchain _riscv32-gnu-toolchain o1vm/resources/programs/riscv32im/bin/*.o -o1vm/resources/programs/mips/bin/*.o + +# modified assembly files generated from cannon's open mips tests +o1vm/resources/programs/mips/src +# mips binary files for open mips tests +o1vm/resources/programs/mips/bin diff --git a/README.md b/README.md index 68f0191f5f..8f6b42bb21 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,8 @@ You can visualize the documentation by opening the file `target/doc/index.html`. This workflow runs benchmarks when a pull request is labeled with "benchmark." It sets up the Rust and OCaml environments, installs necessary tools, and executes cargo criterion benchmarks on the kimchi crate. The benchmark results are then posted as a comment on the pull request for review. - [Deploy Specifications & Docs to GitHub Pages](.github/workflows/gh-page.yml). When CI passes on master, the documentation built from the rust code will be available by this [link](https://o1-labs.github.io/proof-systems/rustdoc) and the book will be available by this [link](https://o1-labs.github.io/proof-systems). +- [MIPS Build and Package](.github/workflows/mips-build.yml) + This workflow runs the assembler and linker on the programs from the OpenMips test suite, and provides a link where you can download the artifacts (recommended if you don't have / can't install the required MIPS tooling). This workflow also runs the o1vm ELF parser on the artifacts to check that our parsing is working. Currently it is run via manual trigger only -- you can find the trigger in the [GitHub actions tab](https://github.com/o1-labs/proof-systems/actions/workflows/mips-build.yml) and the link to the artifacts will appear in logs of the `Upload Artifacts` stage. ## Nix for Dependencies (WIP) diff --git a/o1vm/src/cannon.rs b/o1vm/src/cannon.rs index e9ae23d699..a87e5e92a4 100644 --- a/o1vm/src/cannon.rs +++ b/o1vm/src/cannon.rs @@ -209,7 +209,7 @@ pub struct HostProgram { pub struct VmConfiguration { pub input_state_file: String, pub output_state_file: String, - pub metadata_file: String, + pub metadata_file: Option, pub proof_at: StepFrequency, pub stop_at: StepFrequency, pub snapshot_state_at: StepFrequency, diff --git a/o1vm/src/cli/cannon.rs b/o1vm/src/cli/cannon.rs index 879036e083..9445be62d0 100644 --- a/o1vm/src/cli/cannon.rs +++ b/o1vm/src/cli/cannon.rs @@ -19,13 +19,8 @@ pub struct MipsVmConfigurationArgs { )] output: String, - #[arg( - long, - value_name = "FILE", - default_value = "meta.json", - help = "metadata file" - )] - meta: String, + #[arg(long, value_name = "FILE", help = "metadata file")] + meta: Option, #[arg( long = "proof-at", @@ -104,9 +99,25 @@ pub struct RunArgs { pub vm_cfg: MipsVmConfigurationArgs, } +#[derive(Parser, Debug, Clone)] +pub struct GenStateJsonArgs { + #[arg(short = 'i', long, value_name = "FILE", help = "input ELF file")] + pub input: String, + #[arg( + short = 'o', + long, + value_name = "FILE", + default_value = "state.json", + help = "output state.json file" + )] + pub output: String, +} + #[derive(Subcommand, Clone, Debug)] pub enum Cannon { Run(RunArgs), #[command(name = "test-optimism-preimage-read")] TestPreimageRead(RunArgs), + #[command(name = "gen-state-json")] + GenStateJson(GenStateJsonArgs), } diff --git a/o1vm/src/elf_loader.rs b/o1vm/src/elf_loader.rs index ecdaf895fe..b2e0e1009f 100644 --- a/o1vm/src/elf_loader.rs +++ b/o1vm/src/elf_loader.rs @@ -1,24 +1,19 @@ use crate::cannon::{Page, State, PAGE_SIZE}; -use elf::{endian::LittleEndian, section::SectionHeader, ElfBytes}; +use elf::{ + endian::{BigEndian, EndianParse, LittleEndian}, + section::SectionHeader, + ElfBytes, +}; use log::debug; use std::{collections::HashMap, path::Path}; -/// Parse an ELF file and return the parsed data as a structure that is expected -/// by the o1vm RISC-V 32 bits edition. -// FIXME: parametrize by an architecture. We should return a state depending on the -// architecture. In the meantime, we can have parse_riscv32i and parse_mips. -// FIXME: for now, we return a State structure, either for RISC-V 32i or MIPS. -// We should return a structure specifically built for the o1vm, and not tight -// to Cannon. It will be done in a future PR to avoid breaking the current code -// and have a huge diff. -pub fn parse_riscv32(path: &Path) -> Result { - debug!("Start parsing the ELF file to load a RISC-V 32i compatible state"); - let file_data = std::fs::read(path).expect("Could not read file."); - let slice = file_data.as_slice(); - let file = ElfBytes::::minimal_parse(slice).expect("Open ELF file failed."); +pub enum Architecture { + Mips, + RiscV32, +} +pub fn make_state(file: ElfBytes) -> Result { // Checking it is RISC-V - assert_eq!(file.ehdr.e_machine, 243); let (shdrs_opt, strtab_opt) = file .section_headers_with_strtab() @@ -51,9 +46,11 @@ pub fn parse_riscv32(path: &Path) -> Result { .section_data(text_section) .expect("Failed to read data from .text section"); + // address of starting instruction in code section let code_section_starting_address = text_section.sh_addr as usize; let code_section_size = text_section.sh_size as usize; - let code_section_end_address = code_section_starting_address + code_section_size; + // address of last instruction in code section + let code_section_end_address = code_section_starting_address + code_section_size - 1; debug!( "The executable code starts at address {}, has size {} bytes, and ends at address {}.", code_section_starting_address, code_section_size, code_section_end_address @@ -64,17 +61,22 @@ pub fn parse_riscv32(path: &Path) -> Result { let page_size_usize: usize = PAGE_SIZE.try_into().unwrap(); // Padding to get the right number of pages. We suppose that the memory // index starts at 0. + + // the address that the first page starts on let start_page_address: usize = (code_section_starting_address / page_size_usize) * page_size_usize; - let end_page_address = - (code_section_end_address / (page_size_usize - 1)) * page_size_usize + page_size_usize; + + // the address that the last page starts on + let end_page_address = (code_section_end_address / page_size_usize) * page_size_usize; let first_page_index = start_page_address / page_size_usize; - let last_page_index = (end_page_address - 1) / page_size_usize; + + let last_page_index = end_page_address / page_size_usize; + let mut data_offset = 0; (first_page_index..=last_page_index).for_each(|page_index| { let mut data = vec![0; page_size_usize]; - // Special case of only one page + // Special case where all code fits in one page if first_page_index == last_page_index { let data_length = code_section_end_address - code_section_starting_address; let page_offset = code_section_starting_address - start_page_address; @@ -83,7 +85,7 @@ pub fn parse_riscv32(path: &Path) -> Result { data_offset += data_length; } else { let data_length = if page_index == last_page_index { - code_section_end_address - (page_index * page_size_usize) + code_section_end_address - end_page_address } else { page_size_usize }; @@ -92,8 +94,9 @@ pub fn parse_riscv32(path: &Path) -> Result { } else { 0 }; - data[page_offset..] + data[page_offset..page_offset + data_length] .copy_from_slice(&text_section_data[data_offset..data_offset + data_length]); + data_offset += data_length; } let page = Page { @@ -143,3 +146,22 @@ pub fn parse_riscv32(path: &Path) -> Result { Ok(state) } + +pub fn parse_elf(arch: Architecture, path: &Path) -> Result { + debug!("Start parsing the ELF file to load a compatible state"); + let file_data = std::fs::read(path).expect("Could not read file."); + let slice = file_data.as_slice(); + match arch { + Architecture::Mips => { + let file = ElfBytes::::minimal_parse(slice).expect("Open ELF file failed."); + assert_eq!(file.ehdr.e_machine, 8); + make_state(file) + } + Architecture::RiscV32 => { + let file = + ElfBytes::::minimal_parse(slice).expect("Open ELF file failed."); + assert_eq!(file.ehdr.e_machine, 243); + make_state(file) + } + } +} diff --git a/o1vm/src/interpreters/mips/witness.rs b/o1vm/src/interpreters/mips/witness.rs index 991b946c8d..b5fa8161a0 100644 --- a/o1vm/src/interpreters/mips/witness.rs +++ b/o1vm/src/interpreters/mips/witness.rs @@ -1143,7 +1143,7 @@ impl Env { pub fn step( &mut self, config: &VmConfiguration, - metadata: &Meta, + metadata: &Option, start: &Start, ) -> Instruction { self.reset_scratch_state(); @@ -1267,7 +1267,7 @@ impl Env { } } - fn pp_info(&mut self, at: &StepFrequency, meta: &Meta, start: &Start) { + fn pp_info(&mut self, at: &StepFrequency, meta: &Option, start: &Start) { if self.should_trigger_at(at) { let elapsed = start.time.elapsed(); // Compute the step number removing the MAX_ACC factor @@ -1286,8 +1286,9 @@ impl Env { let mem = self.memory_usage(); let name = meta - .find_address_symbol(pc) - .unwrap_or_else(|| "n/a".to_string()); + .as_ref() + .and_then(|m| m.find_address_symbol(pc)) + .unwrap_or("n/a".to_string()); info!( "processing step={} pc={:010x} insn={:010x} ips={:.2} pages={} mem={} name={}", diff --git a/o1vm/src/legacy/main.rs b/o1vm/src/legacy/main.rs index ade183ede2..e49de199a0 100644 --- a/o1vm/src/legacy/main.rs +++ b/o1vm/src/legacy/main.rs @@ -5,8 +5,8 @@ use kimchi::o1_utils; use kimchi_msm::{proof::ProofInputs, prover::prove, verifier::verify, witness::Witness}; use log::debug; use o1vm::{ - cannon::{self, Meta, Start, State}, - cli, + cannon::{self, Start, State}, + cli, elf_loader, interpreters::{ keccak::{ column::{Steps, N_ZKVM_KECCAK_COLS, N_ZKVM_KECCAK_REL_COLS, N_ZKVM_KECCAK_SEL_COLS}, @@ -33,7 +33,9 @@ use o1vm::{ test_preimage_read, }; use poly_commitment::SRS as _; -use std::{cmp::Ordering, collections::HashMap, fs::File, io::BufReader, process::ExitCode}; +use std::{ + cmp::Ordering, collections::HashMap, fs::File, io::BufReader, path::Path, process::ExitCode, +}; use strum::IntoEnumIterator; /// Domain size shared by the Keccak evaluations, MIPS evaluation and main @@ -50,18 +52,11 @@ pub fn cannon_main(args: cli::cannon::RunArgs) { // Read the JSON contents of the file as an instance of `State`. let state: State = serde_json::from_reader(reader).expect("Error reading input state file"); - let meta_file = File::open(&configuration.metadata_file).unwrap_or_else(|_| { - panic!( - "Could not open metadata file {}", - &configuration.metadata_file - ) - }); - - let meta: Meta = serde_json::from_reader(BufReader::new(meta_file)).unwrap_or_else(|_| { - panic!( - "Error deserializing metadata file {}", - &configuration.metadata_file - ) + let meta = &configuration.metadata_file.as_ref().map(|f| { + let meta_file = + File::open(f).unwrap_or_else(|_| panic!("Could not open metadata file {}", f)); + serde_json::from_reader(BufReader::new(meta_file)) + .unwrap_or_else(|_| panic!("Error deserializing metadata file {}", f)) }); let mut po = PreImageOracle::create(&configuration.host); @@ -124,7 +119,7 @@ pub fn cannon_main(args: cli::cannon::RunArgs) { } while !mips_wit_env.halt { - let instr = mips_wit_env.step(&configuration, &meta, &start); + let instr = mips_wit_env.step(&configuration, meta, &start); if let Some(ref mut keccak_env) = mips_wit_env.keccak_env { // Run all steps of hash @@ -327,6 +322,14 @@ pub fn cannon_main(args: cli::cannon::RunArgs) { // TODO: Logic } +fn gen_state_json(arg: cli::cannon::GenStateJsonArgs) -> Result<(), String> { + let path = Path::new(&arg.input); + let state = elf_loader::parse_elf(elf_loader::Architecture::Mips, path)?; + let file = File::create(&arg.output).expect("Error creating output state file"); + serde_json::to_writer_pretty(file, &state).expect("Error writing output state file"); + Ok(()) +} + pub fn main() -> ExitCode { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); let args = cli::Commands::parse(); @@ -338,6 +341,9 @@ pub fn main() -> ExitCode { cli::cannon::Cannon::TestPreimageRead(args) => { test_preimage_read::main(args); } + cli::cannon::Cannon::GenStateJson(args) => { + gen_state_json(args).expect("Error generating state.json"); + } }, } ExitCode::SUCCESS diff --git a/o1vm/src/pickles/main.rs b/o1vm/src/pickles/main.rs index 03ce2c7fa8..696dad2d68 100644 --- a/o1vm/src/pickles/main.rs +++ b/o1vm/src/pickles/main.rs @@ -9,8 +9,8 @@ use mina_poseidon::{ sponge::{DefaultFqSponge, DefaultFrSponge}, }; use o1vm::{ - cannon::{self, Meta, Start, State}, - cli, + cannon::{self, Start, State}, + cli, elf_loader, interpreters::mips::{ column::N_MIPS_REL_COLS, constraints as mips_constraints, @@ -23,7 +23,7 @@ use o1vm::{ test_preimage_read, }; use poly_commitment::{ipa::SRS, SRS as _}; -use std::{fs::File, io::BufReader, process::ExitCode, time::Instant}; +use std::{fs::File, io::BufReader, path::Path, process::ExitCode, time::Instant}; use strum::IntoEnumIterator; pub const DOMAIN_SIZE: usize = 1 << 15; @@ -40,18 +40,11 @@ pub fn cannon_main(args: cli::cannon::RunArgs) { // Read the JSON contents of the file as an instance of `State`. let state: State = serde_json::from_reader(reader).expect("Error reading input state file"); - let meta_file = File::open(&configuration.metadata_file).unwrap_or_else(|_| { - panic!( - "Could not open metadata file {}", - &configuration.metadata_file - ) - }); - - let meta: Meta = serde_json::from_reader(BufReader::new(meta_file)).unwrap_or_else(|_| { - panic!( - "Error deserializing metadata file {}", - &configuration.metadata_file - ) + let meta = &configuration.metadata_file.as_ref().map(|f| { + let meta_file = + File::open(f).unwrap_or_else(|_| panic!("Could not open metadata file {}", f)); + serde_json::from_reader(BufReader::new(meta_file)) + .unwrap_or_else(|_| panic!("Error deserializing metadata file {}", f)) }); let mut po = PreImageOracle::create(&configuration.host); @@ -93,7 +86,7 @@ pub fn cannon_main(args: cli::cannon::RunArgs) { let mut curr_proof_inputs: ProofInputs = ProofInputs::new(DOMAIN_SIZE); while !mips_wit_env.halt { - let _instr: Instruction = mips_wit_env.step(&configuration, &meta, &start); + let _instr: Instruction = mips_wit_env.step(&configuration, meta, &start); for (scratch, scratch_chunk) in mips_wit_env .scratch_state .iter() @@ -156,6 +149,14 @@ pub fn cannon_main(args: cli::cannon::RunArgs) { } } +fn gen_state_json(arg: cli::cannon::GenStateJsonArgs) -> Result<(), String> { + let path = Path::new(&arg.input); + let state = elf_loader::parse_elf(elf_loader::Architecture::Mips, path)?; + let file = File::create(&arg.output).expect("Error creating output state file"); + serde_json::to_writer_pretty(file, &state).expect("Error writing output state file"); + Ok(()) +} + pub fn main() -> ExitCode { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); let args = cli::Commands::parse(); @@ -167,6 +168,9 @@ pub fn main() -> ExitCode { cli::cannon::Cannon::TestPreimageRead(args) => { test_preimage_read::main(args); } + cli::cannon::Cannon::GenStateJson(args) => { + gen_state_json(args).expect("Error generating state.json"); + } }, } ExitCode::SUCCESS diff --git a/o1vm/test-gen-state-json.sh b/o1vm/test-gen-state-json.sh new file mode 100755 index 0000000000..61a4387c7c --- /dev/null +++ b/o1vm/test-gen-state-json.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +BIN_DIR=${1:-${BIN_DIR:-o1vm/resources/programs/mips/bin}} + +# Ensure the directory exists +if [[ ! -d "$BIN_DIR" ]]; then + echo "Error: Directory '$BIN_DIR' does not exist." + exit 1 +fi + +find "$BIN_DIR" -type f ! -name "*.o" | while read -r file; do + echo "Processing: $file" + cargo run --bin pickles_o1vm -- cannon gen-state-json -i "$file" +done diff --git a/o1vm/tests/test_elf_loader.rs b/o1vm/tests/test_elf_loader.rs index e473c38ccb..b248f8e79a 100644 --- a/o1vm/tests/test_elf_loader.rs +++ b/o1vm/tests/test_elf_loader.rs @@ -1,3 +1,5 @@ +use o1vm::elf_loader::Architecture; + #[test] // This test is used to check that the elf loader is working correctly. // We must export the code used in this test in a function that can be called by @@ -7,7 +9,7 @@ fn test_correctly_parsing_elf() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/fibonacci", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); // This is the output we get by running objdump -d fibonacci assert_eq!(state.pc, 69932); diff --git a/o1vm/tests/test_riscv_elf.rs b/o1vm/tests/test_riscv_elf.rs index d73e008b8e..556f01b708 100644 --- a/o1vm/tests/test_riscv_elf.rs +++ b/o1vm/tests/test_riscv_elf.rs @@ -1,9 +1,12 @@ use mina_curves::pasta::Fp; -use o1vm::interpreters::riscv32im::{ - interpreter::{IInstruction, Instruction, RInstruction}, - registers::RegisterAlias::*, - witness::Env, - PAGE_SIZE, +use o1vm::{ + elf_loader::Architecture, + interpreters::riscv32im::{ + interpreter::{IInstruction, Instruction, RInstruction}, + registers::RegisterAlias::*, + witness::Env, + PAGE_SIZE, + }, }; #[test] @@ -12,7 +15,7 @@ fn test_registers_indexed_by_alias() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/sll", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); assert_eq!(witness.registers[Ip], 65652); @@ -43,7 +46,7 @@ fn test_no_action() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/no-action", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); // This is the output we get by running objdump -d no-action assert_eq!(witness.registers.current_instruction_pointer, 69844); @@ -70,7 +73,7 @@ fn test_fibonacci_7() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/fibonacci-7", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); // This is the output we get by running objdump -d fibonacci-7 assert_eq!(witness.registers.current_instruction_pointer, 69932); @@ -92,7 +95,7 @@ fn test_sll() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/sll", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -109,7 +112,7 @@ fn test_addi() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/addi", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -125,7 +128,7 @@ fn test_add_1() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/add_1", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -141,7 +144,7 @@ fn test_add_2() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/add_2", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -163,7 +166,7 @@ fn test_add_overflow() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/add_overflow", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -183,7 +186,7 @@ fn test_addi_negative() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/addi_negative", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -203,7 +206,7 @@ fn test_add_sub_swap() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/add_sub_swap", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -221,7 +224,7 @@ fn test_addi_overflow() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/addi_overflow", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -239,7 +242,7 @@ fn test_addi_boundary_immediate() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/addi_boundary_immediate", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -256,7 +259,7 @@ fn test_sub() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/sub", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -273,7 +276,7 @@ fn test_sub_2() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/sub_2", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -290,7 +293,7 @@ fn test_sub_3() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/sub_3", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -307,7 +310,7 @@ fn test_xor() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/xor", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -325,7 +328,7 @@ fn test_and() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/and", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -343,7 +346,7 @@ fn test_slt() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/slt", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -362,7 +365,7 @@ fn test_div_by_zero() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/div_by_zero", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -377,7 +380,7 @@ fn test_divu_by_zero() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/divu_by_zero", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -392,7 +395,7 @@ fn test_rem_by_zero() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/rem_by_zero", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -407,7 +410,7 @@ fn test_remu_by_zero() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/remu_by_zero", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -421,7 +424,7 @@ fn test_mul_overflow() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/mul_overflow", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt { @@ -437,7 +440,7 @@ fn test_jal() { let path = curr_dir.join(std::path::PathBuf::from( "resources/programs/riscv32im/bin/jal", )); - let state = o1vm::elf_loader::parse_riscv32(&path).unwrap(); + let state = o1vm::elf_loader::parse_elf(Architecture::RiscV32, &path).unwrap(); let mut witness = Env::::create(PAGE_SIZE.try_into().unwrap(), state); while !witness.halt {