aboutsummaryrefslogtreecommitdiff
path: root/zkvms/nexus/host/src/main.rs
blob: deef6b67fc1af23f78b2f8d6bfe5a468932e0c46 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use zkvms_host_io::{Input, Output, read_args, benchmarkable, RunType::{ Execute, Prove, Verify }};
use nexus_sdk::{
    compile::CompileOpts,
    nova::seq::{Generate, Nova, PP},
    Local, Prover, Verifiable,
};

fn main() {
    let run_info = read_args();
    if run_info.run_type == Execute {
        panic!("Execution is not supported!");
    }

    let elf_path = std::env::var("ELF_PATH").expect("ELF PATH is missing");

    println!("Setting up Nova public parameters...");
    let pp: PP = PP::generate().expect("failed to generate parameters");

    match run_info.run_type {
        Execute => unreachable!(),
        Prove => benchmarkable!{
            // Nova<T> doesn't derive Clone
            println!("Loading guest...");
            let prover: Nova<Local> = Nova::new_from_file(&elf_path).expect("failed to load guest program");

            println!("Proving execution of vm...");
            let proof = prover
                .prove_with_input::<Input>(&pp, &run_info.input)
                .expect("failed to prove program");

            println!(
                " output is {:?}!",
                proof
                .output::<Output>()
                .expect("failed to deserialize output")
                );

            println!(">>>>> Logging\n{}<<<<<", proof.logs().join(""));
        },
        Verify => {
            // Nova<T> doesn't derive Clone
            println!("Loading guest...");
            let prover: Nova<Local> = Nova::new_from_file(&elf_path).expect("failed to load guest program");

            println!("Proving execution of vm...");
            let proof = prover
                .prove_with_input::<Input>(&pp, &run_info.input)
                .expect("failed to prove program");

            println!(
                " output is {:?}!",
                proof
                .output::<Output>()
                .expect("failed to deserialize output")
                );

            println!(">>>>> Logging\n{}<<<<<", proof.logs().join(""));

            benchmarkable! {
                print!("Verifying execution...");
                proof.verify(&pp).expect("failed to verify proof");
            }
        },
    }
}