Skip to content

Commit

Permalink
chore: switch acir_tests over to use json build artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed May 9, 2024
1 parent 8c3c78b commit ae4c980
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 58 deletions.
4 changes: 2 additions & 2 deletions barretenberg/acir_tests/flows/all_cmds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

VFLAG=${VERBOSE:+-v}
BFLAG="-b ./target/acir.gz"
BFLAG="-b ./target/program.json"
FLAGS="-c $CRS_PATH $VFLAG"

# Test we can perform the proof/verify flow.
Expand All @@ -19,4 +19,4 @@ $BIN contract -k vk $BFLAG -o - | grep "Verification Key Hash" > /dev/null
OUTPUT=$($BIN proof_as_fields -k vk -p proof -o - | jq .)
[ -n "$OUTPUT" ] || exit 1
OUTPUT=$($BIN vk_as_fields -k vk -o - | jq .)
[ -n "$OUTPUT" ] || exit 1
[ -n "$OUTPUT" ] || exit 1
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/flows/prove_and_verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ VFLAG=${VERBOSE:+-v}

# This is the fastest flow, because it only generates pk/vk once, gate count once, etc.
# It may not catch all class of bugs.
$BIN prove_and_verify $VFLAG -c $CRS_PATH -b ./target/acir.gz
$BIN prove_and_verify $VFLAG -c $CRS_PATH -b ./target/program.json
4 changes: 2 additions & 2 deletions barretenberg/acir_tests/flows/prove_and_verify_goblin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -eu

VFLAG=${VERBOSE:+-v}

$BIN prove_and_verify_goblin $VFLAG -c $CRS_PATH -b ./target/acir.gz
$BIN prove_and_verify_goblin $VFLAG -c $CRS_PATH -b ./target/program.json

# This command can be used to run all of the tests in sequence with the debugger
# lldb-16 -o run -b -- $BIN prove_and_verify_goblin $VFLAG -c $CRS_PATH -b ./target/acir.gz
# lldb-16 -o run -b -- $BIN prove_and_verify_goblin $VFLAG -c $CRS_PATH -b ./target/program.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -eu

VFLAG=${VERBOSE:+-v}

$BIN prove_and_verify_goblin_ultra_honk $VFLAG -c $CRS_PATH -b ./target/acir.gz
$BIN prove_and_verify_goblin_ultra_honk $VFLAG -c $CRS_PATH -b ./target/program.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -eu

VFLAG=${VERBOSE:+-v}

$BIN prove_and_verify_ultra_honk $VFLAG -c $CRS_PATH -b ./target/acir.gz
$BIN prove_and_verify_ultra_honk $VFLAG -c $CRS_PATH -b ./target/program.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ set -eu

VFLAG=${VERBOSE:+-v}

$BIN prove_and_verify_ultra_honk_program $VFLAG -c $CRS_PATH -b ./target/acir.gz
$BIN prove_and_verify_ultra_honk_program $VFLAG -c $CRS_PATH -b ./target/program.json
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/flows/prove_then_verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

VFLAG=${VERBOSE:+-v}
BFLAG="-b ./target/acir.gz"
BFLAG="-b ./target/program.json"
FLAGS="-c $CRS_PATH $VFLAG"

# Test we can perform the proof/verify flow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

VFLAG=${VERBOSE:+-v}
BFLAG="-b ./target/acir.gz"
BFLAG="-b ./target/program.json"
FLAGS="-c $CRS_PATH $VFLAG"

# Test we can perform the proof/verify flow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

VFLAG=${VERBOSE:+-v}
BFLAG="-b ./target/acir.gz"
BFLAG="-b ./target/program.json"
FLAGS="-c $CRS_PATH $VFLAG"

