Skip to content

Commit

Permalink
Merge branch 'master' into matthias/remove-singer-pro
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgoergens authored Oct 14, 2024
2 parents a8ae9b3 + 7e0f194 commit 67eae9f
Show file tree
Hide file tree
Showing 26 changed files with 437 additions and 227 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
run: |
cargo make --version || cargo install cargo-make
- name: Check code format
run: cargo make fmt
run: cargo make fmt-all-check

- name: Run clippy
env:
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,3 @@ option 1
option 2
- use F_q^2/3 extension field, do not repeat
- rule of thumb: n rounds, soundness ~ (64-n) bits





10 changes: 5 additions & 5 deletions ceno_zkvm/src/chip_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ff_ext::ExtensionField;
use crate::{
error::ZKVMError,
expression::{Expression, ToExpr},
gadgets::IsLtConfig,
gadgets::AssertLTConfig,
instructions::riscv::constants::UINT_LIMBS,
};

Expand Down Expand Up @@ -34,7 +34,7 @@ pub trait RegisterChipOperations<E: ExtensionField, NR: Into<String>, N: FnOnce(
prev_ts: Expression<E>,
ts: Expression<E>,
value: RegisterExpr<E>,
) -> Result<(Expression<E>, IsLtConfig), ZKVMError>;
) -> Result<(Expression<E>, AssertLTConfig), ZKVMError>;

#[allow(clippy::too_many_arguments)]
fn register_write(
Expand All @@ -45,7 +45,7 @@ pub trait RegisterChipOperations<E: ExtensionField, NR: Into<String>, N: FnOnce(
ts: Expression<E>,
prev_values: RegisterExpr<E>,
value: RegisterExpr<E>,
) -> Result<(Expression<E>, IsLtConfig), ZKVMError>;
) -> Result<(Expression<E>, AssertLTConfig), ZKVMError>;
}

/// The common representation of a memory value.
Expand All @@ -61,7 +61,7 @@ pub trait MemoryChipOperations<E: ExtensionField, NR: Into<String>, N: FnOnce()
prev_ts: Expression<E>,
ts: Expression<E>,
value: MemoryExpr<E>,
) -> Result<(Expression<E>, IsLtConfig), ZKVMError>;
) -> Result<(Expression<E>, AssertLTConfig), ZKVMError>;

