Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove (almost) all dead code #462

Merged
merged 8 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ceno_emul/src/rv32im.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ pub struct Emulator {
}

#[derive(Debug)]
#[allow(dead_code)]
pub enum TrapCause {
InstructionAddressMisaligned,
InstructionAccessFault,
Expand Down
5 changes: 0 additions & 5 deletions ceno_zkvm/src/expression/monomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ impl<E: ExtensionField> PartialOrd for Expression<E> {
}
}

#[allow(dead_code)]
fn cmp_field<F: SmallField>(a: &F, b: &F) -> Ordering {
a.to_canonical_u64().cmp(&b.to_canonical_u64())
}

fn cmp_ext<E: ExtensionField>(a: &E, b: &E) -> Ordering {
let a = a.as_bases().iter().map(|f| f.to_canonical_u64());
let b = b.as_bases().iter().map(|f| f.to_canonical_u64());
Expand Down
2 changes: 0 additions & 2 deletions ceno_zkvm/src/instructions/riscv/b_insn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(dead_code)] // TODO: remove after BLT, BEQ, …

use ceno_emul::{InsnKind, StepRecord};
use ff_ext::ExtensionField;

Expand Down
9 changes: 3 additions & 6 deletions ceno_zkvm/src/instructions/riscv/memory/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ impl RIVInstruction for SWOp {
const INST_KIND: InsnKind = InsnKind::SW;
}

// this is actually used in test
#[allow(dead_code)]
#[cfg(test)]
pub type SwInstruction<E> = StoreInstruction<E, SWOp, 2>;

pub struct SHOp;
Expand All @@ -48,8 +47,7 @@ impl RIVInstruction for SHOp {
const INST_KIND: InsnKind = InsnKind::SH;
}

// this is actually used in test
#[allow(dead_code)]
#[cfg(test)]
pub type ShInstruction<E> = StoreInstruction<E, SHOp, 1>;

pub struct SBOp;
Expand All @@ -58,8 +56,7 @@ impl RIVInstruction for SBOp {
const INST_KIND: InsnKind = InsnKind::SB;
}

// this is actually used in test
#[allow(dead_code)]
#[cfg(test)]
pub type SbInstruction<E> = StoreInstruction<E, SBOp, 0>;

