aboutsummaryrefslogtreecommitdiff
path: root/zkvms/nexus/host/src/main.rs
blob: 68593fcac39f9be6243afd89b93ae75eb1b01d57 (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
70
use nexus_sdk::{stwo::seq::Stwo, Local, Prover, Verifiable, Viewable};
use zkvms_host_io::{
    benchmarkable, read_args, Input, Return,
    RunType::{Execute, Prove, Verify},
    output_proof_size,
};

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

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

            println!("Proving execution of vm...");
            let (view, proof) = prover
                .prove_with_input(&run_info.private_input, &run_info.public_input)
                .expect("failed to prove program");

            output_proof_size(&proof);

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

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

            println!("Proving execution of vm...");
            let (view, proof) = prover
                .prove_with_input(&run_info.private_input, &run_info.public_input)
                .expect("failed to prove program");

            output_proof_size(&proof);

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

            println!(
                ">>>>> Logging\n{}<<<<<",
                view.logs().expect("failed to retrieve debug logs").join("")
            );

            benchmarkable! {
                print!("Verifying execution...");
                proof.verify(&view).expect("failed to verify proof");
                println!("  Succeeded!");
            }
        }
    }
}