-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make toBits accept arrays and add test
- Loading branch information
1 parent
9e11de9
commit 89068f5
Showing
4 changed files
with
79 additions
and
9 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
6 changes: 6 additions & 0 deletions
6
tooling/nargo_cli/tests/execution_success/brillig_cow/Nargo.toml
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 = "brillig_cow" | ||
type = "bin" | ||
authors = [""] | ||
|
||
[dependencies] |
7 changes: 7 additions & 0 deletions
7
tooling/nargo_cli/tests/execution_success/brillig_cow/Prover.toml
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,7 @@ | ||
original = [0, 1, 2, 3, 4] | ||
index = 2 | ||
|
||
[expected_result] | ||
original = [0, 1, 2, 3, 4] | ||
modified_once = [0, 1, 27, 3, 4] | ||
modified_twice = [0, 1, 27, 27, 4] |
54 changes: 54 additions & 0 deletions
54
tooling/nargo_cli/tests/execution_success/brillig_cow/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,54 @@ | ||
// Tests the copy on write optimization for arrays. We look for cases where we are modifying an array in place when we shouldn't. | ||
|
||
global ARRAY_SIZE = 5; | ||
|
||
struct ExecutionResult { | ||
original: [Field; ARRAY_SIZE], | ||
modified_once: [Field; ARRAY_SIZE], | ||
modified_twice: [Field; ARRAY_SIZE], | ||
} | ||
|
||
impl ExecutionResult { | ||
fn is_equal(self, other: ExecutionResult) -> bool { | ||
(self.original == other.original) & | ||
(self.modified_once == other.modified_once) & | ||
(self.modified_twice == other.modified_twice) | ||
} | ||
} | ||
|
||
fn modify_in_inlined_constrained(original: [Field; ARRAY_SIZE], index: u64) -> ExecutionResult { | ||
let mut modified = original; | ||
|
||
modified[index] = 27; | ||
|
||
let modified_once = modified; | ||
|
||
modified[index+1] = 27; | ||
|
||
ExecutionResult { | ||
original, | ||
modified_once, | ||
modified_twice: modified | ||
} | ||
} | ||
|
||
unconstrained fn modify_in_unconstrained(original: [Field; ARRAY_SIZE], index: u64) -> ExecutionResult { | ||
let mut modified = original; | ||
|
||
modified[index] = 27; | ||
|
||
let modified_once = modified; | ||
|
||
modified[index+1] = 27; | ||
|
||
ExecutionResult { | ||
original, | ||
modified_once, | ||
modified_twice: modified | ||
} | ||
} | ||
|
||
unconstrained fn main(original: [Field; ARRAY_SIZE], index: u64, expected_result: ExecutionResult) { | ||
assert(expected_result.is_equal(modify_in_unconstrained(original, index))); | ||
assert(expected_result.is_equal(modify_in_inlined_constrained(original, index))); | ||
} |