Skip to content

Commit 1fe39d8

Browse files
committed
improve AIR constraints for execution table
1 parent 14a8e27 commit 1fe39d8

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

crates/lean_vm/src/tables/execution/air.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<const BUS: bool> Air for ExecutionTable<BUS> {
7474
vec![]
7575
}
7676
fn n_constraints(&self) -> usize {
77-
16
77+
14
7878
}
7979

8080
#[inline]
@@ -158,14 +158,14 @@ impl<const BUS: bool> Air for ExecutionTable<BUS> {
158158
builder.assert_zero(deref.clone() * aux.clone() * (value_c.clone() - nu_b.clone()));
159159
builder.assert_zero(deref.clone() * (aux.clone() - AB::F::ONE) * (value_c.clone() - fp.clone()));
160160

161-
builder.assert_zero((jump.clone() - AB::F::ONE) * (next_pc.clone() - pc_plus_one.clone()));
162-
builder.assert_zero((jump.clone() - AB::F::ONE) * (next_fp.clone() - fp.clone()));
161+
let jump_and_condition = jump.clone() * nu_a.clone();
163162

164-
builder.assert_zero(jump.clone() * nu_a.clone() * nu_a_minus_one.clone());
165-
builder.assert_zero(jump.clone() * nu_a.clone() * (next_pc.clone() - nu_b.clone()));
166-
builder.assert_zero(jump.clone() * nu_a.clone() * (next_fp.clone() - nu_c.clone()));
167-
builder.assert_zero(jump.clone() * nu_a_minus_one.clone() * (next_pc.clone() - pc_plus_one.clone()));
168-
builder.assert_zero(jump.clone() * nu_a_minus_one.clone() * (next_fp.clone() - fp.clone()));
163+
builder.assert_zero(jump_and_condition.clone() * nu_a_minus_one.clone());
164+
builder.assert_zero(jump_and_condition.clone() * (next_pc.clone() - nu_b.clone()));
165+
builder.assert_zero(jump_and_condition.clone() * (next_fp.clone() - nu_c.clone()));
166+
let not_jump_and_condition = AB::F::ONE - jump_and_condition;
167+
builder.assert_zero(not_jump_and_condition.clone() * (next_pc.clone() - pc_plus_one.clone()));
168+
builder.assert_zero(not_jump_and_condition * (next_fp.clone() - fp.clone()));
169169
}
170170
}
171171

misc/minimal_zkVM.tex

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -413,21 +413,13 @@ \subsubsection{AIR transition constraints}
413413

414414
\vspace{3mm}\centerline{\rule{10cm}{0.4pt}}\vspace{5mm}
415415

416-
When there is no jump:
416+
For jump and conditional state transitions, let $J = \text{JUMP} \cdot \nu_A$:
417417
\begin{itemize}
418-
\item $(1 - \text{JUMP}) \cdot ( \text{next(pc)} - (\text{pc} + 1)) = 0$
419-
\item $(1 - \text{JUMP}) \cdot (\text{next(fp)} - \text{fp}) = 0$
420-
\end{itemize}
421-
422-
\vspace{3mm}
423-
424-
When JUMP $= 1$, the condition is represented by $\nu_A$:
425-
\begin{itemize}
426-
\item $\text{JUMP} \cdot \nu_A \cdot (1 - \nu_A) = 0$
427-
\item $\text{JUMP} \cdot \nu_A \cdot ( \text{next(pc)} - \nu_B) = 0$
428-
\item $\text{JUMP} \cdot \nu_A \cdot ( \text{next(fp)} - \nu_C) = 0$
429-
\item $\text{JUMP} \cdot (1 - \nu_A) \cdot ( \text{next(pc)} - (\text{pc} + 1)) = 0$
430-
\item $\text{JUMP} \cdot (1 - \nu_A) \cdot (\text{next(fp)} - \text{fp}) = 0$
418+
\item $\text{JUMP} \cdot \nu_A \cdot (1 - \nu_A) = 0$
419+
\item $J \cdot ( \text{next(pc)} - \nu_B) = 0$
420+
\item $J \cdot ( \text{next(fp)} - \nu_C) = 0$
421+
\item $(1 - J) \cdot ( \text{next(pc)} - (\text{pc} + 1)) = 0$
422+
\item $(1 - J) \cdot (\text{next(fp)} - \text{fp}) = 0$
431423
\end{itemize}
432424

433425
Note: the constraint $\text{JUMP} \cdot \nu_A \cdot (1 - \nu_A) = 0$ could be removed, as long as it's correctly enforced in the bytecode.

0 commit comments

Comments
 (0)