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 commits from aztec-packages #4216

Merged
merged 113 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 100 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
6743afc
feat: Aztec CI files in Noir (#3430)
ludamad Nov 27, 2023
5b5046b
Merge branch 'master' into aztec
kevaundray Nov 28, 2023
7f1b857
Merge remote-tracking branch 'origin/master' into aztec
sirasistant Nov 29, 2023
454b140
feat: Pull latest noir for brillig optimizations (#3464)
sirasistant Nov 29, 2023
fc00722
Merge branch 'master' into aztec
kevaundray Dec 10, 2023
0ad7ba5
Merge branch 'master' into aztec
sirasistant Dec 15, 2023
2d265b4
Merge branch 'master' into aztec-packages
sirasistant Dec 18, 2023
d788414
Merge branch 'master' into aztec-packages
sirasistant Dec 19, 2023
f06ab9c
feat: update to latest noir and update noir compiler (#3696)
Thunkar Dec 19, 2023
29ff6ce
chore: revert unwanted changes
TomAFrench Dec 19, 2023
d144743
chore: Cleanup recursion interface (#3744)
vezenovm Dec 19, 2023
20f1652
feat!: updated note hash and nullifier macro (#3777)
benesjan Jan 2, 2024
ce02b01
fix: event macro (#3784)
benesjan Jan 2, 2024
50925ea
feat!: moving `compute_selector` to `FunctionSelector` (#3806)
benesjan Jan 3, 2024
338cb57
chore: Just nargo compile. (#3775)
charlielye Jan 3, 2024
717f1fa
Merge branch 'master' into aztec-packages
sirasistant Jan 4, 2024
1005f32
chore: delete extraneous gzips
sirasistant Jan 4, 2024
50cb28c
chore: fix clippy and fmt
sirasistant Jan 4, 2024
a6289a5
chore: noir sync (#3884)
ludamad Jan 8, 2024
c0826b5
chore!: Remove aggregation objects from RecursionConstraint (#3885)
vezenovm Jan 8, 2024
3521d28
feat: update BB version
sirasistant Jan 9, 2024
a3366d6
test: fix serialization and bb tests
sirasistant Jan 9, 2024
16a4f50
Merge branch 'master' into aztec-packages
sirasistant Jan 9, 2024
c6bc062
fix: remove extraneous usage of hash to field
sirasistant Jan 9, 2024
e9405f0
style: fmt
sirasistant Jan 9, 2024
4178e74
chore: update serialized bytecodes
sirasistant Jan 9, 2024
ad7e3b1
chore: update bbjs
sirasistant Jan 9, 2024
404ffbf
fix: intermediate proof artifacts returns proof without public inputs
sirasistant Jan 9, 2024
0886b1b
Try to fix recursion test and remove unused codegen
sirasistant Jan 9, 2024
812576b
Remove test-cargo workflow
sirasistant Jan 9, 2024
3c8f83e
chore: remove now unused bb abstraction leaks
sirasistant Jan 9, 2024
89bf498
chore: fix builds of `noir_js_backend_barretenberg`
TomAFrench Jan 9, 2024
9affee6
Revert "chore: remove now unused bb abstraction leaks"
TomAFrench Jan 9, 2024
1725e70
chore: clippy fix
TomAFrench Jan 9, 2024
394154e
Revert "chore: fix builds of `noir_js_backend_barretenberg`"
TomAFrench Jan 9, 2024
39d4bfa
fix: avoid decoding public inputs
sirasistant Jan 9, 2024
04f2bf4
Merge branch 'aztec-packages' of github.com:noir-lang/noir into aztec…
sirasistant Jan 9, 2024
5b64df3
Revert "fix: avoid decoding public inputs"
sirasistant Jan 9, 2024
9ec2e07
fix: possible workaround for the hidden public inputs issue
sirasistant Jan 9, 2024
ee2e6c0
test: fix test
sirasistant Jan 9, 2024
742e940
test: fix noir_js_backend_bb test
sirasistant Jan 9, 2024
61c2b9b
fix: output public inputs vector + function to recover a witness map
sirasistant Jan 9, 2024
114aa6f
chore: fix formatting
sirasistant Jan 9, 2024
ee802c9
Merge branch 'master' into aztec-packages
TomAFrench Jan 9, 2024
3f6a24d
Merge branch 'master' into aztec-packages
TomAFrench Jan 11, 2024
f4bbe21
Merge branch 'master' into aztec-packages
TomAFrench Jan 11, 2024
75c8334
Merge branch 'master' into aztec-packages
TomAFrench Jan 11, 2024
3416229
Merge branch 'master' into aztec-packages
TomAFrench Jan 11, 2024
5646354
chore: git subrepo commit (merge) noir (#3955)
ludamad Jan 11, 2024
7c357e4
feat!: implement keccakf1600 in brillig (#3914)
TomAFrench Jan 11, 2024
b5a1eb5
chore!: define key type in maps (#3841)
Thunkar Jan 12, 2024
5162b33
chore: fix rust tests (#3963)
TomAFrench Jan 12, 2024
55aa96f
chore: fix formatter tests
TomAFrench Jan 12, 2024
d7c4c66
Merge branch 'master' into aztec-packages
sirasistant Jan 12, 2024
563c704
feat: Update noir (#3979)
sirasistant Jan 12, 2024
787ccdc
Merge branch 'master' into aztec-packages
TomAFrench Jan 13, 2024
e7da1ab
Merge branch 'master' into aztec-packages
TomAFrench Jan 15, 2024
7f22446
Merge branch 'master' into aztec-packages
TomAFrench Jan 15, 2024
0f38b22
Merge branch 'master' into aztec-packages
TomAFrench Jan 15, 2024
2d92108
chore: sync noir (#4025)
TomAFrench Jan 15, 2024
001b8e0
chore: replace `AztecU128` with `U128` (#3951)
TomAFrench Jan 15, 2024
5e51255
fix: dont spam logs with yarn install (#4027)
ludamad Jan 15, 2024
45165d1
fix: Start witness of ACIR generated by Noir start at zero not one (#…
vezenovm Jan 16, 2024
4980553
chore: bump `bb` version to 0.18.0
TomAFrench Jan 16, 2024
4300ce2
chore: cargo fmt
TomAFrench Jan 16, 2024
9995d2b
Merge branch 'master' into aztec-packages
TomAFrench Jan 16, 2024
a4b6635
chore: sync from noir repo (#4047)
TomAFrench Jan 16, 2024
0c185c2
Merge branch 'master' into aztec-packages
sirasistant Jan 17, 2024
e6d3e73
chore: bump version
TomAFrench Jan 17, 2024
3541dd0
chore: bump bb.js
TomAFrench Jan 17, 2024
0858aa4
feat!: Unify ABIs between nargo and yarn-project (#3989)
spalladino Jan 17, 2024
8ac47e5
git subrepo pull (merge) noir
spalladino Jan 17, 2024
5a1b2bb
fix: Nargo destination path in bootstrap cache (#4103)
spalladino Jan 17, 2024
13f93d5
chore: Fixes many broken urls (#4109)
jzaki Jan 17, 2024
88ecd78
Merge branch 'master' into aztec-packages
TomAFrench Jan 18, 2024
40c2dc3
chore: formatting fix
TomAFrench Jan 18, 2024
3558c72
Merge branch 'master' into aztec-packages
TomAFrench Jan 18, 2024
b26dba8
Merge branch 'master' into aztec-packages
TomAFrench Jan 18, 2024
727473c
Merge branch 'master' of github.com:noir-lang/noir into aztec-packages
Thunkar Jan 18, 2024
602f23f
Merge branch 'master' into aztec-packages
sirasistant Jan 22, 2024
7dba0a1
feat!: Add big int opcodes (without implementation) (#4050)
guipublic Jan 24, 2024
914403d
feat: implement bigint in Noir, using bigint opcodes (#4198)
guipublic Jan 25, 2024
9debf5c
feat: Implement Embedded EC add and double opcodes (#3982)
guipublic Jan 25, 2024
af203d6
feat!: remove ec_double opcode (#4210)
guipublic Jan 25, 2024
435d041
feat!: add opcode for poseidon2 permutation (#4214)
guipublic Jan 25, 2024
e470b94
refactor: delete C++ PK circuits (#4219)
ludamad Jan 25, 2024
2c463bc
feat!: add opcode for sha256 compression function (#4229)
guipublic Jan 26, 2024
52fc077
Merge branch 'master' into aztec-packages
Thunkar Jan 29, 2024
031c534
Merge branch 'master' of github.com:noir-lang/noir into aztec-packages
Thunkar Jan 29, 2024
ea6aebc
Merge branch 'aztec-packages' of github.com:noir-lang/noir into aztec…
Thunkar Jan 29, 2024
14d491b
Update noir_stdlib/src/scalar_mul.nr
TomAFrench Jan 29, 2024
7b50fd9
Update noir_stdlib/src/scalar_mul.nr
TomAFrench Jan 29, 2024
1f246fa
Merge branch 'master' into aztec-packages
TomAFrench Jan 30, 2024
68c05f6
chore: update bb with latest release
sirasistant Jan 30, 2024
6bc7107
chore: disable stdlib functions for unimplemented functionality
TomAFrench Jan 30, 2024
1e43b32
fix: underscore prefix unused vars
sirasistant Jan 30, 2024
aa163e0
Merge branch 'aztec-packages' of github.com:noir-lang/noir into aztec…
sirasistant Jan 30, 2024
5503531
feat: implement `Add` and `double` method on `EmbeddedCurvePoint`
TomAFrench Jan 30, 2024
2badd02
fix: use new add and double methods
sirasistant Jan 30, 2024
ddd94a2
chore: git subrepo commit (merge) noir (#4321)
sirasistant Jan 31, 2024
caf0b25
Update noir_stdlib/src/bigint.nr
TomAFrench Jan 31, 2024
b38ffdd
Merge branch 'master' into aztec-packages
TomAFrench Jan 31, 2024
9944bb1
Merge branch 'master' into aztec-packages
TomAFrench Jan 31, 2024
9a70040
chore(acir)!: Move `is_recursive` flag to be part of the circuit defi…
vezenovm Feb 1, 2024
f1b9151
chore: Sync to noir-lang/noir
AztecBot Feb 7, 2024
99bb998
git_subrepo.sh: Fix parent in .gitrepo file. [skip ci]
AztecBot Feb 8, 2024
658cbb7
chore: bump bb.js to 0.23.0
TomAFrench Feb 8, 2024
5a26142
Merge branch 'master' into aztec-packages
TomAFrench Feb 8, 2024
15a507b
chore: re-add deleted fixes
TomAFrench Feb 8, 2024
2a66948
chore: formatting fix
TomAFrench Feb 8, 2024
6e8836c
Merge branch 'master' into aztec-packages
TomAFrench Feb 8, 2024
be9fbd3
chore: fix barretenberg wrapper
TomAFrench Feb 8, 2024
f5850c8
chore: ignore failing tests
TomAFrench Feb 8, 2024
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
1,641 changes: 1,226 additions & 415 deletions acvm-repo/acir/codegen/acir.cpp

Large diffs are not rendered by default.

42 changes: 36 additions & 6 deletions acvm-repo/acir/src/circuit/black_box_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,22 @@ pub enum BlackBoxFunc {
RecursiveAggregation,
/// Addition over the embedded curve on which [`FieldElement`][acir_field::FieldElement] is defined.
EmbeddedCurveAdd,
/// Point doubling over the embedded curve on which [`FieldElement`][acir_field::FieldElement] is defined.
EmbeddedCurveDouble,
/// BigInt addition
BigIntAdd,
/// BigInt subtraction
BigIntNeg,
/// BigInt multiplication
BigIntMul,
/// BigInt division
BigIntDiv,
/// BigInt from le bytes
BigIntFromLeBytes,
/// BigInt to le bytes
BigIntToLeBytes,
/// Permutation function of Poseidon2
Poseidon2Permutation,
/// SHA256 compression function
Sha256Compression,
}

impl std::fmt::Display for BlackBoxFunc {
Expand All @@ -68,17 +82,25 @@ impl BlackBoxFunc {
BlackBoxFunc::PedersenHash => "pedersen_hash",
BlackBoxFunc::EcdsaSecp256k1 => "ecdsa_secp256k1",
BlackBoxFunc::FixedBaseScalarMul => "fixed_base_scalar_mul",
BlackBoxFunc::EmbeddedCurveAdd => "ec_add",
BlackBoxFunc::EmbeddedCurveDouble => "ec_double",
BlackBoxFunc::EmbeddedCurveAdd => "embedded_curve_add",
BlackBoxFunc::AND => "and",
BlackBoxFunc::XOR => "xor",
BlackBoxFunc::RANGE => "range",
BlackBoxFunc::Keccak256 => "keccak256",
BlackBoxFunc::Keccakf1600 => "keccakf1600",
BlackBoxFunc::RecursiveAggregation => "recursive_aggregation",
BlackBoxFunc::EcdsaSecp256r1 => "ecdsa_secp256r1",
BlackBoxFunc::BigIntAdd => "bigint_add",
BlackBoxFunc::BigIntNeg => "bigint_neg",
BlackBoxFunc::BigIntMul => "bigint_mul",
BlackBoxFunc::BigIntDiv => "bigint_div",
BlackBoxFunc::BigIntFromLeBytes => "bigint_from_le_bytes",
BlackBoxFunc::BigIntToLeBytes => "bigint_to_le_bytes",
BlackBoxFunc::Poseidon2Permutation => "poseidon2_permutation",
BlackBoxFunc::Sha256Compression => "sha256_compression",
}
}

pub fn lookup(op_name: &str) -> Option<BlackBoxFunc> {
match op_name {
"sha256" => Some(BlackBoxFunc::SHA256),
Expand All @@ -90,17 +112,25 @@ impl BlackBoxFunc {
"ecdsa_secp256k1" => Some(BlackBoxFunc::EcdsaSecp256k1),
"ecdsa_secp256r1" => Some(BlackBoxFunc::EcdsaSecp256r1),
"fixed_base_scalar_mul" => Some(BlackBoxFunc::FixedBaseScalarMul),
"ec_add" => Some(BlackBoxFunc::EmbeddedCurveAdd),
"ec_double" => Some(BlackBoxFunc::EmbeddedCurveDouble),
"embedded_curve_add" => Some(BlackBoxFunc::EmbeddedCurveAdd),
"and" => Some(BlackBoxFunc::AND),
"xor" => Some(BlackBoxFunc::XOR),
"range" => Some(BlackBoxFunc::RANGE),
"keccak256" => Some(BlackBoxFunc::Keccak256),
"keccakf1600" => Some(BlackBoxFunc::Keccakf1600),
"recursive_aggregation" => Some(BlackBoxFunc::RecursiveAggregation),
"bigint_add" => Some(BlackBoxFunc::BigIntAdd),
"bigint_neg" => Some(BlackBoxFunc::BigIntNeg),
"bigint_mul" => Some(BlackBoxFunc::BigIntMul),
"bigint_div" => Some(BlackBoxFunc::BigIntDiv),
"bigint_from_le_bytes" => Some(BlackBoxFunc::BigIntFromLeBytes),
"bigint_to_le_bytes" => Some(BlackBoxFunc::BigIntToLeBytes),
"poseidon2_permutation" => Some(BlackBoxFunc::Poseidon2Permutation),
"sha256_compression" => Some(BlackBoxFunc::Sha256Compression),
_ => None,
}
}

pub fn is_valid_black_box_func_name(op_name: &str) -> bool {
BlackBoxFunc::lookup(op_name).is_some()
}
Expand Down
100 changes: 85 additions & 15 deletions acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ pub enum BlackBoxFuncCall {
input2_y: FunctionInput,
outputs: (Witness, Witness),
},
EmbeddedCurveDouble {
input_x: FunctionInput,
input_y: FunctionInput,
outputs: (Witness, Witness),
},
Keccak256 {
inputs: Vec<FunctionInput>,
outputs: Vec<Witness>,
Expand Down Expand Up @@ -120,6 +115,61 @@ pub enum BlackBoxFuncCall {
/// key provided to the circuit matches the key produced by the circuit creator
key_hash: FunctionInput,
},
BigIntAdd {
lhs: u32,
rhs: u32,
output: u32,
},
BigIntNeg {
lhs: u32,
rhs: u32,
output: u32,
},
BigIntMul {
lhs: u32,
rhs: u32,
output: u32,
},
BigIntDiv {
lhs: u32,
rhs: u32,
output: u32,
},
BigIntFromLeBytes {
inputs: Vec<FunctionInput>,
modulus: Vec<u8>,
output: u32,
},
BigIntToLeBytes {
input: u32,
outputs: Vec<Witness>,
},
/// Applies the Poseidon2 permutation function to the given state,
/// outputting the permuted state.
Poseidon2Permutation {
/// Input state for the permutation of Poseidon2
inputs: Vec<FunctionInput>,
/// Permuted state
outputs: Vec<Witness>,
/// State length (in number of field elements)
/// It is the length of inputs and outputs vectors
len: u32,
},
/// Applies the SHA-256 compression function to the input message
///
/// # Arguments
///
/// * `inputs` - input message block
/// * `hash_values` - state from the previous compression
/// * `outputs` - result of the input compressed into 256 bits
Sha256Compression {
/// 512 bits of the input message, represented by 16 u32s
inputs: Vec<FunctionInput>,
/// Vector of 8 u32s used to compress the input
hash_values: Vec<FunctionInput>,
/// Output of the compression, represented by 8 u32s
outputs: Vec<Witness>,
},
}

impl BlackBoxFuncCall {
Expand All @@ -138,11 +188,18 @@ impl BlackBoxFuncCall {
BlackBoxFuncCall::EcdsaSecp256r1 { .. } => BlackBoxFunc::EcdsaSecp256r1,
BlackBoxFuncCall::FixedBaseScalarMul { .. } => BlackBoxFunc::FixedBaseScalarMul,
BlackBoxFuncCall::EmbeddedCurveAdd { .. } => BlackBoxFunc::EmbeddedCurveAdd,
BlackBoxFuncCall::EmbeddedCurveDouble { .. } => BlackBoxFunc::EmbeddedCurveDouble,
BlackBoxFuncCall::Keccak256 { .. } => BlackBoxFunc::Keccak256,
BlackBoxFuncCall::Keccak256VariableLength { .. } => BlackBoxFunc::Keccak256,
BlackBoxFuncCall::Keccakf1600 { .. } => BlackBoxFunc::Keccakf1600,
BlackBoxFuncCall::RecursiveAggregation { .. } => BlackBoxFunc::RecursiveAggregation,
BlackBoxFuncCall::BigIntAdd { .. } => BlackBoxFunc::BigIntAdd,
BlackBoxFuncCall::BigIntNeg { .. } => BlackBoxFunc::BigIntNeg,
BlackBoxFuncCall::BigIntMul { .. } => BlackBoxFunc::BigIntMul,
BlackBoxFuncCall::BigIntDiv { .. } => BlackBoxFunc::BigIntDiv,
BlackBoxFuncCall::BigIntFromLeBytes { .. } => BlackBoxFunc::BigIntFromLeBytes,
BlackBoxFuncCall::BigIntToLeBytes { .. } => BlackBoxFunc::BigIntToLeBytes,
BlackBoxFuncCall::Poseidon2Permutation { .. } => BlackBoxFunc::Poseidon2Permutation,
BlackBoxFuncCall::Sha256Compression { .. } => BlackBoxFunc::Sha256Compression,
}
}

Expand All @@ -158,17 +215,22 @@ impl BlackBoxFuncCall {
| BlackBoxFuncCall::Keccak256 { inputs, .. }
| BlackBoxFuncCall::Keccakf1600 { inputs, .. }
| BlackBoxFuncCall::PedersenCommitment { inputs, .. }
| BlackBoxFuncCall::PedersenHash { inputs, .. } => inputs.to_vec(),
| BlackBoxFuncCall::PedersenHash { inputs, .. }
| BlackBoxFuncCall::BigIntFromLeBytes { inputs, .. }
| BlackBoxFuncCall::Poseidon2Permutation { inputs, .. }
| BlackBoxFuncCall::Sha256Compression { inputs, .. } => inputs.to_vec(),
BlackBoxFuncCall::AND { lhs, rhs, .. } | BlackBoxFuncCall::XOR { lhs, rhs, .. } => {
vec![*lhs, *rhs]
}
BlackBoxFuncCall::BigIntAdd { .. }
| BlackBoxFuncCall::BigIntNeg { .. }
| BlackBoxFuncCall::BigIntMul { .. }
| BlackBoxFuncCall::BigIntDiv { .. }
| BlackBoxFuncCall::BigIntToLeBytes { .. } => Vec::new(),
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::RANGE { input } => vec![*input],
BlackBoxFuncCall::SchnorrVerify {
public_key_x,
Expand Down Expand Up @@ -249,7 +311,10 @@ impl BlackBoxFuncCall {
| BlackBoxFuncCall::Blake2s { outputs, .. }
| BlackBoxFuncCall::Blake3 { outputs, .. }
| BlackBoxFuncCall::Keccak256 { outputs, .. }
| BlackBoxFuncCall::Keccakf1600 { outputs, .. } => outputs.to_vec(),
| BlackBoxFuncCall::Keccakf1600 { outputs, .. }
| BlackBoxFuncCall::Keccak256VariableLength { outputs, .. }
| BlackBoxFuncCall::Poseidon2Permutation { outputs, .. }
| BlackBoxFuncCall::Sha256Compression { outputs, .. } => outputs.to_vec(),
BlackBoxFuncCall::AND { output, .. }
| BlackBoxFuncCall::XOR { output, .. }
| BlackBoxFuncCall::SchnorrVerify { output, .. }
Expand All @@ -258,12 +323,17 @@ impl BlackBoxFuncCall {
| BlackBoxFuncCall::EcdsaSecp256r1 { output, .. } => vec![*output],
BlackBoxFuncCall::FixedBaseScalarMul { outputs, .. }
| BlackBoxFuncCall::PedersenCommitment { outputs, .. }
| BlackBoxFuncCall::EmbeddedCurveAdd { outputs, .. }
| BlackBoxFuncCall::EmbeddedCurveDouble { outputs, .. } => vec![outputs.0, outputs.1],
BlackBoxFuncCall::RANGE { .. } | BlackBoxFuncCall::RecursiveAggregation { .. } => {
| BlackBoxFuncCall::EmbeddedCurveAdd { outputs, .. } => vec![outputs.0, outputs.1],
BlackBoxFuncCall::RANGE { .. }
| BlackBoxFuncCall::RecursiveAggregation { .. }
| BlackBoxFuncCall::BigIntFromLeBytes { .. }
| BlackBoxFuncCall::BigIntAdd { .. }
| BlackBoxFuncCall::BigIntNeg { .. }
| BlackBoxFuncCall::BigIntMul { .. }
| BlackBoxFuncCall::BigIntDiv { .. } => {
vec![]
}
BlackBoxFuncCall::Keccak256VariableLength { outputs, .. } => outputs.to_vec(),
BlackBoxFuncCall::BigIntToLeBytes { outputs, .. } => outputs.to_vec(),
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions acvm-repo/acir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ mod reflection {
path::{Path, PathBuf},
};

use brillig::{
BinaryFieldOp, BinaryIntOp, BlackBoxOp, Opcode as BrilligOpcode, RegisterOrMemory,
};
use brillig::{BinaryFieldOp, BinaryIntOp, BlackBoxOp, Opcode as BrilligOpcode, ValueOrArray};
use serde_reflection::{Tracer, TracerConfig};

use crate::{
Expand Down Expand Up @@ -69,7 +67,7 @@ mod reflection {
tracer.trace_simple_type::<BinaryIntOp>().unwrap();
tracer.trace_simple_type::<BlackBoxOp>().unwrap();
tracer.trace_simple_type::<Directive>().unwrap();
tracer.trace_simple_type::<RegisterOrMemory>().unwrap();
tracer.trace_simple_type::<ValueOrArray>().unwrap();

let registry = tracer.registry().unwrap();

Expand Down
83 changes: 54 additions & 29 deletions acvm-repo/acir/tests/test_program_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use acir::{
native_types::{Expression, Witness},
};
use acir_field::FieldElement;
use brillig::{HeapArray, RegisterIndex, RegisterOrMemory};
use brillig::{HeapArray, MemoryAddress, ValueOrArray};

#[test]
fn addition_circuit() {
Expand Down Expand Up @@ -173,15 +173,23 @@ fn simple_brillig_foreign_call() {
inputs: vec![
BrilligInputs::Single(w_input.into()), // Input Register 0,
],
// This tells the BrilligSolver which witnesses its output registers correspond to
// This tells the BrilligSolver which witnesses its output values correspond to
outputs: vec![
BrilligOutputs::Simple(w_inverted), // Output Register 1
],
bytecode: vec![brillig::Opcode::ForeignCall {
function: "invert".into(),
destinations: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(0))],
inputs: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(0))],
}],
bytecode: vec![
brillig::Opcode::CalldataCopy {
destination_address: MemoryAddress(0),
size: 1,
offset: 0,
},
brillig::Opcode::ForeignCall {
function: "invert".into(),
destinations: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(0))],
inputs: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(0))],
},
brillig::Opcode::Stop { return_data_offset: 0, return_data_size: 1 },
],
predicate: None,
};

Expand All @@ -196,10 +204,11 @@ fn simple_brillig_foreign_call() {
let bytes = Circuit::serialize_circuit(&circuit);

let expected_serialization: Vec<u8> = vec![
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 143, 49, 10, 64, 33, 12, 67, 99, 63, 124, 60, 142,
222, 192, 203, 56, 184, 56, 136, 120, 126, 5, 21, 226, 160, 139, 62, 40, 13, 45, 132, 68,
3, 80, 232, 124, 164, 153, 121, 115, 99, 155, 59, 172, 122, 231, 101, 56, 175, 80, 86, 221,
230, 31, 58, 196, 226, 83, 62, 53, 91, 16, 122, 10, 246, 84, 99, 243, 0, 30, 59, 1, 0, 0,
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 143, 177, 10, 192, 32, 12, 68, 207, 148, 150, 118,
234, 175, 216, 63, 232, 207, 116, 232, 210, 161, 136, 223, 175, 98, 132, 27, 212, 69, 31,
132, 28, 23, 8, 119, 59, 0, 131, 204, 66, 154, 41, 222, 173, 219, 142, 113, 153, 121, 191,
44, 231, 21, 237, 144, 88, 43, 249, 11, 71, 156, 77, 245, 251, 249, 231, 119, 189, 214,
204, 89, 187, 11, 25, 130, 54, 1, 36, 1, 124, 242, 107, 1, 0, 0,
];

assert_eq!(bytes, expected_serialization)
Expand All @@ -221,39 +230,54 @@ fn complex_brillig_foreign_call() {

let brillig_data = Brillig {
inputs: vec![
// Input Register 0
// Input 0,1,2
BrilligInputs::Array(vec![
Expression::from(a),
Expression::from(b),
Expression::from(c),
]),
// Input Register 1
// Input 3
BrilligInputs::Single(Expression {
mul_terms: vec![],
linear_combinations: vec![(fe_1, a), (fe_1, b), (fe_1, c)],
q_c: fe_0,
}),
],
// This tells the BrilligSolver which witnesses its output registers correspond to
// This tells the BrilligSolver which witnesses its output values correspond to
outputs: vec![
BrilligOutputs::Array(vec![a_times_2, b_times_3, c_times_4]), // Output Register 0
BrilligOutputs::Simple(a_plus_b_plus_c), // Output Register 1
BrilligOutputs::Simple(a_plus_b_plus_c_times_2), // Output Register 2
BrilligOutputs::Array(vec![a_times_2, b_times_3, c_times_4]), // Output 0,1,2
BrilligOutputs::Simple(a_plus_b_plus_c), // Output 3
BrilligOutputs::Simple(a_plus_b_plus_c_times_2), // Output 4
],
bytecode: vec![
brillig::Opcode::CalldataCopy {
destination_address: MemoryAddress(32),
size: 3,
offset: 0,
},
brillig::Opcode::Const {
destination: MemoryAddress(0),
value: brillig::Value::from(32_usize),
},
brillig::Opcode::CalldataCopy {
destination_address: MemoryAddress(1),
size: 1,
offset: 3,
},
// Oracles are named 'foreign calls' in brillig
brillig::Opcode::ForeignCall {
function: "complex".into(),
inputs: vec![
RegisterOrMemory::HeapArray(HeapArray { pointer: 0.into(), size: 3 }),
RegisterOrMemory::RegisterIndex(RegisterIndex::from(1)),
ValueOrArray::HeapArray(HeapArray { pointer: 0.into(), size: 3 }),
ValueOrArray::MemoryAddress(MemoryAddress::from(1)),
],
destinations: vec![
RegisterOrMemory::HeapArray(HeapArray { pointer: 0.into(), size: 3 }),
RegisterOrMemory::RegisterIndex(RegisterIndex::from(1)),
RegisterOrMemory::RegisterIndex(RegisterIndex::from(2)),
ValueOrArray::HeapArray(HeapArray { pointer: 0.into(), size: 3 }),
ValueOrArray::MemoryAddress(MemoryAddress::from(35)),
ValueOrArray::MemoryAddress(MemoryAddress::from(36)),
],
},
brillig::Opcode::Stop { return_data_offset: 32, return_data_size: 5 },
],
predicate: None,
};
Expand All @@ -269,13 +293,14 @@ fn complex_brillig_foreign_call() {
let bytes = Circuit::serialize_circuit(&circuit);

let expected_serialization: Vec<u8> = vec![
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 83, 219, 10, 128, 48, 8, 117, 174, 139, 159, 179,
254, 160, 127, 137, 222, 138, 122, 236, 243, 19, 114, 32, 22, 244, 144, 131, 118, 64, 156,
178, 29, 14, 59, 74, 0, 16, 224, 66, 228, 64, 57, 7, 169, 53, 242, 189, 81, 114, 250, 134,
33, 248, 113, 165, 82, 26, 177, 2, 141, 177, 128, 198, 60, 15, 63, 245, 219, 211, 23, 215,
255, 139, 15, 251, 211, 112, 180, 28, 157, 212, 189, 100, 82, 179, 64, 170, 63, 109, 235,
190, 204, 135, 166, 178, 150, 216, 62, 154, 252, 250, 70, 147, 35, 220, 119, 93, 227, 4,
182, 131, 81, 25, 36, 4, 0, 0,
31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 83, 65, 10, 132, 48, 12, 76, 218, 237, 174, 123,
242, 11, 130, 62, 160, 250, 2, 255, 34, 222, 20, 61, 250, 124, 11, 78, 49, 4, 193, 131, 21,
52, 16, 210, 132, 105, 50, 77, 210, 140, 136, 152, 54, 177, 65, 13, 206, 12, 95, 74, 196,
181, 176, 254, 154, 212, 156, 46, 151, 191, 139, 163, 121, 1, 71, 123, 3, 199, 184, 15, 15,
157, 119, 202, 185, 36, 237, 159, 61, 248, 63, 159, 160, 46, 232, 23, 254, 15, 54, 67, 156,
96, 11, 213, 119, 82, 248, 116, 179, 104, 188, 163, 125, 15, 89, 213, 253, 139, 154, 221,
52, 206, 67, 191, 88, 5, 213, 52, 75, 113, 174, 96, 205, 201, 157, 24, 207, 197, 211, 157,
6, 50, 18, 233, 158, 72, 89, 1, 53, 215, 75, 175, 196, 4, 0, 0,
];

assert_eq!(bytes, expected_serialization)
Expand Down
Loading
Loading