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

fix(frontend): Correctly monomorphize turbofish functions #5049

Merged
merged 66 commits into from
May 21, 2024

Conversation

vezenovm
Copy link
Contributor

Description

Problem*

Resolves

Working towards #4514 and fully resolving #4710

Summary*

We need to accurately monomorphize functions with turbofish operators where no function parameters or the return type using the specified generic.

Without this change the following would pass:

fn main(x: Field, y: pub Field) {
    let mut hasher = PoseidonHasher::default();
    hasher.write(x);
    hasher.write(y);
    let poseidon_expected_hash = hasher.finish();
    assert(hash_simple_array::<PoseidonHasher>([x, y]) == poseidon_expected_hash);

    let mut hasher = Poseidon2Hasher::default();
    hasher.write(x);
    hasher.write(y);
    let poseidon2_expected_hash = hasher.finish();
    assert(hash_simple_array::<Poseidon2Hasher>([x, y]) == poseidon_expected_hash);
    assert(hash_simple_array::<Poseidon2Hasher>([x, y]) != poseidon2_expected_hash);
}

fn hash_simple_array<H>(input: [Field; 2]) -> Field where H: Hasher + Default {
    let mut hasher: H = H::default();
    hasher.write(input[0]);
    hasher.write(input[1]);
    hasher.finish()
}

Essentially any future invocations of hash_simple_array would use the PoseidonHasher. We now correctly monomorphize the functions to use the correct type.

Additional Context

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

