-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add to_radix and to_bits support to brillig gen (#2012)
* feat: first version of to_radix and to_bits * refactor: use loop hof * doc: updated comments for radix instructions * chore: point to git acvm * chore: update deps
- Loading branch information
1 parent
08d199a
commit 3eef41c
Showing
14 changed files
with
261 additions
and
19 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
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_to_be_bytes/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,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
1 change: 1 addition & 0 deletions
1
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_to_be_bytes/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 @@ | ||
x = "2040124" |
14 changes: 14 additions & 0 deletions
14
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_to_be_bytes/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,14 @@ | ||
use dep::std; | ||
|
||
unconstrained fn main(x : Field) -> pub [u8; 31] { | ||
// The result of this byte array will be big-endian | ||
let byte_array = x.to_be_bytes(31); | ||
let mut bytes = [0; 31]; | ||
for i in 0..31 { | ||
bytes[i] = byte_array[i]; | ||
} | ||
assert(bytes[30] == 60); | ||
assert(bytes[29] == 33); | ||
assert(bytes[28] == 31); | ||
bytes | ||
} |
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_to_bits/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,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.7.0" | ||
|
||
[dependencies] |
24 changes: 24 additions & 0 deletions
24
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_to_bits/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,24 @@ | ||
use dep::std; | ||
|
||
unconstrained fn main() { | ||
let field = 1000; | ||
let be_bits = field.to_be_bits(16); | ||
let le_bits = field.to_le_bits(16); | ||
|
||
for i in 0..16 { | ||
let x = be_bits[i]; | ||
let y = le_bits[15-i]; | ||
assert(x == y); | ||
} | ||
|
||
let x = 3; | ||
let be_bits_x = x.to_be_bits(4); | ||
let le_bits_x = x.to_le_bits(4); | ||
|
||
for i in 0..4 { | ||
let be_bit = be_bits_x[i]; | ||
let le_bit = le_bits_x[3-i]; | ||
assert(be_bit == le_bit); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_to_bytes_integration/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,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_to_bytes_integration/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,2 @@ | ||
x = "2040124" | ||
_y = "0x2000000000000000000000000000000000000000000000000000000000000000" |
27 changes: 27 additions & 0 deletions
27
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_to_bytes_integration/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,27 @@ | ||
use dep::std; | ||
|
||
unconstrained fn main(x : Field, _y: Field) { | ||
// The result of this byte array will be big-endian | ||
let y: Field = 2040124; | ||
let be_byte_array = y.to_be_bytes(31); | ||
// The result of this byte array will be little-endian | ||
let le_byte_array = x.to_le_bytes(31); | ||
|
||
assert(le_byte_array[0] == 60); | ||
assert(le_byte_array[0] == be_byte_array[30]); | ||
assert(le_byte_array[1] == be_byte_array[29]); | ||
assert(le_byte_array[2] == be_byte_array[28]); | ||
|
||
let z = 0 - 1; | ||
let p_bytes = std::field::modulus_le_bytes(); | ||
let z_bytes = z.to_le_bytes(32); | ||
assert(p_bytes[10] == z_bytes[10]); | ||
assert(p_bytes[0] == z_bytes[0] as u8 + 1 as u8); | ||
|
||
let p_bits = std::field::modulus_le_bits(); | ||
let z_bits = z.to_le_bits(std::field::modulus_num_bits() as u32); | ||
assert(z_bits[0] == 0); | ||
assert(p_bits[100] == z_bits[100]); | ||
|
||
_y.to_le_bits(std::field::modulus_num_bits() as u32); | ||
} |
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_to_le_bytes/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,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
1 change: 1 addition & 0 deletions
1
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_to_le_bytes/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 @@ | ||
x = "2040124" |
14 changes: 14 additions & 0 deletions
14
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_to_le_bytes/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,14 @@ | ||
use dep::std; | ||
|
||
unconstrained fn main(x : Field) -> pub [u8; 4] { | ||
// The result of this byte array will be little-endian | ||
let byte_array = x.to_le_bytes(31); | ||
let mut first_four_bytes = [0; 4]; | ||
for i in 0..4 { | ||
first_four_bytes[i] = byte_array[i]; | ||
} | ||
// Issue #617 fix | ||
// We were incorrectly mapping our output array from bit decomposition functions during acir generation | ||
first_four_bytes[3] = byte_array[31]; | ||
first_four_bytes | ||
} |
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