-
Notifications
You must be signed in to change notification settings - Fork 388
chore: use witnesses from the generated acir in the ABI #2095
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,36 @@ | ||
| use std::collections::BTreeMap; | ||
|
|
||
| use acvm::acir::native_types::Witness; | ||
| use iter_extended::{btree_map, vecmap}; | ||
| use iter_extended::btree_map; | ||
| use noirc_abi::{Abi, AbiParameter, FunctionSignature}; | ||
|
|
||
| /// Arranges a function signature and a generated circuit's return witnesses into a | ||
| /// `noirc_abi::Abi`. | ||
| pub(crate) fn gen_abi(func_sig: FunctionSignature, return_witnesses: Vec<Witness>) -> Abi { | ||
| pub(crate) fn gen_abi( | ||
| func_sig: FunctionSignature, | ||
| input_witnesses: &[Witness], | ||
| return_witnesses: Vec<Witness>, | ||
| ) -> Abi { | ||
| let (parameters, return_type) = func_sig; | ||
| let param_witnesses = param_witnesses_from_abi_param(¶meters); | ||
| let param_witnesses = param_witnesses_from_abi_param(¶meters, input_witnesses); | ||
| Abi { parameters, return_type, param_witnesses, return_witnesses } | ||
| } | ||
|
|
||
| // Takes each abi parameter and shallowly maps to the expected witness range in which the | ||
| // parameter's constituent values live. | ||
| fn param_witnesses_from_abi_param( | ||
| abi_params: &Vec<AbiParameter>, | ||
| input_witnesses: &[Witness], | ||
| ) -> BTreeMap<String, Vec<Witness>> { | ||
| let mut offset = 1; | ||
| let mut idx = 0_usize; | ||
|
|
||
| btree_map(abi_params, |param| { | ||
| let num_field_elements_needed = param.typ.field_count(); | ||
| let idx_start = offset; | ||
| let idx_end = idx_start + num_field_elements_needed; | ||
| let witnesses = vecmap(idx_start..idx_end, Witness); | ||
| offset += num_field_elements_needed; | ||
| (param.name.clone(), witnesses) | ||
| let mut wit = Vec::new(); | ||
| for _ in 0..num_field_elements_needed { | ||
| wit.push(input_witnesses[idx]); | ||
| idx += 1; | ||
| } | ||
| (param.name.clone(), wit) | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.