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

Compiler panics when implementing the NoteInterface #5384

Closed
GustaveCharles opened this issue Jul 2, 2024 · 6 comments
Closed

Compiler panics when implementing the NoteInterface #5384

GustaveCharles opened this issue Jul 2, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@GustaveCharles
Copy link

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

  1. Start a new Aztec project with aztec-nargo new
  2. Copy the Aim code in main
  3. 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

@GustaveCharles GustaveCharles added the bug Something isn't working label Jul 2, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jul 2, 2024
@critesjosh
Copy link
Contributor

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.

@jfecher
Copy link
Contributor

jfecher commented Jul 2, 2024

We should avoid panicking in this case but this code is temporary and will be removed when Noir has proper macro support

@GustaveCharles
Copy link
Author

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.

@GustaveCharles
Copy link
Author

GustaveCharles commented Jul 2, 2024

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 :)

@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Jul 2, 2024
@jfecher jfecher reopened this Jul 2, 2024
@TomAFrench
Copy link
Member

fyi @Thunkar as this seems to be an issue inside aztec_macros.

@Thunkar
Copy link
Contributor

Thunkar commented Jul 22, 2024

Closing since AztecProtocol/aztec-packages#7451 adds a nicer error message while we implement NoteInterface using metaprogramming.

@Thunkar Thunkar closed this as completed Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

5 participants