Skip to content

Commit

Permalink
Update smoke-test to latest API (risc0#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaub authored Jan 18, 2024
1 parent 4fd3244 commit 7242eb4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 52 deletions.
2 changes: 2 additions & 0 deletions tools/smoke-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ edition = "2021"

[dependencies]
risc0-zkvm = "0.21.0-alpha.1"
# Use this only for testing locally before a release.
# risc0-zkvm = { path = "../../risc0/zkvm" }
methods = { path = "methods" }
2 changes: 2 additions & 0 deletions tools/smoke-test/methods/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ edition = "2021"

[build-dependencies]
risc0-build = "0.21.0-alpha.1"
# Use this only for testing locally before a release.
# risc0-build = { path = "../../../risc0/build" }

[package.metadata.risc0]
methods = ["guest"]
2 changes: 2 additions & 0 deletions tools/smoke-test/methods/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ edition = "2021"

[dependencies]
risc0-zkvm = { version = "0.21.0-alpha.1", default-features = false }
# Use this only for testing locally before a release.
# risc0-zkvm = { path = "../../../../risc0/zkvm", default-features = false }
56 changes: 4 additions & 52 deletions tools/smoke-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,66 +13,18 @@
// limitations under the License.

use methods::{GUEST_ELF, GUEST_ID};
use risc0_zkvm::{ApiClient, AssetRequest, Binary, ExecutorEnv, InnerReceipt, ProverOpts, Receipt};
use risc0_zkvm::{default_prover, ExecutorEnv};

fn main() {
let segment_limit_po2 = 16; // 64k cycles
let cycles: u32 = 1 << segment_limit_po2;
let env = ExecutorEnv::builder()
.write(&cycles)
.unwrap()
.segment_limit_po2(segment_limit_po2)
.build()
.unwrap();
let binary = Binary::new_elf_inline(GUEST_ELF.into());

let client = ApiClient::from_env().unwrap();
let mut segments = Vec::new();
let session = client
.execute(&env, binary, AssetRequest::Inline, |_info, asset| {
segments.push(asset);
Ok(())
})
.unwrap();

println!("Segments: {}", segments.len());

let opts = ProverOpts::default();
let rollup = segments
.iter()
.map(|segment| {
let receipt = client
.prove_segment(opts.clone(), segment.clone(), AssetRequest::Inline)
.unwrap();
client
.lift(
opts.clone(),
receipt.try_into().unwrap(),
AssetRequest::Inline,
)
.unwrap()
})
.reduce(|left, right| {
client
.join(
opts.clone(),
left.try_into().unwrap(),
right.try_into().unwrap(),
AssetRequest::Inline,
)
.unwrap()
})
.unwrap();

// TODO: call verify on this receipt
client
.identity_p254(
opts,
rollup.clone().try_into().unwrap(),
AssetRequest::Inline,
)
.unwrap();

let final_receipt = Receipt::new(InnerReceipt::Succinct(rollup), session.journal.bytes.into());
final_receipt.verify(GUEST_ID).unwrap();
let prover = default_prover();
let receipt = prover.prove(env, GUEST_ELF).unwrap();
receipt.verify(GUEST_ID).unwrap();
}

0 comments on commit 7242eb4

Please sign in to comment.