-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add support for nested arrays returned by oracles (#5132)
# Description ## Problem\* Resolves #4561 ## Summary\* Generates brillig arrays of arrays during brillig-gen for types having nested arrays. Populate these nested brillig arrays in the brillig VM when data returned from oracles does not match the size of the outer array ## Additional Context For this to work, it is required that the oracle returns flatten values, although its Noir signature is a nested type. It's certainly possible to deserialise nested json arrays but I could not get it done easily so it'll be better handled in a separate PR. ## Documentation\* Check one: - [ ] No documentation needed. - [X] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [X] I have tested the changes locally. - [X] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --------- Co-authored-by: Álvaro Rodríguez <sirasistant@gmail.com> Co-authored-by: TomAFrench <tom@tomfren.ch>
- Loading branch information
1 parent
939bad2
commit f846879
Showing
5 changed files
with
201 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "regression_4561" | ||
type = "bin" | ||
authors = [""] | ||
|
||
[dependencies] |
44 changes: 44 additions & 0 deletions
44
test_programs/noir_test_success/regression_4561/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Regression test for issue #4561 | ||
use dep::std::test::OracleMock; | ||
|
||
type TReturnElem = [Field; 3]; | ||
type TReturn = [TReturnElem; 2]; | ||
|
||
#[oracle(simple_nested_return)] | ||
unconstrained fn simple_nested_return_oracle() -> TReturn {} | ||
|
||
unconstrained fn simple_nested_return_unconstrained() -> TReturn { | ||
simple_nested_return_oracle() | ||
} | ||
|
||
#[test] | ||
fn test_simple_nested_return() { | ||
OracleMock::mock("simple_nested_return").returns([1, 2, 3, 4, 5, 6]); | ||
assert_eq(simple_nested_return_unconstrained(), [[1, 2, 3], [4, 5, 6]]); | ||
} | ||
|
||
#[oracle(nested_with_fields_return)] | ||
unconstrained fn nested_with_fields_return_oracle() -> (Field, TReturn, Field) {} | ||
|
||
unconstrained fn nested_with_fields_return_unconstrained() -> (Field, TReturn, Field) { | ||
nested_with_fields_return_oracle() | ||
} | ||
|
||
#[test] | ||
fn test_nested_with_fields_return() { | ||
OracleMock::mock("nested_with_fields_return").returns((0, [1, 2, 3, 4, 5, 6], 7)); | ||
assert_eq(nested_with_fields_return_unconstrained(), (0, [[1, 2, 3], [4, 5, 6]], 7)); | ||
} | ||
|
||
#[oracle(two_nested_return)] | ||
unconstrained fn two_nested_return_oracle() -> (Field, TReturn, Field, TReturn) {} | ||
|
||
unconstrained fn two_nested_return_unconstrained() -> (Field, TReturn, Field, TReturn) { | ||
two_nested_return_oracle() | ||
} | ||
|
||
#[test] | ||
fn two_nested_return() { | ||
OracleMock::mock("two_nested_return").returns((0, [1, 2, 3, 4, 5, 6], 7, [1, 2, 3, 4, 5, 6])); | ||
assert_eq(two_nested_return_unconstrained(), (0, [[1, 2, 3], [4, 5, 6]], 7, [[1, 2, 3], [4, 5, 6]])); | ||
} |