Skip to content

Commit

Permalink
chore: pull in noir from upstream (AztecProtocol#3904)
Browse files Browse the repository at this point in the history
subrepo:
  subdir:   "noir"
  merged:   "b2c89b2a0"
upstream:
  origin:   "https://github.com/noir-lang/noir"
  branch:   "aztec-packages"
  commit:   "114aa6f90"
git-subrepo:
  version:  "0.4.6"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "110b9eb"
  • Loading branch information
TomAFrench authored Jan 9, 2024
1 parent 331598d commit ab07e7e
Show file tree
Hide file tree
Showing 98 changed files with 1,097 additions and 3,306 deletions.
51 changes: 0 additions & 51 deletions noir/.github/workflows/test-cargo.yml

This file was deleted.

16 changes: 15 additions & 1 deletion noir/.github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ jobs:
run: yarn workspace @noir-lang/noir_wasm test:browser

test-noir-codegen:
needs: [build-acvm-js, build-noirc-abi]
needs: [build-acvm-js, build-noirc-abi, build-nargo]
name: noir_codegen
runs-on: ubuntu-latest
timeout-minutes: 30
Expand All @@ -328,6 +328,12 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Download nargo binary
uses: actions/download-artifact@v3
with:
name: nargo
path: ./nargo

- name: Download acvm_js package artifact
uses: actions/download-artifact@v3
with:
Expand All @@ -339,6 +345,14 @@ jobs:
with:
name: noirc_abi_wasm
path: ./tooling/noirc_abi_wasm

- name: Set nargo on PATH
run: |
nargo_binary="${{ github.workspace }}/nargo/nargo"
chmod +x $nargo_binary
echo "$(dirname $nargo_binary)" >> $GITHUB_PATH
export PATH="$PATH:$(dirname $nargo_binary)"
nargo -V
- name: Install Yarn dependencies
uses: ./.github/actions/setup
Expand Down
2 changes: 1 addition & 1 deletion 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 = c0826b58272bbba28d6cd25bc07dd5de3cc12e61
commit = 114aa6f90f147fe69ff424e881463a65df26c4e6
parent = 9a80008c623a9d26e1b82c9e86561c304ef185f1
method = merge
cmdver = 0.4.6
2 changes: 0 additions & 2 deletions noir/Cargo.lock

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

2 changes: 1 addition & 1 deletion noir/acvm-repo/acir/src/circuit/black_box_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl BlackBoxFunc {
BlackBoxFunc::XOR => "xor",
BlackBoxFunc::RANGE => "range",
BlackBoxFunc::Keccak256 => "keccak256",
BlackBoxFunc::Keccakf1600 => "keccak_f1600",
BlackBoxFunc::Keccakf1600 => "keccakf1600",
BlackBoxFunc::RecursiveAggregation => "recursive_aggregation",
BlackBoxFunc::EcdsaSecp256r1 => "ecdsa_secp256r1",
}
Expand Down
2 changes: 1 addition & 1 deletion noir/acvm-repo/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl FromStr for OpcodeLocation {
let brillig_index = parts[1].parse()?;
Ok(OpcodeLocation::Brillig { acir_index, brillig_index })
}
_ => unreachable!(),
_ => unreachable!("`OpcodeLocation` has too many components"),
}
}

