@@ -4,15 +4,14 @@ use acvm::{
4
4
acir:: {
5
5
acir_field:: GenericFieldElement ,
6
6
circuit:: { brillig:: BrilligBytecode , Circuit , Opcode , Program } ,
7
- native_types:: Witness ,
7
+ native_types:: { Witness , WitnessMap } ,
8
8
} ,
9
+ blackbox_solver:: StubbedBlackBoxSolver ,
10
+ pwg:: ACVM ,
9
11
AcirField ,
10
12
} ;
11
13
use ark_ff:: Field ;
12
- use ark_relations:: {
13
- lc,
14
- r1cs:: { ConstraintSynthesizer , LinearCombination , Variable } ,
15
- } ;
14
+ use ark_relations:: r1cs:: { ConstraintSynthesizer , LinearCombination , Variable } ;
16
15
use serde:: { Deserialize , Serialize } ;
17
16
18
17
use super :: * ;
@@ -38,6 +37,43 @@ impl NoirProgram {
38
37
pub fn unconstrained_functions ( & self ) -> & Vec < BrilligBytecode < GenericFieldElement < Fr > > > {
39
38
& self . bytecode . unconstrained_functions
40
39
}
40
+
41
+ pub fn solve (
42
+ & self ,
43
+ instance_variables : & [ Fr ] ,
44
+ witness_variables : & [ Fr ] ,
45
+ ) -> WitnessMap < GenericFieldElement < Fr > > {
46
+ let mut acvm = ACVM :: new (
47
+ & StubbedBlackBoxSolver ( false ) ,
48
+ & self . circuit ( ) . opcodes ,
49
+ WitnessMap :: new ( ) ,
50
+ self . unconstrained_functions ( ) ,
51
+ & [ ] ,
52
+ ) ;
53
+
54
+ self . circuit ( )
55
+ . public_parameters
56
+ . 0
57
+ . iter ( )
58
+ . for_each ( |witness| {
59
+ let f =
60
+ GenericFieldElement :: < Fr > :: from_repr ( instance_variables[ witness. as_usize ( ) ] ) ;
61
+ acvm. overwrite_witness ( * witness, f) ;
62
+ } ) ;
63
+
64
+ // write witness values for external_inputs
65
+ self . circuit ( )
66
+ . private_parameters
67
+ . iter ( )
68
+ . for_each ( |witness| {
69
+ let idx = witness. as_usize ( ) - instance_variables. len ( ) ;
70
+
71
+ let f = GenericFieldElement :: < Fr > :: from_repr ( witness_variables[ idx] ) ;
72
+ acvm. overwrite_witness ( * witness, f) ;
73
+ } ) ;
74
+ let _status = acvm. solve ( ) ;
75
+ acvm. finalize ( )
76
+ }
41
77
}
42
78
43
79
impl ConstraintSynthesizer < Fr > for NoirProgram {
@@ -53,12 +89,12 @@ impl ConstraintSynthesizer<Fr> for NoirProgram {
53
89
54
90
// Then, allocate known private witnesses
55
91
let private_params = & self . circuit ( ) . private_parameters ;
56
- for & witness in private_params. iter ( ) {
92
+ for & witness in private_params {
57
93
let var = cs. new_witness_variable ( || Ok ( Fr :: ZERO ) ) ?;
58
94
witness_map. insert ( witness, var) ;
59
95
}
60
96
61
- for opcode in self . circuit ( ) . opcodes . iter ( ) {
97
+ for opcode in & self . circuit ( ) . opcodes {
62
98
if let Opcode :: AssertZero ( gate) = opcode {
63
99
let mut left_terms = LinearCombination :: < Fr > :: new ( ) ;
64
100
let mut right_terms = LinearCombination :: < Fr > :: new ( ) ;
@@ -91,6 +127,9 @@ impl ConstraintSynthesizer<Fr> for NoirProgram {
91
127
// The constraint becomes: left_terms * right_terms + output_terms = 0
92
128
cs. enforce_constraint ( left_terms, right_terms, -output_terms) ?;
93
129
}
130
+ if let Opcode :: MemoryInit { .. } | Opcode :: MemoryOp { .. } = opcode {
131
+ panic ! ( "Memory Opcode was used! This is not currently supported." ) ;
132
+ }
94
133
}
95
134
96
135
Ok ( ( ) )
0 commit comments