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: Start witness of ACIR generated by Noir start at zero not one #3887

Closed
wants to merge 3 commits into from

Conversation

vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Jan 9, 2024

Inside of Noir we have a hardcoded +1 that is a remaining leakage from how we used to convert ACIR to a barretenberg constraint system.

This PR does the necessary changes to remove the +1. I also had to change how we update the index when generating ACIR. Rather than incrementing the index and returning the incremented index, next_witness_index() is now get_current_witness_and_update() which only updates the witness index after returning the current witness index.

Checklist:

Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge.

  • If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag.
  • I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code.
  • Every change is related to the PR description.
  • I have linked this pull request to relevant issues (if any exist).

self.current_witness_index += 1;
Witness(self.current_witness_index)
next_witness_index
Copy link
Contributor

Choose a reason for hiding this comment

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

Hah wow. I've clearly spent no time looking at rust bc I thought this was an error. Can't believe this is the return syntax in rust.

@ledwards2225
Copy link
Contributor

Looks reasonable to me. Obviously we'll have to coordinate because this will break all of the acir tests but my hope is that this PR will make it easy to make things work in bberg after this change.

@vezenovm
Copy link
Contributor Author

vezenovm commented Jan 9, 2024

Looks reasonable to me. Obviously we'll have to coordinate because this will break all of the acir tests but my hope is that this PR will make it easy to make things work in bberg after this change.

Feel free to merge this branch into yours to test and perhaps we can work off of there then.

@ledwards2225 ledwards2225 mentioned this pull request Jan 10, 2024
codygunton pushed a commit that referenced this pull request Jan 10, 2024
The primary feature of this PR is a new a constructor of an UltraCircuitBuilder directly from acir-produced data (similar to the one already implemented for GoblinUltraCircuitBuilder). This pattern is necessary if we want to allow const variables to be added in builder constructors in bberg, since otherwise the explicit witness indices generated by acir are incorrectly offset. This change has the benefit of simplifying the code in `acir_format`. It also makes it easier to update bberg once the hardcoded +1 offset in noir is removed (#3887), which was previously accounted for in several undocumented places.

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge.
- [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag.
- [ ] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code.
- [ ] Every change is related to the PR description.
- [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist).
@vezenovm
Copy link
Contributor Author

Superseded by #3961

@vezenovm vezenovm closed this Jan 11, 2024
michaelelliot pushed a commit to Swoir/noir_rs that referenced this pull request Feb 28, 2024
The primary feature of this PR is a new a constructor of an UltraCircuitBuilder directly from acir-produced data (similar to the one already implemented for GoblinUltraCircuitBuilder). This pattern is necessary if we want to allow const variables to be added in builder constructors in bberg, since otherwise the explicit witness indices generated by acir are incorrectly offset. This change has the benefit of simplifying the code in `acir_format`. It also makes it easier to update bberg once the hardcoded +1 offset in noir is removed (AztecProtocol#3887), which was previously accounted for in several undocumented places.

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge.
- [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag.
- [ ] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code.
- [ ] Every change is related to the PR description.
- [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist).
@ludamad ludamad deleted the mv/start-noir-witness-at-zero branch August 22, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants