forked from noir-lang/noir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable to_radix for any field element (noir-lang#1343)
* Enable to_radix for any field element * add integration test * use proper bound during modulo (and small optimisation) * update integration test
- Loading branch information
1 parent
b7c1561
commit 7234d1f
Showing
3 changed files
with
27 additions
and
8 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
crates/nargo_cli/tests/test_data/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 |
---|---|---|
@@ -1 +1,2 @@ | ||
x = "2040124" | ||
_y = "0x2000000000000000000000000000000000000000000000000000000000000000" |
23 changes: 18 additions & 5 deletions
23
crates/nargo_cli/tests/test_data/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 |
---|---|---|
@@ -1,14 +1,27 @@ | ||
use dep::std; | ||
|
||
fn main(x : Field) { | ||
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); | ||
|
||
constrain le_byte_array[0] == 60; | ||
constrain le_byte_array[0] == be_byte_array[30]; | ||
constrain le_byte_array[1] == be_byte_array[29]; | ||
constrain le_byte_array[2] == be_byte_array[28]; | ||
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); | ||
} |
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