Skip to content

Commit 76ea05c

Browse files
committed
Merge branch 'gkr_protocol' of github.com:lambdaclass/lambdaworks into gkr_protocol
2 parents d6fd18e + 2aef233 commit 76ea05c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

crates/provers/gkr/src/circuit.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ impl CircuitLayer {
5959
#[derive(Debug, Clone)]
6060
pub enum CircuitError {
6161
InputsNotPowerOfTwo,
62-
LayerNotPowerOfTwo(usize), // index of the layer that is not a power of two
63-
GateInputsError(usize), // index of the layer with invalid gate inputs
62+
LayerNotPowerOfTwo(usize),
63+
GateInputsError(usize),
6464
EmptyCircuitError,
6565
}
6666

@@ -95,8 +95,9 @@ pub struct Circuit {
9595
}
9696

9797
/// An evaluation of a `Circuit` on some input.
98+
/// Stores the outputs, every circuit layer intermediate evaluations and the inputs
9899
pub struct CircuitEvaluation<F> {
99-
/// Evaluations on per-layer basis. First layer is the output and last layer is the input.
100+
/// Evaluations on per-layer. First layer is the output and last layer is the input.
100101
pub layers: Vec<Vec<F>>,
101102
}
102103

@@ -125,21 +126,21 @@ impl Circuit {
125126
let next_layer = &layer_pair[1];
126127
let next_layer_gates = next_layer.len();
127128

128-
for gate in &current_layer.gates {
129+
if current_layer.gates.iter().any(|gate| {
129130
let [a, b] = gate.inputs_idx;
130-
if a >= next_layer_gates || b >= next_layer_gates {
131-
return Err(CircuitError::GateInputsError(i));
132-
}
131+
a >= next_layer_gates || b >= next_layer_gates
132+
}) {
133+
return Err(CircuitError::GateInputsError(i));
133134
}
134135
}
135136

136137
// Validate that the last layer gate inputs don't exceed the number of inputs
137138
if let Some(last_layer) = layers.last() {
138-
for gate in &last_layer.gates {
139+
if last_layer.gates.iter().any(|gate| {
139140
let [a, b] = gate.inputs_idx;
140-
if a >= num_inputs || b >= num_inputs {
141-
return Err(CircuitError::GateInputsError(layers.len() - 1));
142-
}
141+
a >= num_inputs || b >= num_inputs
142+
}) {
143+
return Err(CircuitError::GateInputsError(layers.len() - 1));
143144
}
144145
}
145146

0 commit comments

Comments
 (0)