#[allow(clippy::too_many_arguments)]
#[allow(dead_code)]
Expand All @@ -73,5 +73,5 @@ pub trait MemoryChipOperations<E: ExtensionField, NR: Into<String>, N: FnOnce()
ts: Expression<E>,
prev_values: MemoryExpr<E>,
value: MemoryExpr<E>,
) -> Result<(Expression<E>, IsLtConfig), ZKVMError>;
) -> Result<(Expression<E>, AssertLTConfig), ZKVMError>;
}
12 changes: 5 additions & 7 deletions ceno_zkvm/src/chip_handler/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
circuit_builder::CircuitBuilder,
error::ZKVMError,
expression::Expression,
gadgets::IsLtConfig,
gadgets::AssertLTConfig,
instructions::riscv::constants::UINT_LIMBS,
structs::RAMType,
};
Expand All @@ -20,7 +20,7 @@ impl<'a, E: ExtensionField, NR: Into<String>, N: FnOnce() -> NR> MemoryChipOpera
prev_ts: Expression<E>,
ts: Expression<E>,
value: MemoryExpr<E>,
) -> Result<(Expression<E>, IsLtConfig), ZKVMError> {
) -> Result<(Expression<E>, AssertLTConfig), ZKVMError> {
self.namespace(name_fn, |cb| {
// READ (a, v, t)
let read_record = cb.rlc_chip_record(
Expand Down Expand Up @@ -50,12 +50,11 @@ impl<'a, E: ExtensionField, NR: Into<String>, N: FnOnce() -> NR> MemoryChipOpera
cb.write_record(|| "write_record", write_record)?;

// assert prev_ts < current_ts
let lt_cfg = IsLtConfig::construct_circuit(
let lt_cfg = AssertLTConfig::construct_circuit(
cb,
|| "prev_ts < ts",
prev_ts,
ts.clone(),
Some(true),
UINT_LIMBS,
)?;

Expand All @@ -73,7 +72,7 @@ impl<'a, E: ExtensionField, NR: Into<String>, N: FnOnce() -> NR> MemoryChipOpera
ts: Expression<E>,
prev_values: MemoryExpr<E>,
value: MemoryExpr<E>,
) -> Result<(Expression<E>, IsLtConfig), ZKVMError> {
) -> Result<(Expression<E>, AssertLTConfig), ZKVMError> {
self.namespace(name_fn, |cb| {
// READ (a, v, t)
let read_record = cb.rlc_chip_record(
Expand Down Expand Up @@ -102,12 +101,11 @@ impl<'a, E: ExtensionField, NR: Into<String>, N: FnOnce() -> NR> MemoryChipOpera
cb.read_record(|| "read_record", read_record)?;
cb.write_record(|| "write_record", write_record)?;

let lt_cfg = IsLtConfig::construct_circuit(
let lt_cfg = AssertLTConfig::construct_circuit(
cb,
|| "prev_ts < ts",
prev_ts,
ts.clone(),
Some(true),
UINT_LIMBS,
)?;

Expand Down
14 changes: 6 additions & 8 deletions ceno_zkvm/src/chip_handler/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
circuit_builder::CircuitBuilder,
error::ZKVMError,
expression::{Expression, ToExpr},
gadgets::IsLtConfig,
gadgets::AssertLTConfig,
instructions::riscv::constants::UINT_LIMBS,
structs::RAMType,
};
Expand All @@ -21,7 +21,7 @@ impl<'a, E: ExtensionField, NR: Into<String>, N: FnOnce() -> NR> RegisterChipOpe
prev_ts: Expression<E>,
ts: Expression<E>,
value: RegisterExpr<E>,
) -> Result<(Expression<E>, IsLtConfig), ZKVMError> {
) -> Result<(Expression<E>, AssertLTConfig), ZKVMError> {
self.namespace(name_fn, |cb| {
// READ (a, v, t)
let read_record = cb.rlc_chip_record(
Expand Down Expand Up @@ -51,12 +51,11 @@ impl<'a, E: ExtensionField, NR: Into<String>, N: FnOnce() -> NR> RegisterChipOpe
cb.write_record(|| "write_record", write_record)?;

// assert prev_ts < current_ts
let lt_cfg = IsLtConfig::construct_circuit(
let lt_cfg = AssertLTConfig::construct_circuit(
cb,
|| "prev_ts < ts",
prev_ts,
ts.clone(),
Some(true),
UINT_LIMBS,
)?;

Expand All @@ -74,7 +73,7 @@ impl<'a, E: ExtensionField, NR: Into<String>, N: FnOnce() -> NR> RegisterChipOpe
ts: Expression<E>,
prev_values: RegisterExpr<E>,
value: RegisterExpr<E>,
) -> Result<(Expression<E>, IsLtConfig), ZKVMError> {
) -> Result<(Expression<E>, AssertLTConfig), ZKVMError> {
assert!(register_id.expr().degree() <= 1);
self.namespace(name_fn, |cb| {
// READ (a, v, t)
Expand Down Expand Up @@ -104,12 +103,11 @@ impl<'a, E: ExtensionField, NR: Into<String>, N: FnOnce() -> NR> RegisterChipOpe
cb.read_record(|| "read_record", read_record)?;
cb.write_record(|| "write_record", write_record)?;

let lt_cfg = IsLtConfig::construct_circuit(
let lt_cfg = AssertLTConfig::construct_circuit(
cb,
|| "prev_ts < ts",
prev_ts,
ts.clone(),
Some(true),
UINT_LIMBS,
)?;

Expand All @@ -119,7 +117,7 @@ impl<'a, E: ExtensionField, NR: Into<String>, N: FnOnce() -> NR> RegisterChipOpe
{
use crate::chip_handler::{test::DebugIndex, utils::power_sequence};
use itertools::izip;
let pow_u16 = power_sequence((1 << u16::BITS as u64).into(), value.len());
let pow_u16 = power_sequence((1 << u16::BITS as u64).into());
cb.register_debug_expr(
DebugIndex::RdWrite as usize,
izip!(value, pow_u16).map(|(v, pow)| v * pow).sum(),
Expand Down
10 changes: 5 additions & 5 deletions ceno_zkvm/src/chip_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn rlc_chip_record<E: ExtensionField>(
chip_record_beta: Expression<E>,
) -> Expression<E> {
assert!(!records.is_empty());
let beta_pows = power_sequence(chip_record_beta, records.len());
let beta_pows = power_sequence(chip_record_beta);

let item_rlc = beta_pows
.into_iter()
Expand All @@ -23,17 +23,17 @@ pub fn rlc_chip_record<E: ExtensionField>(
}

/// derive power sequence [1, base, base^2, ..., base^(len-1)] of base expression
pub fn power_sequence<E: ExtensionField>(base: Expression<E>, len: usize) -> Vec<Expression<E>> {
pub fn power_sequence<E: ExtensionField>(
base: Expression<E>,
) -> impl Iterator<Item = Expression<E>> {
assert!(
matches!(
base,
Expression::Constant { .. } | Expression::Challenge { .. }
),
"expression must be constant or challenge"
);
successors(Some(Expression::Constant(E::BaseField::ONE)), |prev| {
successors(Some(Expression::Constant(E::BaseField::ONE)), move |prev| {
Some(prev.clone() * base.clone())
})
.take(len)
.collect()
}
7 changes: 3 additions & 4 deletions ceno_zkvm/src/gadgets/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use crate::{
Value,
};

use super::IsLtConfig;
use super::AssertLTConfig;

/// divide gadget
#[derive(Debug, Clone)]
pub struct DivConfig<E: ExtensionField> {
pub dividend: UInt<E>,
pub r_lt: IsLtConfig,
pub r_lt: AssertLTConfig,
pub intermediate_mul: UInt<E>,
}

Expand All @@ -35,12 +35,11 @@ impl<E: ExtensionField> DivConfig<E> {
let (dividend, intermediate_mul) =
divisor.mul_add(|| "divisor * outcome + r", cb, quotient, remainder, true)?;

let r_lt = IsLtConfig::construct_circuit(
let r_lt = AssertLTConfig::construct_circuit(
cb,
|| "remainder < divisor",
remainder.value(),
divisor.value(),
Some(true),
UINT_LIMBS,
)?;

Expand Down
Loading

0 comments on commit 67eae9f

Please sign in to comment.