Expand Down
15 changes: 10 additions & 5 deletions noir/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ impl BlackBoxFuncCall {
vec![*lhs, *rhs]
}
BlackBoxFuncCall::FixedBaseScalarMul { low, high, .. } => vec![*low, *high],
BlackBoxFuncCall::EmbeddedCurveAdd { input1_x, input1_y, input2_x, input2_y, .. } => vec![*input1_x, *input1_y, *input2_x, *input2_y],
BlackBoxFuncCall::EmbeddedCurveDouble { input_x, input_y, .. } => vec![*input_x, *input_y],
BlackBoxFuncCall::EmbeddedCurveAdd {
input1_x, input1_y, input2_x, input2_y, ..
} => vec![*input1_x, *input1_y, *input2_x, *input2_y],
BlackBoxFuncCall::EmbeddedCurveDouble { input_x, input_y, .. } => {
vec![*input_x, *input_y]
}
BlackBoxFuncCall::RANGE { input } => vec![*input],
BlackBoxFuncCall::SchnorrVerify {
public_key_x,
Expand Down Expand Up @@ -245,8 +249,7 @@ impl BlackBoxFuncCall {
| BlackBoxFuncCall::Blake2s { outputs, .. }
| BlackBoxFuncCall::Blake3 { outputs, .. }
| BlackBoxFuncCall::Keccak256 { outputs, .. }
| BlackBoxFuncCall::Keccakf1600 { outputs, .. }
=> outputs.to_vec(),
| BlackBoxFuncCall::Keccakf1600 { outputs, .. } => outputs.to_vec(),
BlackBoxFuncCall::AND { output, .. }
| BlackBoxFuncCall::XOR { output, .. }
| BlackBoxFuncCall::SchnorrVerify { output, .. }
Expand All @@ -257,7 +260,9 @@ impl BlackBoxFuncCall {
| BlackBoxFuncCall::PedersenCommitment { outputs, .. }
| BlackBoxFuncCall::EmbeddedCurveAdd { outputs, .. }
| BlackBoxFuncCall::EmbeddedCurveDouble { outputs, .. } => vec![outputs.0, outputs.1],
BlackBoxFuncCall::RANGE { .. } | BlackBoxFuncCall::RecursiveAggregation { .. } => vec![],
BlackBoxFuncCall::RANGE { .. } | BlackBoxFuncCall::RecursiveAggregation { .. } => {
vec![]
}
BlackBoxFuncCall::Keccak256VariableLength { outputs, .. } => outputs.to_vec(),
}
}
Expand Down
10 changes: 5 additions & 5 deletions noir/acvm-repo/acir/tests/test_program_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ fn pedersen_circuit() {
let bytes = Circuit::serialize_circuit(&circuit);

let expected_serialization: Vec<u8> = vec![
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 138, 9, 10, 0, 64, 8, 2, 103, 15, 250, 255, 139,
163, 162, 130, 72, 16, 149, 241, 3, 135, 84, 164, 172, 173, 213, 175, 251, 45, 198, 96,
243, 211, 50, 152, 67, 220, 211, 92, 0, 0, 0,
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 138, 9, 10, 0, 64, 8, 2, 103, 15, 232, 255, 31, 142,
138, 10, 34, 65, 84, 198, 15, 28, 82, 145, 178, 182, 86, 191, 238, 183, 24, 131, 205, 79,
203, 0, 166, 242, 158, 93, 92, 0, 0, 0,
];

assert_eq!(bytes, expected_serialization)
Expand Down Expand Up @@ -145,7 +145,7 @@ fn schnorr_verify_circuit() {
let expected_serialization: Vec<u8> = vec![
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 210, 87, 78, 2, 1, 20, 134, 209, 177, 247, 222, 123,
71, 68, 68, 68, 68, 68, 68, 68, 68, 68, 221, 133, 251, 95, 130, 145, 27, 206, 36, 78, 50,
57, 16, 94, 200, 253, 191, 159, 36, 73, 134, 146, 193, 19, 142, 241, 183, 255, 14, 179,
57, 16, 94, 200, 253, 191, 159, 36, 73, 134, 146, 193, 19, 142, 243, 183, 255, 14, 179,
233, 247, 145, 254, 59, 217, 127, 71, 57, 198, 113, 78, 48, 125, 167, 56, 205, 25, 206,
114, 142, 243, 92, 224, 34, 151, 184, 204, 21, 174, 114, 141, 235, 220, 224, 38, 183, 184,
205, 29, 238, 114, 143, 251, 60, 224, 33, 143, 120, 204, 19, 158, 242, 140, 25, 158, 51,
Expand All @@ -158,7 +158,7 @@ fn schnorr_verify_circuit() {
91, 159, 218, 56, 99, 219, 172, 77, 115, 182, 204, 219, 176, 96, 187, 162, 205, 74, 182,
42, 219, 168, 98, 155, 170, 77, 106, 182, 168, 219, 160, 225, 246, 77, 55, 111, 185, 113,
219, 109, 59, 110, 218, 117, 203, 158, 27, 166, 55, 75, 239, 150, 184, 101, 250, 252, 1,
19, 89, 159, 101, 220, 3, 0, 0,
55, 204, 92, 74, 220, 3, 0, 0,
];

assert_eq!(bytes, expected_serialization)
Expand Down
3 changes: 2 additions & 1 deletion noir/acvm-repo/acvm/src/compiler/transformers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ pub(super) fn transform_internal(
| acir::circuit::opcodes::BlackBoxFuncCall::XOR { output, .. } => {
transformer.mark_solvable(*output);
}
acir::circuit::opcodes::BlackBoxFuncCall::RANGE { .. } | acir::circuit::opcodes::BlackBoxFuncCall::RecursiveAggregation { .. } => (),
acir::circuit::opcodes::BlackBoxFuncCall::RANGE { .. }
| acir::circuit::opcodes::BlackBoxFuncCall::RecursiveAggregation { .. } => (),
acir::circuit::opcodes::BlackBoxFuncCall::SHA256 { outputs, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::Keccak256 { outputs, .. }
| acir::circuit::opcodes::BlackBoxFuncCall::Keccak256VariableLength {
Expand Down
4 changes: 2 additions & 2 deletions noir/acvm-repo/acvm/src/pwg/blackbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ pub(crate) fn solve(
BlackBoxFuncCall::FixedBaseScalarMul { low, high, outputs } => {
fixed_base_scalar_mul(backend, initial_witness, *low, *high, *outputs)
}
BlackBoxFuncCall::EmbeddedCurveAdd { outputs, input1_x, input1_y, input2_x, input2_y } => {
BlackBoxFuncCall::EmbeddedCurveAdd { .. } => {
todo!();
}
BlackBoxFuncCall::EmbeddedCurveDouble { outputs, input_x, input_y } => {
BlackBoxFuncCall::EmbeddedCurveDouble { .. } => {
todo!();
}
// Recursive aggregation will be entirely handled by the backend and is not solved by the ACVM
Expand Down
4 changes: 2 additions & 2 deletions noir/acvm-repo/acvm_js/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pub async fn execute_circuit_with_black_box_solver(
foreign_call_handler: ForeignCallHandler,
) -> Result<JsWitnessMap, Error> {
console_error_panic_hook::set_once();
let circuit: Circuit =
Circuit::deserialize_circuit(&circuit).expect("Failed to deserialize circuit");
let circuit: Circuit = Circuit::deserialize_circuit(&circuit)
.map_err(|_| JsExecutionError::new("Failed to deserialize circuit. This is likely due to differing serialization formats between ACVM_JS and your compiler".to_string(), None))?;

let mut acvm = ACVM::new(&solver.0, &circuit.opcodes, initial_witness.into());

Expand Down
4 changes: 2 additions & 2 deletions noir/acvm-repo/acvm_js/test/shared/pedersen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// See `pedersen_circuit` integration test in `acir/tests/test_program_serialization.rs`.
export const bytecode = Uint8Array.from([
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 138, 9, 10, 0, 64, 8, 2, 103, 15, 250, 255, 139, 163, 162, 130, 72, 16, 149,
241, 3, 135, 84, 164, 172, 173, 213, 175, 251, 45, 198, 96, 243, 211, 50, 152, 67, 220, 211, 92, 0, 0, 0,
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 138, 9, 10, 0, 64, 8, 2, 103, 15, 232, 255, 31, 142, 138, 10, 34, 65, 84, 198,
15, 28, 82, 145, 178, 182, 86, 191, 238, 183, 24, 131, 205, 79, 203, 0, 166, 242, 158, 93, 92, 0, 0, 0,
]);

export const initialWitnessMap = new Map([[1, '0x0000000000000000000000000000000000000000000000000000000000000001']]);
Expand Down
4 changes: 2 additions & 2 deletions noir/acvm-repo/acvm_js/test/shared/schnorr_verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export const bytecode = Uint8Array.from([
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 210, 87, 78, 2, 1, 20, 134, 209, 177, 247, 222, 123, 71, 68, 68, 68, 68, 68,
68, 68, 68, 68, 221, 133, 251, 95, 130, 145, 27, 206, 36, 78, 50, 57, 16, 94, 200, 253, 191, 159, 36, 73, 134, 146,
193, 19, 142, 241, 183, 255, 14, 179, 233, 247, 145, 254, 59, 217, 127, 71, 57, 198, 113, 78, 48, 125, 167, 56, 205,
193, 19, 142, 243, 183, 255, 14, 179, 233, 247, 145, 254, 59, 217, 127, 71, 57, 198, 113, 78, 48, 125, 167, 56, 205,
25, 206, 114, 142, 243, 92, 224, 34, 151, 184, 204, 21, 174, 114, 141, 235, 220, 224, 38, 183, 184, 205, 29, 238, 114,
143, 251, 60, 224, 33, 143, 120, 204, 19, 158, 242, 140, 25, 158, 51, 203, 11, 230, 120, 201, 60, 175, 88, 224, 53,
139, 188, 97, 137, 183, 44, 243, 142, 21, 222, 179, 202, 7, 214, 248, 200, 58, 159, 216, 224, 51, 155, 124, 97, 235,
Expand All @@ -11,7 +11,7 @@ export const bytecode = Uint8Array.from([
162, 149, 232, 36, 26, 137, 62, 162, 141, 232, 34, 154, 136, 30, 162, 133, 232, 32, 26, 136, 253, 99, 251, 195, 100,
176, 121, 236, 29, 91, 159, 218, 56, 99, 219, 172, 77, 115, 182, 204, 219, 176, 96, 187, 162, 205, 74, 182, 42, 219,
168, 98, 155, 170, 77, 106, 182, 168, 219, 160, 225, 246, 77, 55, 111, 185, 113, 219, 109, 59, 110, 218, 117, 203,
158, 27, 166, 55, 75, 239, 150, 184, 101, 250, 252, 1, 19, 89, 159, 101, 220, 3, 0, 0,
158, 27, 166, 55, 75, 239, 150, 184, 101, 250, 252, 1, 55, 204, 92, 74, 220, 3, 0, 0,
]);

export const initialWitnessMap = new Map([
Expand Down
24 changes: 18 additions & 6 deletions noir/acvm-repo/brillig_vm/src/black_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ pub(crate) fn evaluate_black_box<Solver: BlackBoxFunctionSolver>(
signature,
result: result_register,
} => {
let bb_func = match op {
BlackBoxOp::EcdsaSecp256k1 { .. } => BlackBoxFunc::EcdsaSecp256k1,
BlackBoxOp::EcdsaSecp256r1 { .. } => BlackBoxFunc::EcdsaSecp256r1,
_ => unreachable!(),
};
let bb_func = black_box_function_from_op(op);

let public_key_x: [u8; 32] = to_u8_vec(read_heap_array(
memory,
Expand Down Expand Up @@ -117,7 +113,7 @@ pub(crate) fn evaluate_black_box<Solver: BlackBoxFunctionSolver>(
BlackBoxOp::EcdsaSecp256r1 { .. } => {
ecdsa_secp256r1_verify(&hashed_msg, &public_key_x, &public_key_y, &signature)?
}
_ => unreachable!(),
_ => unreachable!("`BlackBoxOp` is guarded against being a non-ecdsa operation"),
};

registers.set(*result_register, result.into());
Expand Down Expand Up @@ -187,6 +183,22 @@ pub(crate) fn evaluate_black_box<Solver: BlackBoxFunctionSolver>(
}
}

fn black_box_function_from_op(op: &BlackBoxOp) -> BlackBoxFunc {
match op {
BlackBoxOp::Sha256 { .. } => BlackBoxFunc::SHA256,
BlackBoxOp::Blake2s { .. } => BlackBoxFunc::Blake2s,
BlackBoxOp::Keccak256 { .. } => BlackBoxFunc::Keccak256,
BlackBoxOp::EcdsaSecp256k1 { .. } => BlackBoxFunc::EcdsaSecp256k1,
BlackBoxOp::EcdsaSecp256r1 { .. } => BlackBoxFunc::EcdsaSecp256r1,
BlackBoxOp::SchnorrVerify { .. } => BlackBoxFunc::SchnorrVerify,
BlackBoxOp::PedersenCommitment { .. } => BlackBoxFunc::PedersenCommitment,
BlackBoxOp::PedersenHash { .. } => BlackBoxFunc::PedersenHash,
BlackBoxOp::FixedBaseScalarMul { .. } => BlackBoxFunc::FixedBaseScalarMul,
BlackBoxOp::EmbeddedCurveAdd { .. } => BlackBoxFunc::EmbeddedCurveAdd,
BlackBoxOp::EmbeddedCurveDouble { .. } => BlackBoxFunc::EmbeddedCurveDouble,
}
}

#[cfg(test)]
mod test {
use acir::brillig::BlackBoxOp;
Expand Down
20 changes: 9 additions & 11 deletions noir/compiler/integration-tests/circuits/recursion/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use dep::std;

fn main(
verification_key : [Field; 114],
proof : [Field; 94],
public_inputs : [Field; 1],
key_hash : Field,
) -> pub [Field;16]{
let input_aggregation_object = [0; 16];
verification_key: [Field; 114],
proof: [Field; 93],
public_inputs: [Field; 1],
key_hash: Field
) {
std::verify_proof(
verification_key.as_slice(),
proof.as_slice(),
public_inputs.as_slice(),
key_hash,
input_aggregation_object
verification_key.as_slice(),
proof.as_slice(),
public_inputs.as_slice(),
key_hash
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ describe('It compiles noir program code, receiving circuit bytes and abi object.
proof: proofAsFields,
public_inputs: [main_inputs.y as Field],
key_hash: vkHash,
input_aggregation_object: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
};

logger.debug('recursion_inputs', recursion_inputs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
PathToFileSourceMap,
} from '@noir-lang/noir_wasm';
import { Noir } from '@noir-lang/noir_js';
import { BarretenbergBackend, flattenPublicInputs } from '@noir-lang/backend_barretenberg';
import { BarretenbergBackend } from '@noir-lang/backend_barretenberg';
import { Field, InputMap } from '@noir-lang/noirc_abi';

compilerLogLevel('INFO');
Expand Down Expand Up @@ -71,10 +71,7 @@ it(`smart contract can verify a recursive proof`, async () => {

const contract = await ethers.deployContract('contracts/recursion.sol:UltraVerifier', []);

const result = await contract.verify.staticCall(
recursion_proof.proof,
flattenPublicInputs(recursion_proof.publicInputs),
);
const result = await contract.verify.staticCall(recursion_proof.proof, recursion_proof.publicInputs);

expect(result).to.be.true;
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import toml from 'toml';

import { PathToFileSourceMap, compile, init_log_level as compilerLogLevel } from '@noir-lang/noir_wasm';
import { Noir } from '@noir-lang/noir_js';
import { BarretenbergBackend, flattenPublicInputs } from '@noir-lang/backend_barretenberg';
import { BarretenbergBackend } from '@noir-lang/backend_barretenberg';

compilerLogLevel('INFO');

Expand Down Expand Up @@ -61,7 +61,7 @@ test_cases.forEach((testInfo) => {

const contract = await ethers.deployContract(testInfo.compiled, []);

const result = await contract.verify(proofData.proof, flattenPublicInputs(proofData.publicInputs));
const result = await contract.verify(proofData.proof, proofData.publicInputs);

expect(result).to.be.true;
});
Expand Down
2 changes: 1 addition & 1 deletion noir/compiler/noirc_driver/src/abi_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(super) fn compute_function_abi(
) -> (Vec<AbiParameter>, Option<AbiType>) {
let func_meta = context.def_interner.function_meta(func_id);

let (parameters, return_type) = func_meta.into_function_signature();
let (parameters, return_type) = func_meta.function_signature();
let parameters = into_abi_params(context, parameters);
let return_type = return_type.map(|typ| AbiType::from_type(context, &typ));
(parameters, return_type)
Expand Down
Loading

0 comments on commit ab07e7e

Please sign in to comment.