Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Sync from noir #6986

Merged
merged 36 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0e01b10
[1 changes] feat!: add session id to foreign call RPC requests (https…
AztecBot Jun 10, 2024
667085b
chore: apply sync fixes
AztecBot Jun 10, 2024
bdddac9
Merge branch 'master' into sync-noir
TomAFrench Jun 10, 2024
7eba86e
chore: update cargo.lock
TomAFrench Jun 10, 2024
2470833
Update noir/noir-repo/compiler/integration-tests/test/node/prove_and_…
TomAFrench Jun 10, 2024
14df10d
temp
TomAFrench Jun 10, 2024
9b4b174
Merge branch 'master' into sync-noir
TomAFrench Jun 11, 2024
ff8b27e
Merge branch 'master' into sync-noir
TomAFrench Jun 11, 2024
cb6e6b9
[1 changes] chore: avoid `bn254_blackbox_solver` polluting feature fl…
AztecBot Jun 11, 2024
b456ac1
chore: apply sync fixes
AztecBot Jun 11, 2024
e1dc886
chore: avoid `bn254_blackbox_solver` polluting feature flags (https:/…
AztecBot Jun 11, 2024
c30f091
push a scope in interpreter enter_function even when scopes.len() == 1
vezenovm Jun 11, 2024
f8c16cb
Merge branch 'master' into sync-noir
vezenovm Jun 11, 2024
d7877de
Merge branch 'master' into sync-noir
TomAFrench Jun 12, 2024
ee7965f
try bug fix with checking let_.comptime
vezenovm Jun 12, 2024
b0317ac
Merge remote-tracking branch 'origin/sync-noir' into sync-noir
vezenovm Jun 12, 2024
110385f
nargo fmt
vezenovm Jun 12, 2024
ca708d4
clippy and fmt
vezenovm Jun 12, 2024
5b34bec
Merge branch 'master' into sync-noir
vezenovm Jun 12, 2024
b1bc45d
a little debug cleanup
vezenovm Jun 12, 2024
ffecb8c
Merge remote-tracking branch 'origin/sync-noir' into sync-noir
vezenovm Jun 12, 2024
7d08148
nargo fmt aztec-nr
vezenovm Jun 12, 2024
14235fe
cleanup old debug stuff
vezenovm Jun 12, 2024
1eb3857
bring back verify_honk_proof test
vezenovm Jun 12, 2024
8f41207
format verify_honk_proof
vezenovm Jun 12, 2024
c1f3881
bring back honk_recursion flag that got reverted
vezenovm Jun 12, 2024
c9234c8
fix up hardcoded abis in noirc_abi_wasm
vezenovm Jun 12, 2024
b04cc42
update yarn lock
vezenovm Jun 12, 2024
6e45192
bring back testing integration-tests in series that was reverted
vezenovm Jun 12, 2024
e819ebe
one backendi nstance in prove_and_verify.test.ts integration-tests
vezenovm Jun 12, 2024
a6da3b3
Merge branch 'master' into sync-noir
vezenovm Jun 13, 2024
7fd2bec
Merge branch 'master' into sync-noir
vezenovm Jun 13, 2024
62996ab
remove last references to param_witnesses
vezenovm Jun 13, 2024
f5d1dda
Merge branch 'master' into sync-noir
vezenovm Jun 13, 2024
b2e8fe1
delete noir yarn.lock
vezenovm Jun 13, 2024
d8fa1c7
Merge remote-tracking branch 'origin/sync-noir' into sync-noir
vezenovm Jun 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9c99a97ca8f42bee23cf97ebd724fdc51e647c60
2e543b40eb83ef2080e4d8f870f525fadd631099
1 change: 1 addition & 0 deletions avm-transpiler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use dep::aztec::{
traits::{ToField, Serialize, FromField}, grumpkin_point::GrumpkinPoint,
constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL
},
encrypted_logs::encrypted_note_emission::encode_and_encrypt_with_keys, note::note_getter::view_notes,
state_vars::PrivateSet, note::constants::MAX_NOTES_PER_PAGE
encrypted_logs::encrypted_note_emission::encode_and_encrypt_with_keys,
note::note_getter::view_notes, state_vars::PrivateSet, note::constants::MAX_NOTES_PER_PAGE
Copy link
Contributor

@vezenovm vezenovm Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just fmt, and the same thing for the aztec-nr changes.

};
use dep::std;
use dep::std::{option::Option};
Expand Down
27 changes: 0 additions & 27 deletions noir/noir-repo/.github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,32 +221,6 @@ jobs:
- name: Run browser tests
run: yarn workspace @noir-lang/noirc_abi test:browser

test-noir-js-backend-barretenberg:
needs: [build-noirc-abi]
name: noir-js-backend-barretenberg
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download wasm package artifact
uses: actions/download-artifact@v4
with:
name: noirc_abi_wasm
path: ./tooling/noirc_abi_wasm

- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Build noir_js_types
run: yarn workspace @noir-lang/types build

- name: Run barretenberg wrapper tests
run: |
yarn workspace @noir-lang/backend_barretenberg test

test-noir-js:
needs: [build-nargo, build-acvm-js, build-noirc-abi]
name: Noir JS
Expand Down Expand Up @@ -546,7 +520,6 @@ jobs:
- test-acvm_js-node
- test-acvm_js-browser
- test-noirc-abi
- test-noir-js-backend-barretenberg
- test-noir-js
- test-noir-wasm
- test-noir-codegen
Expand Down
8 changes: 5 additions & 3 deletions noir/noir-repo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions noir/noir-repo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ noirc_abi = { path = "tooling/noirc_abi" }
bb_abstraction_leaks = { path = "tooling/bb_abstraction_leaks" }
acvm_cli = { path = "tooling/acvm_cli" }

# Arkworks
ark-bn254 = { version = "^0.4.0", default-features = false, features = ["curve"] }
ark-bls12-381 = { version = "^0.4.0", default-features = false, features = ["curve"] }
grumpkin = { version = "0.1.0", package = "noir_grumpkin", features = ["std"] }
ark-ec = { version = "^0.4.0", default-features = false }
ark-ff = { version = "^0.4.0", default-features = false }
ark-std = { version = "^0.4.0", default-features = false }

# Misc utils crates
iter-extended = { path = "utils/iter-extended" }

Expand Down Expand Up @@ -131,6 +139,8 @@ similar-asserts = "1.5.0"
tempfile = "3.6.0"
jsonrpc = { version = "0.16.0", features = ["minreq_http"] }
flate2 = "1.0.24"
rand = "0.8.5"
proptest = "1.2.0"

im = { version = "15.1", features = ["serde"] }
tracing = "0.1.40"
Expand Down
9 changes: 6 additions & 3 deletions noir/noir-repo/acvm-repo/acir_field/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ hex.workspace = true
num-bigint.workspace = true
serde.workspace = true

ark-bn254 = { version = "^0.4.0", default-features = false, features = ["curve"] }
ark-bls12-381 = { version = "^0.4.0", optional = true, default-features = false, features = ["curve"] }
ark-ff = { version = "^0.4.0", default-features = false }
ark-bn254.workspace = true
ark-bls12-381 = { workspace = true, optional = true }
ark-ff.workspace = true

cfg-if = "1.0.0"

[dev-dependencies]
proptest.workspace = true

[features]
bn254 = []
bls12_381 = ["dep:ark-bls12-381"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc c1b2755b427c874de3ee55c2969e8adc1b4b0331a28173e9e1e492b3fee6b7b7 # shrinks to hex = "3a0aaaa0aa0aaa00000aaaaaaaa0000a000aaa0a00a0000aa00a00aa0a000a0a"
133 changes: 32 additions & 101 deletions noir/noir-repo/acvm-repo/acir_field/src/field_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ impl<F: PrimeField> FieldElement<F> {
self.0
}

fn is_negative(&self) -> bool {
self.neg().num_bits() < self.num_bits()
}

fn fits_in_u128(&self) -> bool {
self.num_bits() <= 128
}
Expand All @@ -195,15 +191,6 @@ impl<F: PrimeField> FieldElement<F> {
Some(FieldElement(fr))
}

// mask_to methods will not remove any bytes from the field
// they are simply zeroed out
// Whereas truncate_to will remove those bits and make the byte array smaller
fn mask_to_be_bytes(&self, num_bits: u32) -> Vec<u8> {
let mut bytes = self.to_be_bytes();
mask_vector_le(&mut bytes, num_bits as usize);
bytes
}

fn bits(&self) -> Vec<bool> {
fn byte_to_bit(byte: u8) -> Vec<bool> {
let mut bits = Vec::with_capacity(8);
Expand All @@ -220,29 +207,6 @@ impl<F: PrimeField> FieldElement<F> {
}
bits
}

fn and_xor(&self, rhs: &FieldElement<F>, num_bits: u32, is_xor: bool) -> FieldElement<F> {
// XXX: Gadgets like SHA256 need to have their input be a multiple of 8
// This is not a restriction caused by SHA256, as it works on bits
// but most backends assume bytes.
// We could implicitly pad, however this may not be intuitive for users.
// assert!(
// num_bits % 8 == 0,
// "num_bits is not a multiple of 8, it is {}",
// num_bits
// );

let lhs_bytes = self.mask_to_be_bytes(num_bits);
let rhs_bytes = rhs.mask_to_be_bytes(num_bits);

let and_byte_arr: Vec<_> = lhs_bytes
.into_iter()
.zip(rhs_bytes)
.map(|(lhs, rhs)| if is_xor { lhs ^ rhs } else { lhs & rhs })
.collect();

FieldElement::from_be_bytes_reduce(&and_byte_arr)
}
}

impl<F: PrimeField> AcirField for FieldElement<F> {
Expand Down Expand Up @@ -310,7 +274,10 @@ impl<F: PrimeField> AcirField for FieldElement<F> {
}

fn to_i128(self) -> i128 {
let is_negative = self.is_negative();
// Negative integers are represented by the range [p + i128::MIN, p) whilst
// positive integers are represented by the range [0, i128::MAX).
// We can then differentiate positive from negative values by their MSB.
let is_negative = self.neg().num_bits() < self.num_bits();
let bytes = if is_negative { self.neg() } else { self }.to_be_bytes();
i128::from_be_bytes(bytes[16..32].try_into().unwrap()) * if is_negative { -1 } else { 1 }
}
Expand Down Expand Up @@ -376,13 +343,6 @@ impl<F: PrimeField> AcirField for FieldElement<F> {

bytes[0..num_elements].to_vec()
}

fn and(&self, rhs: &FieldElement<F>, num_bits: u32) -> FieldElement<F> {
self.and_xor(rhs, num_bits, false)
}
fn xor(&self, rhs: &FieldElement<F>, num_bits: u32) -> FieldElement<F> {
self.and_xor(rhs, num_bits, true)
}
}

impl<F: PrimeField> Neg for FieldElement<F> {
Expand Down Expand Up @@ -433,35 +393,6 @@ impl<F: PrimeField> SubAssign for FieldElement<F> {
}
}

fn mask_vector_le(bytes: &mut [u8], num_bits: usize) {
// reverse to big endian format
bytes.reverse();

let mask_power = num_bits % 8;
let array_mask_index = num_bits / 8;

for (index, byte) in bytes.iter_mut().enumerate() {
match index.cmp(&array_mask_index) {
std::cmp::Ordering::Less => {
// do nothing if the current index is less than
// the array index.
}
std::cmp::Ordering::Equal => {
let mask = 2u8.pow(mask_power as u32) - 1;
// mask the byte
*byte &= mask;
}
std::cmp::Ordering::Greater => {
// Anything greater than the array index
// will be set to zero
*byte = 0;
}
}
}
// reverse back to little endian
bytes.reverse();
}

// For pretty printing powers
fn superscript(n: u64) -> String {
if n == 0 {
Expand Down Expand Up @@ -494,19 +425,7 @@ fn superscript(n: u64) -> String {
#[cfg(test)]
mod tests {
use super::{AcirField, FieldElement};

#[test]
fn and() {
let max = 10_000u32;

let num_bits = (std::mem::size_of::<u32>() * 8) as u32 - max.leading_zeros();

for x in 0..max {
let x = FieldElement::<ark_bn254::Fr>::from(x as i128);
let res = x.and(&x, num_bits);
assert_eq!(res.to_be_bytes(), x.to_be_bytes());
}
}
use proptest::prelude::*;

#[test]
fn serialize_fixed_test_vectors() {
Expand All @@ -524,24 +443,36 @@ mod tests {
}
}

#[test]
fn deserialize_even_and_odd_length_hex() {
// Test cases of (odd, even) length hex strings
let hex_strings =
vec![("0x0", "0x00"), ("0x1", "0x01"), ("0x002", "0x0002"), ("0x00003", "0x000003")];
for (i, case) in hex_strings.into_iter().enumerate() {
let i_field_element = FieldElement::<ark_bn254::Fr>::from(i as i128);
let odd_field_element = FieldElement::<ark_bn254::Fr>::from_hex(case.0).unwrap();
let even_field_element = FieldElement::<ark_bn254::Fr>::from_hex(case.1).unwrap();

assert_eq!(i_field_element, odd_field_element);
assert_eq!(odd_field_element, even_field_element);
}
}

#[test]
fn max_num_bits_smoke() {
let max_num_bits_bn254 = FieldElement::<ark_bn254::Fr>::max_num_bits();
assert_eq!(max_num_bits_bn254, 254);
}

proptest! {
// This currently panics due to the fact that we allow inputs which are greater than the field modulus,
// automatically reducing them to fit within the canonical range.
#[test]
#[should_panic(expected = "serialized field element is not equal to input")]
fn recovers_original_hex_string(hex in "[0-9a-f]{64}") {
let fe: FieldElement::<ark_bn254::Fr> = FieldElement::from_hex(&hex).expect("should accept any 32 byte hex string");
let output_hex = fe.to_hex();

prop_assert_eq!(hex, output_hex, "serialized field element is not equal to input");
}

#[test]
fn accepts_odd_length_hex_strings(hex in "(?:0x)[0-9a-fA-F]+") {
// Here we inject a "0" immediately after the "0x" (if it exists) to construct an equivalent
// hex string with the opposite parity length.
let insert_index = if hex.starts_with("0x") { 2 } else { 0 };
let mut opposite_parity_string = hex.to_string();
opposite_parity_string.insert(insert_index, '0');

let fe_1: FieldElement::<ark_bn254::Fr> = FieldElement::from_hex(&hex).unwrap();
let fe_2: FieldElement::<ark_bn254::Fr> = FieldElement::from_hex(&opposite_parity_string).unwrap();

prop_assert_eq!(fe_1, fe_2, "equivalent hex strings with opposite parity deserialized to different values");
}
}
}
3 changes: 0 additions & 3 deletions noir/noir-repo/acvm-repo/acir_field/src/generic_ark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,4 @@ pub trait AcirField:
/// Returns the closest number of bytes to the bits specified
/// This method truncates
fn fetch_nearest_bytes(&self, num_bits: usize) -> Vec<u8>;

fn and(&self, rhs: &Self, num_bits: u32) -> Self;
fn xor(&self, rhs: &Self, num_bits: u32) -> Self;
}
2 changes: 1 addition & 1 deletion noir/noir-repo/acvm-repo/acir_field/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]
mod generic_ark;

mod field_element;
mod generic_ark;

pub use generic_ark::AcirField;

Expand Down
6 changes: 2 additions & 4 deletions noir/noir-repo/acvm-repo/acvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repository.workspace = true
num-bigint.workspace = true
thiserror.workspace = true
tracing.workspace = true
serde.workspace = true

acir.workspace = true
brillig_vm.workspace = true
Expand All @@ -36,7 +37,4 @@ bls12_381 = [
]

[dev-dependencies]
rand = "0.8.5"
proptest = "1.2.0"
paste = "1.0.14"
ark-bls12-381 = { version = "^0.4.0", default-features = false, features = ["curve"] }
ark-bls12-381 = { version = "^0.4.0", default-features = false, features = ["curve"] }
Loading
Loading