Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: sync Noir repo #4020

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions noir/.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 noir/.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: [email protected]

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

Expand Down
4 changes: 2 additions & 2 deletions noir/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/noir-lang/noir
branch = aztec-packages
commit = 563c7041fd95f22fe76dc4dee75188fc4b3d8381
parent = 605e3e82a6adb4aeffe8b35cb27c7018f3c9bbac
commit = 7f22446f3940f8ef7ccae785a4b29835f2e869fe
parent = 468998824f1b1e2f4f8a929ba970f3599bf34ab0
method = merge
cmdver = 0.4.6
1 change: 0 additions & 1 deletion noir/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 noir/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 noir/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 noir/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