Try   HackMD

Building the RISC-V VM

This is the rust target I am interested in;
riscv32im-risc0-zkvm-elf
riscv32im-unknown-none-elf

#resources
https://github.com/0xPolygonHermez/zisk/tree/develop/riscv

ELF: The Extensible and Linkable Format

The main uses of ELF are for;

  1. Executable
  2. Shared Library
  3. Object File Format

The main terms you would be hearing in context of ELF are;
a. Sections
b. Segments

Each ELF file can coontain zero or more segment and zero or more sections.
Segements and sectios are two very different things, the most importatnt thing you need to note is that segements are exclusively used at runtime and section are exclusively used at link time.

Segment and section both represent data from the ELF file.

Structure of the ELF File

  1. ELF header
  2. Program Header Table (if applicable)
  3. Section Header Table
  4. Sections and Segments
  5. String Tables, Symbol Tables, and Debug Information (optional)

This is the crate I would like to use to handle the ELF parsing: https://github.com/cole14/rust-elf

Ended up making use of the ELF parser code implemented in the SP1 Succinct labs;

Modules

I would be implementing two classes of crates in this project;

  1. Binaries
  2. Libraries

Binaries

Would be implementing only one binary crate which would be tasked to run the VM in debug mode printing each instruction in it disassembled format.

Libraries

  • Core: This is a very important crate that holds globally used data structures, constants and some traits.
  • ELF Parser: This is the ELF parser code gotten from the SP1 codebase.
  • Emulator SDK: This crate holds all the logic needed to run this VM.

RUST implemenation of the project can be found here;
https://github.com/developeruche/riscv-emulator