From 356f7bb88576cc88fb82e1868706f90aac65fd0a Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Wed, 8 May 2024 15:17:19 +0100 Subject: [PATCH] chore: enforce formatting of noir code (#6271) We're getting unformatted Noir code being synced back out into the main repo so this PR enforces that aztec-packages runs the formatter. --- .github/workflows/ci.yml | 21 ++++++++ noir-projects/Earthfile | 15 +++++- noir-projects/aztec-nr/aztec/src/hash.nr | 48 +++++++++---------- noir-projects/aztec-nr/aztec/src/keys.nr | 5 +- .../aztec/src/keys/point_to_symmetric_key.nr | 5 +- .../aztec-nr/aztec/src/note/constants.nr | 2 +- .../aztec-nr/aztec/src/note/note_getter.nr | 11 ++++- .../aztec-nr/aztec/src/oracle/encryption.nr | 1 - .../aztec-nr/aztec/src/oracle/keys.nr | 26 ++++------ .../aztec-nr/aztec/src/oracle/logs.nr | 2 +- .../aztec/src/oracle/nullifier_key.nr | 2 +- .../aztec-nr/tests/src/mock/test_note.nr | 5 +- .../aztec-nr/value-note/src/value_note.nr | 5 +- .../src/subscription_note.nr | 4 +- .../contracts/card_game_contract/src/cards.nr | 7 +-- .../src/types/card_note.nr | 2 +- .../src/ecdsa_public_key_note.nr | 6 +-- .../key_registry_contract/src/main.nr | 4 +- .../pending_note_hashes_contract/src/main.nr | 4 +- .../src/public_key_note.nr | 2 +- .../src/types/transparent_note.nr | 2 +- .../contracts/uniswap_contract/src/main.nr | 3 +- .../crates/parity-root/src/main.nr | 2 +- .../src/abis/append_only_tree_snapshot.nr | 2 +- .../abis/nullifier_key_validation_request.nr | 2 +- .../crates/types/src/address/aztec_address.nr | 8 ++-- .../types/src/address/public_keys_hash.nr | 30 ++++++------ .../crates/types/src/grumpkin_private_key.nr | 5 +- .../crates/types/src/recursion.nr | 2 +- .../types/src/recursion/verification_key.nr | 6 +-- noir/Earthfile | 13 +++++ noir/noir-repo/noir_stdlib/src/aes128.nr | 1 - .../brillig_embedded_curve/src/main.nr | 6 +-- 33 files changed, 139 insertions(+), 120 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e92f513a023..237feef58f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -137,6 +137,27 @@ jobs: # working-directory: ./yarn-project/scripts # run: earthly-ci -P --secret AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} --secret AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} --secret AZTEC_BOT_COMMENTER_GITHUB_TOKEN=${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} +bench-comment + noir-format: + needs: setup + runs-on: ${{ inputs.username || github.actor }}-x86 + steps: + - { + uses: actions/checkout@v4, + with: { ref: "${{ github.event.pull_request.head.sha }}" }, + } + - uses: ./.github/ci-setup-action + with: + dockerhub_password: "${{ secrets.DOCKERHUB_PASSWORD }}" + concurrency_key: noir-format-${{ inputs.username || github.actor }}-x86 + - name: "Format Noir" + working-directory: ./noir/ + timeout-minutes: 25 + run: earthly-ci --no-output ./+format + - name: "Format noir-projects" + working-directory: ./noir-projects/ + timeout-minutes: 25 + run: earthly-ci --no-output ./+format + # barretenberg (prover) native and AVM (public VM) tests # only ran on x86 for resource reasons (memory intensive) bb-native-tests: diff --git a/noir-projects/Earthfile b/noir-projects/Earthfile index 645eddc4973..907f009151d 100644 --- a/noir-projects/Earthfile +++ b/noir-projects/Earthfile @@ -30,6 +30,19 @@ test: RUN cd aztec-nr && nargo test --silence-warnings RUN cd noir-contracts && nargo test --silence-warnings +format: + FROM +build + + # TODO: https://github.com/noir-lang/noir/issues/4980 + # WORKDIR /usr/src/noir-projects/noir-protocol-circuits + # RUN nargo fmt --check + + WORKDIR /usr/src/noir-projects/noir-contracts + RUN nargo fmt --check + + WORKDIR /usr/src/noir-projects/aztec-nr + RUN nargo fmt --check + gates-report: FROM +build WORKDIR /usr/src/noir-projects/noir-protocol-circuits @@ -38,4 +51,4 @@ gates-report: RUN NARGO_BACKEND_PATH=/usr/src/barretenberg/cpp/build/bin/bb nargo info --json > gates_report.json - SAVE ARTIFACT gates_report.json gates_report.json \ No newline at end of file + SAVE ARTIFACT gates_report.json gates_report.json diff --git a/noir-projects/aztec-nr/aztec/src/hash.nr b/noir-projects/aztec-nr/aztec/src/hash.nr index db600f4f542..989ecfb0f31 100644 --- a/noir-projects/aztec-nr/aztec/src/hash.nr +++ b/noir-projects/aztec-nr/aztec/src/hash.nr @@ -12,22 +12,20 @@ pub fn compute_secret_hash(secret: Field) -> Field { pedersen_hash([secret], GENERATOR_INDEX__SECRET_HASH) } -pub fn compute_encrypted_log_hash( - encrypted_log: [Field; M] -) -> Field where [Field; N]: LensForEncryptedLog { +pub fn compute_encrypted_log_hash(encrypted_log: [Field; M]) -> Field where [Field; N]: LensForEncryptedLog { let mut bytes = [0; L]; // Note that bytes.append(encrypted_log[i].to_be_bytes(31)) results in bound error - for i in 0..M-1 { + for i in 0..M - 1 { let to_add = encrypted_log[i].to_be_bytes(31); for j in 0..31 { bytes[i*31 + j] = to_add[j]; } } // can't assign as L - not in scope error for: L-31*(M-1) - let num_bytes = bytes.len() as u32 - 31*(M-1); - let to_add_final = encrypted_log[M-1].to_be_bytes(num_bytes); + let num_bytes = bytes.len() as u32 - 31 * (M - 1); + let to_add_final = encrypted_log[M - 1].to_be_bytes(num_bytes); for j in 0..num_bytes { - bytes[(M-1)*31 + j] = to_add_final[j]; + bytes[(M-1)*31 + j] = to_add_final[j]; } sha256_to_field(bytes) } @@ -35,7 +33,7 @@ pub fn compute_encrypted_log_hash( pub fn compute_unencrypted_log_hash( contract_address: AztecAddress, event_selector: Field, - log: T, + log: T ) -> Field where T: ToBytesForUnencryptedLog { let message_bytes: [u8; N] = log.to_be_bytes_arr(); // can't use N - not in scope error @@ -182,7 +180,7 @@ fn compute_enc_log_hash_304() { 0x00b938289e563b0fe01982cd9b8d9e33e3069046768ad01c0fb05e429e7b7909, 0x00fbcc257a3211f705b471eee763b0f43876a2b2178fab6d2b09bd2b7e086584, 0x000000000000008c3289b5793b7448f4d45ecde039d004b6f037cad10b5c2336 - ]; + ]; let hash = compute_encrypted_log_hash(input); assert(hash == 0x001e3c013994947fe28957a876bf1b2c3a69ac69cc92909efd4f2ae9b972f893); } @@ -190,34 +188,34 @@ fn compute_enc_log_hash_304() { #[test] fn compute_enc_log_hash_368() { let input = [ - 0x0000000000000000000000000000000000000000000000000000000000000000, - 0x002190697d2a50e229a7a077e0951073f7d51e46679f10466153c308b63b1ea9, - 0x00543e346facc6799b94514c9d461bcc836c04b083b13c2e4544a39130473c1e, - 0x000df76d59526f8f953bcc7d9f77cdaefd36435931f0d7348f794bc275b42ded, - 0x00a6d390ee1723af7f7ac1ae4fc81a266b2370fe07040a36d06dbe242e02413e, - 0x00acbce15b6af1fbe94bd0f7b70f11768265dff77bfe63398f2a053efdfdf26d, - 0x00b8b131b9f42c689beb095ba4f4a836d4d15c9068d0422e9add6ca82b786329, - 0x00661a6a654b38f0f97d404ef5553e0efea9ed670561ae86685b31bbb2824fac, - 0x00113a6b58edfaec0065b365f66ba8d8aa68254b8690035e8d671a17a843f0a1, - 0x0023f2d2eae8c4449bac8f268a3e62a3faace1fe1401f0efdc8b0ccfbc8fb271, - 0x00cf6603f8c61993dd2f662c719671c61727a2f4e925fb988b23d31feccd77d9, - 0x0000000000a402a84b7294671799c38dd805f6a827a3a12633fdf91a57debe1f - ]; + 0x0000000000000000000000000000000000000000000000000000000000000000, + 0x002190697d2a50e229a7a077e0951073f7d51e46679f10466153c308b63b1ea9, + 0x00543e346facc6799b94514c9d461bcc836c04b083b13c2e4544a39130473c1e, + 0x000df76d59526f8f953bcc7d9f77cdaefd36435931f0d7348f794bc275b42ded, + 0x00a6d390ee1723af7f7ac1ae4fc81a266b2370fe07040a36d06dbe242e02413e, + 0x00acbce15b6af1fbe94bd0f7b70f11768265dff77bfe63398f2a053efdfdf26d, + 0x00b8b131b9f42c689beb095ba4f4a836d4d15c9068d0422e9add6ca82b786329, + 0x00661a6a654b38f0f97d404ef5553e0efea9ed670561ae86685b31bbb2824fac, + 0x00113a6b58edfaec0065b365f66ba8d8aa68254b8690035e8d671a17a843f0a1, + 0x0023f2d2eae8c4449bac8f268a3e62a3faace1fe1401f0efdc8b0ccfbc8fb271, + 0x00cf6603f8c61993dd2f662c719671c61727a2f4e925fb988b23d31feccd77d9, + 0x0000000000a402a84b7294671799c38dd805f6a827a3a12633fdf91a57debe1f + ]; let hash = compute_encrypted_log_hash(input); - assert(hash == 0x00a0d651ac0cbc01b72430fa6a05d91738595af6e0229347b4c9968223387aeb); + assert(hash == 0x00a0d651ac0cbc01b72430fa6a05d91738595af6e0229347b4c9968223387aeb); } #[test] fn compute_unenc_log_hash_array() { let contract_address = AztecAddress::from_field(0x233a3e0df23b2b15b324194cb4a151f26c0b7333250781d34cc269d85dc334c6); let event_selector = 5; - let log = [ + let log = [ 0x20660de09f35f876e3e69d227b2a35166ad05f09d82d06366ec9b6f65a51fec2, 0x1b52bfe3b8689761916f76dc3d38aa8810860db325cd39ca611eed980091f01c, 0x2e559c4045c378a56ad13b9edb1e8de4e7ad3b3aa35cc7ba9ec77f7a68fa43a4, 0x25d0f689c4a4178a29d59306f2675824d19be6d25e44fa03b03f49c263053dd2, 0x2d513a722d6f352dc0961f156afdc5e31495b9f0e35cb069261a8e55e2df67fd - ]; + ]; let hash = compute_unencrypted_log_hash(contract_address, event_selector, log); assert(hash == 0x00846d6969c8c2f61d39cd2762efcb0abb14f88d59c2675910251ef2bcffe9a7); } diff --git a/noir-projects/aztec-nr/aztec/src/keys.nr b/noir-projects/aztec-nr/aztec/src/keys.nr index 3bef24ec2bf..dd41b77ea5f 100644 --- a/noir-projects/aztec-nr/aztec/src/keys.nr +++ b/noir-projects/aztec-nr/aztec/src/keys.nr @@ -1,8 +1,7 @@ mod getters; mod point_to_symmetric_key; -use crate::keys::getters::{get_npk_m, get_ivpk_m, -// Commented out as it's currently not enabled in key registry +// Add once enabled in key registry: // get_ovpk_m, // get_tpk_m -}; +use crate::keys::getters::{get_npk_m, get_ivpk_m}; diff --git a/noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr b/noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr index 1c80662dcb3..e2f0edfcd70 100644 --- a/noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr +++ b/noir-projects/aztec-nr/aztec/src/keys/point_to_symmetric_key.nr @@ -1,4 +1,7 @@ -use dep::protocol_types::{constants::GENERATOR_INDEX__SYMMETRIC_KEY, grumpkin_private_key::GrumpkinPrivateKey, grumpkin_point::GrumpkinPoint, utils::arr_copy_slice}; +use dep::protocol_types::{ + constants::GENERATOR_INDEX__SYMMETRIC_KEY, grumpkin_private_key::GrumpkinPrivateKey, + grumpkin_point::GrumpkinPoint, utils::arr_copy_slice +}; use dep::std::{hash::sha256, embedded_curve_ops::multi_scalar_mul}; // TODO(#5726): This function is called deriveAESSecret in TS. I don't like point_to_symmetric_key name much since diff --git a/noir-projects/aztec-nr/aztec/src/note/constants.nr b/noir-projects/aztec-nr/aztec/src/note/constants.nr index 66a404c1b3d..3b238572e90 100644 --- a/noir-projects/aztec-nr/aztec/src/note/constants.nr +++ b/noir-projects/aztec-nr/aztec/src/note/constants.nr @@ -3,4 +3,4 @@ global MAX_NOTE_FIELDS_LENGTH: u64 = 20; // + 2 for EXTRA_DATA: [number_of_return_notes, contract_address] global GET_NOTE_ORACLE_RETURN_LENGTH: u64 = MAX_NOTE_FIELDS_LENGTH + 1 + 2; global MAX_NOTES_PER_PAGE: u64 = 10; -global VIEW_NOTE_ORACLE_RETURN_LENGTH: u64 = MAX_NOTES_PER_PAGE * (MAX_NOTE_FIELDS_LENGTH + 1) + 2; \ No newline at end of file +global VIEW_NOTE_ORACLE_RETURN_LENGTH: u64 = MAX_NOTES_PER_PAGE * (MAX_NOTE_FIELDS_LENGTH + 1) + 2; diff --git a/noir-projects/aztec-nr/aztec/src/note/note_getter.nr b/noir-projects/aztec-nr/aztec/src/note/note_getter.nr index 21fa5ad1530..24f1ba45dd9 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_getter.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_getter.nr @@ -8,7 +8,10 @@ use crate::note::{ }; use crate::oracle; -fn extract_property_value_from_selector(serialized_note: [Field; N], selector: PropertySelector) -> Field { +fn extract_property_value_from_selector( + serialized_note: [Field; N], + selector: PropertySelector +) -> Field { // Selectors use PropertySelectors in order to locate note properties inside the serialized note. // This allows easier packing and custom (de)serialization schemas. A note property is located // inside the serialized note using the index inside the array, a byte offset and a length. @@ -26,7 +29,11 @@ fn extract_property_value_from_selector(serialized_note: [Field; N], selector value_field } -fn check_note_header(context: PrivateContext, storage_slot: Field, note: Note) where Note: NoteInterface { +fn check_note_header( + context: PrivateContext, + storage_slot: Field, + note: Note +) where Note: NoteInterface { let header = note.get_header(); let contract_address = context.this_address(); assert(header.contract_address.eq(contract_address)); diff --git a/noir-projects/aztec-nr/aztec/src/oracle/encryption.nr b/noir-projects/aztec-nr/aztec/src/oracle/encryption.nr index c8084432437..3532baec223 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/encryption.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/encryption.nr @@ -1,4 +1,3 @@ - #[oracle(aes128Encrypt)] pub fn aes128_encrypt_oracle(input: [u8; N], iv: [u8; 16], key: [u8; 16]) -> [u8; M] {} diff --git a/noir-projects/aztec-nr/aztec/src/oracle/keys.nr b/noir-projects/aztec-nr/aztec/src/oracle/keys.nr index d8737a0dd06..a985e385e81 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/keys.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/keys.nr @@ -1,10 +1,4 @@ -use dep::protocol_types::{ - address::{ - AztecAddress, - PartialAddress, - }, - grumpkin_point::GrumpkinPoint, -}; +use dep::protocol_types::{address::{AztecAddress, PartialAddress}, grumpkin_point::GrumpkinPoint}; use crate::hash::poseidon2_hash; @@ -12,17 +6,17 @@ use crate::hash::poseidon2_hash; fn get_public_keys_and_partial_address_oracle(_address: AztecAddress) -> [Field; 9] {} unconstrained fn get_public_keys_and_partial_address_oracle_wrapper(address: AztecAddress) -> [Field; 9] { - get_public_keys_and_partial_address_oracle(address) + get_public_keys_and_partial_address_oracle(address) } fn get_public_keys_and_partial_address(address: AztecAddress) -> ([GrumpkinPoint; 4], PartialAddress) { - let result = get_public_keys_and_partial_address_oracle_wrapper(address); + let result = get_public_keys_and_partial_address_oracle_wrapper(address); - let nullifier_pub_key = GrumpkinPoint::new(result[0], result[1]); - let incoming_pub_key = GrumpkinPoint::new(result[2], result[3]); - let outgoing_pub_key = GrumpkinPoint::new(result[4], result[5]); - let tagging_pub_key = GrumpkinPoint::new(result[6], result[7]); - let partial_address = PartialAddress::from_field(result[8]); + let nullifier_pub_key = GrumpkinPoint::new(result[0], result[1]); + let incoming_pub_key = GrumpkinPoint::new(result[2], result[3]); + let outgoing_pub_key = GrumpkinPoint::new(result[4], result[5]); + let tagging_pub_key = GrumpkinPoint::new(result[6], result[7]); + let partial_address = PartialAddress::from_field(result[8]); - ([nullifier_pub_key, incoming_pub_key, outgoing_pub_key, tagging_pub_key], partial_address) -} \ No newline at end of file + ([nullifier_pub_key, incoming_pub_key, outgoing_pub_key, tagging_pub_key], partial_address) +} diff --git a/noir-projects/aztec-nr/aztec/src/oracle/logs.nr b/noir-projects/aztec-nr/aztec/src/oracle/logs.nr index 48df110c32a..d692329a82f 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/logs.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/logs.nr @@ -10,7 +10,7 @@ fn emit_encrypted_log_oracle( _note_type_id: Field, _encryption_pub_key: GrumpkinPoint, _preimage: [Field; N], - _counter: u32, + _counter: u32 ) -> [Field; M] {} unconstrained pub fn emit_encrypted_log( diff --git a/noir-projects/aztec-nr/aztec/src/oracle/nullifier_key.nr b/noir-projects/aztec-nr/aztec/src/oracle/nullifier_key.nr index 0926fca65e6..39282a12e2a 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/nullifier_key.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/nullifier_key.nr @@ -15,7 +15,7 @@ unconstrained fn get_nullifier_keys_internal(account: AztecAddress) -> Nullifier NullifierKeys { account, master_nullifier_public_key: GrumpkinPoint { x: result[0], y: result[1] }, - app_nullifier_secret_key: result[2], + app_nullifier_secret_key: result[2] } } diff --git a/noir-projects/aztec-nr/tests/src/mock/test_note.nr b/noir-projects/aztec-nr/tests/src/mock/test_note.nr index bc4f262550f..17f6d968d36 100644 --- a/noir-projects/aztec-nr/tests/src/mock/test_note.nr +++ b/noir-projects/aztec-nr/tests/src/mock/test_note.nr @@ -1,8 +1,5 @@ use dep::aztec::context::PrivateContext; -use dep::aztec::note::{ - note_header::NoteHeader, - note_interface::NoteInterface, -}; +use dep::aztec::note::{note_header::NoteHeader, note_interface::NoteInterface}; global TEST_NOTE_LENGTH = 1; diff --git a/noir-projects/aztec-nr/value-note/src/value_note.nr b/noir-projects/aztec-nr/value-note/src/value_note.nr index d6597caa352..019ea4bf543 100644 --- a/noir-projects/aztec-nr/value-note/src/value_note.nr +++ b/noir-projects/aztec-nr/value-note/src/value_note.nr @@ -1,8 +1,5 @@ use dep::aztec::{ - protocol_types::{ - address::AztecAddress, traits::{Deserialize, Serialize}, - constants::GENERATOR_INDEX__NOTE_NULLIFIER -}, + protocol_types::{address::AztecAddress, traits::{Deserialize, Serialize}, constants::GENERATOR_INDEX__NOTE_NULLIFIER}, note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption}, oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}, hash::poseidon2_hash, context::PrivateContext diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr index 18a9123e1d4..c2543a14707 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr @@ -1,7 +1,7 @@ use dep::aztec::prelude::{AztecAddress, PrivateContext, NoteHeader, NoteInterface}; use dep::aztec::{ - protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER, note::utils::compute_note_hash_for_consumption, - hash::poseidon2_hash, + protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER, + note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash, oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key} }; diff --git a/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr b/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr index 7ae2edbda8b..c43ba634b10 100644 --- a/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr +++ b/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr @@ -1,12 +1,9 @@ use dep::aztec::prelude::{AztecAddress, FunctionSelector, PrivateContext, NoteHeader, NoteGetterOptions, NoteViewerOptions}; use dep::aztec::{ - protocol_types::{ - traits::{ToField, Serialize, FromField}, - constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, -}, + protocol_types::{traits::{ToField, Serialize, FromField}, constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL}, context::{PublicContext, Context}, note::note_getter::view_notes, state_vars::PrivateSet, - note::constants::MAX_NOTES_PER_PAGE, + note::constants::MAX_NOTES_PER_PAGE }; use dep::std; use dep::std::{option::Option}; diff --git a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr index 684314291fb..3f952146c2b 100644 --- a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr +++ b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr @@ -2,7 +2,7 @@ use dep::aztec::prelude::{AztecAddress, NoteInterface, NoteHeader, PrivateContex use dep::aztec::{ note::{utils::compute_note_hash_for_consumption}, oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}, - hash::poseidon2_hash, protocol_types::{traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER}, + hash::poseidon2_hash, protocol_types::{traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER} }; // Shows how to create a custom note diff --git a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr index 6804c0f483a..20fd400e967 100644 --- a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr @@ -1,11 +1,9 @@ -use dep::aztec::prelude::{ - AztecAddress, FunctionSelector, NoteHeader, NoteInterface, NoteGetterOptions, PrivateContext -}; +use dep::aztec::prelude::{AztecAddress, FunctionSelector, NoteHeader, NoteInterface, NoteGetterOptions, PrivateContext}; use dep::aztec::{ note::utils::compute_note_hash_for_consumption, oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}, - hash::poseidon2_hash, protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER, + hash::poseidon2_hash, protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER }; global ECDSA_PUBLIC_KEY_NOTE_LEN: Field = 5; diff --git a/noir-projects/noir-contracts/contracts/key_registry_contract/src/main.nr b/noir-projects/noir-contracts/contracts/key_registry_contract/src/main.nr index f8e62b1e4d7..b985c829d26 100644 --- a/noir-projects/noir-contracts/contracts/key_registry_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/key_registry_contract/src/main.nr @@ -3,9 +3,7 @@ contract KeyRegistry { use dep::aztec::{ state_vars::{SharedMutable, Map}, - protocol_types::{ - grumpkin_point::GrumpkinPoint, address::{AztecAddress, PartialAddress}, - } + protocol_types::{grumpkin_point::GrumpkinPoint, address::{AztecAddress, PartialAddress}} }; global KEY_ROTATION_DELAY = 5; diff --git a/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr b/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr index f49828140bf..9cce1d75274 100644 --- a/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr @@ -4,9 +4,7 @@ // be read/nullified before their creation etc. contract PendingNoteHashes { // Libs - use dep::aztec::prelude::{ - AztecAddress, FunctionSelector, NoteHeader, NoteGetterOptions, PrivateContext, Map, PrivateSet - }; + use dep::aztec::prelude::{AztecAddress, FunctionSelector, NoteHeader, NoteGetterOptions, PrivateContext, Map, PrivateSet}; use dep::value_note::{balance_utils, filter::filter_notes_min_sum, value_note::{VALUE_NOTE_LEN, ValueNote}}; use dep::aztec::context::{PublicContext, Context}; diff --git a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr index c7061cac998..95fbe422f78 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr @@ -2,7 +2,7 @@ use dep::aztec::prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContex use dep::aztec::{ note::utils::compute_note_hash_for_consumption, hash::poseidon2_hash, oracle::{nullifier_key::get_app_nullifier_secret_key, get_public_key::get_public_key}, - protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER, + protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER }; global PUBLIC_KEY_NOTE_LEN: Field = 3; diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr index 9fc1d0737fc..d5cf7197cef 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr @@ -2,7 +2,7 @@ use dep::aztec::{ note::{note_getter_options::PropertySelector, utils::compute_note_hash_for_consumption}, hash::poseidon2_hash, prelude::{NoteHeader, NoteInterface, PrivateContext}, - protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER, + protocol_types::constants::GENERATOR_INDEX__NOTE_NULLIFIER }; global TRANSPARENT_NOTE_LEN: Field = 2; diff --git a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr index 9ab011d9e0e..afacb220568 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr @@ -223,7 +223,7 @@ contract Uniswap { token.eq(TokenBridge::at(token_bridge).get_token().static_call(&mut context)), "input_asset address is not the same as seen in the bridge contract" ); } - + // /// Unconstrained /// // this method exists solely for e2e tests to test that nonce gets incremented each time. @@ -231,5 +231,4 @@ contract Uniswap { storage.nonce_for_burn_approval.read() } // docs:end:assert_token_is_same - } diff --git a/noir-projects/noir-protocol-circuits/crates/parity-root/src/main.nr b/noir-projects/noir-protocol-circuits/crates/parity-root/src/main.nr index 6f704d260f0..7356387215f 100644 --- a/noir-projects/noir-protocol-circuits/crates/parity-root/src/main.nr +++ b/noir-projects/noir-protocol-circuits/crates/parity-root/src/main.nr @@ -1,6 +1,6 @@ use dep::parity_lib::{RootParityInputs, ParityPublicInputs}; #[recursive] -fn main(inputs: RootParityInputs) -> pub ParityPublicInputs { +fn main(inputs: RootParityInputs) -> pub ParityPublicInputs { inputs.root_parity_circuit() } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr index 12c74237a56..83925d95897 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/append_only_tree_snapshot.nr @@ -26,4 +26,4 @@ impl Eq for AppendOnlyTreeSnapshot { fn eq(self, other : AppendOnlyTreeSnapshot) -> bool { (self.root == other.root) & (self.next_available_leaf_index == other.next_available_leaf_index) } -} \ No newline at end of file +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr index f0d24b204a4..19789c938a6 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr @@ -1,7 +1,7 @@ use dep::std::cmp::Eq; use crate::{ address::AztecAddress, - constants::{NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH, SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH}, + constants::{SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH, NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH}, traits::{Empty, Serialize, Deserialize}, grumpkin_point::GrumpkinPoint, utils::{arrays::array_concat, reader::Reader} }; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr index 06463ce268c..6413bedf15e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr @@ -55,9 +55,7 @@ impl AztecAddress { pub fn compute(pub_keys_hash: PublicKeysHash, partial_address: PartialAddress) -> AztecAddress { AztecAddress::from_field( - poseidon2_hash( - [pub_keys_hash.to_field(), partial_address.to_field(), GENERATOR_INDEX__CONTRACT_ADDRESS_V1] - ) + poseidon2_hash([pub_keys_hash.to_field(), partial_address.to_field(), GENERATOR_INDEX__CONTRACT_ADDRESS_V1]) ) } @@ -66,13 +64,13 @@ impl AztecAddress { incoming_public_key: GrumpkinPoint, outgoing_public_key: GrumpkinPoint, tagging_public_key: GrumpkinPoint, - partial_address: PartialAddress, + partial_address: PartialAddress ) -> AztecAddress { let public_keys_hash = PublicKeysHash::compute_new( nullifier_public_key, incoming_public_key, outgoing_public_key, - tagging_public_key, + tagging_public_key ); let computed_address = AztecAddress::compute(public_keys_hash, partial_address); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/public_keys_hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/public_keys_hash.nr index bff82cc1644..f91d1383a19 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/public_keys_hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/public_keys_hash.nr @@ -1,7 +1,7 @@ use crate::{ - constants::{GENERATOR_INDEX__PARTIAL_ADDRESS, GENERATOR_INDEX__PUBLIC_KEYS_HASH}, hash::pedersen_hash, grumpkin_point::GrumpkinPoint, - traits::{ToField, Serialize, Deserialize}, - hash::poseidon2_hash, + constants::{GENERATOR_INDEX__PARTIAL_ADDRESS, GENERATOR_INDEX__PUBLIC_KEYS_HASH}, + hash::pedersen_hash, grumpkin_point::GrumpkinPoint, traits::{ToField, Serialize, Deserialize}, + hash::poseidon2_hash }; // Public keys hash. Used in the computation of an address. @@ -59,17 +59,19 @@ impl PublicKeysHash { tagging_public_key: GrumpkinPoint ) -> Self { PublicKeysHash::from_field( - poseidon2_hash([ - nullifier_public_key.x, - nullifier_public_key.y, - incoming_public_key.x, - incoming_public_key.y, - outgoing_public_key.x, - outgoing_public_key.y, - tagging_public_key.x, - tagging_public_key.y, - GENERATOR_INDEX__PUBLIC_KEYS_HASH, - ]) + poseidon2_hash( + [ + nullifier_public_key.x, + nullifier_public_key.y, + incoming_public_key.x, + incoming_public_key.y, + outgoing_public_key.x, + outgoing_public_key.y, + tagging_public_key.x, + tagging_public_key.y, + GENERATOR_INDEX__PUBLIC_KEYS_HASH + ] + ) ) } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr index 79261ec4f20..f9d8526ddb8 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/grumpkin_private_key.nr @@ -1,8 +1,5 @@ use dep::std::{cmp::Eq, embedded_curve_ops::fixed_base_scalar_mul}; -use crate::{ - grumpkin_point::GrumpkinPoint, - traits::Empty -}; +use crate::{grumpkin_point::GrumpkinPoint, traits::Empty}; global GRUMPKIN_PRIVATE_KEY_SERIALIZED_LEN: Field = 2; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/recursion.nr b/noir-projects/noir-protocol-circuits/crates/types/src/recursion.nr index f2e54c0a05b..80f02c240e9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/recursion.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/recursion.nr @@ -1,2 +1,2 @@ mod verification_key; -mod proof; \ No newline at end of file +mod proof; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr index 3412fc4294b..c4cc9b2230f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr @@ -1,8 +1,4 @@ - -use crate::{ - traits::{Serialize, Deserialize, Empty}, - constants::{ VERIFICATION_KEY_LENGTH_IN_FIELDS }, -}; +use crate::{traits::{Serialize, Deserialize, Empty}, constants::VERIFICATION_KEY_LENGTH_IN_FIELDS}; global SERIALIZED_VERIFICATION_KEY_LENGTH = VERIFICATION_KEY_LENGTH_IN_FIELDS + 1; diff --git a/noir/Earthfile b/noir/Earthfile index 5f0f0c928f4..700e241ed6e 100644 --- a/noir/Earthfile +++ b/noir/Earthfile @@ -44,6 +44,19 @@ test: COPY noir-repo/.rustfmt.toml noir-repo/.rustfmt.toml RUN ./scripts/test_native.sh +format: + FROM +nargo + ENV PATH=$PATH:/usr/src/noir-repo/target/release + + COPY ./noir-repo/test_programs ./noir-repo/test_programs + COPY ./noir-repo/noir_stdlib ./noir-repo/noir_stdlib + + WORKDIR ./noir-repo/test_programs + RUN ./format.sh check + + WORKDIR ../noir_stdlib + RUN nargo fmt --check + packages-deps: BUILD ../barretenberg/ts/+build # prefetch diff --git a/noir/noir-repo/noir_stdlib/src/aes128.nr b/noir/noir-repo/noir_stdlib/src/aes128.nr index ac5c2b48ad8..e6e2a5e4997 100644 --- a/noir/noir-repo/noir_stdlib/src/aes128.nr +++ b/noir/noir-repo/noir_stdlib/src/aes128.nr @@ -1,4 +1,3 @@ - #[foreign(aes128_encrypt)] // docs:start:aes128 pub fn aes128_encrypt(input: [u8; N], iv: [u8; 16], key: [u8; 16]) -> [u8] {} diff --git a/noir/noir-repo/test_programs/execution_success/brillig_embedded_curve/src/main.nr b/noir/noir-repo/test_programs/execution_success/brillig_embedded_curve/src/main.nr index 1a183bb13d9..8a1a7f08975 100644 --- a/noir/noir-repo/test_programs/execution_success/brillig_embedded_curve/src/main.nr +++ b/noir/noir-repo/test_programs/execution_success/brillig_embedded_curve/src/main.nr @@ -1,10 +1,6 @@ use dep::std; -unconstrained fn main( - priv_key: Field, - pub_x: pub Field, - pub_y: pub Field, -) { +unconstrained fn main(priv_key: Field, pub_x: pub Field, pub_y: pub Field) { let g1_y = 17631683881184975370165255887551781615748388533673675138860; let g1 = std::embedded_curve_ops::EmbeddedCurvePoint { x: 1, y: g1_y };