aboutsummaryrefslogtreecommitdiff
path: root/zkvms/nexus/host/src/main.rs
blob: 1a3f05ab6c7e6b5da5552b05e3968492ef73dc0d (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
66
67
68
69
use nexus_sdk::{
    compile::CompileOpts,
    nova::seq::{Generate, Nova, PP},
    Local, Prover, Verifiable,
};
use zkvms_host_io::{
    benchmarkable, read_args, Input, Output,
    RunType::{Execute, Prove, Verify},
};

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");
            }
        }
    }
}