Skip to content

Commit

Permalink
chore: handle std::field references
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Nov 30, 2023
1 parent a9049bd commit 71abc61
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ unconstrained fn main(x: Field, _y: Field) {
assert(le_byte_array[2] == be_byte_array[28]);

let z = 0 - 1;
let p_bytes = std::field::modulus_le_bytes();
let p_bytes = std::field_element::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);
let p_bits = std::field_element::modulus_le_bits();
let z_bits = z.to_le_bits(std::field_element::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);
_y.to_le_bits(std::field_element::modulus_num_bits() as u32);
}
10 changes: 5 additions & 5 deletions test_programs/execution_success/modulus/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use dep::std;

fn main(bn254_modulus_be_bytes: [u8; 32], bn254_modulus_be_bits: [u1; 254]) {
let modulus_size = std::field::modulus_num_bits();
let modulus_size = std::field_element::modulus_num_bits();
// NOTE: The constraints used in this circuit will only work when testing nargo with the plonk bn254 backend
assert(modulus_size == 254);

let modulus_be_byte_array = std::field::modulus_be_bytes();
let modulus_be_byte_array = std::field_element::modulus_be_bytes();
for i in 0..32 {
assert(modulus_be_byte_array[i] == bn254_modulus_be_bytes[i]);
}
let modulus_le_byte_array = std::field::modulus_le_bytes();
let modulus_le_byte_array = std::field_element::modulus_le_bytes();
for i in 0..32 {
assert(modulus_le_byte_array[i] == bn254_modulus_be_bytes[31 - i]);
}

let modulus_be_bits = std::field::modulus_be_bits();
let modulus_be_bits = std::field_element::modulus_be_bits();
for i in 0..254 {
assert(modulus_be_bits[i] == bn254_modulus_be_bits[i]);
}
let modulus_le_bits = std::field::modulus_le_bits();
let modulus_le_bits = std::field_element::modulus_le_bits();
for i in 0..254 {
assert(modulus_le_bits[i] == bn254_modulus_be_bits[253 - i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ fn main(x: Field, a: Field) {
assert(le_byte_array[2] == be_byte_array[28]);

let z = 0 - 1;
let p_bytes = std::field::modulus_le_bytes();
let p_bytes = std::field_element::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);
let p_bits = std::field_element::modulus_le_bits();
let z_bits = z.to_le_bits(std::field_element::modulus_num_bits() as u32);
assert(z_bits[0] == 0);
assert(p_bits[100] == z_bits[100]);

a.to_le_bits(std::field::modulus_num_bits() as u32);
a.to_le_bits(std::field_element::modulus_num_bits() as u32);
}

0 comments on commit 71abc61

Please sign in to comment.