Giacomo Pasini 85a3e941b9
add zone tx inclusion proof (#20)
* add zone tx inclusion proof

* rename input to tx
2024-08-09 11:52:42 +02:00

70 lines
2.2 KiB
Rust

// These constants represent the RISC-V ELF and the image ID generated by risc0-build.
// The ELF is used for proving and the ID is used for verification.
use common::*;
use risc0_zkvm::{default_prover, ExecutorEnv};
use std::path::PathBuf;
use clap::Parser;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
enum Action {
Stf {
// path to bincode-encoded state witness
state: PathBuf,
// path to bincode-encoded inputs
inputs: PathBuf,
},
}
fn stf_prove_stark(state: StateWitness, inputs: Vec<Tx>) {
let env = ExecutorEnv::builder()
.write(&inputs)
.unwrap()
.write(&state)
.unwrap()
.build()
.unwrap();
// Obtain the default prover.
let prover = default_prover();
use std::time::Instant;
let start_t = Instant::now();
// Proof information by proving the specified ELF binary.
// This struct contains the receipt along with statistics about execution of the guest
let opts = risc0_zkvm::ProverOpts::succinct();
let prove_info = prover
.prove_with_opts(env, goas_risc0_proofs::ZONE_STATE_ELF, &opts)
.unwrap();
println!("STARK prover time: {:.2?}", start_t.elapsed());
// extract the receipt.
let receipt = prove_info.receipt;
// TODO: Implement code for retrieving receipt journal here.
std::fs::write("proof.stark", bincode::serialize(&receipt).unwrap()).unwrap();
// The receipt was verified at the end of proving, but the below code is an
// example of how someone else could verify this receipt.
receipt.verify(goas_risc0_proofs::ZONE_STATE_ID).unwrap();
}
fn main() {
// Initialize tracing. In order to view logs, run `RUST_LOG=info cargo run`
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::filter::EnvFilter::from_default_env())
.init();
let action = Action::parse();
match action {
Action::Stf { state, inputs } => {
let state = bincode::deserialize(&std::fs::read(state).unwrap()).unwrap();
let inputs = bincode::deserialize(&std::fs::read(inputs).unwrap()).unwrap();
stf_prove_stark(state, inputs);
}
}
}