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(brillig): foreign call/oracle compilation #1600

Merged
merged 42 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6184f52
remove mac runner
kevaundray Jun 6, 2023
823bd84
chore: generate brillig opcode for simple identity unconstrained func…
guipublic Jun 6, 2023
545d333
feat(brillig): added arithmetic operations on brillig (#1565)
sirasistant Jun 6, 2023
f6810af
make ranges be polymorphic integers
kevaundray Jun 6, 2023
c5e34c5
chore(brillig): Clean up handling of Binary operations (#1571)
kevaundray Jun 6, 2023
06543b5
chore(ssa refactor): Rename Brillig example (#1563)
kevaundray Jun 6, 2023
3c9f106
chore(brillig): added tests for all field binary operations (#1586)
sirasistant Jun 7, 2023
9a9c461
chore(brillig): added tests for brillig integer operations (#1590)
sirasistant Jun 7, 2023
043c3c4
feat: process blocks and jumps when compiling brillig (#1591)
guipublic Jun 7, 2023
e51d3c6
feat: process blocks and jumps when compiling brillig (#1591)
guipublic Jun 7, 2023
1ed956b
feat(brillig): start of oracles/foreign calls
ludamad Jun 7, 2023
2a797a1
fix: broken tests
ludamad Jun 7, 2023
cd39144
feat(brillig): parsing oracles/foreign calls (#1596)
ludamad Jun 7, 2023
ba8ae00
feat: more foreign call work
ludamad Jun 8, 2023
cf393ff
Merge remote-tracking branch 'origin/master' into kw/brillig-main
kevaundray Jun 8, 2023
4644da9
self.data -> self.vars
kevaundray Jun 8, 2023
d50c69f
Merge remote-tracking branch 'origin/master' into kw/brillig-main
kevaundray Jun 8, 2023
398ddf9
chore(brillig): Add handling of the not instruction (#1609)
kevaundray Jun 8, 2023
c5b9579
Merge
ludamad Jun 8, 2023
aa2185c
Merge master
ludamad Jun 8, 2023
3847f0a
test: brillig oracle
ludamad Jun 8, 2023
828c116
Reinstate option
ludamad Jun 8, 2023
1d52f5e
make behavior consistent
kevaundray Jun 8, 2023
2d3ab61
remove closure
kevaundray Jun 8, 2023
801a739
change index_type
kevaundray Jun 8, 2023
2bcfc24
Update crates/noirc_frontend/src/hir/type_check/expr.rs
jfecher Jun 8, 2023
49a151d
Merge remote-tracking branch 'origin/master' into kw/brillig-main
kevaundray Jun 8, 2023
5247a48
Merge remote-tracking branch 'origin/kw/polymorphic-integers-on-for-l…
kevaundray Jun 8, 2023
5995b30
feat(brillig): loops (#1610)
sirasistant Jun 8, 2023
6d83b22
feat: Foreign calls compiling and basic print executed in nargo (#1612)
vezenovm Jun 8, 2023
1a9d33c
chore: resolve immutable array merge differences (#1617)
joss-aztec Jun 9, 2023
2787cc9
chore(ssa refactor): Add more documentation for truncation (#1607)
kevaundray Jun 9, 2023
8713a89
Merge remote-tracking branch 'origin/master' into kw/brillig-main
kevaundray Jun 9, 2023
70f8fe2
Update .github/workflows/test.yml
kevaundray Jun 9, 2023
91defbc
Update .github/workflows/test.yml
kevaundray Jun 9, 2023
4269ac2
resolve merge conflicts
vezenovm Jun 9, 2023
48405c6
remove dbg
vezenovm Jun 9, 2023
f49d69c
merge conflicts
vezenovm Jun 9, 2023
f309bac
change printer for foreign call
vezenovm Jun 9, 2023
efd84b8
Update crates/noirc_evaluator/src/ssa_refactor/ir/function.rs
kevaundray Jun 9, 2023
f5bbb70
Update crates/noirc_evaluator/src/ssa_refactor/ir/instruction.rs
vezenovm Jun 9, 2023
d6c7496
Update crates/noirc_evaluator/src/ssa_refactor/acir_gen/acir_ir/acir_…
kevaundray Jun 9, 2023
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 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ result
*.pk
*.vk
**/Verifier.toml
**/target
20 changes: 10 additions & 10 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ edition = "2021"
rust-version = "1.66"

[workspace.dependencies]
acvm = "=0.14.1"
acvm = "=0.14.2"
arena = { path = "crates/arena" }
fm = { path = "crates/fm" }
iter-extended = { path = "crates/iter-extended" }
Expand Down
39 changes: 36 additions & 3 deletions crates/nargo/src/ops/execute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use acvm::pwg::{solve, PartialWitnessGeneratorStatus};
use acvm::acir::brillig_vm::ForeignCallResult;
use acvm::acir::circuit::Opcode;
use acvm::pwg::{solve, PartialWitnessGeneratorStatus, UnresolvedBrilligCall};
use acvm::PartialWitnessGenerator;
use acvm::{acir::circuit::Circuit, acir::native_types::WitnessMap, pwg::block::Blocks};

Expand All @@ -11,8 +13,39 @@ pub fn execute_circuit(
) -> Result<WitnessMap, NargoError> {
let mut blocks = Blocks::default();
let solver_status = solve(backend, &mut initial_witness, &mut blocks, circuit.opcodes)?;
if matches!(solver_status, PartialWitnessGeneratorStatus::RequiresOracleData { .. }) {
todo!("Add oracle support to nargo execute")

// TODO(#1615): Nargo only supports "oracle_print_impl" functions that print a singular value and nothing else
// expand this in a general logging refactor
if let PartialWitnessGeneratorStatus::RequiresOracleData {
unresolved_brillig_calls,
required_oracle_data,
unsolved_opcodes,
} = solver_status
{
if !required_oracle_data.is_empty() {
unreachable!("oracles are not supported by nargo execute")
}
for unresolved_brillig_call in unresolved_brillig_calls {
let UnresolvedBrilligCall { foreign_call_wait_info, mut brillig } =
unresolved_brillig_call;
let value = foreign_call_wait_info.inputs[0];

// Execute foreign call "oracle_print_impl"
println!("{:?}", value.to_field().to_hex());

// TODO(#1615): "oracle_print_impl" is just an identity func
brillig.foreign_call_results.push(ForeignCallResult { values: vec![value] });

let mut next_opcodes_for_solving = vec![Opcode::Brillig(brillig)];
next_opcodes_for_solving.extend_from_slice(&unsolved_opcodes[..]);

let solver_status =
solve(backend, &mut initial_witness, &mut blocks, next_opcodes_for_solving)?;
if matches!(solver_status, PartialWitnessGeneratorStatus::RequiresOracleData { .. }) {
todo!("Add multiple foreign call support to nargo execute")
// TODO 1557
}
}
}

Ok(initial_witness)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = "1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Tests a very simple program.
//
// The features being tested is basic conditonal on brillig
fn main(x: Field) {
assert(4 == conditional(x as bool));
}

unconstrained fn conditional(x : bool) -> Field {
if x {
4
}else {
5
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Tests arithmetic operations on fields
fn main() {
let x = 4;
let y = 2;
assert((x + y) == add(x, y));
assert((x - y) == sub(x, y));
assert((x * y) == mul(x, y));
assert((x / y) == div(x, y));
}

unconstrained fn add(x : Field, y : Field) -> Field {
x + y
}

unconstrained fn sub(x : Field, y : Field) -> Field {
x - y
}

unconstrained fn mul(x : Field, y : Field) -> Field {
x * y
}

unconstrained fn div(x : Field, y : Field) -> Field {
x / y
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "3"

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Tests a very simple program.
//
// The features being tested is the identity function in Brillig
fn main(x : Field) {
assert(x == identity(x));
}

unconstrained fn identity(x : Field) -> Field {
x
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Tests arithmetic operations on integers
fn main() {
let x: u32 = 6;
let y: u32 = 2;

assert((x + y) == add(x, y));

assert((x - y) == sub(x, y));

assert((x * y) == mul(x, y));

assert((x / y) == div(x, y));

// TODO SSA => ACIR has some issues with i32 ops
assert(check_signed_div(6, 2, 3));

assert(eq(1, 2) == false);
assert(eq(1, 1));

assert(lt(x, y) == false);
assert(lt(y, x));

assert((x & y) == and(x, y));
assert((x | y) == or(x, y));

// TODO SSA => ACIR has some issues with xor ops

assert(check_xor(x, y, 4));
assert((x >> y) == shr(x, y));
assert((x << y) == shl(x, y));
}

unconstrained fn add(x : u32, y : u32) -> u32 {
x + y
}

unconstrained fn sub(x : u32, y : u32) -> u32 {
x - y
}

unconstrained fn mul(x : u32, y : u32) -> u32 {
x * y
}

unconstrained fn div(x : u32, y : u32) -> u32 {
x / y
}

unconstrained fn check_signed_div(x: i32, y: i32, result: i32) -> bool {
(x / y) == result
}

unconstrained fn eq(x : u32, y : u32) -> bool {
x == y
}

unconstrained fn lt(x : u32, y : u32) -> bool {
x < y
}

unconstrained fn and(x : u32, y : u32) -> u32 {
x & y
}

unconstrained fn or(x : u32, y : u32) -> u32 {
x | y
}

unconstrained fn check_xor(x : u32, y : u32, result: u32) -> bool {
(x ^ y) == result
}

unconstrained fn shr(x : u32, y : u32) -> u32 {
x >> y
}

unconstrained fn shl(x : u32, y : u32) -> u32 {
x << y
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sum = "6"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Tests a very simple program.
//
// The features being tested is basic looping on brillig
fn main(sum: u32){
assert(loop(4) == sum);
}

unconstrained fn loop(x: u32) -> u32 {
let mut sum = 0;
for i in 0..x {
sum = sum + i;
}
sum
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "1"
y = "0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Tests a very simple Brillig function.
//
// The features being tested is not instruction on brillig
fn main(x: Field, y : Field) {
assert(false == not_operator(x as bool));
assert(true == not_operator(y as bool));
}

unconstrained fn not_operator(x : bool) -> bool {
!x
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "10"

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Tests oracle usage in brillig/unconstrained functions
fn main(x: Field) {
// call through a brillig wrapper
oracle_print_wrapper(x);
}


#[oracle(oracle_print_impl)]
unconstrained fn oracle_print(_x : Field) {}

unconstrained fn oracle_print_wrapper(x: Field) {
oracle_print(x);
}


Loading