Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

feat: Solve Keccak opcodes #247

Closed
wants to merge 4 commits into from
Closed

feat: Solve Keccak opcodes #247

wants to merge 4 commits into from

Conversation

guipublic
Copy link
Contributor

Related issue(s)

Related to (noir-lang/noir#1189)

Description

Summary of changes

Solve Keccak opcodes

Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt with default settings.
  • I have linked this PR to the issue(s) that it resolves.
  • I have reviewed the changes on GitHub, line by line.
  • I have ensured all changes are covered in the description.

@guipublic guipublic changed the title Gd/keccak2 feat: Solve Keccak opcodes Apr 28, 2023
acvm/src/pwg/hash.rs Outdated Show resolved Hide resolved
generic_sha3::<Keccak256>(initial_witness, gadget_call)
}

fn generic_sha3<D: sha3::Digest>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same Digest trait as used by generic_hash_256 so we don't need a duplicate implementation ( you may need to adjust versions of dependencies)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not the same because the two crates do not use the same version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, you'll need to adjust the dependency version for the blake2 crate to match.

Comment on lines +127 to +132
let status = solve_black_box_function(initial_witness, bb_func);
if matches!(status, Err(OpcodeResolutionError::OpcodeNotSolvable(_))) {
self.solve_black_box_function_call(initial_witness, bb_func)
} else {
status
}
Copy link
Member

@TomAFrench TomAFrench Apr 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unrelated to supporting keccak opcodes and has significant knock on effects for all backends so shouldn't be included in this PR.

This change is breaking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is a breaking change, what is broken?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's changing the contract between backends and ACVM.

Previously ACVM provided reference methods for executing black box functions to the backends however backends were in charge of solving the black box function and returning the result. After this change this is still the case for all other opcodes but we'll never send keccak256 in particular to the backend.

This split between keccak256 and all the other functions doesn't make sense and we shouldn't split responsibility for black box function execution between the backend and the ACVM. Until we have a rust implementation of all black box functions then we should allow the backend to handle this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in fact this is not breaking anything.
Solving Keccak in ACVM does make sense, as well as all other 'blackbox'. I will move the solving into ACVM for all but pedersen, which will still be handled by the backend until we have a rust implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change would mean that a lot of code in aztec_backend would become dead code without us actually realizing it. The backend has a match on all black box functions but those code paths would never be executed.

This could lead to confusing bugs between Noir and the backend and it seems hard to communicate to backend implementors.

I'm torn on where this should happen because I don't want aztec_backend to implement keccak itself 😬 I'd probably be fine making a separate PR for this change, just so we can mark it breaking and have a clear CHANGELOG entry. @TomAFrench thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course we would remove the dead code as long as it is integrated in ACVM, so I don't see this as an issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course we would remove the dead code as long as it is integrated in ACVM, so I don't see this as an issue.

This assumes that we are in control of all the backends, but we need to develop as though there are other backends that need to integrate ACVM and they will be confused without accurate documentation & changelog entries.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could land something like #257 before this and then it wouldn't be an issue.

@kevaundray
Copy link
Contributor

I'm not a fan of PRs that don't say what they do in the title, since it makes it harder to find where changes happened and why and it also invites feature creap into PRs.

Lets just add Keccak into this PR exactly like how it is done for other functions, then any other changes can be done in a separate PR and discussed.

@TomAFrench
Copy link
Member

Closing this as it's been superceded by #259 and #264

@TomAFrench TomAFrench closed this May 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants