-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add back Pedersen blackbox functions (revert PR 5221) (#5318)
# Description ## Problem\* This PR adds (back) the blackbox functions for Pedersen hash/commitment, until we get a similar circuit (in term of number of gates) with the Noir implementation. ## Summary\* The Noir version is kept and assert to ouput the same value in a test. ## Additional Context This PR reverts the PR #5221 ## 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. --------- Co-authored-by: Tom French <tom@tomfren.ch> Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
- Loading branch information
1 parent
b859ef9
commit f2f8ecc
Showing
17 changed files
with
309 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use acir::{ | ||
circuit::opcodes::FunctionInput, | ||
native_types::{Witness, WitnessMap}, | ||
AcirField, | ||
}; | ||
|
||
use crate::{ | ||
pwg::{insert_value, witness_to_value, OpcodeResolutionError}, | ||
BlackBoxFunctionSolver, | ||
}; | ||
|
||
pub(super) fn pedersen<F: AcirField>( | ||
backend: &impl BlackBoxFunctionSolver<F>, | ||
initial_witness: &mut WitnessMap<F>, | ||
inputs: &[FunctionInput], | ||
domain_separator: u32, | ||
outputs: (Witness, Witness), | ||
) -> Result<(), OpcodeResolutionError<F>> { | ||
let scalars: Result<Vec<_>, _> = | ||
inputs.iter().map(|input| witness_to_value(initial_witness, input.witness)).collect(); | ||
let scalars: Vec<_> = scalars?.into_iter().cloned().collect(); | ||
|
||
let (res_x, res_y) = backend.pedersen_commitment(&scalars, domain_separator)?; | ||
|
||
insert_value(&outputs.0, res_x, initial_witness)?; | ||
insert_value(&outputs.1, res_y, initial_witness)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub(super) fn pedersen_hash<F: AcirField>( | ||
backend: &impl BlackBoxFunctionSolver<F>, | ||
initial_witness: &mut WitnessMap<F>, | ||
inputs: &[FunctionInput], | ||
domain_separator: u32, | ||
output: Witness, | ||
) -> Result<(), OpcodeResolutionError<F>> { | ||
let scalars: Result<Vec<_>, _> = | ||
inputs.iter().map(|input| witness_to_value(initial_witness, input.witness)).collect(); | ||
let scalars: Vec<_> = scalars?.into_iter().cloned().collect(); | ||
|
||
let res = backend.pedersen_hash(&scalars, domain_separator)?; | ||
|
||
insert_value(&output, res, initial_witness)?; | ||
|
||
Ok(()) | ||
} |
This file contains 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 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 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 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 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 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
Oops, something went wrong.