# Test we can perform the proof/verify flow.
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/acir_tests/flows/sol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export PROOF_AS_FIELDS="$(pwd)/proof_fields.json"
$BIN prove -o proof
$BIN write_vk -o vk
$BIN proof_as_fields -k vk -c $CRS_PATH -p $PROOF
$BIN contract -k vk -c $CRS_PATH -b ./target/acir.gz -o Key.sol
$BIN contract -k vk -c $CRS_PATH -b ./target/program.json -o Key.sol

# Export the paths to the environment variables for the js test runner
export KEY_PATH="$(pwd)/Key.sol"
Expand All @@ -20,4 +20,4 @@ export BASE_PATH=$(realpath "../../../sol/src/ultra/BaseUltraVerifier.sol")
# index.js will start an anvil, on a random port
# Deploy the verifier then send a test transaction
export TEST_NAME=$(basename $(pwd))
node ../../sol-test/src/index.js
node ../../sol-test/src/index.js
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/flows/write_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -eu
export TEST_NAME=$(basename $(pwd))

$BIN write_vk -o vk
$BIN contract -k vk -c $CRS_PATH -b ./target/acir.gz -o $TEST_NAME.sol
$BIN contract -k vk -c $CRS_PATH -b ./target/program.json -o $TEST_NAME.sol
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/gen_inner_proof_inputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $BIN vk_as_fields $VFLAG -c $CRS_PATH
echo "Generate proof to file..."
[ -d "$PROOF_DIR" ] || mkdir $PWD/proofs
[ -e "$PROOF_PATH" ] || touch $PROOF_PATH
$BIN prove $VFLAG -c $CRS_PATH -b ./target/acir.gz -o "./proofs/$PROOF_NAME" $RFLAG
$BIN prove $VFLAG -c $CRS_PATH -b ./target/program.json -o "./proofs/$PROOF_NAME" $RFLAG

echo "Write proof as fields for recursion..."
$BIN proof_as_fields $VFLAG -c $CRS_PATH -p "./proofs/$PROOF_NAME"
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/run_acir_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ else
continue
fi

