Skip to content

Commit

Permalink
chore: apply sync fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AztecBot committed Dec 18, 2024
1 parent b3bca76 commit ae2120f
Show file tree
Hide file tree
Showing 16 changed files with 282 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5e4b46d577ebf63114a5a5a1c5b6d2947d3b2567
51d82aaf62b84885eb388b1565c1a119c60d849e
46 changes: 46 additions & 0 deletions .github/workflows/reports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,49 @@ jobs:
with:
header: memory
message: ${{ steps.memory_report.outputs.markdown }}

generate_compilation_report:
name: Compilation time
needs: [build-nargo]
runs-on: ubuntu-22.04
permissions:
pull-requests: write

steps:
- uses: actions/checkout@v4

- 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: Generate Compilation report
working-directory: ./test_programs
run: |
./compilation_report.sh
mv compilation_report.json ../compilation_report.json
- name: Parse compilation report
id: compilation_report
uses: noir-lang/noir-bench-report@0d7464a8c39170523932d7846b6e6b458a294aea
with:
report: compilation_report.json
header: |
# Compilation Report
memory_report: false

- name: Add memory report to sticky comment
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: compilation
message: ${{ steps.compilation_report.outputs.markdown }}
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"rust-analyzer.server.extraEnv": { "RUSTUP_TOOLCHAIN": "stable" }
}
}
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
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,
},
}
16 changes: 11 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,27 @@ 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() {
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 +342,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ impl DependencyContext {
Value::Function(callee) => match all_functions[&callee].runtime() {
RuntimeType::Brillig(_) => {
// Record arguments/results for each Brillig call for the check

self.tainted.insert(
*instruction,
BrilligTaintedIds::new(&arguments, &results),
Expand Down
Loading

0 comments on commit ae2120f

Please sign in to comment.