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

chore: removing noir bug workaround #10535

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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<Note, let N: u32>(
context: &mut PrivateContext,
recipient: AztecAddress,
Expand Down
3 changes: 3 additions & 0 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ fn compute_encrypted_log<let P: u32, let M: u32>(
// 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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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]
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down
24 changes: 7 additions & 17 deletions noir-projects/noir-contracts/contracts/token_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why I needed to do this change (was getting a failing test, see screenshot). But it seems inconsequential so would not worry about it. I think it might have something to do with us pruning the debug metadata from contracts artifacts or smt.

image

});
});
});
Loading