Skip to content

Commit

Permalink
chore: Save witness in correct format that bb.js expects (#1876)
Browse files Browse the repository at this point in the history
* save witness in correct format that bb.js expects and updates acvm-backend-barretenberg dep to show all old CI passing

* add feature flag for witness writing

* rename line

* use one flat witness feature flag

* fix flat_witness feature flag

* switch between witness map serialization feature flag on a feature flag
  • Loading branch information
vezenovm authored Jul 7, 2023
1 parent 1d5d84d commit 28d43dc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ wasm-bindgen-test = "0.3.33"

[patch.crates-io]
async-lsp = { git = "https://github.com/oxalica/async-lsp", rev = "09dbcc11046f7a188a80137f8d36484d86c78c78" }
acvm-backend-barretenberg = { git = "https://github.com/noir-lang/acvm-backend-barretenberg.git", rev = "0842911beed6c54b7efcd721372fb73431c95bbf" }
1 change: 1 addition & 0 deletions crates/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ default = ["plonk_bn254"]
# The plonk backend can only use bn254, so we do not specify the field
plonk_bn254 = ["acvm-backend-barretenberg/native"]
plonk_bn254_wasm = ["acvm-backend-barretenberg/wasm"]
flat_witness = ["acvm-backend-barretenberg/native"]
2 changes: 1 addition & 1 deletion crates/nargo_cli/src/backends.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub(crate) use acvm_backend_barretenberg::Barretenberg as ConcreteBackend;

#[cfg(not(any(feature = "plonk_bn254", feature = "plonk_bn254_wasm")))]
#[cfg(not(any(feature = "plonk_bn254", feature = "plonk_bn254_wasm", feature = "flat_witness")))]
compile_error!("please specify a backend to compile with");

#[cfg(all(feature = "plonk_bn254", feature = "plonk_bn254_wasm"))]
Expand Down
19 changes: 17 additions & 2 deletions crates/nargo_cli/src/cli/fs/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@ use super::{create_named_dir, write_to_file};
use crate::{constants::WITNESS_EXT, errors::FilesystemError};

pub(crate) fn save_witness_to_dir<P: AsRef<Path>>(
witness: WitnessMap,
witnesses: WitnessMap,
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(WITNESS_EXT);

let buf: Vec<u8> = witness.try_into()?;
let buf: Vec<u8> = serialize_witness_map(witnesses)?;

write_to_file(buf.as_slice(), &witness_path);

Ok(witness_path)
}

#[cfg(not(feature = "flat_witness"))]
fn serialize_witness_map(witnesses: WitnessMap) -> Result<Vec<u8>, FilesystemError> {
let buf: Vec<u8> = witnesses.try_into()?;
Ok(buf)
}

#[cfg(feature = "flat_witness")]
fn serialize_witness_map(witnesses: WitnessMap) -> Result<Vec<u8>, FilesystemError> {
let mut buf: Vec<u8> = Vec::new();
for (_, value) in witnesses {
buf.extend_from_slice(&value.to_be_bytes());
}
Ok(buf)
}

0 comments on commit 28d43dc

Please sign in to comment.