Skip to content

Commit

Permalink
fix: using correct length in storage slot allocation (#11601)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Jan 30, 2025
1 parent 1c7d208 commit 7f802a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/macros/storage/mod.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::umap::UHashMap, hash::{BuildHasherDefault, poseidon2::Poseidon2Hasher}};

use super::utils::get_serialized_size;
use super::utils::get_packed_size;
use super::utils::is_note;

/// Stores a map from a module to the name of the struct that describes its storage layout.
Expand Down Expand Up @@ -135,7 +135,7 @@ comptime fn generate_storage_field_constructor(
// TODO(#8659): remove the PublicMutable exception above
1
} else {
get_serialized_size(stored_struct)
get_packed_size(stored_struct)
}
};

Expand Down
15 changes: 7 additions & 8 deletions noir-projects/aztec-nr/aztec/src/macros/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,15 @@ pub(crate) comptime fn compute_event_selector(s: StructDefinition) -> Field {
unquote!(computation_quote)
}

pub(crate) comptime fn get_serialized_size(typ: Type) -> u32 {
pub(crate) comptime fn get_packed_size(typ: Type) -> u32 {
let any = fresh_type_variable();
let maybe_serialize_impl =
typ.get_trait_impl(quote { protocol_types::traits::Serialize<$any> }.as_trait_constraint());
let maybe_packed_impl =
typ.get_trait_impl(quote { protocol_types::traits::Packable<$any> }.as_trait_constraint());

maybe_serialize_impl
.expect(
f"Attempted to fetch serialization length, but {typ} does not implement the Serialize trait",
)
.trait_generic_args()[0]
maybe_packed_impl
.expect(f"Attempted to fetch packed length, but {typ} does not implement the Packable trait"
)
.trait_generic_args()[0]
.as_constant()
.unwrap()
}
Expand Down
3 changes: 0 additions & 3 deletions noir-projects/aztec-nr/value-note/src/value_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ use dep::aztec::{
pub(crate) global VALUE_NOTE_LEN: u32 = 3; // 3 plus a header.

// docs:start:value-note-def
// ValueNote is used as fn parameter in the Claim contract, so it has to implement the Serialize trait.
// It is important that the order of these annotations is preserved so that derive(Serialize) runs AFTER the note macro, which injects the note header.
#[note]
#[derive(Serialize)]
pub struct ValueNote {
value: Field,
owner: AztecAddress,
Expand Down

0 comments on commit 7f802a4

Please sign in to comment.