nexus_sdk/legacy/
traits.rs1use serde::{de::DeserializeOwned, Serialize};
2use std::fs;
3use std::path::Path;
4
5use nexus_core::nvm::View;
6
7use crate::error::IOError;
8use crate::legacy::compile::*;
9use crate::traits::*;
10
11pub trait UncheckedView {}
13impl UncheckedView for View {}
14
15pub trait LegacyProver<'a>: Setup<'a> {
17 type Proof: LegacyVerifiable<'a>;
18 type View: LegacyViewable;
19
20 fn new(elf_bytes: &[u8]) -> Result<Self, Self::Error>
22 where
23 Self: Sized;
24
25 fn new_from_file<P: AsRef<Path>>(path: &P) -> Result<Self, Self::Error>
27 where
28 Self: Sized,
29 Self::Error: From<std::io::Error>,
30 {
31 Self::new(&fs::read(path)?)
32 }
33
34 fn compile(opts: &CompileOpts) -> Result<Self, Self::Error>
36 where
37 Self: Sized,
38 Self::Error: From<std::io::Error>;
39
40 fn run(self) -> Result<Self::View, Self::Error>
42 where
43 Self: Sized,
44 {
45 Self::run_with_input::<()>(self, &())
46 }
47
48 fn run_with_input<S: Serialize + Sized>(
50 self,
51 private_input: &S,
52 ) -> Result<Self::View, Self::Error>;
53
54 fn prove(self) -> Result<Self::Proof, Self::Error>
56 where
57 Self: Sized,
58 {
59 Self::prove_with_input::<()>(self, &())
60 }
61
62 fn prove_with_input<S: Serialize + Sized>(
64 self,
65 private_input: &S,
66 ) -> Result<Self::Proof, Self::Error>;
67}
68
69pub trait LegacyViewable {
71 fn output<U: DeserializeOwned>(&self) -> Result<U, IOError>;
73
74 fn logs(&self) -> &Vec<String>;
76}
77
78pub trait LegacyVerifiable<'a>: Setup<'a> + Serialize + DeserializeOwned {
80 type View: LegacyViewable;
81
82 fn output<U: DeserializeOwned>(&self) -> Result<U, Self::Error>;
84
85 fn logs(&self) -> &Vec<String>;
87
88 fn detach(&mut self);
90
91 fn verify(&self) -> Result<(), Self::Error>;
93}