Skip to content

Commit

Permalink
feat:add initial support for precompile (#185)
Browse files Browse the repository at this point in the history
* add emulator support and test case for sys verify

* add initial support for precompile

* fix input problems

* add missed elf

* update zkmips

* fix clippy

* remove unused return

* update example test

* update SHA_ID and readme

* fix input type

* remove duplicated code

* fix fmt
  • Loading branch information
weilzkm authored Nov 30, 2024
1 parent 7cd2e69 commit 921cd4c
Show file tree
Hide file tree
Showing 36 changed files with 1,280 additions and 205 deletions.
4 changes: 4 additions & 0 deletions emulator/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,10 @@ impl InstrumentedState {
log::trace!("set local user {:X} {:X} {:X}", a0, a1, a2);
self.state.local_user = a0;
}
0xF2 => {
log::trace!("sys_verify {:X} {:X} {:X}", a0, a1, a2);
// DO Nothing Here
}
_ => {}
}

Expand Down
2 changes: 1 addition & 1 deletion emulator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn split_prog_into_segs(
break;
}
let cycles = instrumented_state.step();
if cycles >= seg_size as u64 {
if cycles > (seg_size - 1) as u64 {
instrumented_state.split_segment(true, seg_path, new_writer);
}
}
Expand Down
20 changes: 20 additions & 0 deletions prover/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,23 @@ Or
RUST_LOG=info ELF_PATH=examples/revme/target/mips-unknown-linux-musl/release/evm HOST_PROGRAM=revm JSON_PATH=../emulator/test-vectors/test.json SEG_OUTPUT=/tmp/output SEG_SIZE=262144 cargo run --release --example zkmips prove_host_program
```

## Prove precompile code
* Build the sha2-rust
```
cd prover/examples/sha2-rust
cargo build -r --target=mips-unknown-linux-musl
```

* Build the sha2-precompile
```
cd prover/examples/sha2-precompile
cargo build -r --target=mips-unknown-linux-musl
```

* Run the host program
```
cd ../..
RUST_LOG=info PRECOMPILE_PATH=examples/sha2-rust/target/mips-unknown-linux-musl/release/sha2-rust ELF_PATH=examples/sha2-precompile/target/mips-unknown-linux-musl/release/sha2-precompile HOST_PROGRAM=sha2_precompile SEG_OUTPUT=/tmp/output cargo run --release --example zkmips prove_host_program
```
48 changes: 0 additions & 48 deletions prover/examples/add-go/add.go

This file was deleted.

7 changes: 0 additions & 7 deletions prover/examples/add-go/go.mod

This file was deleted.

278 changes: 278 additions & 0 deletions prover/examples/sha2-precompile/Cargo.lock

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

10 changes: 10 additions & 0 deletions prover/examples/sha2-precompile/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[workspace]
[package]
version = "0.1.0"
name = "sha2-precompile"
edition = "2021"

[dependencies]
# zkm-runtime = { git = "https://github.com/zkMIPS/zkm", package = "zkm-runtime" }
zkm-runtime = { path = "../../../runtime/entrypoint" }
sha2 = { version = "0.10.8", default-features = false }
4 changes: 4 additions & 0 deletions prover/examples/sha2-precompile/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "nightly-2023-04-06"
targets = ["mips-unknown-linux-musl"]
profile = "minimal"
Loading

0 comments on commit 921cd4c

Please sign in to comment.