Closed CeciliaZ030 closed 6 months ago
- some other minor things
? dude what's the point of making this a point lol
- some other minor things
? dude what's the point of making this a point lol
Minor things that I can't be bothered to type out. :duck:
Problem:
#[test]
, which means we need to compile Rust's test harness into risv32 elfSolution
I'm gonna make the build pipeline myself so that I don't want to bother about the upstream, and also to test and benchmark my code however i want. also. Here are some of the design considerations:
Currently most ZkVM build the guest in
build.rs
, and gen proofs & verify inmain.rs
, which means these are the processes actually being run:1) compiling
build.rs
, resulting in binarytarget/debug/build/hello-world-b4166fd/build-script-build
2) runbuild-script-build
, which invokes another cargo process that builds the guest ELF; here's how the command can look like:3) the ELF is produced, we enter
main.rs
which loads the ELF into our VM runtime and generates a proof.I'm making the build stage explicit, which means having a
builder
crate to replacebuild.rs
. Within the pipeline, there are two steps: 1) configure the right flags and env to generate a correct command 2) execute the command and place the ELFs in some user-specified directories. Resulting file structure:Workflow
Build the ELFs
Run the ELFs
Builder
The resultant pipeline starts with parsing the Cargo manifest, then setup the
Builder
with the right flags.The executor runs the desired action (e.g.
cargo build
orcargo test
) and finally place the ELF to specified dest directory.Test Harness
I implemented a light-weight harness to build test suits and run them in the ELF's main. The main with normal
cargo test
compilation is an alternative entrypoint is created that collide with the ZkVM entrypoint. The resulted test workflow looks like this:After you write tests in the guest program, compile them:
This will gives you binaries equivalent to
cargo test --no-run --bin example -- bin foo
. Then in the host: