This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
forked from 0xPolygonZero/plonky2
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Constrain clock (0xPolygonZero#1343)
- Loading branch information
1 parent
954d1a7
commit 01bbf1a
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use plonky2::field::extension::Extendable; | ||
use plonky2::field::packed::PackedField; | ||
use plonky2::hash::hash_types::RichField; | ||
use plonky2::iop::ext_target::ExtensionTarget; | ||
|
||
use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; | ||
use crate::cpu::columns::CpuColumnsView; | ||
|
||
/// Check the correct updating of `clock`. | ||
pub fn eval_packed<P: PackedField>( | ||
lv: &CpuColumnsView<P>, | ||
nv: &CpuColumnsView<P>, | ||
yield_constr: &mut ConstraintConsumer<P>, | ||
) { | ||
// The clock is 0 at the beginning. | ||
yield_constr.constraint_first_row(lv.clock); | ||
// The clock is incremented by 1 at each row. | ||
yield_constr.constraint_transition(nv.clock - lv.clock - P::ONES); | ||
} | ||
|
||
/// Circuit version of `eval_packed`. | ||
/// Check the correct updating of `clock`. | ||
pub fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>( | ||
builder: &mut plonky2::plonk::circuit_builder::CircuitBuilder<F, D>, | ||
lv: &CpuColumnsView<ExtensionTarget<D>>, | ||
nv: &CpuColumnsView<ExtensionTarget<D>>, | ||
yield_constr: &mut RecursiveConstraintConsumer<F, D>, | ||
) { | ||
// The clock is 0 at the beginning. | ||
yield_constr.constraint_first_row(builder, lv.clock); | ||
// The clock is incremented by 1 at each row. | ||
{ | ||
let new_clock = builder.add_const_extension(lv.clock, F::ONE); | ||
let constr = builder.sub_extension(nv.clock, new_clock); | ||
yield_constr.constraint_transition(builder, constr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters