Skip to content

Commit

Permalink
chore: rename barretenberg_blackbox_solver to `bn254_blackbox_solve…
Browse files Browse the repository at this point in the history
…r` (#3874)

# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

This PR renames `barretenberg_blackbox_solver` to
`bn254_blackbox_solver` and marks it as not deprecated.

This signifies that these blackbox solvers should work against all
backends targetting the bn254 curve and not just barretenberg. That
we're using barretenberg to solve them is then just an implementation
detail.

We've decided to retain the `BlackBoxFunctionSolver` trait to allow
these solvers to be swapped out based on the `FieldElement`
implementation and so the new `Bn254BlackBoxSolver` is not deprecated.


## Additional Context

Now that this solver is tied to a curve rather than a particular
backend, it's now proper to integrate it into the compiler such that we
can solve black box functions such as that which caused #3865

## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench authored Dec 19, 2023
1 parent c2c3388 commit 7a4e845
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 63 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-acvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ jobs:
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.ACVM_CRATES_IO_TOKEN }}

- name: Publish barretenberg_blackbox_solver
- name: Publish bn254_blackbox_solver
run: |
cargo publish --package barretenberg_blackbox_solver
cargo publish --package bn254_blackbox_solver
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.ACVM_CRATES_IO_TOKEN }}

