Skip to content

Commit

Permalink
feat: Sync from aztec-packages (#7241)
Browse files Browse the repository at this point in the history
Co-authored-by: TomAFrench <[email protected]>
Co-authored-by: Tom French <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2025
1 parent 15bbaa8 commit a2a0478
Show file tree
Hide file tree
Showing 43 changed files with 385 additions and 159 deletions.
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
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
48 changes: 43 additions & 5 deletions .github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
yarn-lock:
runs-on: ubuntu-22.04
timeout-minutes: 30

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


- name: Install `bb`
run: |
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -695,6 +732,7 @@ jobs:
- test-integration-node
- test-integration-browser
- test-examples
- compile-noir-contracts

steps:
- name: Report overall success
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand All @@ -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;
}
Expand Down
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
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions acvm-repo/brillig/src/black_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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,
Expand All @@ -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(())
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions compiler/integration-tests/web-test-runner.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/noirc_evaluator/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
16 changes: 10 additions & 6 deletions compiler/noirc_evaluator/src/ssa/ir/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
Loading

2 comments on commit a2a0478

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: a2a0478 Previous: 15bbaa8 Ratio
noir-lang_noir_check_shuffle_ 1 s 0 s +∞

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: a2a0478 Previous: 15bbaa8 Ratio
noir-lang_noir_check_shuffle_ 1 s 0 s +∞

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

Please sign in to comment.