Skip to content
Merged
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 .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/program_artifacts
169 changes: 169 additions & 0 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "null-vm"
version = "0.1.0"
edition = "2024"

[dependencies]
elf = "0.7.4"
hashbrown = { version = "0.14.5", features = ["serde", "inline-more"] }
thiserror = "1.0.68"
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
ASM_PROGRAMS_DIR=./programs/asm
ASM_ARTIFACTS_DIR=./program_artifacts/asm

RUST_PROGRAMS_DIR=./programs/rust
RUST_ARTIFACTS_DIR=./program_artifacts/rust


ASM_PROGRAMS = $(wildcard $(ASM_PROGRAMS_DIR)/*.s)
ARTIFACTS_ASM = $(patsubst $(ASM_PROGRAMS_DIR)/%.s, $(ASM_ARTIFACTS_DIR)/%.elf, $(ASM_PROGRAMS))

RUST_PROGRAM_DIRS := $(dir $(wildcard $(RUST_PROGRAMS_DIR)/*/Cargo.toml))
RUST_PROGRAMS := $(notdir $(basename $(RUST_PROGRAM_DIRS:%/=%)))
RUST_ARTIFACTS := $(addprefix $(RUST_ARTIFACTS_DIR)/, $(addsuffix .elf, $(RUST_PROGRAMS)))

compile-programs-asm: clean $(ARTIFACTS_ASM)

compile-programs-rust: clean $(RUST_ARTIFACTS)

compile-programs: compile-programs-asm compile-programs-rust

# Compile assembly .s -> .o
$(ASM_ARTIFACTS_DIR)/%.o: $(ASM_PROGRAMS_DIR)/%.s
clang --target=riscv32 -c $< -o $@

# Link assembly .o -> .elf
$(ASM_ARTIFACTS_DIR)/%.elf: $(ASM_ARTIFACTS_DIR)/%.o
riscv64-unknown-elf-ld -m elf32lriscv $< -o $@ -e main

# Compile rust
$(RUST_ARTIFACTS_DIR)/%.elf: $(RUST_PROGRAMS_DIR)/%/Cargo.toml
cd $(RUST_PROGRAMS_DIR)/$* && \
cargo +nightly rustc \
--target riscv32im-unknown-none-elf \
-Z build-std=core,compiler_builtins \
-- --emit asm -C debuginfo=0 -C link-arg=-e -C link-arg=main
cp $(RUST_PROGRAMS_DIR)/$*/target/riscv32im-unknown-none-elf/debug/$* $@
rm -rf $(RUST_PROGRAMS_DIR)/$*/target

clean:
-rm -rf $(ASM_ARTIFACTS_DIR)
mkdir -p $(ASM_ARTIFACTS_DIR)
-rm -rf $(RUST_ARTIFACTS_DIR)
mkdir -p $(RUST_ARTIFACTS_DIR)

test: compile-programs
cargo test

test-asm: compile-programs-asm
cargo test --test asm

test-rust: compile-programs-rust
cargo test --test rust
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,26 @@
Verifiable VM made in collaboration with Lambdaclass and 3MI

Non-null name TBD

## Testing

### ASM Tests

In order to add a new asm test you should add the `.s` file under `programs/asm`
Then add the corresponding test under `tests/asm.rs`

To run them you can use

`make test`

This will compile them and run the tests

### Rust Tests

In order to add a new rust test you should add the cargo project under `programs/rust` as a new directory.
The folder should have the same name as the `Cargo.toml` program name.
Then add the corresponding test under `tests/rust.rs`

You can run it with

`make test`
8 changes: 8 additions & 0 deletions programs/asm/basic_program.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.attribute 5, "rv32i2p1_m2p0_zmmul1p0"
.Lfunc_end0:
.globl main
main:
addi a0, zero, 0
jalr zero, 0(ra)
.Lfunc_end1:
.size main, .Lfunc_end1-main
7 changes: 7 additions & 0 deletions programs/rust/basic_rust/Cargo.lock

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

6 changes: 6 additions & 0 deletions programs/rust/basic_rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "basic_rust"
version = "0.1.0"
edition = "2024"

[dependencies]
14 changes: 14 additions & 0 deletions programs/rust/basic_rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![no_std]
#![no_main]

use core::panic::PanicInfo;

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}

#[unsafe(export_name = "main")]
pub fn main() -> i32 {
return 0;
}
Loading