Skip to content

Commit

Permalink
chore(ci): Test just execution (#1804)
Browse files Browse the repository at this point in the history
* test execute only

* clippy fix

* switch is_ok to expect

* switch back to is_ok

* switch to execute_cmd

* switch to correct abi

* ue correct params for execute_program

* remove comments

* back to 1 thread

---------

Co-authored-by: vezenovm <mvezenov@gmail.com>
  • Loading branch information
kevaundray and vezenovm authored Jul 6, 2023
1 parent 66865d6 commit 2ef9c34
Showing 1 changed file with 2 additions and 51 deletions.
53 changes: 2 additions & 51 deletions crates/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ pub fn start_cli() -> eyre::Result<()> {
// helper function which tests noir programs by trying to generate a proof and verify it without reading/writing to the filesystem
pub fn prove_and_verify(program_dir: &Path, experimental_ssa: bool) -> bool {
use compile_cmd::compile_circuit;
use fs::common_reference_string::update_common_reference_string;
use nargo::ops::preprocess_program;

let backend = crate::backends::ConcreteBackend::default();

Expand All @@ -103,64 +101,17 @@ pub fn prove_and_verify(program_dir: &Path, experimental_ssa: bool) -> bool {

let program =
compile_circuit(&backend, program_dir, &compile_options).expect("Compile should succeed");
let common_reference_string = update_common_reference_string(
&backend,
// Empty CRS is always used since we don't read/write a cached version in these tests
&[],
&program.circuit,
)
.expect("Should fetch CRS");
let preprocessed_program = preprocess_program(&backend, &common_reference_string, program)
.expect("Preprocess should succeed");

let nargo::artifacts::program::PreprocessedProgram {
abi,
bytecode,
proving_key,
verification_key,
..
} = preprocessed_program;

// Parse the initial witness values from Prover.toml
let (inputs_map, _) = fs::inputs::read_inputs_from_file(
program_dir,
crate::constants::PROVER_INPUT_FILE,
noirc_abi::input_parser::Format::Toml,
&abi,
&program.abi,
)
.expect("Should read inputs");

let solved_witness =
match execute_cmd::execute_program(&backend, bytecode.clone(), &abi, &inputs_map) {
Ok(witness) => witness,
// Failure to execute is an invalid proof
Err(_) => return false,
};

let public_abi = abi.public_abi();
let (public_inputs, return_value) =
public_abi.decode(&solved_witness).expect("Solved witness should decode");

let proof = nargo::ops::prove_execution(
&backend,
&common_reference_string,
&bytecode,
solved_witness,
&proving_key,
)
.expect("Circuit should prove");

let public_inputs =
public_abi.encode(&public_inputs, return_value).expect("Public inputs should encode");
nargo::ops::verify_proof(
&backend,
&common_reference_string,
&bytecode,
&proof,
public_inputs,
&verification_key,
)
.expect("Proof should verify")
execute_cmd::execute_program(&backend, program.circuit, &program.abi, &inputs_map).is_ok()
}

// FIXME: I not sure that this is the right place for this tests.
Expand Down

0 comments on commit 2ef9c34

Please sign in to comment.