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

Cannot create a PublicImmutable Storage that holds an array #11159

Open
0xThemis opened this issue Jan 10, 2025 · 0 comments
Open

Cannot create a PublicImmutable Storage that holds an array #11159

0xThemis opened this issue Jan 10, 2025 · 0 comments

Comments

@0xThemis
Copy link

Version

I am using aztec-packages-v0.69.1.

Problem

The PublicImmutable Storage struct is expected to hold arbitrary data types provided as template parameters. While this functionality works for ordinary elements, like Field, it fails when attempting to use arrays such as [Field; 3]. The compiler crashes with a panic.

Steps to Reproduce

Setup inspired by the Counter Tutorial:

  1. Create a new project:
    mkdir immutable-array
    cd immutable-array
    mkdir contracts
    
  2. Create a contract:
cd contracts
aztec-nargo new --contract immutable_array
  1. Add dependencies to Nargo.toml:
[dependencies]
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="aztec-packages-v0.69.1", directory="noir-projects/aztec-nr/aztec" }
  1. Define the contract:
use dep::aztec::macros::aztec;

#[aztec]
contract ArrayPublicImmutable {
    use aztec::macros::{functions::{initializer, public}, storage::storage};
    use aztec::prelude::PublicImmutable;

    #[storage]
    struct Storage<Context> {
        state: PublicImmutable<[Field; 3], Context>,
    }

    #[initializer]
    #[public]
    fn initialize(arr: [Field; 3]) {
        storage.state.initialize(arr);
    }
}
  1. Compile the contract:
aztec-nargo compile
  1. Check the error log.
error: Assertion failed
   ┌─ std/option.nr:33:1633assert(self._is_some);
   │                -------------= Call stack:
[..omitted]
error: Could not resolve 'init' in path
   ┌─ src/main.nr:19:119 │ 
   │  
   │

error: Object type is unknown in field access
   ┌─ src/main.nr:16:1716storage.state.initialize(arr);
   │                 ----- Type must be known by this point= Try adding a type annotation for the object type before this expression

Aborting due to 3 previous errors

Expected Behavior

The PublicImmutable Storage struct should seamlessly handle arrays like [Field; 3] without any issues.

Actual Behavior

The program crashes with a panic when trying to use [Field; 3] as the parameter.

Notes

The bug occurs in noir-projects/aztec-nr/aztec/src/macros/utils.nr:227:5. Here, the program tries to compute the serialized size of the element provided as the template parameter, which apparently does not work for arrays.

I implemented a temporary fix for my use case, but someone with more expertise should address this properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant