Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
8d61d03
feat: minimal example for calling extern rust from asm
GunaDD Sep 30, 2025
8e25519
feat: made a minor change to executor
GunaDD Oct 1, 2025
cdd67e3
feat: add generate asm function for riscv add instruction
GunaDD Oct 1, 2025
96305b4
feat: in-progress of adding BEQ and managing pc in register
GunaDD Oct 1, 2025
fccec9a
feat: add instruction handling in executor
GunaDD Oct 2, 2025
0bff9a8
fix: change compilation command to workfor x86 linux
Oct 2, 2025
05da1f5
feat: make changes to assembly header and footer
Oct 2, 2025
fe3533f
feat: add register debugging tools
Oct 2, 2025
9eed4dd
feat: add loadb operation
Oct 2, 2025
78a8349
feat: tests for loadb and add
Oct 2, 2025
e2c9a66
feat: add BEQ assembly impl and some tests
Oct 2, 2025
45da4a6
feat: add in-progress fibonacci tests and some assembly to run the tests
Oct 3, 2025
5a81bfd
feat: pass in vmstate to aot assembly
Oct 3, 2025
d489603
feat: save temporary aot asm
Oct 6, 2025
11a478b
feat: add rust bridge functions
Oct 6, 2025
5bbf2e9
feat: add rust bridge
Oct 6, 2025
41bc748
feat: add shared memory handling in executor
Oct 6, 2025
317c9ad
feat: got conversion from MemoryLog to VmExecState working for ADD_RV32
Oct 6, 2025
1683bbe
feat(in progress): adding pre_compute_insns
Oct 9, 2025
e2de90b
feat(in-progress): trying to get pre_compute_insns to compile
Oct 9, 2025
144c77a
feat(in-progress): getting pre_compute_insns to compile
Oct 9, 2025
bfbc482
feat: got gunadi_dev to compile
Oct 9, 2025
e625d21
feat: pre_compute_insns compiles
Oct 9, 2025
e998173
feat: storing the splitted precompute buffers
Oct 9, 2025
6cf6b8c
feat: calling extern handler from the rust bridge
Oct 10, 2025
0d7be2f
fix: fixed memory leaks
Oct 10, 2025
de704df
feat: aotinstance in dev crate
Oct 10, 2025
7e39f26
feat: make AotInstance be written in a similar way as InterpretedInst…
Oct 10, 2025
45600af
fix: move creation of mmap to execute and remove mmap from struct member
Oct 10, 2025
07aac61
feat: got execute to return vmstate
Oct 10, 2025
3637fc0
feat: added ctx generic to aotinstance
Oct 10, 2025
91a0e9d
feat: added executor generic to new in aotinstance
Oct 10, 2025
0b1cb5c
feat: added F generic to aotinstance
Oct 10, 2025
7ba27ec
feat: added metered execution
Oct 10, 2025
dc1e3cd
feat: moved aot from dev crate to openvm circuit
Oct 13, 2025
ca9dc64
feat: add some code for metered exec support
Oct 13, 2025
943e0b8
feat: added partialeq to segment
Oct 13, 2025
e046a37
feat: add some testing tools for aot specifically
Oct 14, 2025
b8a79bf
chore: remove dev crate
Oct 14, 2025
92f9c01
chore: exclude asm file
Oct 14, 2025
bd3d78c
chore: set aluop back to private
Oct 14, 2025
8e51201
feat: make asm bridge a standalone crate outside of the openvm root
Oct 14, 2025
720cc56
Revert "feat: make asm bridge a standalone crate outside of the openv…
Oct 14, 2025
ec018f5
feat: make multithreading work
Oct 15, 2025
49ee137
feat: change metered exec to box the vmstate instead of mmap
Oct 15, 2025
9608791
feat: add testing assertions and temporary changes to air_test_impl
Oct 15, 2025
bbdd7ec
feat: make pure exec work
Oct 15, 2025
9393019
feat: metered execution working
Oct 16, 2025
bd66ac4
chore: remove unneccessary code, run formatter and clippy
Oct 16, 2025
9729e50
feat: add should_suspend for pure execution
Oct 16, 2025
d74b746
chore: fix clippy warnings
Oct 16, 2025
fd8d847
fix: fix parameters when calling metered_set_instret_and_pc
Oct 16, 2025
982be3e
docs: add documentation for the asm_run assemblies
Oct 16, 2025
e0123ed
chore: revert unnecessary changes
Oct 16, 2025
8100958
feat: make the asm name configurable
Oct 17, 2025
05c9feb
chore: fix linter
Oct 17, 2025
3fb53fb
chore: changes to make workflow work
Oct 17, 2025
c847c7b
fix: apply forge fmt to Solidity files
Oct 17, 2025
2d8051f
fix: feature gate aot with not tco since we use some functions that i…
Oct 17, 2025
da6961d
fix: revert changes that shouldn't be made
Oct 17, 2025
67dc039
fix: revert changes that shouldn't be made
Oct 17, 2025
83bca9a
fix: revert changes that shouldn't be made
Oct 17, 2025
aef3e00
fix: change asm name to asm_x86_run to allow aot for other archs if n…
Oct 17, 2025
c63876c
feat (in progress): initial code for metered_cost; does not support m…
Maillew Oct 14, 2025
07af52a
feat: metered_cost execution, passing native/circuit integration tests
Maillew Oct 15, 2025
e433eae
feat: update workflow to run aot with x86; include cfg for x86 and ap…
Maillew Oct 15, 2025
632a4e5
fix: aot crate cfg for x86
Maillew Oct 15, 2025
0553cbd
fix: cfg x86
Maillew Oct 15, 2025
0000122
fix: integration test VmState memory checker
Maillew Oct 16, 2025
a16efc4
fix: modified code structure
Maillew Oct 16, 2025
6fe942d
fix: get rid of arm64 in workflow
Maillew Oct 16, 2025
2059211
fix: formatting, aot cfg for not tco
Maillew Oct 16, 2025
60fde49
fix: lint
Maillew Oct 16, 2025
2a1dea1
chore: branch clean up
Maillew Oct 16, 2025
a19bfb8
chore: revert .sol file changes, update fmt linter from main
Maillew Oct 17, 2025
b2d8594
feat: updated stark_utils to test metered_cost and aot_metered_cost
Maillew Oct 17, 2025
ca3edf4
chore: small fixes to match feat/aot branch
Maillew Oct 20, 2025
0681c7d
chore: rebase clean up
Maillew Oct 20, 2025
2491e4c
chore: more rebase clean up
Maillew Oct 20, 2025
625a279
chore: clean up integration tests
Maillew Oct 20, 2025
e256328
chore: experiment with generic_utils for common refactoring for exter…
Maillew Oct 20, 2025
4f14250
chore: typo
Maillew Oct 20, 2025
b70bd6d
chore: refactor aot.rs for metered/metered_cost
Maillew Oct 20, 2025
f721230
chore: typo
Maillew Oct 20, 2025
d04313e
fix: added AOT metered cost assertions in stark_utils.rs
Maillew Oct 20, 2025
8f37793
chore: clean up comments
Maillew Oct 20, 2025
5106b3a
chore: fix for ci/cd
Maillew Oct 20, 2025
f1b2964
chore: lint
Maillew Oct 20, 2025
9fcc6a3
chore: typo
Maillew Oct 20, 2025
57a23f3
chore: linter
Maillew Oct 20, 2025
87142eb
chore: linta
Maillew Oct 20, 2025
b75f7ad
chore: refactor of extern_handlers for pure n metered
Maillew Oct 20, 2025
5136562
chore: cargo fmt
shuklaayush Oct 21, 2025
f24f382
chore: remove unused dep
shuklaayush Oct 21, 2025
a0fb03a
fix: function instead of macro
Maillew Oct 27, 2025
34adf2b
chore: fmt
Maillew Oct 27, 2025
818b4b3
chore: fmt
Maillew Oct 27, 2025
7383b62
chore: fmt
Maillew Oct 27, 2025
3cd568f
chore: lint
Maillew Oct 27, 2025
1684eff
chore: precommit
Maillew Oct 27, 2025
cf4fc41
chore: bruh what
Maillew Oct 27, 2025
05605d1
Merge branch 'feat/aot' into feat/aot-metered-cost
Maillew Oct 27, 2025
ed20582
chore: reorganize crates
Maillew Oct 27, 2025
c1af494
chore: precommit formatting
Maillew Oct 27, 2025
76e2d35
chore: clippy
Maillew Oct 27, 2025
7d84792
chore: typo
Maillew Oct 27, 2025
88db90d
Merge remote-tracking branch 'origin/feat/aot' into feat/aot-metered-…
Maillew Oct 29, 2025
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
26 changes: 23 additions & 3 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ members = [
"crates/toolchain/tests",
"crates/continuations",
"crates/vm",
"crates/vm/src/arch/asm_bridge",
"crates/vm/src/arch/asm_bridge_metered",
"crates/asm/asm_bridge",
"crates/asm/asm_bridge_metered",
"crates/asm/asm_bridge_metered_cost",
"extensions/rv32im/circuit",
"extensions/rv32im/transpiler",
"extensions/rv32im/guest",
Expand Down
19 changes: 19 additions & 0 deletions crates/asm/asm_bridge/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "asm_bridge"
version.workspace = true
edition.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true

[lib]
crate-type = ["cdylib"]

[dependencies]
cc = "1.0"
openvm-circuit = { workspace = true, features = ["test-utils"] }
openvm-stark-sdk = { workspace = true }
asm_bridge_utils = { path = "../asm_bridge_utils" }

[package.metadata.cargo-shear]
ignored = ["cc"]
95 changes: 95 additions & 0 deletions crates/asm/asm_bridge/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
use std::ffi::c_void;

use openvm_circuit::{
arch::{execution_mode::ExecutionCtx, VmExecState},
system::memory::online::GuestMemory,
};
use openvm_stark_sdk::p3_baby_bear::BabyBear;

extern "C" {
fn asm_run_internal(
vm_exec_state_ptr: *mut c_void, // rdi = vm_exec_state
pre_compute_insns_ptr: *const c_void, // rsi = pre_compute_insns
from_state_pc: u32, // rdx = from_state.pc
from_state_instret: u64, // rcx = from_state.instret
);
}

/// Runs the VM execution from assembly
///
/// # Safety
///
///
/// This function is unsafe because:
/// - `vm_exec_state_ptr` must be valid
/// - `pre_compute_insns` must point to valid pre-compute instructions
#[no_mangle]
pub unsafe extern "C" fn asm_run(
vm_exec_state_ptr: *mut c_void,
pre_compute_insns_ptr: *const c_void, // rsi = pre_compute_insns
from_state_pc: u32,
from_state_instret: u64,
) {
asm_run_internal(
vm_exec_state_ptr,
pre_compute_insns_ptr,
from_state_pc,
from_state_instret,
);
}

type F = BabyBear;
type Ctx = ExecutionCtx;

// at the end of the execution, you want to store the instret and pc from the x86 registers
// to update the vm state's pc and instret
#[no_mangle]
pub extern "C" fn set_instret_and_pc(
vm_exec_state_ptr: *mut c_void, // rdi = vm_exec_state
_pre_compute_insns_ptr: *const c_void, // rsi = pre_compute_insns
final_pc: u32, // rdx = final_pc
final_instret: u64, // rcx = final_instret
) {
// reference to vm_exec_state
asm_bridge_utils::set_instret_and_pc_generic::<Ctx>(vm_exec_state_ptr, final_pc, final_instret);
}

/// # Safety
/// - vm_exec_state_ptr must point to a valid VmExecState<F, GuestMemory, Ctx>.
/// - pre_compute_insns_ptr must be a valid, contiguous array of PreComputeInstruction<'static, F,
/// Ctx>.
/// - cur_pc must be a valid PC for the current program.
#[no_mangle]
pub unsafe extern "C" fn extern_handler(
vm_exec_state_ptr: *mut c_void,
pre_compute_insns_ptr: *const c_void,
cur_pc: u32,
cur_instret: u64,
) -> u32 {
unsafe {
let (vm_ptr, pre_ptr, ctx_ptr) = asm_bridge_utils::extern_prep_generic::<Ctx>(
vm_exec_state_ptr,
pre_compute_insns_ptr,
cur_pc,
);
// `arg` is a runtime constant that we want to keep in register
// - For pure execution it is `instret_end`
let arg = (*ctx_ptr).instret_end;
asm_bridge_utils::extern_finish_generic::<Ctx>(vm_ptr, pre_ptr, cur_pc, cur_instret, arg)
}
}

#[no_mangle]
pub extern "C" fn should_suspend(instret: u64, _pc: u32, exec_state_ptr: *mut c_void) -> u32 {
// reference to vm_exec_state
let vm_exec_state_ref =
unsafe { &mut *(exec_state_ptr as *mut VmExecState<F, GuestMemory, Ctx>) };

let instret_end = vm_exec_state_ref.ctx.instret_end;

if instret >= instret_end {
1 // should suspend is `true`
} else {
0 // should suspend is `false`
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[package]
name = "asm_bridge_metered"
version.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true

[package.metadata.cargo-shear]
ignored = ["cc"]

[lib]
crate-type = ["cdylib"]

[dependencies]
cc = "1.0"
openvm-circuit = { workspace = true, features = ["test-utils"] }
openvm-stark-sdk.workspace = true
openvm-instructions.workspace = true
openvm-stark-sdk = { workspace = true }
asm_bridge_utils = { path = "../asm_bridge_utils" }

[package.metadata.cargo-shear]
ignored = ["cc"]
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::ffi::c_void;

use openvm_circuit::{
arch::{execution_mode::MeteredCtx, interpreter::PreComputeInstruction, VmExecState},
arch::{execution_mode::MeteredCtx, VmExecState},
system::memory::online::GuestMemory,
};
use openvm_instructions::program::DEFAULT_PC_STEP;
use openvm_stark_sdk::p3_baby_bear::BabyBear;

/*
Expand All @@ -27,7 +26,6 @@ extern "C" {
///
/// # Safety
///
///
/// This function is unsafe because:
/// - `vm_exec_state_ptr` must be valid
/// - `pre_compute_insns` must point to valid pre-compute instructions
Expand Down Expand Up @@ -60,58 +58,31 @@ pub extern "C" fn metered_set_instret_and_pc(
final_instret: u64, // rcx = final_instret
) {
// reference to vm_exec_state
let vm_exec_state_ref =
unsafe { &mut *(vm_exec_state_ptr as *mut VmExecState<F, GuestMemory, Ctx>) };
vm_exec_state_ref
.vm_state
.set_instret_and_pc(final_instret, final_pc);
asm_bridge_utils::set_instret_and_pc_generic::<Ctx>(vm_exec_state_ptr, final_pc, final_instret);
}

/// # Safety
/// - vm_exec_state_ptr must point to VmExecState<F, GuestMemory, MeteredCtx>.
/// - pre_compute_insns_ptr must be a valid, contiguous array of PreComputeInstruction<'static, F,
/// MeteredCtx>.
/// - cur_pc must be a valid PC for the current program.
#[no_mangle]
pub extern "C" fn metered_extern_handler(
pub unsafe extern "C" fn metered_extern_handler(
vm_exec_state_ptr: *mut c_void,
pre_compute_insns_ptr: *const c_void,
cur_pc: u32,
cur_instret: u64,
) -> u32 {
let mut instret: Box<u64> = Box::new(cur_instret); // placeholder to call the handler function
let mut pc: Box<u32> = Box::new(cur_pc);

let vm_exec_state_ref =
unsafe { &mut *(vm_exec_state_ptr as *mut VmExecState<F, GuestMemory, Ctx>) };

// pointer to the first element of `pre_compute_insns`
let pre_compute_insns_base_ptr =
pre_compute_insns_ptr as *const PreComputeInstruction<'static, F, Ctx>;
let pc_idx = (cur_pc / DEFAULT_PC_STEP) as usize;

let pre_compute_insns = unsafe { &*pre_compute_insns_base_ptr.add(pc_idx) };

let ctx = &vm_exec_state_ref.ctx;
// `arg` is a runtime constant that we want to keep in register
// - For metered execution it is `segment_check_insns`
let arg = ctx.segmentation_ctx.segment_check_insns;

unsafe {
(pre_compute_insns.handler)(
pre_compute_insns.pre_compute,
&mut instret,
&mut pc,
arg,
vm_exec_state_ref,
let (vm_ptr, pre_ptr, ctx_ptr) = asm_bridge_utils::extern_prep_generic::<Ctx>(
vm_exec_state_ptr,
pre_compute_insns_ptr,
cur_pc,
);
};

match vm_exec_state_ref.exit_code {
Ok(None) => {
// execution continues
*pc
}
_ => {
// special indicator that we must terminate
// this won't collide with actual pc value because pc values are always multiple of 4
1
}
// `arg` is a runtime constant that we want to keep in register
// - For metered execution it is `segment_check_insns`
let arg = (*ctx_ptr).segmentation_ctx.segment_check_insns;
asm_bridge_utils::extern_finish_generic::<Ctx>(vm_ptr, pre_ptr, cur_pc, cur_instret, arg)
}
}

Expand Down
19 changes: 19 additions & 0 deletions crates/asm/asm_bridge_metered_cost/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "asm_bridge_metered_cost"
version.workspace = true
edition.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true

[lib]
crate-type = ["cdylib"]

[dependencies]
cc = "1.0"
openvm-circuit = { workspace = true, features = ["test-utils"] }
openvm-stark-sdk = { workspace = true }
asm_bridge_utils = { path = "../asm_bridge_utils" }

[package.metadata.cargo-shear]
ignored = ["cc"]
Loading
Loading