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

'internal error: entered unreachable code: Cannot flatten a dynamic array' when adding if #3817

Closed
0xShaito opened this issue Dec 15, 2023 · 3 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@0xShaito
Copy link

Aim

Sometimes adding some if statements leads to more checks needed on notes or it fails compiling with:

'internal error: entered unreachable code: Cannot flatten a dynamic array'.

This is fixed by utilizing the Aztec note ONLY inside an if statement that checks that the note exists:

Works:

    let options = NoteGetterOptions::new().select(1, from.address).set_limit(1);
    let note = stored_set.get_notes(options)[0];
    if (note .is_some()) {
        stored_set.remove(note.unwrap_unchecked()); 
    }

Doesn't work:

    let options = NoteGetterOptions::new().select(1, from.address).set_limit(1);
    let note = stored_set.get_notes(options)[0];
    assert(note.is_some());
    stored_set.remove(note.unwrap_unchecked()); 

Expected Behavior

Asserting that the note exists should be the same as using it inside an if statement.

Even if the note is not asserted, the error should be more expressive into what the actual issue is.

Bug

Code:

https://github.com/drgorillamd/aztec-big-gist/tree/feat/array-in-struct/src

Error:

'internal error: entered unreachable code: Cannot flatten a dynamic array'

This bug only happens when adding if statements. In the code sent, removing the if from the start of the function makes the contract compile:

        if (from.address != context.msg_sender()) { // commenting out this fixes compilation
            assert_current_call_valid_authwit(&mut context, from);
        } 

To Reproduce

Repo with the reproduction: https://github.com/drgorillamd/aztec-big-gist/tree/feat/array-in-struct/src

Installation Method

None

Nargo Version

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@0xShaito 0xShaito added the bug Something isn't working label Dec 15, 2023
@kevaundray kevaundray added this to the 0.24.0 milestone Jan 15, 2024
@Savio-Sou Savio-Sou modified the milestones: 0.24, 0.25 Feb 9, 2024
@vezenovm
Copy link
Contributor

vezenovm commented Feb 15, 2024

Would you be able to provide a smaller more up-to-date example? We recently had a fix that I think is related to this issue but the project is using compiler version 0.18.0 and old versions of aztec-nr so it is difficult to reproduce.

Also if you could post a more full stack trace that would be very helpful.

@drgorillamd
Copy link

Hey @vezenovm I just updated that branch to use 0.24.0 and confirm this still happens.

I included some comments with more context in main.nr, hit me up if I can help you further/you need more context

@vezenovm
Copy link
Contributor

@drgorillamd Thank you for the update! I'm assuming you are using 0.24.0 of aztec-packages. The recent fix has not yet been released but it is on master. I can successfully compile the supplied contract with the fix on master. Going to close this issue as it has been fixed but please do re-open it if after the release you are still running into issues.

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