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

Artifact Generation broken when you have the Token Contract as a Dependency in Nargo.toml #8532

Closed
Cheetah0x opened this issue Sep 13, 2024 · 2 comments · Fixed by #8880
Closed

Comments

@Cheetah0x
Copy link

Bug Report: Incorrect Contract Storage Layout Generated with Token Dependency

Aztec Version: v0.54.0
Repo for Replication: aztec-artifact-bug

Bug Description

When adding the token contract as a dependency in Nargo.toml, without actually importing or using it in the contract, the generated Contract Storage Layout reflects the storage of the token contract instead of the contract being worked on.

In the provided example, the simple counter contract should have the following storage layout in the generated TypeScript artifact:

public static get storage(): ContractStorageLayout<'counters'> {
  return {
    counters: {
      slot: new Fr(1n),
    },
  } as ContractStorageLayout<'counters'>;
}

However, when adding the token contract as a dependency in Nargo.toml, without importing it in the contract, the storage layout that is generated incorrectly maps to the storage slots of the token contract:

public static get storage(): ContractStorageLayout<'admin' | 'minters' | 'balances' | 'total_supply' | 'pending_shields' | 'public_balances' | 'symbol' | 'name' | 'decimals'> {
  return {
    admin: {
      slot: new Fr(1n),
    },
    minters: {
      slot: new Fr(2n),
    },
    balances: {
      slot: new Fr(3n),
    },
    total_supply: {
      slot: new Fr(4n),
    },
    pending_shields: {
      slot: new Fr(5n),
    },
    public_balances: {
      slot: new Fr(6n),
    },
    symbol: {
      slot: new Fr(7n),
    },
    name: {
      slot: new Fr(8n),
    },
    decimals: {
      slot: new Fr(9n),
    },
  } as ContractStorageLayout<'admin' | 'minters' | 'balances' | 'total_supply' | 'pending_shields' | 'public_balances' | 'symbol' | 'name' | 'decimals'>;
}

Steps to Reproduce

Clone the repo: aztec-artifact-bug.
Check the Nargo.toml file where the token contract is added as a dependency but not imported in the contract.

Compile the contract using:

aztec-nargo compile
aztec codegen -o src/artifacts target

Observe the incorrect storage layout in the generated TypeScript artifact.

Expected Behavior
The generated storage layout should match the contract being worked on (e.g., the simple counter contract) and not the token contract when it’s merely a dependency in Nargo.toml but not actually imported.

@benesjan
Copy link
Contributor

This is related to aztec macros and we are soon about to migrate them all to meta programming (should be by next week). Once that is in master I will investigate whether this bug pertains.

@Cheetah0x Thanks for reporting the bug!

@benesjan
Copy link
Contributor

I confirm that the bug pertains after the macro migration. Updated the reproduction repo with the new version in this fork.

The reproduction was very easy to follow. Thanks again @Cheetah0x

@github-project-automation github-project-automation bot moved this from Todo to Done in A3 Sep 30, 2024
AztecBot pushed a commit to AztecProtocol/aztec-nr that referenced this issue Oct 1, 2024
Closes: AztecProtocol/aztec-packages#8532

Includes the contract name in the exported storage layout, so that the
artifact generator can distinguish between main and dependent contracts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants