Skip to content

Commit

Permalink
Drop _elf suffix from API (risc0#1195)
Browse files Browse the repository at this point in the history
This is a breaking change which causes the older doc-tests to fail. A
refactor is made so that each doc-test version has its own workspace for
deps.
  • Loading branch information
flaub authored Dec 9, 2023
1 parent 4607520 commit c211f52
Show file tree
Hide file tree
Showing 49 changed files with 486 additions and 85 deletions.
68 changes: 62 additions & 6 deletions .github/workflows/website-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,79 @@ env:
RISC0_TOOLCHAIN_VERSION: test-release-2

jobs:
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
versions: ${{ steps.filter.outputs.changes }}
steps:
- uses: actions/checkout@v4
- uses: risc0/paths-filter@4067d885736b84de7c414f582ac45897079b0a78
id: filter
with:
filters: |
main:
- bonsai/**
- risc0/**
- website/api/**
- website/doc-test/main/**
- website/docs/**
version-0.18:
- website/api_versioned_docs/version-0.18/**
- website/doc-test/version-0.18/**
version-0.19:
- website/api_versioned_docs/version-0.19/**
- website/doc-test/version-0.19/**
# see: https://github.com/orgs/community/discussions/26822
doc-test:
runs-on: [self-hosted, prod, Linux, cpu]
if: always()
needs:
- matrix
runs-on: ubuntu-latest
steps:
- name: Check all job status
# see https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#needs-context
# see https://stackoverflow.com/a/67532120/4907315
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1

matrix:
needs: changes
strategy:
fail-fast: false
matrix:
version: ${{ fromJSON(needs.changes.outputs.versions) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Recursive checkout required to build Solidity contracts and bindings.
submodules: recursive
- uses: ./.github/actions/rustup
with:
toolchain: "1.73"
- uses: ./.github/actions/sccache
with:
key: Linux-default
- uses: risc0/foundry-toolchain@2fe7e70b520f62368a0e3c464f997df07ede420f
with:
version: nightly-34f684ddfacc5b2ed371353ba6f730c485616ffe
- run: cargo run --bin cargo-risczero --no-default-features -- risczero install --version $RISC0_TOOLCHAIN_VERSION
- name: build
run: cargo test -p doc-test --no-run
- name: test
run: cargo test -p doc-test
- uses: risc0/cargo-install@2cfb0024938d23011106cbf127b393bc83fddba1
with:
crate: cargo-binstall
version: "1.4"
- run: cargo binstall -y --force [email protected]
- run: cargo risczero install --version $RISC0_TOOLCHAIN_VERSION
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: build ${{ matrix.version }}
run: cargo test --release --no-run
working-directory: website/doc-test/${{ matrix.version }}
- name: test ${{ matrix.version }}
run: cargo test --release
working-directory: website/doc-test/${{ matrix.version }}

- run: sccache --show-stats
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ members = [
"risc0/zkvm/methods",
"risc0/zkvm/platform",
"risc0/zkvm/receipts",
"website/doc-test",
"website/doc-test/main",
"xtask",
]
exclude = ["tools/crates-validator"]
Expand Down
2 changes: 1 addition & 1 deletion bonsai/examples/governance/methods/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod test {
.build()
.unwrap();
let exec = default_executor();
let session = exec.execute_elf(env, FINALIZE_VOTES_ELF).unwrap();
let session = exec.execute(env, FINALIZE_VOTES_ELF).unwrap();
assert_eq!(&session.journal.bytes, TEST_OUTPUT);
}
}
2 changes: 1 addition & 1 deletion bonsai/examples/governance/relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn execute_locally(elf: &[u8], input: Vec<u8>) -> Result<Output> {
.build()
.context("Failed to build ExecutorEnv")?;
let exec = default_executor();
let session = exec.execute_elf(env, elf).context("Execution failed")?;
let session = exec.execute(env, elf).context("Execution failed")?;
Ok(Output::Execution {
journal: session.journal.bytes.into(),
})
Expand Down
2 changes: 1 addition & 1 deletion bonsai/rest-api-mock/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Prover {
})?;
let exec = default_executor();
let session = exec
.execute_elf(env, elf)
.execute(env, elf)
.context("Executor failed to generate a successful session")?;

let receipt = Receipt {
Expand Down
2 changes: 1 addition & 1 deletion examples/bevy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() {
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove_elf(env, BEVY_GUEST_ELF).unwrap();
let receipt = prover.prove(env, BEVY_GUEST_ELF).unwrap();

// The prover already runs a verify internally and so it's redundant to verify
// again here. However, this is how other users would verify the receipt:
Expand Down
2 changes: 1 addition & 1 deletion examples/chess/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn chess(inputs: &Inputs) -> Receipt {
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
prover.prove_elf(env, CHECKMATE_ELF).unwrap()
prover.prove(env, CHECKMATE_ELF).unwrap()
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion examples/cycle-counter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub trait CycleCounter {

pub fn exec<'a>(name: &str, elf: &[u8], env: ExecutorEnv<'a>) -> Metrics {
let exec = default_executor();
let session_info = exec.execute_elf(env, elf).unwrap();
let session_info = exec.execute(env, elf).unwrap();
let cycles = session_info
.segments
.iter()
Expand Down
2 changes: 1 addition & 1 deletion examples/digital-signature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn sign(pass_str: impl AsRef<[u8]>, msg_str: impl AsRef<[u8]>) -> Result<Sig
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove_elf(env, SIGN_ELF)?;
let receipt = prover.prove(env, SIGN_ELF)?;

Ok(SignatureWithReceipt { receipt })
}
Expand Down
2 changes: 1 addition & 1 deletion examples/ecdsa/src/bin/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ use risc0_zkvm::{default_executor, ExecutorEnv};
fn main() {
let env = ExecutorEnv::builder().build().unwrap();
let exec = default_executor();
std::hint::black_box(exec.execute_elf(env, BENCHMARK_ELF)).unwrap();
std::hint::black_box(exec.execute(env, BENCHMARK_ELF)).unwrap();
}
2 changes: 1 addition & 1 deletion examples/ecdsa/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn prove_ecdsa_verification(
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
prover.prove_elf(env, ECDSA_VERIFY_ELF).unwrap()
prover.prove(env, ECDSA_VERIFY_ELF).unwrap()
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn multiply(a: u64, b: u64) -> (Receipt, u64) {
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove_elf(env, MULTIPLY_ELF).unwrap();
let receipt = prover.prove(env, MULTIPLY_ELF).unwrap();

// Extract journal of receipt (i.e. output c, where c = a * b)
let c: u64 = receipt.journal.decode().expect(
Expand Down
2 changes: 1 addition & 1 deletion examples/json/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn search_json(data: &str) -> Outputs {
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove_elf(env, SEARCH_JSON_ELF).unwrap();
let receipt = prover.prove(env, SEARCH_JSON_ELF).unwrap();

receipt.journal.decode().unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion examples/password-checker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn password_checker(request: PasswordRequest) -> Digest {
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove_elf(env, PW_CHECKER_ELF).unwrap();
let receipt = prover.prove(env, PW_CHECKER_ELF).unwrap();

receipt.journal.decode().unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion examples/profiling/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() -> anyhow::Result<()> {
// Execute the guest code.
let env = ExecutorEnv::builder().write(&iterations)?.build()?;
let exec = default_executor();
exec.execute_elf(env, FIBONACCI_ELF)?;
exec.execute(env, FIBONACCI_ELF)?;

Ok(())
}
2 changes: 1 addition & 1 deletion examples/prorata/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn allocate(input: &str, output: &str, recipient: &str, amount: &Decimal) {
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove_elf(env, PRORATA_GUEST_ELF).unwrap();
let receipt = prover.prove(env, PRORATA_GUEST_ELF).unwrap();

// Verify receipt to confirm that it is correctly formed. Not strictly
// necessary.
Expand Down
2 changes: 1 addition & 1 deletion examples/sha/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn provably_hash(input: &str, use_rust_crypto: bool) -> (Digest, Receipt) {
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove_elf(env, elf).unwrap();
let receipt = prover.prove(env, elf).unwrap();

let digest = receipt.journal.decode().unwrap();
(digest, receipt)
Expand Down
4 changes: 2 additions & 2 deletions examples/smartcore-ml/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn predict() -> Vec<u32> {

// This initiates a session, runs the STARK prover on the resulting exection
// trace, and produces a receipt.
let receipt = prover.prove_elf(env, ML_TEMPLATE_ELF).unwrap();
let receipt = prover.prove(env, ML_TEMPLATE_ELF).unwrap();

// We read the result that the guest code committed to the journal. The
// receipt can also be serialized and sent to a verifier.
Expand Down Expand Up @@ -159,7 +159,7 @@ mod test {

// We run the executor and bypass the prover.
let exec = default_executor();
let session = exec.execute_elf(env, ML_TEMPLATE_ELF).unwrap();
let session = exec.execute(env, ML_TEMPLATE_ELF).unwrap();

// We read the result commited to the journal by the guest code.
let result: Vec<f64> = session.journal.decode().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions examples/voting-machine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl PollingStation {
tracing::info!("init");
let env = ExecutorEnv::builder().write(&self.state)?.build()?;
let prover = default_prover();
let receipt = prover.prove_elf(env, INIT_ELF)?;
let receipt = prover.prove(env, INIT_ELF)?;
Ok(InitMessage { receipt })
}

Expand All @@ -91,7 +91,7 @@ impl PollingStation {
.stdout(&mut output)
.build()?;
let prover = default_prover();
let receipt = prover.prove_elf(env, SUBMIT_ELF)?;
let receipt = prover.prove(env, SUBMIT_ELF)?;
self.state = from_slice(&output)?;
Ok(SubmitBallotMessage { receipt })
}
Expand All @@ -105,7 +105,7 @@ impl PollingStation {
.stdout(&mut output)
.build()?;
let prover = default_prover();
let receipt = prover.prove_elf(env, FREEZE_ELF)?;
let receipt = prover.prove(env, FREEZE_ELF)?;
let result: FreezeVotingMachineResult = from_slice(&output)?;
self.state = result.state;
Ok(FreezeStationMessage { receipt })
Expand Down
2 changes: 1 addition & 1 deletion examples/waldo/src/bin/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove_elf(env, IMAGE_CROP_ELF).unwrap();
let receipt = prover.prove(env, IMAGE_CROP_ELF).unwrap();

// Save the receipt to disk so it can be sent to the verifier.
fs::write(&args.receipt, bincode::serialize(&receipt).unwrap())?;
Expand Down
2 changes: 1 addition & 1 deletion examples/wasm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn run_guest(iters: i32) -> i32 {
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove_elf(env, WASM_INTERP_ELF).unwrap();
let receipt = prover.prove(env, WASM_INTERP_ELF).unwrap();

receipt.verify(WASM_INTERP_ID).expect(
"Code you have proven should successfully verify; did you specify the correct image ID?",
Expand Down
2 changes: 1 addition & 1 deletion examples/wordle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'a> Server<'a> {
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
prover.prove_elf(env, WORDLE_GUEST_ELF).unwrap()
prover.prove(env, WORDLE_GUEST_ELF).unwrap()
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/xgboost/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn predict() -> f64 {
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove_elf(env, XGBOOST_ELF).unwrap();
let receipt = prover.prove(env, XGBOOST_ELF).unwrap();

// We return the inference value committed to the journal.
receipt.journal.decode().unwrap()
Expand Down
2 changes: 1 addition & 1 deletion examples/zkevm-demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async fn main() {
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove_elf(exec_env, EVM_ELF).unwrap();
let receipt = prover.prove(exec_env, EVM_ELF).unwrap();

let res: EvmResult = receipt
.journal
Expand Down
2 changes: 1 addition & 1 deletion risc0/cargo-risczero/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl BuildCommand {
.build()?;

let exec = default_executor();
let session = exec.execute_elf(env, &fs::read(test)?)?;
let session = exec.execute(env, &fs::read(test)?)?;
ensure!(
session.exit_code == ExitCode::Halted(0),
"test exited with code {:?}",
Expand Down
2 changes: 1 addition & 1 deletion risc0/r0vm/tests/external_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn prove_nothing() -> Result<Receipt> {
.unwrap();
let r0vm_path = cargo_bin("r0vm");
let prover = ExternalProver::new("r0vm", r0vm_path);
prover.prove_elf(env, MULTI_TEST_ELF)
prover.prove(env, MULTI_TEST_ELF)
}

#[test_log::test]
Expand Down
2 changes: 1 addition & 1 deletion risc0/zkvm/src/host/api/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl Server {
let opts: ProverOpts = request.opts.ok_or(malformed_err())?.into();
let prover = get_prover_server(&opts)?;
let ctx = VerifierContext::default();
let receipt = prover.prove_elf_with_ctx(env, &ctx, &bytes)?;
let receipt = prover.prove_with_ctx(env, &ctx, &bytes)?;

let receipt_pb: pb::core::Receipt = receipt.into();
let receipt_bytes = receipt_pb.encode_to_vec();
Expand Down
4 changes: 2 additions & 2 deletions risc0/zkvm/src/host/api/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn with_server<T, F: FnOnce() -> Result<T>>(addr: SocketAddr, f: F) -> T {
}

#[test]
fn execute_elf() {
fn execute() {
let env = ExecutorEnv::builder()
.write(&MultiTestSpec::DoNothing)
.unwrap()
Expand All @@ -146,7 +146,7 @@ fn execute_elf() {
}

#[test]
fn prove_elf() {
fn prove() {
let env = ExecutorEnv::builder()
.write(&MultiTestSpec::DoNothing)
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion risc0/zkvm/src/host/client/prove/bonsai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Prover for BonsaiProver {
self.name.clone()
}

fn prove_elf_with_ctx(
fn prove_with_ctx(
&self,
env: ExecutorEnv<'_>,
ctx: &VerifierContext,
Expand Down
4 changes: 2 additions & 2 deletions risc0/zkvm/src/host/client/prove/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl ExternalProver {
}

impl Prover for ExternalProver {
fn prove_elf_with_ctx(
fn prove_with_ctx(
&self,
env: ExecutorEnv<'_>,
ctx: &VerifierContext,
Expand Down Expand Up @@ -74,7 +74,7 @@ impl Prover for ExternalProver {
}

impl Executor for ExternalProver {
fn execute_elf(&self, env: ExecutorEnv<'_>, elf: &[u8]) -> Result<SessionInfo> {
fn execute(&self, env: ExecutorEnv<'_>, elf: &[u8]) -> Result<SessionInfo> {
let binary = Asset::Inline(elf.to_vec().into());
let client = ApiClient::new_sub_process(&self.r0vm_path)?;
let segments_out = AssetRequest::Inline;
Expand Down
Loading

0 comments on commit c211f52

Please sign in to comment.