From 8be882f3f00a0652abe1a70709eeb9374a768b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bene=C5=A1?= Date: Mon, 13 Jan 2025 10:02:59 -0600 Subject: [PATCH] chore: removing noir bug workaround (#10535) --- .../encrypted_logs/encrypted_note_emission.nr | 3 -- .../aztec/src/encrypted_logs/payload.nr | 3 ++ .../token_blacklist_contract/src/main.nr | 34 ++++++++++--------- .../contracts/token_contract/src/main.nr | 24 ++++--------- .../transfer_in_private.test.ts | 4 +-- 5 files changed, 29 insertions(+), 39 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr index 9695a3edb66..f7f6f7cf52f 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_note_emission.nr @@ -47,9 +47,6 @@ where compute_payload(context, note, recipient, sender) } -// This function seems to be affected by the following Noir bug: -// https://github.com/noir-lang/noir/issues/5771 -// If you get weird behavior it might be because of it. pub fn encode_and_encrypt_note( context: &mut PrivateContext, recipient: AztecAddress, diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr index 440cebde13c..3ea33631215 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr @@ -145,6 +145,9 @@ fn compute_encrypted_log( // Then we fill in the rest as the incoming body ciphertext let size = M - offset; assert_eq(size, incoming_body_ciphertext.len(), "ciphertext length mismatch"); + // Nargo seems to struggle with realizing that `offset` is a constant at this point. + // We then redefine it in terms of the assertion above to give nargo a hint. + let offset = M - incoming_body_ciphertext.len(); for i in 0..size { encrypted_bytes[offset + i] = incoming_body_ciphertext[i]; } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr index ec66fd86590..f6ca73e99fe 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr @@ -14,7 +14,9 @@ use dep::aztec::macros::aztec; contract TokenBlacklist { // Libs use dep::aztec::{ - encrypted_logs::encrypted_note_emission::encode_and_encrypt_note_unconstrained, + encrypted_logs::encrypted_note_emission::{ + encode_and_encrypt_note, encode_and_encrypt_note_unconstrained, + }, hash::compute_secret_hash, macros::{functions::{initializer, internal, private, public, view}, storage::storage}, prelude::{AztecAddress, Map, NoteGetterOptions, PrivateSet, PublicMutable, SharedMutable}, @@ -186,11 +188,11 @@ contract TokenBlacklist { assert(notes.len() == 1, "note not popped"); // Add the token note to user's balances set - // TODO: constrain encryption below - we are using unconstrained here only because of the following Noir issue - // https://github.com/noir-lang/noir/issues/5771 - storage.balances.add(to, U128::from_integer(amount)).emit( - encode_and_encrypt_note_unconstrained(&mut context, to, context.msg_sender()), - ); + storage.balances.add(to, U128::from_integer(amount)).emit(encode_and_encrypt_note( + &mut context, + to, + context.msg_sender(), + )); } #[private] @@ -206,11 +208,11 @@ contract TokenBlacklist { assert(nonce == 0, "invalid nonce"); } - // TODO: constrain encryption below - we are using unconstrained here only becuase of the following Noir issue - // https://github.com/noir-lang/noir/issues/5771 - storage.balances.sub(from, U128::from_integer(amount)).emit( - encode_and_encrypt_note_unconstrained(&mut context, from, from), - ); + storage.balances.sub(from, U128::from_integer(amount)).emit(encode_and_encrypt_note( + &mut context, + from, + from, + )); TokenBlacklist::at(context.this_address())._increase_public_balance(to, amount).enqueue( &mut context, @@ -255,11 +257,11 @@ contract TokenBlacklist { assert(nonce == 0, "invalid nonce"); } - // TODO: constrain encryption below - we are using unconstrained here only because of the following Noir issue - // https://github.com/noir-lang/noir/issues/5771 - storage.balances.sub(from, U128::from_integer(amount)).emit( - encode_and_encrypt_note_unconstrained(&mut context, from, from), - ); + storage.balances.sub(from, U128::from_integer(amount)).emit(encode_and_encrypt_note( + &mut context, + from, + from, + )); TokenBlacklist::at(context.this_address())._reduce_total_supply(amount).enqueue(&mut context); } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr index f1ec6266f7e..d0e0f6f758a 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -22,7 +22,9 @@ contract Token { context::{PrivateCallInterface, PrivateContext}, encrypted_logs::{ encrypted_event_emission::encode_and_encrypt_event_unconstrained, - encrypted_note_emission::encode_and_encrypt_note_unconstrained, + encrypted_note_emission::{ + encode_and_encrypt_note, encode_and_encrypt_note_unconstrained, + }, }, macros::{ events::event, @@ -250,10 +252,8 @@ contract Token { assert(nonce == 0, "invalid nonce"); } - // TODO: constrain encryption below - we are using unconstrained here only because of the following Noir issue - // https://github.com/noir-lang/noir/issues/5771 storage.balances.at(from).sub(from, U128::from_integer(amount)).emit( - encode_and_encrypt_note_unconstrained(&mut context, from, from), + encode_and_encrypt_note(&mut context, from, from), ); Token::at(context.this_address())._increase_public_balance(to, amount).enqueue(&mut context); } @@ -376,22 +376,14 @@ contract Token { let amount = U128::from_integer(amount); // docs:start:increase_private_balance // docs:start:encrypted - // TODO: constrain encryption below - we are using unconstrained here only becuase of the following Noir issue - // https://github.com/noir-lang/noir/issues/5771 - storage.balances.at(from).sub(from, amount).emit(encode_and_encrypt_note_unconstrained( + storage.balances.at(from).sub(from, amount).emit(encode_and_encrypt_note( &mut context, from, from, )); // docs:end:encrypted // docs:end:increase_private_balance - // TODO: constrain encryption below - we are using unconstrained here only becuase of the following Noir issue - // https://github.com/noir-lang/noir/issues/5771 - storage.balances.at(to).add(to, amount).emit(encode_and_encrypt_note_unconstrained( - &mut context, - to, - from, - )); + storage.balances.at(to).add(to, amount).emit(encode_and_encrypt_note(&mut context, to, from)); } // docs:end:transfer_in_private @@ -403,10 +395,8 @@ contract Token { } else { assert(nonce == 0, "invalid nonce"); } - // TODO: constrain encryption below - we are using unconstrained here only becuase of the following Noir issue - // https://github.com/noir-lang/noir/issues/5771 storage.balances.at(from).sub(from, U128::from_integer(amount)).emit( - encode_and_encrypt_note_unconstrained(&mut context, from, from), + encode_and_encrypt_note(&mut context, from, from), ); Token::at(context.this_address())._reduce_total_supply(amount).enqueue(&mut context); } diff --git a/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts index d2cf242aff0..7b1aedfef2f 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/transfer_in_private.test.ts @@ -196,9 +196,7 @@ describe('e2e_token_contract transfer private', () => { .withWallet(wallets[1]) .methods.transfer_in_private(badAccount.address, accounts[1].address, 0, nonce) .send(); - await expect(txCancelledAuthwit.wait()).rejects.toThrow( - "Assertion failed: Message not authorized by account 'result == IS_VALID_SELECTOR'", - ); + await expect(txCancelledAuthwit.wait()).rejects.toThrow('Assertion failed: Message not authorized by account'); }); }); });