forked from nexus-xyz/nexus-zkvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update nexus tools with proof commands
- Loading branch information
Showing
10 changed files
with
276 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
mod new; | ||
mod options; | ||
mod util; | ||
mod new; | ||
mod run; | ||
mod prove; | ||
|
||
pub use options::*; | ||
pub use util::*; | ||
|
||
fn main() -> CmdResult { | ||
match &options().command { | ||
fn main() { | ||
let res = match &options().command { | ||
New { .. } => new::new(), | ||
cmd => { | ||
println!("Not Yet Implemented: {:?}", cmd); | ||
Err("TODO".into()) | ||
} | ||
Run { .. } => run::run(), | ||
Prove { .. } => prove::prove(), | ||
Query { .. } => prove::query(), | ||
Verify { .. } => prove::verify(), | ||
LocalProve { .. } => prove::local(), | ||
cmd => Err(format!("Not Yet Implemented: {:?}", cmd).into()), | ||
}; | ||
|
||
match res { | ||
Ok(_) => (), | ||
Err(CmdErr(s)) => eprintln!("{}", s), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use std::io::BufReader; | ||
use std::fs::File; | ||
|
||
use nexus_riscv::VMOpts; | ||
use nexus_prover::{pp::gen_or_load, run, prove_par}; | ||
use nexus_network::pcd::{decode, NexusMsg::PCDRes}; | ||
use nexus_network::api::Proof; | ||
use nexus_network::client::*; | ||
|
||
use crate::*; | ||
|
||
pub fn prove() -> CmdResult<()> { | ||
let Opts { command: Prove { release, bin } } = options() else { | ||
panic!() | ||
}; | ||
let t = get_target(*release, bin)?; | ||
let proof = submit_proof("account".to_string(), &t)?; | ||
|
||
println!("{} submitted", proof.hash); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn query() -> CmdResult<()> { | ||
let Opts { command: Query { hash, file } } = options() else { | ||
panic!() | ||
}; | ||
|
||
let proof = fetch_proof(hash)?; | ||
|
||
if proof.total_nodes > proof.complete_nodes { | ||
let pct = (proof.complete_nodes as f32) / (proof.total_nodes as f32); | ||
println!("{} {:.2}% complete", proof.hash, pct); | ||
} else { | ||
println!("{} 100% complete, saving...", proof.hash); | ||
let vec = serde_json::to_vec(&proof)?; | ||
write_file(file.clone(), &vec)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn verify() -> CmdResult<()> { | ||
let Opts { command: Verify { pp_file, file } } = options() else { | ||
panic!() | ||
}; | ||
|
||
let file = File::open(file)?; | ||
let reader = BufReader::new(file); | ||
let proof: Proof = serde_json::from_reader(reader)?; | ||
|
||
let Some(vec) = proof.proof else { | ||
return Err("invalid proof object".into()); | ||
}; | ||
|
||
let PCDRes(node) = decode(&vec)? else { | ||
return Err("invalid proof object".into()); | ||
}; | ||
|
||
let state = gen_or_load(false, 1, pp_file)?; | ||
|
||
match node.verify(&state) { | ||
Ok(_) => println!("{} verified", proof.hash), | ||
Err(_) => println!("{} NOT verified", proof.hash), | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub fn local() -> CmdResult<()> { | ||
let Opts { | ||
command: LocalProve { pp_file, release, bin }, | ||
} = options() | ||
else { | ||
panic!() | ||
}; | ||
let t = get_target(*release, bin)?; | ||
let opts = VMOpts { | ||
k: 1, | ||
nop: None, | ||
loopk: None, | ||
file: Some(t), | ||
}; | ||
let trace = run(&opts, true)?; | ||
let state = gen_or_load(false, 1, pp_file)?; | ||
prove_par(state, trace)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use nexus_riscv::*; | ||
|
||
use crate::*; | ||
|
||
pub fn run() -> CmdResult<()> { | ||
let Opts { command: Run { verbose, release, bin } } = options() else { | ||
panic!() | ||
}; | ||
let t = get_target(*release, bin)?; | ||
|
||
let opts = VMOpts { | ||
k: 1, | ||
nop: None, | ||
loopk: None, | ||
file: Some(t), | ||
}; | ||
|
||
Ok(run_vm(&opts, *verbose)?) | ||
} |
Oops, something went wrong.