miden_processor/operations/
circuit_eval.rs

1use vm_core::mast::BasicBlockNode;
2
3use crate::{ExecutionError, Process, chiplets::eval_circuit, errors::ErrorContext};
4
5impl Process {
6    /// Checks that the evaluation of an arithmetic circuit is equal to zero.
7    ///
8    /// The inputs are composed of:
9    ///
10    /// 1. a pointer to the memory region containing the arithmetic circuit description, which
11    ///    itself is arranged as:
12    ///
13    ///    a. `Read` section:
14    ///       1. Inputs to the circuit which are elements in the quadratic extension field,
15    ///       2. Constants of the circuit which are elements in the quadratic extension field,
16    ///
17    ///    b. `Eval` section, which contains the encodings of the evaluation gates of the circuit.
18    ///    Each gate is encoded as a single base field element.
19    /// 2. the number of rows in the `READ` section,
20    /// 3. the number of rows in the `EVAL` section,
21    ///
22    /// Stack transition:
23    /// [ptr, num_read_rows, num_eval_rows, ...] -> [ptr, num_read_rows, num_eval_rows, ...]
24    pub fn arithmetic_circuit_eval(
25        &mut self,
26        error_ctx: &ErrorContext<'_, BasicBlockNode>,
27    ) -> Result<(), ExecutionError> {
28        let num_eval_rows = self.stack.get(2);
29        let num_read_rows = self.stack.get(1);
30        let ptr = self.stack.get(0);
31        let ctx = self.system.ctx();
32        let clk = self.system.clk();
33        let circuit_evaluation = eval_circuit(
34            ctx,
35            ptr,
36            clk,
37            num_read_rows,
38            num_eval_rows,
39            &mut self.chiplets.memory,
40            error_ctx,
41        )?;
42        self.chiplets.ace.add_circuit_evaluation(clk, circuit_evaluation);
43
44        self.stack.copy_state(0);
45
46        Ok(())
47    }
48}