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 /// Each gate is encoded as a single base field element.
17 /// 2. the number of rows in the `READ` section,
18 /// 3. the number of rows in the `EVAL` section,
19 ///
20 /// Stack transition:
21 /// [ptr, num_read_rows, num_eval_rows, ...] -> [ptr, num_read_rows, num_eval_rows, ...]
22 pub fn arithmetic_circuit_eval(
23 &mut self,
24 err_ctx: &impl ErrorContext,
25 ) -> Result<(), ExecutionError> {
26 let num_eval_rows = self.stack.get(2);
27 let num_read_rows = self.stack.get(1);
28 let ptr = self.stack.get(0);
29 let ctx = self.system.ctx();
30 let clk = self.system.clk();
31 let circuit_evaluation = eval_circuit(
32 ctx,
33 ptr,
34 clk,
35 num_read_rows,
36 num_eval_rows,
37 &mut self.chiplets.memory,
38 err_ctx,
39 )?;
40 self.chiplets.ace.add_circuit_evaluation(clk, circuit_evaluation);
41
42 self.stack.copy_state(0);
43
44 Ok(())
45 }
46}