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

feat: Sync from aztec-packages #7241

Merged
merged 21 commits into from
Jan 31, 2025
Merged
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
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5e4b46d577ebf63114a5a5a1c5b6d2947d3b2567
a7f8d9670902dfa4856b8514ce5eb4ad031a44fc
2 changes: 1 addition & 1 deletion .github/scripts/playwright-install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
set -eu

npx -y playwright@1.42 install --with-deps
npx -y playwright@1.50 install --with-deps
6 changes: 3 additions & 3 deletions .github/workflows/reports.yml
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ jobs:
./rebuild.sh
./gates_report.sh
mv gates_report.json ../gates_report.json

- name: Compare gates reports
id: gates_diff
uses: noir-lang/noir-gates-diff@dbe920a8dcc3370af4be4f702ca9cef29317bec1
@@ -150,7 +150,7 @@ jobs:
message: ${{ steps.brillig_bytecode_diff.outputs.markdown }}

compare_brillig_execution_reports:
name: Brillig execution trace sizes
name: Brillig execution trace sizes
needs: [build-nargo]
runs-on: ubuntu-22.04
permissions:
@@ -210,7 +210,7 @@ jobs:
message: ${{ steps.brillig_execution_diff.outputs.markdown }}

generate_memory_report:
name: Peak memory usage
name: Peak memory usage
needs: [build-nargo]
runs-on: ubuntu-22.04
permissions:
48 changes: 43 additions & 5 deletions .github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ jobs:
yarn-lock:
runs-on: ubuntu-22.04
timeout-minutes: 30

steps:
- name: Checkout
uses: actions/checkout@v4
@@ -492,7 +492,7 @@ jobs:
uses: foundry-rs/[email protected]
with:
version: nightly-8660e5b941fe7f4d67e246cfd3dafea330fb53b1


- name: Install `bb`
run: |
@@ -530,10 +530,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build list of libraries
id: get_critical_libraries
run: |
run: |
LIBRARIES=$(grep -Po "^https://github.com/\K.+" ./CRITICAL_NOIR_LIBRARIES | jq -R -s -c 'split("\n") | map(select(. != "")) | map({ repo: ., path: ""})')
echo "libraries=$LIBRARIES"
echo "libraries=$LIBRARIES" >> $GITHUB_OUTPUT
@@ -593,7 +593,7 @@ jobs:
# Github actions seems to not expand "**" in globs by default.
shopt -s globstar
sed -i '/^compiler_version/d' ./**/Nargo.toml

- name: Run nargo test
id: test_report
working-directory: ./test-repo/${{ matrix.project.path }}
@@ -631,6 +631,43 @@ jobs:
retention-days: 3
overwrite: true

compile-noir-contracts:
needs: [build-nargo]
runs-on: ubuntu-22.04
timeout-minutes: 30
name: Compile `noir-contracts` zero inliner aggressiveness
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: AztecProtocol/aztec-packages
path: test-repo

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

- 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: Remove requirements on compiler version
working-directory: ./test-repo
run: |
# Github actions seems to not expand "**" in globs by default.
shopt -s globstar
sed -i '/^compiler_version/d' ./**/Nargo.toml

- name: Run nargo compile
working-directory: ./test-repo/noir-projects/noir-contracts
run: nargo compile --inliner-aggressiveness 0

upload_critical_library_report:
name: Upload critical library report
needs: [external-repo-checks]
@@ -695,6 +732,7 @@ jobs:
- test-integration-node
- test-integration-browser
- test-examples
- compile-noir-contracts

steps:
- name: Report overall success
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -51,3 +51,5 @@ tooling/noir_js/lib

# docs autogen build
/docs/docs/noir_js/reference/

