Skip to content

Commit

Permalink
Reduce visibility for a bunch of structs and methods in EVM crate (#1289
Browse files Browse the repository at this point in the history
)

* Reduce visibility for a bunch of structs and methods

* Remove redundant
  • Loading branch information
Nashtare authored Nov 13, 2023
1 parent 5800e6a commit 88fcc32
Show file tree
Hide file tree
Showing 52 changed files with 278 additions and 265 deletions.
16 changes: 8 additions & 8 deletions evm/src/all_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ use crate::stark::Stark;
/// Structure containing all STARKs and the cross-table lookups.
#[derive(Clone)]
pub struct AllStark<F: RichField + Extendable<D>, const D: usize> {
pub arithmetic_stark: ArithmeticStark<F, D>,
pub byte_packing_stark: BytePackingStark<F, D>,
pub cpu_stark: CpuStark<F, D>,
pub keccak_stark: KeccakStark<F, D>,
pub keccak_sponge_stark: KeccakSpongeStark<F, D>,
pub logic_stark: LogicStark<F, D>,
pub memory_stark: MemoryStark<F, D>,
pub cross_table_lookups: Vec<CrossTableLookup<F>>,
pub(crate) arithmetic_stark: ArithmeticStark<F, D>,
pub(crate) byte_packing_stark: BytePackingStark<F, D>,
pub(crate) cpu_stark: CpuStark<F, D>,
pub(crate) keccak_stark: KeccakStark<F, D>,
pub(crate) keccak_sponge_stark: KeccakSpongeStark<F, D>,
pub(crate) logic_stark: LogicStark<F, D>,
pub(crate) memory_stark: MemoryStark<F, D>,
pub(crate) cross_table_lookups: Vec<CrossTableLookup<F>>,
}