if [[ ! -f ./$TEST_NAME/target/acir.gz || ! -f ./$TEST_NAME/target/witness.gz ]]; then
if [[ ! -f ./$TEST_NAME/target/program.json || ! -f ./$TEST_NAME/target/witness.gz ]]; then
echo -e "\033[33mSKIPPED\033[0m (uncompiled)"
continue
fi
Expand Down
4 changes: 0 additions & 4 deletions noir/noir-repo/compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ pub struct CompileOptions {
#[arg(long, conflicts_with = "deny_warnings")]
pub silence_warnings: bool,

/// Output ACIR gzipped bytecode instead of the JSON artefact
#[arg(long, hide = true)]
pub only_acir: bool,

/// Disables the builtin Aztec macros being used in the compiler
#[arg(long, hide = true)]
pub disable_macros: bool,
Expand Down
5 changes: 3 additions & 2 deletions noir/noir-repo/test_programs/rebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ process_dir() {
if [ -d ./target/ ]; then
rm -r ./target/
fi
nargo compile --only-acir && nargo execute witness
nargo execute witness

if [ -d "$current_dir/acir_artifacts/$dir_name/target" ]; then
rm -r "$current_dir/acir_artifacts/$dir_name/target"
fi
mkdir $current_dir/acir_artifacts/$dir_name/target

mv ./target/$dir_name.json $current_dir/acir_artifacts/$dir_name/target/program.json
mv ./target/*.gz $current_dir/acir_artifacts/$dir_name/target/

cd $current_dir
Expand Down Expand Up @@ -70,4 +71,4 @@ if [ ! -z "$exit_status" ]; then
echo "Rebuild failed!"
exit $exit_status
fi
echo "Rebuild Succeeded!"
echo "Rebuild Succeeded!"
19 changes: 4 additions & 15 deletions noir/noir-repo/tooling/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use notify_debouncer_full::new_debouncer;

use crate::errors::CliError;

use super::fs::program::only_acir;
use super::fs::program::{read_program_from_file, save_contract_to_file, save_program_to_file};
use super::NargoConfig;
use rayon::prelude::*;
Expand Down Expand Up @@ -136,10 +135,9 @@ pub(super) fn compile_workspace_full(
.partition(|package| package.is_binary());

// Save build artifacts to disk.
let only_acir = compile_options.only_acir;
for (package, program) in binary_packages.into_iter().zip(compiled_programs) {
let program = nargo::ops::transform_program(program, compile_options.expression_width);
save_program(program.clone(), &package, &workspace.target_directory_path(), only_acir);
save_program(program.clone(), &package, &workspace.target_directory_path());
}
let circuit_dir = workspace.target_directory_path();
for (package, contract) in contract_packages.into_iter().zip(compiled_contracts) {
Expand Down Expand Up @@ -197,18 +195,9 @@ pub(super) fn compile_workspace(
}
}

pub(super) fn save_program(
program: CompiledProgram,
package: &Package,
circuit_dir: &Path,
only_acir_opt: bool,
) {
if only_acir_opt {
only_acir(program.program, circuit_dir);
} else {
let program_artifact = ProgramArtifact::from(program.clone());
save_program_to_file(&program_artifact, &package.name, circuit_dir);
}
pub(super) fn save_program(program: CompiledProgram, package: &Package, circuit_dir: &Path) {
let program_artifact = ProgramArtifact::from(program.clone());
save_program_to_file(&program_artifact, &package.name, circuit_dir);
}

fn save_contract(contract: CompiledContract, package: &Package, circuit_dir: &Path) {
Expand Down
31 changes: 10 additions & 21 deletions noir/noir-repo/tooling/nargo_cli/src/cli/fs/program.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::path::{Path, PathBuf};

use acvm::acir::circuit::Program;
use nargo::artifacts::{contract::ContractArtifact, program::ProgramArtifact};
use noirc_frontend::graph::CrateName;

Expand All @@ -17,16 +16,6 @@ pub(crate) fn save_program_to_file<P: AsRef<Path>>(
save_build_artifact_to_file(program_artifact, &circuit_name, circuit_dir)
}

/// Writes the bytecode as acir.gz
pub(crate) fn only_acir<P: AsRef<Path>>(program: Program, circuit_dir: P) -> PathBuf {
create_named_dir(circuit_dir.as_ref(), "target");
let circuit_path = circuit_dir.as_ref().join("acir").with_extension("gz");
let bytes = Program::serialize_program(&program);
write_to_file(&bytes, &circuit_path);

circuit_path
}

pub(crate) fn save_contract_to_file<P: AsRef<Path>>(
compiled_contract: &ContractArtifact,
circuit_name: &str,
Expand Down Expand Up @@ -61,15 +50,15 @@ pub(crate) fn read_program_from_file<P: AsRef<Path>>(
Ok(program)
}

pub(crate) fn read_contract_from_file<P: AsRef<Path>>(
circuit_path: P,
) -> Result<ContractArtifact, FilesystemError> {
let file_path = circuit_path.as_ref().with_extension("json");
// pub(crate) fn read_contract_from_file<P: AsRef<Path>>(
// circuit_path: P,
// ) -> Result<ContractArtifact, FilesystemError> {
// let file_path = circuit_path.as_ref().with_extension("json");

let input_string =
std::fs::read(&file_path).map_err(|_| FilesystemError::PathNotValid(file_path))?;
let contract = serde_json::from_slice(&input_string)
.map_err(|err| FilesystemError::ProgramSerializationError(err.to_string()))?;
// let input_string =
// std::fs::read(&file_path).map_err(|_| FilesystemError::PathNotValid(file_path))?;
// let contract = serde_json::from_slice(&input_string)
// .map_err(|err| FilesystemError::ProgramSerializationError(err.to_string()))?;

Ok(contract)
}
// Ok(contract)
// }

0 comments on commit ae4c980

Please sign in to comment.