Expand Down
48 changes: 24 additions & 24 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ members = [
"acvm-repo/brillig",
"acvm-repo/brillig_vm",
"acvm-repo/blackbox_solver",
"acvm-repo/barretenberg_blackbox_solver",
"acvm-repo/bn254_blackbox_solver",
]
default-members = ["tooling/nargo_cli"]
resolver = "2"
Expand All @@ -56,7 +56,7 @@ stdlib = { version = "0.37.1", package = "acvm_stdlib", path = "acvm-repo/stdlib
brillig = { version = "0.38.0", path = "acvm-repo/brillig", default-features = false }
brillig_vm = { version = "0.38.0", path = "acvm-repo/brillig_vm", default-features = false }
acvm_blackbox_solver = { version = "0.38.0", path = "acvm-repo/blackbox_solver", default-features = false }
barretenberg_blackbox_solver = { version = "0.38.0", path = "acvm-repo/barretenberg_blackbox_solver", default-features = false }
bn254_blackbox_solver = { version = "0.38.0", path = "acvm-repo/bn254_blackbox_solver", default-features = false }

# Noir compiler workspace dependencies
arena = { path = "compiler/utils/arena" }
Expand Down
8 changes: 4 additions & 4 deletions acvm-repo/acvm_js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ crate-type = ["cdylib"]
cfg-if = "1.0.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
acvm = { path = "../acvm", default-features = false }
barretenberg_blackbox_solver = { path = "../barretenberg_blackbox_solver", default-features = false }
acvm.workspace = true
bn254_blackbox_solver = { workspace = true, optional = true }
wasm-bindgen.workspace = true
wasm-bindgen-futures.workspace = true
console_error_panic_hook.workspace = true
Expand All @@ -41,5 +41,5 @@ wasm-bindgen-test.workspace = true

[features]
default = ["bn254"]
bn254 = ["acvm/bn254", "barretenberg_blackbox_solver/bn254"]
bls12_381 = ["acvm/bls12_381", "barretenberg_blackbox_solver/bls12_381"]
bn254 = ["acvm/bn254", "dep:bn254_blackbox_solver"]
bls12_381 = ["acvm/bls12_381"]
9 changes: 3 additions & 6 deletions acvm-repo/acvm_js/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use acvm::{
acir::circuit::Circuit,
pwg::{ACVMStatus, ErrorLocation, OpcodeResolutionError, ACVM},
};
#[allow(deprecated)]
use barretenberg_blackbox_solver::BarretenbergSolver;
use bn254_blackbox_solver::Bn254BlackBoxSolver;

use js_sys::Error;
use wasm_bindgen::prelude::wasm_bindgen;
Expand All @@ -14,13 +13,11 @@ use crate::{
};

#[wasm_bindgen]
#[allow(deprecated)]
pub struct WasmBlackBoxFunctionSolver(BarretenbergSolver);
pub struct WasmBlackBoxFunctionSolver(Bn254BlackBoxSolver);

impl WasmBlackBoxFunctionSolver {
async fn initialize() -> WasmBlackBoxFunctionSolver {
#[allow(deprecated)]
WasmBlackBoxFunctionSolver(BarretenbergSolver::initialize().await)
WasmBlackBoxFunctionSolver(Bn254BlackBoxSolver::initialize().await)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "barretenberg_blackbox_solver"
description = "A wrapper around a barretenberg WASM binary to execute black box functions for which there is no rust implementation"
name = "bn254_blackbox_solver"
description = "Solvers for black box functions which are specific for the bn254 curve"
# x-release-please-start-version
version = "0.38.0"
# x-release-please-end
Expand Down Expand Up @@ -54,4 +54,3 @@ reqwest = { version = "0.11.20", default-features = false, features = [
[features]
default = ["bn254"]
bn254 = ["acir/bn254"]
bls12_381 = ["acir/bls12_381"]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,32 @@ use wasm::Barretenberg;

use self::wasm::{Pedersen, SchnorrSig};

#[deprecated = "The `BarretenbergSolver` is a temporary solution and will be removed in future."]
pub struct BarretenbergSolver {
pub struct Bn254BlackBoxSolver {
blackbox_vendor: Barretenberg,
}

#[allow(deprecated)]
impl BarretenbergSolver {
impl Bn254BlackBoxSolver {
#[cfg(target_arch = "wasm32")]
pub async fn initialize() -> BarretenbergSolver {
pub async fn initialize() -> Bn254BlackBoxSolver {
let blackbox_vendor = Barretenberg::initialize().await;
BarretenbergSolver { blackbox_vendor }
Bn254BlackBoxSolver { blackbox_vendor }
}

#[cfg(not(target_arch = "wasm32"))]
pub fn new() -> BarretenbergSolver {
pub fn new() -> Bn254BlackBoxSolver {
let blackbox_vendor = Barretenberg::new();
BarretenbergSolver { blackbox_vendor }
Bn254BlackBoxSolver { blackbox_vendor }
}
}

#[cfg(not(target_arch = "wasm32"))]
#[allow(deprecated)]
impl Default for BarretenbergSolver {
impl Default for Bn254BlackBoxSolver {
fn default() -> Self {
Self::new()
}
}

#[allow(deprecated)]
impl BlackBoxFunctionSolver for BarretenbergSolver {
impl BlackBoxFunctionSolver for Bn254BlackBoxSolver {
fn schnorr_verify(
&self,
public_key_x: &FieldElement,
Expand All @@ -57,7 +53,6 @@ impl BlackBoxFunctionSolver for BarretenbergSolver {
let sig_s: [u8; 32] = signature[0..32].try_into().unwrap();
let sig_e: [u8; 32] = signature[32..64].try_into().unwrap();

#[allow(deprecated)]
self.blackbox_vendor.verify_signature(pub_key, sig_s, sig_e, message).map_err(|err| {
BlackBoxResolutionError::Failed(BlackBoxFunc::SchnorrVerify, err.to_string())
})
Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ noirc_frontend.workspace = true
noirc_abi.workspace = true
noirc_errors.workspace = true
acvm.workspace = true
barretenberg_blackbox_solver.workspace = true
bn254_blackbox_solver.workspace = true
toml.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions tooling/nargo_cli/src/cli/debug_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;

use acvm::acir::native_types::WitnessMap;
use bn254_blackbox_solver::Bn254BlackBoxSolver;
use clap::Args;

use nargo::artifacts::debug::DebugArtifact;
Expand Down Expand Up @@ -134,8 +135,7 @@ pub(crate) fn debug_program(
compiled_program: &CompiledProgram,
inputs_map: &InputMap,
) -> Result<Option<WitnessMap>, CliError> {
#[allow(deprecated)]
let blackbox_solver = barretenberg_blackbox_solver::BarretenbergSolver::new();
let blackbox_solver = Bn254BlackBoxSolver::new();

let initial_witness = compiled_program.abi.encode(inputs_map, None)?;

Expand Down
4 changes: 2 additions & 2 deletions tooling/nargo_cli/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use acvm::acir::native_types::WitnessMap;
use bn254_blackbox_solver::Bn254BlackBoxSolver;
use clap::Args;

use nargo::artifacts::debug::DebugArtifact;
Expand Down Expand Up @@ -107,8 +108,7 @@ pub(crate) fn execute_program(
compiled_program: &CompiledProgram,
inputs_map: &InputMap,
) -> Result<WitnessMap, CliError> {
#[allow(deprecated)]
let blackbox_solver = barretenberg_blackbox_solver::BarretenbergSolver::new();
let blackbox_solver = Bn254BlackBoxSolver::new();

let initial_witness = compiled_program.abi.encode(inputs_map, None)?;

Expand Down
4 changes: 2 additions & 2 deletions tooling/nargo_cli/src/cli/lsp_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use async_lsp::{
client_monitor::ClientProcessMonitorLayer, concurrency::ConcurrencyLayer,
panic::CatchUnwindLayer, server::LifecycleLayer, tracing::TracingLayer,
};
use bn254_blackbox_solver::Bn254BlackBoxSolver;
use clap::Args;
use noir_lsp::NargoLspService;
use tower::ServiceBuilder;
Expand Down Expand Up @@ -30,8 +31,7 @@ pub(crate) fn run(

runtime.block_on(async {
let (server, _) = async_lsp::MainLoop::new_server(|client| {
#[allow(deprecated)]
let blackbox_solver = barretenberg_blackbox_solver::BarretenbergSolver::new();
let blackbox_solver = Bn254BlackBoxSolver::new();
let router = NargoLspService::new(&client, blackbox_solver);

ServiceBuilder::new()
Expand Down
4 changes: 2 additions & 2 deletions tooling/nargo_cli/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::io::Write;

use acvm::BlackBoxFunctionSolver;
use bn254_blackbox_solver::Bn254BlackBoxSolver;
use clap::Args;
use fm::FileManager;
use nargo::{
Expand Down Expand Up @@ -73,8 +74,7 @@ pub(crate) fn run(
None => FunctionNameMatch::Anything,
};

#[allow(deprecated)]
let blackbox_solver = barretenberg_blackbox_solver::BarretenbergSolver::new();
let blackbox_solver = Bn254BlackBoxSolver::new();
for package in &workspace {
// By unwrapping here with `?`, we stop the test runner upon a package failing
// TODO: We should run the whole suite even if there are failures in a package
Expand Down

0 comments on commit 7a4e845

Please sign in to comment.