impl<F: RichField + Extendable<D>, const D: usize> Default for AllStark<F, D> {
Expand Down
2 changes: 1 addition & 1 deletion evm/src/arithmetic/arithmetic_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub(crate) fn ctl_arithmetic_rows<F: Field>() -> TableWithColumns<F> {

/// Structure representing the `Arithmetic` STARK, which carries out all the arithmetic operations.
#[derive(Copy, Clone, Default)]
pub struct ArithmeticStark<F, const D: usize> {
pub(crate) struct ArithmeticStark<F, const D: usize> {
pub f: PhantomData<F>,
}

Expand Down
4 changes: 2 additions & 2 deletions evm/src/byte_packing/byte_packing_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub(crate) fn ctl_looked_data<F: Field>() -> Vec<Column<F>> {
}

/// CTL filter for the `BytePackingStark` looked table.
pub fn ctl_looked_filter<F: Field>() -> Column<F> {
pub(crate) fn ctl_looked_filter<F: Field>() -> Column<F> {
// The CPU table is only interested in our sequence end rows,
// since those contain the final limbs of our packed int.
Column::single(SEQUENCE_END)
Expand Down Expand Up @@ -136,7 +136,7 @@ pub(crate) struct BytePackingOp {
}

#[derive(Copy, Clone, Default)]
pub struct BytePackingStark<F, const D: usize> {
pub(crate) struct BytePackingStark<F, const D: usize> {
pub(crate) f: PhantomData<F>,
}

Expand Down
24 changes: 12 additions & 12 deletions evm/src/constraint_consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct ConstraintConsumer<P: PackedField> {
}

impl<P: PackedField> ConstraintConsumer<P> {
pub fn new(
pub(crate) fn new(
alphas: Vec<P::Scalar>,
z_last: P,
lagrange_basis_first: P,
Expand All @@ -44,17 +44,17 @@ impl<P: PackedField> ConstraintConsumer<P> {
}
}

pub fn accumulators(self) -> Vec<P> {
pub(crate) fn accumulators(self) -> Vec<P> {
self.constraint_accs
}

/// Add one constraint valid on all rows except the last.
pub fn constraint_transition(&mut self, constraint: P) {
pub(crate) fn constraint_transition(&mut self, constraint: P) {
self.constraint(constraint * self.z_last);
}

/// Add one constraint on all rows.
pub fn constraint(&mut self, constraint: P) {
pub(crate) fn constraint(&mut self, constraint: P) {
for (&alpha, acc) in self.alphas.iter().zip(&mut self.constraint_accs) {
*acc *= alpha;
*acc += constraint;
Expand All @@ -63,13 +63,13 @@ impl<P: PackedField> ConstraintConsumer<P> {

/// Add one constraint, but first multiply it by a filter such that it will only apply to the
/// first row of the trace.
pub fn constraint_first_row(&mut self, constraint: P) {
pub(crate) fn constraint_first_row(&mut self, constraint: P) {
self.constraint(constraint * self.lagrange_basis_first);
}

/// Add one constraint, but first multiply it by a filter such that it will only apply to the
/// last row of the trace.
pub fn constraint_last_row(&mut self, constraint: P) {
pub(crate) fn constraint_last_row(&mut self, constraint: P) {
self.constraint(constraint * self.lagrange_basis_last);
}
}
Expand All @@ -96,7 +96,7 @@ pub struct RecursiveConstraintConsumer<F: RichField + Extendable<D>, const D: us
}

impl<F: RichField + Extendable<D>, const D: usize> RecursiveConstraintConsumer<F, D> {
pub fn new(
pub(crate) fn new(
zero: ExtensionTarget<D>,
alphas: Vec<Target>,
z_last: ExtensionTarget<D>,
Expand All @@ -113,12 +113,12 @@ impl<F: RichField + Extendable<D>, const D: usize> RecursiveConstraintConsumer<F
}
}

pub fn accumulators(self) -> Vec<ExtensionTarget<D>> {
pub(crate) fn accumulators(self) -> Vec<ExtensionTarget<D>> {
self.constraint_accs
}

/// Add one constraint valid on all rows except the last.
pub fn constraint_transition(
pub(crate) fn constraint_transition(
&mut self,
builder: &mut CircuitBuilder<F, D>,
constraint: ExtensionTarget<D>,
Expand All @@ -128,7 +128,7 @@ impl<F: RichField + Extendable<D>, const D: usize> RecursiveConstraintConsumer<F
}

/// Add one constraint valid on all rows.
pub fn constraint(
pub(crate) fn constraint(
&mut self,
builder: &mut CircuitBuilder<F, D>,
constraint: ExtensionTarget<D>,
Expand All @@ -140,7 +140,7 @@ impl<F: RichField + Extendable<D>, const D: usize> RecursiveConstraintConsumer<F

/// Add one constraint, but first multiply it by a filter such that it will only apply to the
/// first row of the trace.
pub fn constraint_first_row(
pub(crate) fn constraint_first_row(
&mut self,
builder: &mut CircuitBuilder<F, D>,
constraint: ExtensionTarget<D>,
Expand All @@ -151,7 +151,7 @@ impl<F: RichField + Extendable<D>, const D: usize> RecursiveConstraintConsumer<F

/// Add one constraint, but first multiply it by a filter such that it will only apply to the
/// last row of the trace.
pub fn constraint_last_row(
pub(crate) fn constraint_last_row(
&mut self,
builder: &mut CircuitBuilder<F, D>,
constraint: ExtensionTarget<D>,
Expand Down
4 changes: 2 additions & 2 deletions evm/src/cpu/columns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub type MemValue<T> = [T; memory::VALUE_LIMBS];
/// View of the columns required for one memory channel.
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct MemoryChannelView<T: Copy> {
pub(crate) struct MemoryChannelView<T: Copy> {
/// 1 if this row includes a memory operation in the `i`th channel of the memory bus, otherwise
/// 0.
pub used: T,
Expand All @@ -40,7 +40,7 @@ pub struct MemoryChannelView<T: Copy> {
/// View of all the columns in `CpuStark`.
#[repr(C)]
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
pub struct CpuColumnsView<T: Copy> {
pub(crate) struct CpuColumnsView<T: Copy> {
/// Filter. 1 if the row is part of bootstrapping the kernel code, 0 otherwise.
pub is_bootstrap_kernel: T,

Expand Down
2 changes: 1 addition & 1 deletion evm/src/cpu/columns/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::util::transmute_no_compile_time_size_checks;
/// Structure representing the flags for the various opcodes.
#[repr(C)]
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
pub struct OpsColumnsView<T: Copy> {
pub(crate) struct OpsColumnsView<T: Copy> {
/// Combines ADD, MUL, SUB, DIV, MOD, LT, GT and BYTE flags.
pub binary_op: T,
/// Combines ADDMOD, MULMOD and SUBMOD flags.
Expand Down
4 changes: 2 additions & 2 deletions evm/src/cpu/contextops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ fn eval_ext_circuit_set<F: RichField + Extendable<D>, const D: usize>(
}

/// Evaluates the constraints for the GET and SET opcodes.
pub fn eval_packed<P: PackedField>(
pub(crate) fn eval_packed<P: PackedField>(
lv: &CpuColumnsView<P>,
nv: &CpuColumnsView<P>,
yield_constr: &mut ConstraintConsumer<P>,
Expand Down Expand Up @@ -376,7 +376,7 @@ pub fn eval_packed<P: PackedField>(

/// Circuit version of èval_packed`.
/// Evaluates the constraints for the GET and SET opcodes.
pub fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
pub(crate) fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
builder: &mut CircuitBuilder<F, D>,
lv: &CpuColumnsView<ExtensionTarget<D>>,
nv: &CpuColumnsView<ExtensionTarget<D>>,
Expand Down
4 changes: 2 additions & 2 deletions evm/src/cpu/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(crate) fn get_start_pc<F: Field>() -> F {
}

/// Evaluates the constraints related to the flow of instructions.
pub fn eval_packed_generic<P: PackedField>(
pub(crate) fn eval_packed_generic<P: PackedField>(
lv: &CpuColumnsView<P>,
nv: &CpuColumnsView<P>,
yield_constr: &mut ConstraintConsumer<P>,
Expand Down Expand Up @@ -83,7 +83,7 @@ pub fn eval_packed_generic<P: PackedField>(

/// Circuit version of `eval_packed`.
/// Evaluates the constraints related to the flow of instructions.
pub fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
pub(crate) 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>>,
Expand Down
28 changes: 14 additions & 14 deletions evm/src/cpu/cpu_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::stark::Stark;

/// Creates the vector of `Columns` corresponding to the General Purpose channels when calling the Keccak sponge:
/// the CPU reads the output of the sponge directly from the `KeccakSpongeStark` table.
pub fn ctl_data_keccak_sponge<F: Field>() -> Vec<Column<F>> {
pub(crate) fn ctl_data_keccak_sponge<F: Field>() -> Vec<Column<F>> {
// When executing KECCAK_GENERAL, the GP memory channels are used as follows:
// GP channel 0: stack[-1] = context
// GP channel 1: stack[-2] = segment
Expand All @@ -47,7 +47,7 @@ pub fn ctl_data_keccak_sponge<F: Field>() -> Vec<Column<F>> {
}

/// CTL filter for a call to the Keccak sponge.
pub fn ctl_filter_keccak_sponge<F: Field>() -> Column<F> {
pub(crate) fn ctl_filter_keccak_sponge<F: Field>() -> Column<F> {
Column::single(COL_MAP.is_keccak_sponge)
}

Expand All @@ -73,20 +73,20 @@ fn ctl_data_ternops<F: Field>() -> Vec<Column<F>> {
}

/// Creates the vector of columns corresponding to the opcode, the two inputs and the output of the logic operation.
pub fn ctl_data_logic<F: Field>() -> Vec<Column<F>> {
pub(crate) fn ctl_data_logic<F: Field>() -> Vec<Column<F>> {
// Instead of taking single columns, we reconstruct the entire opcode value directly.
let mut res = vec![Column::le_bits(COL_MAP.opcode_bits)];
res.extend(ctl_data_binops());
res
}

/// CTL filter for logic operations.
pub fn ctl_filter_logic<F: Field>() -> Column<F> {
pub(crate) fn ctl_filter_logic<F: Field>() -> Column<F> {
Column::single(COL_MAP.op.logic_op)
}

/// Returns the `TableWithColumns` for the CPU rows calling arithmetic operations.
pub fn ctl_arithmetic_base_rows<F: Field>() -> TableWithColumns<F> {
pub(crate) fn ctl_arithmetic_base_rows<F: Field>() -> TableWithColumns<F> {
// Instead of taking single columns, we reconstruct the entire opcode value directly.
let mut columns = vec![Column::le_bits(COL_MAP.opcode_bits)];
columns.extend(ctl_data_ternops());
Expand All @@ -112,17 +112,17 @@ pub fn ctl_arithmetic_base_rows<F: Field>() -> TableWithColumns<F> {

/// Creates the vector of `Columns` corresponding to the contents of General Purpose channels when calling byte packing.
/// We use `ctl_data_keccak_sponge` because the `Columns` are the same as the ones computed for `KeccakSpongeStark`.
pub fn ctl_data_byte_packing<F: Field>() -> Vec<Column<F>> {
pub(crate) fn ctl_data_byte_packing<F: Field>() -> Vec<Column<F>> {
ctl_data_keccak_sponge()
}

/// CTL filter for the `MLOAD_32BYTES` operation.
pub fn ctl_filter_byte_packing<F: Field>() -> Column<F> {
pub(crate) fn ctl_filter_byte_packing<F: Field>() -> Column<F> {
Column::single(COL_MAP.op.mload_32bytes)
}

/// Creates the vector of `Columns` corresponding to the contents of General Purpose channels when calling byte unpacking.
pub fn ctl_data_byte_unpacking<F: Field>() -> Vec<Column<F>> {
pub(crate) fn ctl_data_byte_unpacking<F: Field>() -> Vec<Column<F>> {
// When executing MSTORE_32BYTES, the GP memory channels are used as follows:
// GP channel 0: stack[-1] = context
// GP channel 1: stack[-2] = segment
Expand All @@ -145,7 +145,7 @@ pub fn ctl_data_byte_unpacking<F: Field>() -> Vec<Column<F>> {
}

/// CTL filter for the `MSTORE_32BYTES` operation.
pub fn ctl_filter_byte_unpacking<F: Field>() -> Column<F> {
pub(crate) fn ctl_filter_byte_unpacking<F: Field>() -> Column<F> {
Column::single(COL_MAP.op.mstore_32bytes)
}

Expand All @@ -162,7 +162,7 @@ fn mem_time_and_channel<F: Field>(channel: usize) -> Column<F> {
}

/// Creates the vector of `Columns` corresponding to the contents of the code channel when reading code values.
pub fn ctl_data_code_memory<F: Field>() -> Vec<Column<F>> {
pub(crate) fn ctl_data_code_memory<F: Field>() -> Vec<Column<F>> {
let mut cols = vec![
Column::constant(F::ONE), // is_read
Column::single(COL_MAP.code_context), // addr_context
Expand All @@ -182,7 +182,7 @@ pub fn ctl_data_code_memory<F: Field>() -> Vec<Column<F>> {
}

/// Creates the vector of `Columns` corresponding to the contents of General Purpose channels.
pub fn ctl_data_gp_memory<F: Field>(channel: usize) -> Vec<Column<F>> {
pub(crate) fn ctl_data_gp_memory<F: Field>(channel: usize) -> Vec<Column<F>> {
let channel_map = COL_MAP.mem_channels[channel];
let mut cols: Vec<_> = Column::singles([
channel_map.is_read,
Expand All @@ -200,18 +200,18 @@ pub fn ctl_data_gp_memory<F: Field>(channel: usize) -> Vec<Column<F>> {
}

/// CTL filter for code read and write operations.
pub fn ctl_filter_code_memory<F: Field>() -> Column<F> {
pub(crate) fn ctl_filter_code_memory<F: Field>() -> Column<F> {
Column::sum(COL_MAP.op.iter())
}

/// CTL filter for General Purpose memory read and write operations.
pub fn ctl_filter_gp_memory<F: Field>(channel: usize) -> Column<F> {
pub(crate) fn ctl_filter_gp_memory<F: Field>(channel: usize) -> Column<F> {
Column::single(COL_MAP.mem_channels[channel].used)
}

/// Structure representing the CPU Stark.
#[derive(Copy, Clone, Default)]
pub struct CpuStark<F, const D: usize> {
pub(crate) struct CpuStark<F, const D: usize> {
pub f: PhantomData<F>,
}

Expand Down
4 changes: 2 additions & 2 deletions evm/src/cpu/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const fn bits_from_opcode(opcode: u8) -> [bool; 8] {
}

/// Evaluates the constraints for opcode decoding.
pub fn eval_packed_generic<P: PackedField>(
pub(crate) fn eval_packed_generic<P: PackedField>(
lv: &CpuColumnsView<P>,
yield_constr: &mut ConstraintConsumer<P>,
) {
Expand Down Expand Up @@ -181,7 +181,7 @@ pub fn eval_packed_generic<P: PackedField>(

/// Circuit version of `eval_packed_generic`.
/// Evaluates the constraints for opcode decoding.
pub fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
pub(crate) fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
builder: &mut plonky2::plonk::circuit_builder::CircuitBuilder<F, D>,
lv: &CpuColumnsView<ExtensionTarget<D>>,
yield_constr: &mut RecursiveConstraintConsumer<F, D>,
Expand Down
4 changes: 2 additions & 2 deletions evm/src/cpu/dup_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ fn eval_ext_circuit_swap<F: RichField + Extendable<D>, const D: usize>(
}

/// Evaluates the constraints for the DUP and SWAP opcodes.
pub fn eval_packed<P: PackedField>(
pub(crate) fn eval_packed<P: PackedField>(
lv: &CpuColumnsView<P>,
nv: &CpuColumnsView<P>,
yield_constr: &mut ConstraintConsumer<P>,
Expand All @@ -339,7 +339,7 @@ pub fn eval_packed<P: PackedField>(

/// Circuit version of `eval_packed`.
/// Evaluates the constraints for the DUP and SWAP opcodes.
pub fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
pub(crate) fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
builder: &mut CircuitBuilder<F, D>,
lv: &CpuColumnsView<ExtensionTarget<D>>,
nv: &CpuColumnsView<ExtensionTarget<D>>,
Expand Down
4 changes: 2 additions & 2 deletions evm/src/cpu/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn eval_packed_init<P: PackedField>(
}

/// Evaluate the gas constraints for the opcodes that cost a constant gas.
pub fn eval_packed<P: PackedField>(
pub(crate) fn eval_packed<P: PackedField>(
lv: &CpuColumnsView<P>,
nv: &CpuColumnsView<P>,
yield_constr: &mut ConstraintConsumer<P>,
Expand Down Expand Up @@ -300,7 +300,7 @@ fn eval_ext_circuit_init<F: RichField + Extendable<D>, const D: usize>(

/// Circuit version of `eval_packed`.
/// Evaluate the gas constraints for the opcodes that cost a constant gas.
pub fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
pub(crate) 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>>,
Expand Down
4 changes: 2 additions & 2 deletions evm/src/cpu/halt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::cpu::columns::{CpuColumnsView, COL_MAP};
use crate::cpu::membus::NUM_GP_CHANNELS;

/// Evaluates constraints for the `halt` flag.
pub fn eval_packed<P: PackedField>(
pub(crate) fn eval_packed<P: PackedField>(
lv: &CpuColumnsView<P>,
nv: &CpuColumnsView<P>,
yield_constr: &mut ConstraintConsumer<P>,
Expand Down Expand Up @@ -48,7 +48,7 @@ pub fn eval_packed<P: PackedField>(

/// Circuit version of `eval_packed`.
/// Evaluates constraints for the `halt` flag.
pub fn eval_ext_circuit<F: RichField + Extendable<D>, const D: usize>(
pub(crate) 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>>,
Expand Down
Loading

0 comments on commit 88fcc32

Please sign in to comment.