Skip to content

Commit

Permalink
feat: Sync from aztec-packages (#4792)
Browse files Browse the repository at this point in the history
Automated pull of Noir development from
[aztec-packages](https://github.com/AztecProtocol/aztec-packages).
BEGIN_COMMIT_OVERRIDE
fix: primary_message typo in errors.rs
(AztecProtocol/aztec-packages#5646)
feat: Sync from noir
(AztecProtocol/aztec-packages#5725)
feat: Proving the rollup circuits
(AztecProtocol/aztec-packages#5599)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Santiago Palladino <santiago@aztecprotocol.com>
Co-authored-by: vezenovm <mvezenov@gmail.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
  • Loading branch information
4 people committed Apr 15, 2024
1 parent 25ad018 commit 5b352d6
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10d9ad99200a5897417ff5669763ead4e38d87fa
1dfbe7bc3bf3c455d8fb6c8b5fe6a96c1edf7af9
2 changes: 1 addition & 1 deletion aztec_macros/src/utils/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl From<AztecMacroError> for MacroError {
fn from(err: AztecMacroError) -> Self {
match err {
AztecMacroError::AztecDepNotFound {} => MacroError {
primary_message: "Aztec dependency not found. Please add aztec as a dependency in your Cargo.toml. For more information go to https://docs.aztec.network/developers/debugging/aztecnr-errors#aztec-dependency-not-found-please-add-aztec-as-a-dependency-in-your-nargotoml".to_owned(),
primary_message: "Aztec dependency not found. Please add aztec as a dependency in your Nargo.toml. For more information go to https://docs.aztec.network/developers/debugging/aztecnr-errors#aztec-dependency-not-found-please-add-aztec-as-a-dependency-in-your-nargotoml".to_owned(),
secondary_message: None,
span: None,
},
Expand Down
7 changes: 3 additions & 4 deletions tooling/acvm_cli/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use bn254_blackbox_solver::Bn254BlackBoxSolver;
use clap::Args;

use crate::cli::fs::inputs::{read_bytecode_from_file, read_inputs_from_file};
use crate::cli::fs::witness::save_witness_to_dir;
use crate::errors::CliError;
use nargo::ops::{execute_program, DefaultForeignCallExecutor};

use super::fs::witness::create_output_witness_string;
use super::fs::witness::{create_output_witness_string, save_witness_to_dir};

/// Executes a circuit to calculate its return value
#[derive(Debug, Clone, Args)]
Expand Down Expand Up @@ -46,9 +45,9 @@ fn run_command(args: ExecuteCommand) -> Result<String, CliError> {
)?;
if args.output_witness.is_some() {
save_witness_to_dir(
&output_witness_string,
&args.working_directory,
output_witness,
&args.output_witness.unwrap(),
&args.working_directory,
)?;
}
Ok(output_witness_string)
Expand Down
47 changes: 34 additions & 13 deletions tooling/acvm_cli/src/cli/fs/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ use std::{
path::{Path, PathBuf},
};

use acvm::acir::native_types::WitnessMap;
use acvm::acir::native_types::{WitnessMap, WitnessStack};

use crate::errors::{CliError, FilesystemError};

/// Saves the provided output witnesses to a toml file created at the given location
pub(crate) fn save_witness_to_dir<P: AsRef<Path>>(
output_witness: &String,
witness_dir: P,
file_name: &String,
) -> Result<PathBuf, FilesystemError> {
let witness_path = witness_dir.as_ref().join(file_name);
fn create_named_dir(named_dir: &Path, name: &str) -> PathBuf {
std::fs::create_dir_all(named_dir)
.unwrap_or_else(|_| panic!("could not create the `{name}` directory"));

PathBuf::from(named_dir)
}

let mut file = File::create(&witness_path)
.map_err(|_| FilesystemError::OutputWitnessCreationFailed(file_name.clone()))?;
write!(file, "{}", output_witness)
.map_err(|_| FilesystemError::OutputWitnessWriteFailed(file_name.clone()))?;
fn write_to_file(bytes: &[u8], path: &Path) -> String {
let display = path.display();

Ok(witness_path)
let mut file = match File::create(path) {
Err(why) => panic!("couldn't create {display}: {why}"),
Ok(file) => file,
};

match file.write_all(bytes) {
Err(why) => panic!("couldn't write to {display}: {why}"),
Ok(_) => display.to_string(),
}
}

/// Creates a toml representation of the provided witness map
Expand All @@ -34,3 +39,19 @@ pub(crate) fn create_output_witness_string(witnesses: &WitnessMap) -> Result<Str

toml::to_string(&witness_map).map_err(|_| CliError::OutputWitnessSerializationFailed())
}

pub(crate) fn save_witness_to_dir<P: AsRef<Path>>(
witnesses: WitnessStack,
witness_name: &str,
witness_dir: P,
) -> Result<PathBuf, FilesystemError> {
create_named_dir(witness_dir.as_ref(), "witness");
let witness_path = witness_dir.as_ref().join(witness_name).with_extension("gz");

let buf: Vec<u8> = witnesses
.try_into()
.map_err(|_op| FilesystemError::OutputWitnessCreationFailed(witness_name.to_string()))?;
write_to_file(buf.as_slice(), &witness_path);

Ok(witness_path)
}
3 changes: 0 additions & 3 deletions tooling/acvm_cli/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ pub(crate) enum FilesystemError {

#[error(" Error: failed to create output witness file {0}.")]
OutputWitnessCreationFailed(String),

#[error(" Error: failed to write output witness file {0}.")]
OutputWitnessWriteFailed(String),
}

#[derive(Debug, Error)]
Expand Down
5 changes: 2 additions & 3 deletions tooling/noirc_abi_wasm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function run_if_available {
require_command jq
require_command cargo
require_command wasm-bindgen
require_command wasm-opt

self_path=$(dirname "$(readlink -f "$0")")
pname=$(cargo read-manifest | jq -r '.name')
Expand All @@ -49,5 +48,5 @@ BROWSER_WASM=${BROWSER_DIR}/${pname}_bg.wasm
run_or_fail cargo build --lib --release --target $TARGET --package ${pname}
run_or_fail wasm-bindgen $WASM_BINARY --out-dir $NODE_DIR --typescript --target nodejs
run_or_fail wasm-bindgen $WASM_BINARY --out-dir $BROWSER_DIR --typescript --target web
run_or_fail wasm-opt $NODE_WASM -o $NODE_WASM -O
run_or_fail wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O
run_if_available wasm-opt $NODE_WASM -o $NODE_WASM -O
run_if_available wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O
11 changes: 10 additions & 1 deletion tooling/noirc_abi_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// See Cargo.toml for explanation.
use getrandom as _;

use acvm::acir::native_types::WitnessMap;
use acvm::acir::native_types::{WitnessMap, WitnessStack};
use iter_extended::try_btree_map;
use noirc_abi::{
errors::InputParserError,
Expand Down Expand Up @@ -113,3 +113,12 @@ pub fn abi_decode(abi: JsAbi, witness_map: JsWitnessMap) -> Result<JsValue, JsAb
<wasm_bindgen::JsValue as JsValueSerdeExt>::from_serde(&return_struct)
.map_err(|err| err.to_string().into())
}

#[wasm_bindgen(js_name = serializeWitness)]
pub fn serialise_witness(witness_map: JsWitnessMap) -> Result<Vec<u8>, JsAbiError> {
console_error_panic_hook::set_once();
let converted_witness: WitnessMap = witness_map.into();
let witness_stack: WitnessStack = converted_witness.into();
let output = witness_stack.try_into();
output.map_err(|_| JsAbiError::new("Failed to convert to Vec<u8>".to_string()))
}

0 comments on commit 5b352d6

Please sign in to comment.