-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(std_lib)!: modulus bits/bytes methods, and to_bits -> to_le_bits (…
…#697) * added modulus_bits command, have to add modulus * add modulus_bits and modulus_be_byte_array builtin funcs * cargo fm * cargo clippy * more clippy format fixes * slight comment fix * rename modulus to bytes methods * remove comments and dbg * rename to have le and be trailing func names * match rust with endianness before bytes/bits * tiny comments rename * to_le_bytes test naming * remove dbg! stmt
- Loading branch information
Showing
13 changed files
with
114 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
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,3 @@ | ||
bn254_modulus_be_bytes = [48, 100, 78, 114, 225, 49, 160, 41, 184, 80, 69, 182, 129, 129, 88, 93, 40, 51, 232, 72, 121, 185, 112, 145, 67, 225, 245, 147, 240, 0, 0, 1] | ||
bn254_modulus_be_bits = [1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] | ||
return = "" |
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; | ||
|
||
fn main(bn254_modulus_be_bytes : [u8; 32], bn254_modulus_be_bits : [u1; 254]) -> pub Field { | ||
let modulus_size = std::field::modulus_num_bits(); | ||
// NOTE: The constraints used in this circuit will only work when testing nargo with the plonk bn254 backend | ||
constrain modulus_size == 254; | ||
|
||
let modulus_be_byte_array = std::field::modulus_be_bytes(); | ||
for i in 0..32 { | ||
constrain modulus_be_byte_array[i] == bn254_modulus_be_bytes[i]; | ||
} | ||
let modulus_le_byte_array = std::field::modulus_le_bytes(); | ||
for i in 0..32 { | ||
constrain modulus_le_byte_array[i] == bn254_modulus_be_bytes[31-i]; | ||
} | ||
|
||
let modulus_be_bits = std::field::modulus_be_bits(); | ||
for i in 0..254 { | ||
constrain modulus_be_bits[i] == bn254_modulus_be_bits[i]; | ||
} | ||
let modulus_le_bits = std::field::modulus_le_bits(); | ||
for i in 0..254 { | ||
constrain modulus_le_bits[i] == bn254_modulus_be_bits[253-i]; | ||
} | ||
|
||
modulus_size | ||
} |
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,2 +1,2 @@ | ||
x = "2040124" | ||
return = [0x3c, 0x21, 0x1f, 0x00] | ||
return = [0x3c, 0x21, 0x1f, 0x00] |
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
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,26 @@ | ||
#[builtin(to_le_bits)] | ||
fn to_le_bits(_x : Field, _bit_size: u32) -> [u1] {} | ||
|
||
fn to_le_bytes(x : Field, byte_size: u32) -> [u8] { | ||
to_radix(x, 256, byte_size) | ||
} | ||
|
||
#[builtin(to_radix)] | ||
//decompose _x into a _result_len vector over the _radix basis | ||
//_radix must be less than 256 | ||
fn to_radix(_x : Field, _radix: u32, _result_len: u32) -> [u8] {} | ||
|
||
#[builtin(modulus_num_bits)] | ||
fn modulus_num_bits() -> comptime Field {} | ||
|
||
#[builtin(modulus_be_bits)] | ||
fn modulus_be_bits() -> [u1] {} | ||
|
||
#[builtin(modulus_le_bits)] | ||
fn modulus_le_bits() -> [u1] {} | ||
|
||
#[builtin(modulus_be_bytes)] | ||
fn modulus_be_bytes() -> [u8] {} | ||
|
||
#[builtin(modulus_le_bytes)] | ||
fn modulus_le_bytes() -> [u8] {} |
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