jfecher and others added 30 commits November 21, 2023 15:26
* master: (120 commits)
  feat: allow passing custom foreign call handlers when creating proofs in NoirJS (#3764)
  fix: add missing assertion to test (#3765)
  chore: re-export the items needed for the lsp from the fm crate instead of importing codespan_reporting (#3757)
  chore: remove special casing for `pedersen_hash` black box function (#3744)
  chore: remove extraneous dbg statement (#3761)
  chore: fix un-needed fully qualified path (#3755)
  feat: aztec-packages (#3754)
  feat: allow underscores in integer literals (#3746)
  fix: deserialize odd length hex literals (#3747)
  feat: optimize out unnecessary truncation instructions (#3717)
  chore: use `tsx` instead of `ts-node` for `noir_js` (#3750)
  chore(ci): fail `tests-end` job if any dependants failed (#3737)
  chore: allow common ascii punctuation in attributes (#3733)
  chore: fix broken onboarding link in README (#3732)
  feat: Dockerfile to test cargo and JS packages (#3684)
  feat(lsp): add goto definition for locals (#3705)
  feat: docs landing page with a playground (#3667)
  fix: `try_unify` no longer binds types on failure (#3697)
  fix: parse negative integer literals (#3698)
  fix: unsigned integers cannot be negated (#3688)
  ...
Base automatically changed from mv/trait-method-reference to master May 21, 2024 18:40
@vezenovm vezenovm added this pull request to the merge queue May 21, 2024
Merged via the queue into master with commit fd772e7 May 21, 2024
41 checks passed
@vezenovm vezenovm deleted the mv/turbofish-monomorphize-fix branch May 21, 2024 19:27
github-merge-queue bot pushed a commit that referenced this pull request May 21, 2024
# Description

## Problem\*

Resolves #4514 

## Summary\*

This updates `eddsa_verify_with_hasher` to have the following signature
now that we support the turbofish operator:
```rust
pub fn eddsa_verify_with_hasher<H>(
    pub_key_x: Field,
    pub_key_y: Field,
    signature_s: Field,
    signature_r8_x: Field,
    signature_r8_y: Field,
    message: Field
) -> bool 
where H: Hasher + Default {
  [function body ...]
}
``` 
This re-work was only possible with further bug fixes from
#5049 and
#5041. The original turbofish PR
can be found here (#3542).

## Additional Context

This PR can most likely be merged into its parent #5049 but I just made
this separate PR to separate the bug fix and the stdlib library breaking
change.

## Documentation\*

Check one:
- [ ] No documentation needed.
- [x] 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.

---------

Co-authored-by: Jake Fecher <jake@aztecprotocol.com>
Co-authored-by: Jake Fecher <jfecher11@gmail.com>
Co-authored-by: Tom French <tom@tomfren.ch>
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request May 23, 2024
chore: automatically clear any unwanted directories in `test_programs` (noir-lang/noir#5081)
chore: update `nargo info` table to remove circuit size column
feat: Activate return_data in ACIR opcodes (noir-lang/noir#5080)
fix: Use plain integer addresses for opcodes in DAP disassembly view (noir-lang/noir#4941)
chore(experimental): Elaborate globals (noir-lang/noir#5069)
chore(experimental): Add types and traits to the elaborator (noir-lang/noir#5066)
feat: remove conditional compilation of `bn254_blackbox_solver` (noir-lang/noir#5058)
chore: use `bbup` to install `bb` (noir-lang/noir#5073)
feat: Sync from aztec-packages (noir-lang/noir#5070)
chore: update docs to represent zksync supporting necessary precompiles (noir-lang/noir#5071)
feat(stdlib)!: eddsa function using turbofish (noir-lang/noir#5050)
fix(frontend): Correctly monomorphize turbofish functions (noir-lang/noir#5049)
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request May 27, 2024
…r-lang/noir#5097)

chore(docs): Link to evmdiff for supported EVM chains (noir-lang/noir#5107)
chore: Avoid creating witness for simple multiplications (noir-lang/noir#5100)
feat: Add intrinsic to get if running inside an unconstrained context (noir-lang/noir#5098)
chore: Move turbofish changes to the elaborator (noir-lang/noir#5094)
fix: Apply self type from generic trait constraint before instantiating identifiers (noir-lang/noir#5087)
chore: reactivate gates report (noir-lang/noir#5084)
chore: automatically clear any unwanted directories in `test_programs` (noir-lang/noir#5081)
chore: update `nargo info` table to remove circuit size column
feat: Activate return_data in ACIR opcodes (noir-lang/noir#5080)
fix: Use plain integer addresses for opcodes in DAP disassembly view (noir-lang/noir#4941)
chore(experimental): Elaborate globals (noir-lang/noir#5069)
chore(experimental): Add types and traits to the elaborator (noir-lang/noir#5066)
feat: remove conditional compilation of `bn254_blackbox_solver` (noir-lang/noir#5058)
chore: use `bbup` to install `bb` (noir-lang/noir#5073)
feat: Sync from aztec-packages (noir-lang/noir#5070)
chore: update docs to represent zksync supporting necessary precompiles (noir-lang/noir#5071)
feat(stdlib)!: eddsa function using turbofish (noir-lang/noir#5050)
fix(frontend): Correctly monomorphize turbofish functions (noir-lang/noir#5049)
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request May 27, 2024
…5097)

chore(docs): Link to evmdiff for supported EVM chains (noir-lang/noir#5107)
chore: Avoid creating witness for simple multiplications (noir-lang/noir#5100)
feat: Add intrinsic to get if running inside an unconstrained context (noir-lang/noir#5098)
chore: Move turbofish changes to the elaborator (noir-lang/noir#5094)
fix: Apply self type from generic trait constraint before instantiating identifiers (noir-lang/noir#5087)
chore: reactivate gates report (noir-lang/noir#5084)
chore: automatically clear any unwanted directories in `test_programs` (noir-lang/noir#5081)
chore: update `nargo info` table to remove circuit size column
feat: Activate return_data in ACIR opcodes (noir-lang/noir#5080)
fix: Use plain integer addresses for opcodes in DAP disassembly view (noir-lang/noir#4941)
chore(experimental): Elaborate globals (noir-lang/noir#5069)
chore(experimental): Add types and traits to the elaborator (noir-lang/noir#5066)
feat: remove conditional compilation of `bn254_blackbox_solver` (noir-lang/noir#5058)
chore: use `bbup` to install `bb` (noir-lang/noir#5073)
feat: Sync from aztec-packages (noir-lang/noir#5070)
chore: update docs to represent zksync supporting necessary precompiles (noir-lang/noir#5071)
feat(stdlib)!: eddsa function using turbofish (noir-lang/noir#5050)
fix(frontend): Correctly monomorphize turbofish functions (noir-lang/noir#5049)
sirasistant added a commit to AztecProtocol/aztec-packages that referenced this pull request May 27, 2024
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
feat: Consider block parameters in variable liveness
(noir-lang/noir#5097)
chore(docs): Link to evmdiff for supported EVM chains
(noir-lang/noir#5107)
chore: Avoid creating witness for simple multiplications
(noir-lang/noir#5100)
feat: Add intrinsic to get if running inside an unconstrained context
(noir-lang/noir#5098)
chore: Move turbofish changes to the elaborator
(noir-lang/noir#5094)
fix: Apply self type from generic trait constraint before instantiating
identifiers (noir-lang/noir#5087)
chore: reactivate gates report
(noir-lang/noir#5084)
chore: automatically clear any unwanted directories in `test_programs`
(noir-lang/noir#5081)
chore: update `nargo info` table to remove circuit size column
feat: Activate return_data in ACIR opcodes
(noir-lang/noir#5080)
fix: Use plain integer addresses for opcodes in DAP disassembly view
(noir-lang/noir#4941)
chore(experimental): Elaborate globals
(noir-lang/noir#5069)
chore(experimental): Add types and traits to the elaborator
(noir-lang/noir#5066)
feat: remove conditional compilation of `bn254_blackbox_solver`
(noir-lang/noir#5058)
chore: use `bbup` to install `bb`
(noir-lang/noir#5073)
feat: Sync from aztec-packages
(noir-lang/noir#5070)
chore: update docs to represent zksync supporting necessary precompiles
(noir-lang/noir#5071)
feat(stdlib)!: eddsa function using turbofish
(noir-lang/noir#5050)
fix(frontend): Correctly monomorphize turbofish functions
(noir-lang/noir#5049)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: sirasistant <sirasistant@gmail.com>
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

Successfully merging this pull request may close these issues.

None yet

3 participants