-
Notifications
You must be signed in to change notification settings - Fork 250
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
Compiler panics with Cannot flatten a dynamic array
when returning an array from memory
#4258
Labels
bug
Something isn't working
Comments
Seems to also happen on non-returned values (or might be from the fn compute_root(leaf: [u8; 32], path: [u8; 64], _index: u32, root: [u8; 32]) {
let mut current = leaf;
let mut index = _index;
for i in 0..2 {
let mut hash_input = [0; 64];
let offset = i * 32;
let is_right = (index & 1) != 0;
let a = if is_right { 32 } else { 0 };
let b = if is_right { 0 } else { 32 };
for j in 0..32 {
hash_input[j + a] = current[j];
hash_input[j + b] = path[offset + j];
}
current = sha256(hash_input);
index = index >> 1;
}
// Either of the following two lines will make it fail with `Cannot flatten a dynamic array`
// println(current);
// assert(root == current);
} On |
Yep, blackbox functions are another situation where we flatten values. |
github-merge-queue bot
pushed a commit
that referenced
this issue
Feb 13, 2024
# Description ## Problem\* Resolves #4258 ## Summary\* There are some instances where we want to flatten a single AcirValue into its AcirVars. We were operating under the assumption that we cannot flatten dynamic arrays. I have changed the `flatten` method to be on an `AcirContext` so that we can read from dynamic memory when appropriate. I have added two tests performing what is done in the issue. 1. Returning a dynamic array from main 2. Preparing a dynamic array as inputs to a black box function ## Additional Context Further investigation should be done to see if we should fully remove the `flatten()` method on `AcirValue` and move to only using the `flatten` which lives on the AcirContext. I chose to leave that for separate work though and scope this PR to just the bug fix in the issue. ## Documentation\* Check one: - [X] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [X] I have tested the changes locally. - [X] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --------- Co-authored-by: Tom French <tom@tomfren.ch>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Aim
I would like to prove the following program
Expected Behavior
This should be able to be compiled to a circuit where I write
x
into memory, write0
at indexindex
in this memory, then read out the entirety of the block of memory to form the return value.Bug
The compiler produces the SSA
acirgen then panics with
To Reproduce
Installation Method
Compiled from source
Nargo Version
noirc version = 0.23.0+bdf64ed81d7f34d6478ed9bde5b69e45d171d5f0
Additional Context
No response
Would you like to submit a PR for this Issue?
No
Support Needs
No response
The text was updated successfully, but these errors were encountered: