acvm_blackbox_solver/
curve_specific_solver.rs

1use acir::BlackBoxFunc;
2
3use crate::BlackBoxResolutionError;
4
5/// This component will generate outputs for Blackbox function calls where the underlying [`acir::BlackBoxFunc`]
6/// doesn't have a canonical Rust implementation.
7///
8/// Returns an [`BlackBoxResolutionError`] if the backend does not support the given [`acir::BlackBoxFunc`].
9pub trait BlackBoxFunctionSolver<F> {
10    fn multi_scalar_mul(
11        &self,
12        points: &[F],
13        scalars_lo: &[F],
14        scalars_hi: &[F],
15        predicate: bool,
16    ) -> Result<(F, F), BlackBoxResolutionError>;
17
18    fn ec_add(
19        &self,
20        input1_x: &F,
21        input1_y: &F,
22        input2_x: &F,
23        input2_y: &F,
24        predicate: bool,
25    ) -> Result<(F, F), BlackBoxResolutionError>;
26
27    fn poseidon2_permutation(&self, inputs: &[F]) -> Result<Vec<F>, BlackBoxResolutionError>;
28}
29pub struct StubbedBlackBoxSolver;
30
31impl StubbedBlackBoxSolver {
32    fn fail(black_box_function: BlackBoxFunc) -> BlackBoxResolutionError {
33        BlackBoxResolutionError::Failed(
34            black_box_function,
35            format!("{} is not supported", black_box_function.name()),
36        )
37    }
38}
39
40impl<F> BlackBoxFunctionSolver<F> for StubbedBlackBoxSolver {
41    fn multi_scalar_mul(
42        &self,
43        _points: &[F],
44        _scalars_lo: &[F],
45        _scalars_hi: &[F],
46        _predicate: bool,
47    ) -> Result<(F, F), BlackBoxResolutionError> {
48        Err(Self::fail(BlackBoxFunc::MultiScalarMul))
49    }
50    fn ec_add(
51        &self,
52        _input1_x: &F,
53        _input1_y: &F,
54        _input2_x: &F,
55        _input2_y: &F,
56        _predicate: bool,
57    ) -> Result<(F, F), BlackBoxResolutionError> {
58        Err(Self::fail(BlackBoxFunc::EmbeddedCurveAdd))
59    }
60    fn poseidon2_permutation(&self, _inputs: &[F]) -> Result<Vec<F>, BlackBoxResolutionError> {
61        Err(Self::fail(BlackBoxFunc::Poseidon2Permutation))
62    }
63}