miden_processor/operations/circuit_eval.rs
1use crate::{ExecutionError, Process, chiplets::eval_circuit, errors::ErrorContext};
2
3impl Process {
4 /// Checks that the evaluation of an arithmetic circuit is equal to zero.
5 ///
6 /// The inputs are composed of:
7 ///
8 /// 1. a pointer to the memory region containing the arithmetic circuit description, which
9 /// itself is arranged as:
10 ///
11 /// a. `Read` section:
12 /// 1. Inputs to the circuit which are elements in the quadratic extension field,
13 /// 2. Constants of the circuit which are elements in the quadratic extension field,
14 ///
15 /// b. `Eval` section, which contains the encodings of the evaluation gates of the circuit,
16 /// where each gate is encoded as a single base field element.
17 /// 2. the number of quadratic extension field elements read in the `READ` section,
18 /// 3. the number of field elements, one base field element per gate, in the `EVAL` section,
19 ///
20 /// Stack transition:
21 /// [ptr, num_read, num_eval, ...] -> [ptr, num_read, num_eval, ...]
22 pub fn op_eval_circuit(&mut self, err_ctx: &impl ErrorContext) -> Result<(), ExecutionError> {
23 let num_eval = self.stack.get(2);
24 let num_read = self.stack.get(1);
25 let ptr = self.stack.get(0);
26 let ctx = self.system.ctx();
27 let clk = self.system.clk();
28 let circuit_evaluation =
29 eval_circuit(ctx, ptr, clk, num_read, num_eval, &mut self.chiplets.memory, err_ctx)?;
30 self.chiplets.ace.add_circuit_evaluation(clk, circuit_evaluation);
31
32 self.stack.copy_state(0);
33
34 Ok(())
35 }
36}