Skip to content

Commit

Permalink
Merge branch 'master' into aztec-packages
Browse files Browse the repository at this point in the history
* master:
  feat: add `noir-compiler` checks to `aztec_macros` (#4031)
  chore: remove unnecessary visibility modifiers from u128 trait impls (#4023)
  chore(ci): install fixed version of `wasm-pack` in CI (#4034)
  chore: remove `release-tests` package (#4032)
  chore(docs): bumping playground version (#4030)
  fix: allow ast when macro errors (#4005)
  chore: provide a canonical "failing" `BlackBoxFunctionSolver` (#4028)
  feat: assert maximum bit size when creating a U128 from an integer (#4024)
  • Loading branch information
TomAFrench committed Jan 13, 2024
2 parents 563c704 + 420a5c7 commit 787ccdc
Show file tree
Hide file tree
Showing 23 changed files with 211 additions and 777 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/publish-nargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ jobs:
path: ./dist/*
retention-days: 3

- name: Install Yarn dependencies
if: matrix.target == 'x86_64-apple-darwin'
uses: ./.github/actions/setup

- name: Test built artifact
if: matrix.target == 'x86_64-apple-darwin'
run: |
cp ./target/${{ matrix.target }}/release/nargo ~/.cargo/bin/
yarn workspace release-tests test
- name: Upload binaries to release tag
uses: svenstaro/upload-release-action@v2
if: ${{ inputs.publish || github.event_name == 'schedule' }}
Expand Down Expand Up @@ -161,16 +151,6 @@ jobs:
path: ./dist/*
retention-days: 3

- name: Install Yarn dependencies
if: startsWith(matrix.target, 'x86_64-unknown-linux')
uses: ./.github/actions/setup

- name: Test built artifact
if: startsWith(matrix.target, 'x86_64-unknown-linux')
run: |
cp ./target/${{ matrix.target }}/release/nargo ~/.cargo/bin/
yarn workspace release-tests test
- name: Upload binaries to release tag
uses: svenstaro/upload-release-action@v2
if: ${{ inputs.publish }}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ jobs:
name: noirc_abi_wasm
path: ./tooling/noirc_abi_wasm

- name: Install wasm-pack
uses: taiki-e/install-action@v2
with:
tool: wasm-pack@0.12.1

- name: Install Yarn dependencies
uses: ./.github/actions/setup

Expand Down
1 change: 0 additions & 1 deletion Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ COPY ./tooling/noir_js_backend_barretenberg/package.json ./tooling/noir_js_backe
COPY ./tooling/noir_js/package.json ./tooling/noir_js/
COPY ./tooling/noir_codegen/package.json ./tooling/noir_codegen/
COPY ./compiler/integration-tests/package.json ./compiler/integration-tests/
COPY ./release-tests/package.json ./release-tests/
COPY ./docs/package.json ./docs/
RUN yarn --immutable
COPY . .
74 changes: 9 additions & 65 deletions acvm-repo/acvm/tests/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,8 @@ use acir::{
FieldElement,
};

use acvm::{
pwg::{ACVMStatus, ErrorLocation, ForeignCallWaitInfo, OpcodeResolutionError, ACVM},
BlackBoxFunctionSolver,
};
use acvm_blackbox_solver::BlackBoxResolutionError;

pub(crate) struct StubbedBackend;

impl BlackBoxFunctionSolver for StubbedBackend {
fn schnorr_verify(
&self,
_public_key_x: &FieldElement,
_public_key_y: &FieldElement,
_signature: &[u8],
_message: &[u8],
) -> Result<bool, BlackBoxResolutionError> {
panic!("Path not trodden by this test")
}
fn pedersen_commitment(
&self,
_inputs: &[FieldElement],
_domain_separator: u32,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
panic!("Path not trodden by this test")
}
fn pedersen_hash(
&self,
_inputs: &[FieldElement],
_domain_separator: u32,
) -> Result<FieldElement, BlackBoxResolutionError> {
panic!("Path not trodden by this test")
}
fn fixed_base_scalar_mul(
&self,
_low: &FieldElement,
_high: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
panic!("Path not trodden by this test")
}

fn ec_add(
&self,
_input1_x: &FieldElement,
_input1_y: &FieldElement,
_input2_x: &FieldElement,
_input2_y: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
panic!("Path not trodden by this test")
}

fn ec_double(
&self,
_input_x: &FieldElement,
_input_y: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
panic!("Path not trodden by this test")
}
}
use acvm::pwg::{ACVMStatus, ErrorLocation, ForeignCallWaitInfo, OpcodeResolutionError, ACVM};
use acvm_blackbox_solver::StubbedBlackBoxSolver;

// Reenable these test cases once we move the brillig implementation of inversion down into the acvm stdlib.

Expand Down Expand Up @@ -153,7 +97,7 @@ fn inversion_brillig_oracle_equivalence() {
])
.into();

let mut acvm = ACVM::new(&StubbedBackend, &opcodes, witness_assignments);
let mut acvm = ACVM::new(&StubbedBlackBoxSolver, &opcodes, witness_assignments);
// use the partial witness generation solver with our acir program
let solver_status = acvm.solve();

Expand Down Expand Up @@ -282,7 +226,7 @@ fn double_inversion_brillig_oracle() {
])
.into();

let mut acvm = ACVM::new(&StubbedBackend, &opcodes, witness_assignments);
let mut acvm = ACVM::new(&StubbedBlackBoxSolver, &opcodes, witness_assignments);

// use the partial witness generation solver with our acir program
let solver_status = acvm.solve();
Expand Down Expand Up @@ -403,7 +347,7 @@ fn oracle_dependent_execution() {
let witness_assignments =
BTreeMap::from([(w_x, FieldElement::from(2u128)), (w_y, FieldElement::from(2u128))]).into();

let mut acvm = ACVM::new(&StubbedBackend, &opcodes, witness_assignments);
let mut acvm = ACVM::new(&StubbedBlackBoxSolver, &opcodes, witness_assignments);

// use the partial witness generation solver with our acir program
let solver_status = acvm.solve();
Expand Down Expand Up @@ -502,7 +446,7 @@ fn brillig_oracle_predicate() {
])
.into();

let mut acvm = ACVM::new(&StubbedBackend, &opcodes, witness_assignments);
let mut acvm = ACVM::new(&StubbedBlackBoxSolver, &opcodes, witness_assignments);
let solver_status = acvm.solve();
assert_eq!(solver_status, ACVMStatus::Solved, "should be fully solved");

Expand Down Expand Up @@ -535,7 +479,7 @@ fn unsatisfied_opcode_resolved() {
values.insert(d, FieldElement::from(2_i128));

let opcodes = vec![Opcode::AssertZero(opcode_a)];
let mut acvm = ACVM::new(&StubbedBackend, &opcodes, values);
let mut acvm = ACVM::new(&StubbedBlackBoxSolver, &opcodes, values);
let solver_status = acvm.solve();
assert_eq!(
solver_status,
Expand Down Expand Up @@ -615,7 +559,7 @@ fn unsatisfied_opcode_resolved_brillig() {

let opcodes = vec![brillig_opcode, Opcode::AssertZero(opcode_a)];

let mut acvm = ACVM::new(&StubbedBackend, &opcodes, values);
let mut acvm = ACVM::new(&StubbedBlackBoxSolver, &opcodes, values);
let solver_status = acvm.solve();
assert_eq!(
solver_status,
Expand Down Expand Up @@ -659,7 +603,7 @@ fn memory_operations() {

let opcodes = vec![init, read_op, expression];

let mut acvm = ACVM::new(&StubbedBackend, &opcodes, initial_witness);
let mut acvm = ACVM::new(&StubbedBlackBoxSolver, &opcodes, initial_witness);
let solver_status = acvm.solve();
assert_eq!(solver_status, ACVMStatus::Solved);
let witness_map = acvm.finalize();
Expand Down
104 changes: 104 additions & 0 deletions acvm-repo/blackbox_solver/src/curve_specific_solver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use acir::{BlackBoxFunc, FieldElement};

use crate::BlackBoxResolutionError;

/// This component will generate outputs for Blackbox function calls where the underlying [`acir::BlackBoxFunc`]
/// doesn't have a canonical Rust implementation.
///
/// Returns an [`BlackBoxResolutionError`] if the backend does not support the given [`acir::BlackBoxFunc`].
pub trait BlackBoxFunctionSolver {
fn schnorr_verify(
&self,
public_key_x: &FieldElement,
public_key_y: &FieldElement,
signature: &[u8],
message: &[u8],
) -> Result<bool, BlackBoxResolutionError>;
fn pedersen_commitment(
&self,
inputs: &[FieldElement],
domain_separator: u32,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError>;
fn pedersen_hash(
&self,
inputs: &[FieldElement],
domain_separator: u32,
) -> Result<FieldElement, BlackBoxResolutionError>;
fn fixed_base_scalar_mul(
&self,
low: &FieldElement,
high: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError>;
fn ec_add(
&self,
input1_x: &FieldElement,
input1_y: &FieldElement,
input2_x: &FieldElement,
input2_y: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError>;
fn ec_double(
&self,
input_x: &FieldElement,
input_x: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError>;
}

pub struct StubbedBlackBoxSolver;

impl StubbedBlackBoxSolver {
fn fail(black_box_function: BlackBoxFunc) -> BlackBoxResolutionError {
BlackBoxResolutionError::Failed(
black_box_function,
format!("{} is not supported", black_box_function.name()),
)
}
}

impl BlackBoxFunctionSolver for StubbedBlackBoxSolver {
fn schnorr_verify(
&self,
_public_key_x: &FieldElement,
_public_key_y: &FieldElement,
_signature: &[u8],
_message: &[u8],
) -> Result<bool, BlackBoxResolutionError> {
Err(Self::fail(BlackBoxFunc::SchnorrVerify))
}
fn pedersen_commitment(
&self,
_inputs: &[FieldElement],
_domain_separator: u32,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
Err(Self::fail(BlackBoxFunc::PedersenCommitment))
}
fn pedersen_hash(
&self,
_inputs: &[FieldElement],
_domain_separator: u32,
) -> Result<FieldElement, BlackBoxResolutionError> {
Err(Self::fail(BlackBoxFunc::PedersenHash))
}
fn fixed_base_scalar_mul(
&self,
_low: &FieldElement,
_high: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
Err(Self::fail(BlackBoxFunc::FixedBaseScalarMul))
}
fn ec_add(
&self,
_input1_x: &FieldElement,
_input1_y: &FieldElement,
_input2_x: &FieldElement,
_input2_y: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
Err(Self::fail(BlackBoxFunc::EmbeddedCurveAdd))
}
fn ec_double(
&self,
_input_x: &FieldElement,
_input_y: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
Err(Self::fail(BlackBoxFunc::EmbeddedCurveDouble))
}
}
47 changes: 5 additions & 42 deletions acvm-repo/blackbox_solver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,23 @@
//! For functions that are backend-dependent, it provides a Trait [BlackBoxFunctionSolver] that must be implemented by the backend.
//! For functions that have a reference implementation, such as [keccak256], this crate exports the reference implementation directly.

use acir::{BlackBoxFunc, FieldElement};
use acir::BlackBoxFunc;
use blake2::digest::generic_array::GenericArray;
use blake2::{Blake2s256, Digest};
use sha2::Sha256;
use sha3::Keccak256;
use thiserror::Error;

mod curve_specific_solver;

pub use curve_specific_solver::{BlackBoxFunctionSolver, StubbedBlackBoxSolver};

#[derive(Clone, PartialEq, Eq, Debug, Error)]
pub enum BlackBoxResolutionError {
#[error("failed to solve blackbox function: {0}, reason: {1}")]
Failed(BlackBoxFunc, String),
}

/// This component will generate outputs for Blackbox function calls where the underlying [`acir::BlackBoxFunc`]
/// doesn't have a canonical Rust implementation.
///
/// Returns an [`BlackBoxResolutionError`] if the backend does not support the given [`acir::BlackBoxFunc`].
pub trait BlackBoxFunctionSolver {
fn schnorr_verify(
&self,
public_key_x: &FieldElement,
public_key_y: &FieldElement,
signature: &[u8],
message: &[u8],
) -> Result<bool, BlackBoxResolutionError>;
fn pedersen_commitment(
&self,
inputs: &[FieldElement],
domain_separator: u32,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError>;
fn pedersen_hash(
&self,
inputs: &[FieldElement],
domain_separator: u32,
) -> Result<FieldElement, BlackBoxResolutionError>;
fn fixed_base_scalar_mul(
&self,
low: &FieldElement,
high: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError>;
fn ec_add(
&self,
input1_x: &FieldElement,
input1_y: &FieldElement,
input2_x: &FieldElement,
input2_y: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError>;
fn ec_double(
&self,
input_x: &FieldElement,
input_x: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError>;
}

pub fn sha256(inputs: &[u8]) -> Result<[u8; 32], BlackBoxResolutionError> {
generic_hash_256::<Sha256>(inputs)
.map_err(|err| BlackBoxResolutionError::Failed(BlackBoxFunc::SHA256, err))
Expand Down
Loading

0 comments on commit 787ccdc

Please sign in to comment.