codegen
14 changes: 9 additions & 5 deletions acvm-repo/acir/codegen/acir.cpp
Original file line number Diff line number Diff line change
@@ -424,8 +424,9 @@ namespace Program {
struct ToRadix {
Program::MemoryAddress input;
Program::MemoryAddress radix;
Program::HeapArray output;
bool output_bits;
Program::MemoryAddress output_pointer;
Program::MemoryAddress num_limbs;
Program::MemoryAddress output_bits;

friend bool operator==(const ToRadix&, const ToRadix&);
std::vector<uint8_t> bincodeSerialize() const;
@@ -3898,7 +3899,8 @@ namespace Program {
inline bool operator==(const BlackBoxOp::ToRadix &lhs, const BlackBoxOp::ToRadix &rhs) {
if (!(lhs.input == rhs.input)) { return false; }
if (!(lhs.radix == rhs.radix)) { return false; }
if (!(lhs.output == rhs.output)) { return false; }
if (!(lhs.output_pointer == rhs.output_pointer)) { return false; }
if (!(lhs.num_limbs == rhs.num_limbs)) { return false; }
if (!(lhs.output_bits == rhs.output_bits)) { return false; }
return true;
}
@@ -3925,7 +3927,8 @@ template <typename Serializer>
void serde::Serializable<Program::BlackBoxOp::ToRadix>::serialize(const Program::BlackBoxOp::ToRadix &obj, Serializer &serializer) {
serde::Serializable<decltype(obj.input)>::serialize(obj.input, serializer);
serde::Serializable<decltype(obj.radix)>::serialize(obj.radix, serializer);
serde::Serializable<decltype(obj.output)>::serialize(obj.output, serializer);
serde::Serializable<decltype(obj.output_pointer)>::serialize(obj.output_pointer, serializer);
serde::Serializable<decltype(obj.num_limbs)>::serialize(obj.num_limbs, serializer);
serde::Serializable<decltype(obj.output_bits)>::serialize(obj.output_bits, serializer);
}

@@ -3935,7 +3938,8 @@ Program::BlackBoxOp::ToRadix serde::Deserializable<Program::BlackBoxOp::ToRadix>
Program::BlackBoxOp::ToRadix obj;
obj.input = serde::Deserializable<decltype(obj.input)>::deserialize(deserializer);
obj.radix = serde::Deserializable<decltype(obj.radix)>::deserialize(deserializer);
obj.output = serde::Deserializable<decltype(obj.output)>::deserialize(deserializer);
obj.output_pointer = serde::Deserializable<decltype(obj.output_pointer)>::deserialize(deserializer);
obj.num_limbs = serde::Deserializable<decltype(obj.num_limbs)>::deserialize(deserializer);
obj.output_bits = serde::Deserializable<decltype(obj.output_bits)>::deserialize(deserializer);
return obj;
}
2 changes: 1 addition & 1 deletion acvm-repo/acvm_js/test/node/build_info.test.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ it('returns the correct build info', () => {
let revision: string;

try {
revision = child_process.execSync('git rev-parse HEAD').toString().trim();
revision = process.env.GIT_COMMIT || child_process.execSync('git rev-parse HEAD').toString().trim();
} catch (error) {
console.log('Failed to get revision, skipping test.');
return;
5 changes: 3 additions & 2 deletions acvm-repo/brillig/src/black_box.rs
Original file line number Diff line number Diff line change
@@ -102,7 +102,8 @@ pub enum BlackBoxOp {
ToRadix {
input: MemoryAddress,
radix: MemoryAddress,
output: HeapArray,
output_bits: bool,
output_pointer: MemoryAddress,
num_limbs: MemoryAddress,
output_bits: MemoryAddress,
},
}
34 changes: 29 additions & 5 deletions acvm-repo/brillig_vm/src/black_box.rs
Original file line number Diff line number Diff line change
@@ -310,21 +310,45 @@ pub(crate) fn evaluate_black_box<F: AcirField, Solver: BlackBoxFunctionSolver<F>
memory.write_slice(memory.read_ref(output.pointer), &state);
Ok(())
}
BlackBoxOp::ToRadix { input, radix, output, output_bits } => {
BlackBoxOp::ToRadix { input, radix, output_pointer, num_limbs, output_bits } => {
let input: F = *memory.read(*input).extract_field().expect("ToRadix input not a field");
let radix = memory
.read(*radix)
.expect_integer_with_bit_size(IntegerBitSize::U32)
.expect("ToRadix opcode's radix bit size does not match expected bit size 32");
let num_limbs = memory.read(*num_limbs).to_usize();
let output_bits = !memory
.read(*output_bits)
.expect_integer_with_bit_size(IntegerBitSize::U1)
.expect("ToRadix opcode's output_bits size does not match expected bit size 1")
.is_zero();

let mut input = BigUint::from_bytes_be(&input.to_be_bytes());
let radix = BigUint::from_bytes_be(&radix.to_be_bytes());

let mut limbs: Vec<MemoryValue<F>> = vec![MemoryValue::default(); output.size];
let mut limbs: Vec<MemoryValue<F>> = vec![MemoryValue::default(); num_limbs];

for i in (0..output.size).rev() {
assert!(
radix >= BigUint::from(2u32) && radix <= BigUint::from(256u32),
"Radix out of the valid range [2,256]. Value: {}",
radix
);

assert!(
num_limbs >= 1 || input == BigUint::from(0u32),
"Input value {} is not zero but number of limbs is zero.",
input
);

assert!(
!output_bits || radix == BigUint::from(2u32),
"Radix {} is not equal to 2 and bit mode is activated.",
radix
);

for i in (0..num_limbs).rev() {
let limb = &input % &radix;
if *output_bits {
if output_bits {
limbs[i] = MemoryValue::new_integer(
if limb.is_zero() { 0 } else { 1 },
IntegerBitSize::U1,
@@ -336,7 +360,7 @@ pub(crate) fn evaluate_black_box<F: AcirField, Solver: BlackBoxFunctionSolver<F>
input /= &radix;
}

memory.write_slice(memory.read_ref(output.pointer), &limbs);
memory.write_slice(memory.read_ref(*output_pointer), &limbs);

Ok(())
}
2 changes: 1 addition & 1 deletion compiler/integration-tests/package.json
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0"
},
"dependencies": {
"@aztec/bb.js": "0.66.0",
"@aztec/bb.js": "0.72.1",
"@noir-lang/noir_js": "workspace:*",
"@noir-lang/noir_wasm": "workspace:*",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
7 changes: 7 additions & 0 deletions compiler/integration-tests/web-test-runner.config.mjs
Original file line number Diff line number Diff line change
@@ -26,6 +26,13 @@ export default {
// playwrightLauncher({ product: "webkit" }),
// playwrightLauncher({ product: "firefox" }),
],
middleware: [async function setGzHeader(ctx, next) {
if (ctx.url.endsWith('.gz')) {
ctx.set('Content-Encoding', 'gzip');
ctx.res.removeHeader('Content-Length');
}
await next();
}],
plugins: [
esbuildPlugin({
ts: true,
Original file line number Diff line number Diff line change
@@ -75,23 +75,27 @@ impl<F: AcirField + DebugToString, Registers: RegisterAllocator> BrilligContext<
assert!(source_field.bit_size == F::max_num_bits());
assert!(radix.bit_size == 32);

let bits_register = self.make_constant_instruction(output_bits.into(), 1);
self.codegen_initialize_array(target_array);

let heap_array = self.codegen_brillig_array_to_heap_array(target_array);
let pointer = self.codegen_make_array_items_pointer(target_array);
let num_limbs = self.make_usize_constant_instruction(target_array.size.into());

// Perform big-endian ToRadix
self.black_box_op_instruction(BlackBoxOp::ToRadix {
input: source_field.address,
radix: radix.address,
output: heap_array,
output_bits,
output_pointer: pointer,
num_limbs: num_limbs.address,
output_bits: bits_register.address,
});

if little_endian {
let items_len = self.make_usize_constant_instruction(target_array.size.into());
self.codegen_array_reverse(heap_array.pointer, items_len.address);
self.codegen_array_reverse(pointer, items_len.address);
self.deallocate_single_addr(items_len);
}
self.deallocate_register(heap_array.pointer);
self.deallocate_register(pointer);
self.deallocate_single_addr(bits_register);
self.deallocate_single_addr(num_limbs);
}
}
7 changes: 4 additions & 3 deletions compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs
Original file line number Diff line number Diff line change
@@ -397,13 +397,14 @@ impl DebugShow {
output
);
}
BlackBoxOp::ToRadix { input, radix, output, output_bits: _ } => {
BlackBoxOp::ToRadix { input, radix, output_pointer, num_limbs, output_bits: _ } => {
debug_println!(
self.enable_debug_trace,
" TO_RADIX {} {} -> {}",
" TO_RADIX {} {} {} -> {}",
input,
radix,
output
num_limbs,
output_pointer
);
}
}
4 changes: 3 additions & 1 deletion compiler/noirc_evaluator/src/ssa.rs
Original file line number Diff line number Diff line change
@@ -154,7 +154,9 @@ fn optimize_all(builder: SsaBuilder, options: &SsaEvaluatorOptions) -> Result<Ss
.run_pass(Ssa::remove_unreachable_functions, "Removing Unreachable Functions (1st)")
.run_pass(Ssa::defunctionalize, "Defunctionalization")
.run_pass(Ssa::inline_simple_functions, "Inlining simple functions")
.run_pass(Ssa::mem2reg, "Mem2Reg (1st)")
// BUG: Enabling this mem2reg causes an integration test failure in aztec-package; see:
// https://github.com/AztecProtocol/aztec-packages/pull/11294#issuecomment-2622809518
//.run_pass(Ssa::mem2reg, "Mem2Reg (1st)")
.run_pass(Ssa::remove_paired_rc, "Removing Paired rc_inc & rc_decs")
.run_pass(
|ssa| ssa.preprocess_functions(options.inliner_aggressiveness),
16 changes: 10 additions & 6 deletions compiler/noirc_evaluator/src/ssa/ir/dfg.rs
Original file line number Diff line number Diff line change
@@ -261,17 +261,18 @@ impl DataFlowGraph {

pub(crate) fn insert_instruction_and_results_without_simplification(
&mut self,
instruction_data: Instruction,
instruction: Instruction,
block: BasicBlockId,
ctrl_typevars: Option<Vec<Type>>,
call_stack: CallStackId,
) -> InsertInstructionResult {
if !self.is_handled_by_runtime(&instruction_data) {
panic!("Attempted to insert instruction not handled by runtime: {instruction_data:?}");
if !self.is_handled_by_runtime(&instruction) {
// Panicking to raise attention. If we're not supposed to simplify it immediately,
// pushing the instruction would just cause a potential panic later on.
panic!("Attempted to insert instruction not handled by runtime: {instruction:?}");
}

let id = self.insert_instruction_without_simplification(
instruction_data,
instruction,
block,
ctrl_typevars,
call_stack,
@@ -308,7 +309,10 @@ impl DataFlowGraph {
existing_id: Option<InstructionId>,
) -> InsertInstructionResult {
if !self.is_handled_by_runtime(&instruction) {
panic!("Attempted to insert instruction not handled by runtime: {instruction:?}");
// BUG: With panicking it fails to build the `token_contract`; see:
// https://github.com/AztecProtocol/aztec-packages/pull/11294#issuecomment-2624379102
// panic!("Attempted to insert instruction not handled by runtime: {instruction:?}");
return InsertInstructionResult::InstructionRemoved;
}

match instruction.simplify(self, block, ctrl_typevars.clone(), call_stack) {
Loading

Unchanged files with check annotations Beta

#[derive(Clone, Debug, Hash, Copy, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
pub enum BlackBoxFunc {
/// Ciphers (encrypts) the provided plaintext using AES128 in CBC mode,
/// padding the input using PKCS#7.

Check warning on line 13 in acvm-repo/acir/src/circuit/black_box_functions.rs

GitHub Actions / Code

Unknown word (PKCS)
/// - inputs: byte array `[u8; N]`
/// - iv: initialization vector `[u8; 16]`
/// - key: user key `[u8; 16]`
match databus {
BlockType::Memory => write!(f, "INIT ")?,
BlockType::CallData(id) => write!(f, "INIT CALLDATA {} ", id)?,
BlockType::ReturnData => write!(f, "INIT RETURNDATA ")?,

Check warning on line 169 in acvm-repo/acir/src/circuit/opcodes.rs

GitHub Actions / Code

Unknown word (RETURNDATA)
}
write!(f, "(id: {}, len: {}) ", block_id.0, init.len())
}
use acir_field::{AcirField, FieldElement};
#[test]
fn add_mul_smoketest() {

Check warning on line 360 in acvm-repo/acir/src/native_types/expression/mod.rs

GitHub Actions / Code

Unknown word (smoketest)
let a = Expression {
mul_terms: vec![(FieldElement::from(2u128), Witness(1), Witness(2))],
..Default::default()
use hash::{solve_generic_256_hash_opcode, solve_sha_256_permutation_opcode};
use logic::{and, xor};
pub(crate) use range::solve_range_opcode;
use signature::ecdsa::{secp256k1_prehashed, secp256r1_prehashed};

Check warning on line 30 in acvm-repo/acvm/src/pwg/blackbox/mod.rs

GitHub Actions / Code

Unknown word (prehashed)

Check warning on line 30 in acvm-repo/acvm/src/pwg/blackbox/mod.rs

GitHub Actions / Code

Unknown word (prehashed)
/// Check if all of the inputs to the function have assignments
///
signature,
hashed_message: message,
output,
} => secp256k1_prehashed(

Check warning on line 115 in acvm-repo/acvm/src/pwg/blackbox/mod.rs

GitHub Actions / Code

Unknown word (prehashed)
initial_witness,
public_key_x,
public_key_y,
signature,
hashed_message: message,
output,
} => secp256r1_prehashed(

Check warning on line 129 in acvm-repo/acvm/src/pwg/blackbox/mod.rs

GitHub Actions / Code

Unknown word (prehashed)
initial_witness,
public_key_x,
public_key_y,
RequiresForeignCall(ForeignCallWaitInfo<F>),
/// The ACVM has encountered a request for an ACIR [call][acir::circuit::Opcode]
/// to execute a separate ACVM instance. The result of the ACIR call must be passd back to the ACVM.

Check warning on line 58 in acvm-repo/acvm/src/pwg/mod.rs

GitHub Actions / Code

Unknown word (passd)
///
/// Once this is done, the ACVM can be restarted to solve the remaining opcodes.
RequiresAcirCall(AcirCallWaitInfo<F>),
pedantic_solving,
op.clone(),
)
.expect("injectivity test operations to have valid input")

Check warning on line 1394 in acvm-repo/acvm/tests/solver.rs

GitHub Actions / Code

Unknown word (injectivity)
!= solve_array_input_blackbox_call(
distinct_inputs,
num_outputs,
pedantic_solving,
op,
)
.expect("injectivity test operations to have valid input");

Check warning on line 1402 in acvm-repo/acvm/tests/solver.rs

GitHub Actions / Code

Unknown word (injectivity)
(equal_inputs || outputs_not_equal, message)
}