impl<E: ExtensionField, I: RIVInstruction, const N_ZEROS: usize> Instruction<E>
Expand Down
6 changes: 4 additions & 2 deletions ceno_zkvm/src/instructions/riscv/shift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ pub struct ShiftConfig<E: ExtensionField> {

pub struct ShiftLogicalInstruction<E, I>(PhantomData<(E, I)>);

#[allow(dead_code)]
#[cfg(test)]
struct SllOp;
#[cfg(test)]
impl RIVInstruction for SllOp {
const INST_KIND: InsnKind = InsnKind::SLL;
}

#[allow(dead_code)]
#[cfg(test)]
struct SrlOp;
#[cfg(test)]
impl RIVInstruction for SrlOp {
const INST_KIND: InsnKind = InsnKind::SRL;
}
Expand Down
2 changes: 1 addition & 1 deletion ceno_zkvm/src/instructions/riscv/slt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct SltConfig<E: ExtensionField> {

rs1_read: UInt<E>,
rs2_read: UInt<E>,
#[allow(dead_code)]
#[cfg_attr(not(test), allow(dead_code))]
rd_written: UInt<E>,

signed_lt: SignedLtConfig,
Expand Down
2 changes: 1 addition & 1 deletion ceno_zkvm/src/instructions/riscv/sltu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct ArithConfig<E: ExtensionField> {

rs1_read: UInt<E>,
rs2_read: UInt<E>,
#[allow(dead_code)]
#[cfg_attr(not(test), allow(dead_code))]
rd_written: UInt<E>,

is_lt: IsLtConfig,
Expand Down
5 changes: 3 additions & 2 deletions ceno_zkvm/src/scheme/mock_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,12 @@ mod tests {
use multilinear_extensions::mle::{IntoMLE, IntoMLEs};

#[derive(Debug)]
#[allow(dead_code)]
struct AssertZeroCircuit {
#[allow(dead_code)]
pub a: WitIn,
#[allow(dead_code)]
pub b: WitIn,
#[allow(dead_code)]
pub c: WitIn,
}

Expand Down Expand Up @@ -832,7 +834,6 @@ mod tests {
assert_eq!(err[0].inst_id(), 0);
}

#[allow(dead_code)]
#[derive(Debug)]
struct AssertLtCircuit {
pub a: WitIn,
Expand Down
4 changes: 2 additions & 2 deletions ceno_zkvm/src/scheme/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ pub(crate) fn wit_infer_by_expr<'a, E: ExtensionField, const N: usize>(
)
}

#[allow(dead_code)]
#[cfg(test)]
pub(crate) fn eval_by_expr<E: ExtensionField>(
witnesses: &[E],
challenges: &[E],
Expand All @@ -361,7 +361,7 @@ pub(crate) fn eval_by_expr<E: ExtensionField>(
eval_by_expr_with_fixed(&[], witnesses, challenges, expr)
}

#[allow(dead_code)]
#[cfg(test)]
pub(crate) fn eval_by_expr_with_fixed<E: ExtensionField>(
fixed: &[E],
witnesses: &[E],
Expand Down
1 change: 0 additions & 1 deletion ceno_zkvm/src/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,6 @@ impl ValueMul {

#[derive(Clone)]
pub struct Value<'a, T: Into<u64> + From<u32> + Copy + Default> {
#[allow(dead_code)]
val: T,
pub limbs: Cow<'a, [u16]>,
}
Expand Down
30 changes: 0 additions & 30 deletions ceno_zkvm/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ use itertools::Itertools;
use multilinear_extensions::util::max_usable_threads;
use transcript::Transcript;

/// convert ext field element to u64, assume it is inside the range
#[allow(dead_code)]
pub fn ext_to_u64<E: ExtensionField>(x: &E) -> u64 {
let bases = x.as_bases();
bases[0].to_canonical_u64()
}

pub fn i64_to_base<F: SmallField>(x: i64) -> F {
if x >= 0 {
F::from(x as u64)
Expand All @@ -20,20 +13,6 @@ pub fn i64_to_base<F: SmallField>(x: i64) -> F {
}
}

/// This is helper function to convert witness of u8 limb into u16 limb
/// TODO: need a better way to keep consistency of LIMB_BITS
#[allow(dead_code)]
pub fn limb_u8_to_u16(input: &[u8]) -> Vec<u16> {
input
.chunks(2)
.map(|chunk| {
let low = chunk[0] as u16;
let high = if chunk.len() > 1 { chunk[1] as u16 } else { 0 };
high * 256 + low
})
.collect()
}

pub fn split_to_u8<T: From<u8>>(value: u32) -> Vec<T> {
(0..(u32::BITS / 8))
.scan(value, |acc, _| {
Expand Down Expand Up @@ -72,15 +51,6 @@ pub(crate) fn add_one_to_big_num<F: Field>(limb_modulo: F, limbs: &[F]) -> Vec<F
result
}

#[allow(dead_code)]
pub(crate) fn i64_to_base_field<E: ExtensionField>(x: i64) -> E::BaseField {
if x >= 0 {
E::BaseField::from(x as u64)
} else {
-E::BaseField::from((-x) as u64)
}
}

/// derive challenge from transcript and return all pows result
pub fn get_challenge_pows<E: ExtensionField>(
size: usize,
Expand Down
1 change: 0 additions & 1 deletion ceno_zkvm/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ pub struct LkMultiplicity {
multiplicity: Arc<ThreadLocal<RefCell<[HashMap<u64, usize>; mem::variant_count::<ROMType>()]>>>,
}

#[allow(dead_code)]
impl LkMultiplicity {
/// assert within range
#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion gkr-graph/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub enum PredType {
#[derive(Clone, Debug)]
pub struct CircuitNode<E: ExtensionField> {
pub(crate) id: usize,
// TODO(Matthias): See whether we can remove this field.
// Note: only for debug output.
#[allow(dead_code)]
pub(crate) label: &'static str,
pub(crate) circuit: Arc<Circuit<E>>,
Expand Down
20 changes: 0 additions & 20 deletions gkr/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ where
in_eq_vec: &[E],
challenges: &HashMap<ChallengeConst, Vec<E::BaseField>>,
) -> E;
// TODO(Matthias, by 2024-11-01): review whether we need this function after all.
#[allow(dead_code)]
fn fix_out_variables(
&self,
in_size: usize,
out_eq_vec: &[E],
challenges: &HashMap<ChallengeConst, Vec<E::BaseField>>,
) -> Vec<E>;
}

impl<E> EvaluateGate1In<E> for &[Gate1In<ConstantType<E>>]
Expand All @@ -68,18 +60,6 @@ where
* gate.scalar.eval(challenges)
})
}
fn fix_out_variables(
&self,
in_size: usize,
out_eq_vec: &[E],
challenges: &HashMap<ChallengeConst, Vec<E::BaseField>>,
) -> Vec<E> {
let mut ans = vec![E::ZERO; in_size];
for gate in self.iter() {
ans[gate.idx_in[0]] += out_eq_vec[gate.idx_out] * gate.scalar.eval(challenges);
}
ans
}
}

pub trait EvaluateGate2In<E>
Expand Down
33 changes: 1 addition & 32 deletions multilinear_extensions/src/virtual_poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ark_std::{end_timer, iterable::Iterable, rand::Rng, start_timer};
use ff::{Field, PrimeField};
use ff_ext::ExtensionField;
use rayon::{
iter::{IntoParallelIterator, IntoParallelRefIterator},
iter::IntoParallelIterator,
prelude::{IndexedParallelIterator, ParallelIterator},
slice::ParallelSliceMut,
};
Expand Down Expand Up @@ -478,37 +478,6 @@ pub fn build_eq_x_r_vec<E: ExtensionField>(r: &[E]) -> Vec<E> {
}
}

/// A helper function to build eq(x, r) via dynamic programing tricks.
/// This function takes 2^num_var iterations, and per iteration with 1 multiplication.
#[allow(dead_code)]
fn build_eq_x_r_helper<E: ExtensionField>(r: &[E], buf: &mut [Vec<E>; 2]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for general reference: the current implementation of build_eq_x_r uses a similar function build_eq_x_r_helper_sequential, so the removed unused code here looks to be redundant.

buf[0][0] = E::ONE;
if r.is_empty() {
buf[0].resize(1, E::ZERO);
return;
}
for (i, r) in r.iter().rev().enumerate() {
let [current, next] = buf;
let (cur_size, next_size) = (1 << i, 1 << (i + 1));
// suppose at the previous step we processed buf [0..size]
// for the current step we are populating new buf[0..2*size]
// for j travese 0..size
// buf[2*j + 1] = r * buf[j]
// buf[2*j] = (1 - r) * buf[j]
current[0..cur_size]
.par_iter()
.zip_eq(next[0..next_size].par_chunks_mut(2))
.with_min_len(64)
.for_each(|(prev_val, next_vals)| {
assert!(next_vals.len() == 2);
let tmp = *r * prev_val;
next_vals[1] = tmp;
next_vals[0] = *prev_val - tmp;
});
buf.swap(0, 1); // swap rolling buffer
}
}

#[cfg(test)]
mod tests {
use crate::virtual_poly::{build_eq_x_r_vec, build_eq_x_r_vec_sequential};
Expand Down
17 changes: 1 addition & 16 deletions singer/src/scheme.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
use ff_ext::ExtensionField;

// TODO: to be changed to a real PCS scheme.
type BatchedPCSProof<F> = Vec<Vec<F>>;
type Commitment<F> = Vec<F>;

pub mod prover;
pub mod verifier;

pub struct CommitPhaseProof<E: ExtensionField> {
// TODO(Matthias): Check whether we need this field.
#[allow(dead_code)]
commitments: Vec<Commitment<E>>,
}

pub type GKRGraphProof<F> = gkr_graph::structs::IOPProof<F>;
pub type GKRGraphProverState<F> = gkr_graph::structs::IOPProverState<F>;
pub type GKRGraphVerifierState<F> = gkr_graph::structs::IOPVerifierState<F>;

pub struct OpenPhaseProof<E: ExtensionField> {
// TODO(Matthias): Check whether we need this field.
#[allow(dead_code)]
pcs_proof: BatchedPCSProof<E>,
}

pub struct SingerProof<E: ExtensionField> {
// commitment_phase_proof: CommitPhaseProof<F>,
// TODO: restore and implement `commitment_phase_proof` and `open_phase_proof`
gkr_phase_proof: GKRGraphProof<E>,
// open_phase_proof: OpenPhaseProof<F>,
}
10 changes: 0 additions & 10 deletions singer/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ use ff_ext::ExtensionField;
use itertools::izip;
use simple_frontend::structs::{CellId, CircuitBuilder};

// TODO(Matthias): Check whether we need this function.
#[allow(dead_code)]
pub(crate) fn i64_to_base_field<E: ExtensionField>(x: i64) -> E::BaseField {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a copy and paste from singer-utils/src/chip_handler/range.rs (or vice versa).

if x >= 0 {
E::BaseField::from(x as u64)
} else {
-E::BaseField::from((-x) as u64)
}
}

pub(crate) fn add_assign_each_cell<E: ExtensionField>(
circuit_builder: &mut CircuitBuilder<E>,
dest: &[CellId],
Expand Down
1 change: 0 additions & 1 deletion sumcheck/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub struct IOPProof<E: ExtensionField> {
pub proofs: Vec<IOPProverMessage<E>>,
}
impl<E: ExtensionField> IOPProof<E> {
#[allow(dead_code)]
pub fn extract_sum(&self) -> E {
self.proofs[0].evaluations[0] + self.proofs[0].evaluations[1]
}
Expand Down
Loading