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

#[no_predicates] makes compiler panic if used within a brillig function #5010

Closed
sirasistant opened this issue May 10, 2024 · 1 comment · Fixed by #5012
Closed

#[no_predicates] makes compiler panic if used within a brillig function #5010

sirasistant opened this issue May 10, 2024 · 1 comment · Fixed by #5012
Labels
bug Something isn't working

Comments

@sirasistant
Copy link
Contributor

sirasistant commented May 10, 2024

Aim

Using no_predicates in a poseidon function to make it more performant in acir, but also use it in unconstrained functions.

Expected Behavior

It should compile

Bug

The application panicked (crashed).
Message:  not yet implemented: enable_side_effects not supported by brillig
Location: compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs:701

To Reproduce

use dep::std::hash::{pedersen_hash_with_separator, poseidon2::Poseidon2};

global NUM_HASHES = 2;
global HASH_LENGTH = 10;

#[no_predicates]
pub fn poseidon_hash<N>(inputs: [Field; N]) -> Field {
    Poseidon2::hash(inputs, inputs.len())
}

unconstrained fn main(
    to_hash: [[Field; HASH_LENGTH]; NUM_HASHES],
    enable: [bool; NUM_HASHES]
) -> pub [Field; NUM_HASHES + 1] {
    let mut result = [0; NUM_HASHES + 1];
    for i in 0..NUM_HASHES {
        let enable = enable[i];
        let to_hash = to_hash[i];
        if enable {
            result[i] = poseidon_hash(to_hash);
        }
    }

    // We want to make sure that the function marked with `#[no_predicates]` with a numeric generic
    // is monomorphized correctly.
    let mut double_preimage = [0; 20];
    for i in 0..HASH_LENGTH * 2 {
        double_preimage[i] = to_hash[0][i % HASH_LENGTH];
    }
    result[NUM_HASHES] = poseidon_hash(double_preimage);

    result
}

Project Impact

None

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

No response

Installation Method

None

Nargo Version

No response

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@sirasistant sirasistant added the bug Something isn't working label May 10, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir May 10, 2024
@sirasistant
Copy link
Contributor Author

sirasistant commented May 10, 2024

This is caused because the inliner leaves the poseidon_hash acir function existing since it's no predicates, and then it's flattened. But a flattened function isn't convertible to brillig, so brillig_gen fails trying to generate brillig code for it

github-merge-queue bot pushed a commit that referenced this issue May 10, 2024
# Description

## Problem\*

Resolves #5010

## Summary\*

Ignores no predicates for brillig functions to avoid trying to convert
to brillig flattened functions.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** 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.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir May 10, 2024
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

Successfully merging a pull request may close this issue.

1 participant