noir
noir copied to clipboard
Compiler panics when implementing the NoteInterface
Aim
use dep::aztec::{
prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext},
protocol_types::{constants::GENERATOR_INDEX__NOTE_NULLIFIER, grumpkin_point::GrumpkinPoint, hash::poseidon2_hash},
note::utils::compute_note_hash_for_consumption, oracle::unsafe_rand::unsafe_rand,
keys::getters::get_nsk_app
};
global TOKEN_NOTE_LEN: Field = 3;
#[aztec(note)]
struct TokenNote {
amount: U128,
npk_m_hash: Field,
randomness: Field,
}
impl NoteInterface<TOKEN_NOTE_LEN> for TokenNote {
fn compute_nullifier(self, context: &mut PrivateContext) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = context.request_nsk_app(self.npk_m_hash);
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}
fn compute_nullifier_without_context(self) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_nsk_app(self.npk_m_hash);
poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
}
fn broadcast(self, context: &mut PrivateContext, slot: Field, ivpk_m: GrumpkinPoint) {
if !(self.amount == U128::from_integer(0)) {
context.encrypt_and_emit_note(
(*context).this_address(),
slot,
Self::get_note_type_id(),
ivpk_m,
self,
);
}
}
}
Expected Behavior
No error, the code should compile.
Bug
The application panicked (crashed).
Message: called Result::unwrap() on an Err value: ["TOKEN_NOTE_LEN"]
Location: aztec_macros/src/transforms/note_interface.rs:102
This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/. If there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml
To Reproduce
- Start a new Aztec project with aztec-nargo new
- Copy the Aim code in main
- run aztec-cargo compile
Project Impact
Blocker
Impact Context
No response
Workaround
None
Workaround Description
No response
Additional Context
No response
Installation Method
Binary (noirup default)
Nargo Version
nargo version = 0.30.0 noirc version = 0.30.0+48d9df4ff227c08a6e66f21c0286bc6349151671
NoirJS Version
No response
Would you like to submit a PR for this Issue?
None
Support Needs
No response
You are putting this code into main.nr?
You should put your contract into main.nr and import any new types into your contract. You can see the token contract folder for an example.
We should avoid panicking in this case but this code is temporary and will be removed when Noir has proper macro support
You are putting this code into main.nr?
You should put your contract into main.nr and import any new types into your contract. You can see the token contract folder for an example.
I put it in main for example purposes. Putting it in a folder gives the same error.
We should avoid panicking in this case but this code is temporary and will be removed when Noir has proper macro support
The problem on my side was that I didn't pass the second generic parameter to the NoteInterface. A better error message could also be useful :)
fyi @Thunkar as this seems to be an issue inside aztec_macros.
Closing since https://github.com/AztecProtocol/aztec-packages/pull/7451 adds a nicer error message while we implement NoteInterface using metaprogramming.