From 518ab6227420971a3310e5e6b412f7a9efeec9c1 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 18 Feb 2025 11:33:37 +0000 Subject: [PATCH] bug fix --- noir-projects/aztec-nr/aztec/src/macros/mod.nr | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/macros/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/mod.nr index ab95d159263e..bad9eff471a3 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/mod.nr @@ -15,8 +15,6 @@ use utils::module_has_storage; global NOTE_INTERFACE: TraitConstraint = quote { crate::note::note_interface::NoteInterface }.as_trait_constraint(); -global PACKABLE: TraitConstraint = - quote { crate::protocol_types::traits::Packable<_> }.as_trait_constraint(); /// Marks a contract as an Aztec contract, generating the interfaces for its functions and notes, as well as injecting /// the `compute_note_hash_and_optionally_a_nullifier` function PXE requires in order to validate notes. @@ -148,7 +146,13 @@ comptime fn generate_compute_note_hash_and_optionally_a_nullifier() -> Quoted { )[0] .as_typed_expr(); - let unpack = typ.get_trait_impl(PACKABLE).unwrap().methods().filter(|m| { + // We obtain the packable trait constraint here rather than storing it as a global variable. This is because + // the trait has a generic parameter that gets matched on first use. If we used a global variable, we would + // fail to get trait implementations for types that don't match the already-matched generic parameter. + let packable: TraitConstraint = + quote { crate::protocol_types::traits::Packable<_> }.as_trait_constraint(); + + let unpack = typ.get_trait_impl(packable).unwrap().methods().filter(|m| { m.name() == quote { unpack } })[0] .as_typed_expr(); @@ -253,7 +257,13 @@ comptime fn generate_process_log() -> Quoted { })[0] .as_typed_expr(); - let unpack = typ.get_trait_impl(PACKABLE).unwrap().methods().filter(|m| { + // We obtain the packable trait constraint here rather than storing it as a global variable. This is because + // the trait has a generic parameter that gets matched on first use. If we used a global variable, we would + // fail to get trait implementations for types that don't match the already-matched generic parameter. + let packable: TraitConstraint = + quote { crate::protocol_types::traits::Packable<_> }.as_trait_constraint(); + + let unpack = typ.get_trait_impl(packable).unwrap().methods().filter(|m| { m.name() == quote { unpack } })[0] .as_typed_expr();