Skip to content

Commit

Permalink
Merge bc4aca3 into 15be73d
Browse files Browse the repository at this point in the history
  • Loading branch information
nhtyy authored Dec 3, 2024
2 parents 15be73d + bc4aca3 commit c165917
Show file tree
Hide file tree
Showing 61 changed files with 212 additions and 169 deletions.
2 changes: 1 addition & 1 deletion crates/core/executor/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Program {
.map(|shape| {
shape
.inner
.get(&air.name())
.get(air.name())
.unwrap_or_else(|| panic!("Chip {} not found in specified shape", air.name()))
})
.copied()
Expand Down
2 changes: 1 addition & 1 deletion crates/core/executor/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl ExecutionRecord {
.map(|shape| {
shape
.inner
.get(&air.name())
.get(air.name())
.unwrap_or_else(|| panic!("Chip {} not found in specified shape", air.name()))
})
.copied()
Expand Down
2 changes: 1 addition & 1 deletion crates/core/executor/src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl CoreShape {

/// Determines whether the execution record contains a trace for a given chip.
pub fn included<F: PrimeField, A: MachineAir<F>>(&self, air: &A) -> bool {
self.inner.contains_key(&air.name())
self.inner.contains_key(air.name())
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/alu/add_sub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl<F: PrimeField> MachineAir<F> for AddSubChip {

type Program = Program;

fn name(&self) -> String {
"AddSub".to_string()
fn name(&self) -> &'static str {
"AddSub"
}

fn generate_trace(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/alu/bitwise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ impl<F: PrimeField> MachineAir<F> for BitwiseChip {

type Program = Program;

fn name(&self) -> String {
"Bitwise".to_string()
fn name(&self) -> &'static str {
"Bitwise"
}

fn generate_trace(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/alu/divrem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ impl<F: PrimeField> MachineAir<F> for DivRemChip {

type Program = Program;

fn name(&self) -> String {
"DivRem".to_string()
fn name(&self) -> &'static str {
"DivRem"
}

fn generate_trace(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/alu/lt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ impl<F: PrimeField32> MachineAir<F> for LtChip {

type Program = Program;

fn name(&self) -> String {
"Lt".to_string()
fn name(&self) -> &'static str {
"Lt"
}

fn generate_trace(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/alu/mul/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ impl<F: PrimeField> MachineAir<F> for MulChip {

type Program = Program;

fn name(&self) -> String {
"Mul".to_string()
fn name(&self) -> &'static str {
"Mul"
}

fn generate_trace(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/alu/sll/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ impl<F: PrimeField> MachineAir<F> for ShiftLeft {

type Program = Program;

fn name(&self) -> String {
"ShiftLeft".to_string()
fn name(&self) -> &'static str {
"ShiftLeft"
}

fn generate_trace(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/alu/sr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ impl<F: PrimeField> MachineAir<F> for ShiftRightChip {

type Program = Program;

fn name(&self) -> String {
"ShiftRight".to_string()
fn name(&self) -> &'static str {
"ShiftRight"
}

fn generate_trace(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/bytes/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ impl<F: Field> MachineAir<F> for ByteChip<F> {

type Program = Program;

fn name(&self) -> String {
"Byte".to_string()
fn name(&self) -> &'static str {
"Byte"
}

fn preprocessed_width(&self) -> usize {
Expand Down
6 changes: 3 additions & 3 deletions crates/core/machine/src/cpu/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ impl<F: PrimeField32> MachineAir<F> for CpuChip {

type Program = Program;

fn name(&self) -> String {
"CPU".to_string()
fn name(&self) -> &'static str {
"CPU"
}

fn generate_trace(
Expand All @@ -35,7 +35,7 @@ impl<F: PrimeField32> MachineAir<F> for CpuChip {
) -> RowMajorMatrix<F> {
let n_real_rows = input.cpu_events.len();
let padded_nb_rows = if let Some(shape) = &input.shape {
1 << shape.inner[&MachineAir::<F>::name(self)]
1 << shape.inner[MachineAir::<F>::name(self)]
} else if n_real_rows < 16 {
16
} else {
Expand Down
6 changes: 3 additions & 3 deletions crates/core/machine/src/memory/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ impl<F: PrimeField32> MachineAir<F> for MemoryGlobalChip {

type Program = Program;

fn name(&self) -> String {
fn name(&self) -> &'static str {
match self.kind {
MemoryChipType::Initialize => "MemoryGlobalInit".to_string(),
MemoryChipType::Finalize => "MemoryGlobalFinalize".to_string(),
MemoryChipType::Initialize => "MemoryGlobalInit",
MemoryChipType::Finalize => "MemoryGlobalFinalize",
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/memory/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ impl<F: PrimeField32> MachineAir<F> for MemoryLocalChip {

type Program = Program;

fn name(&self) -> String {
"MemoryLocal".to_string()
fn name(&self) -> &'static str {
"MemoryLocal"
}

fn generate_dependencies(&self, _input: &ExecutionRecord, _output: &mut ExecutionRecord) {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/memory/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ impl<F: PrimeField> MachineAir<F> for MemoryProgramChip {

type Program = Program;

fn name(&self) -> String {
"MemoryProgram".to_string()
fn name(&self) -> &'static str {
"MemoryProgram"
}

fn preprocessed_width(&self) -> usize {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/operations/field/field_den.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ mod tests {

type Program = Program;

fn name(&self) -> String {
"FieldDen".to_string()
fn name(&self) -> &'static str {
"FieldDen"
}

fn generate_trace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ mod tests {

type Program = Program;

fn name(&self) -> String {
"FieldInnerProduct".to_string()
fn name(&self) -> &'static str {
"FieldInnerProduct"
}

fn generate_trace(
Expand Down
9 changes: 7 additions & 2 deletions crates/core/machine/src/operations/field/field_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,13 @@ mod tests {

type Program = Program;

fn name(&self) -> String {
format!("FieldOp{:?}", self.operation)
fn name(&self) -> &'static str {
match self.operation {
FieldOperation::Add => "FieldAdd",
FieldOperation::Mul => "FieldMul",
FieldOperation::Sub => "FieldSub",
FieldOperation::Div => "FieldDiv",
}
}

fn generate_trace(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/operations/field/field_sqrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ mod tests {

type Program = Program;

fn name(&self) -> String {
"EdSqrtChip".to_string()
fn name(&self) -> &'static str {
"EdSqrtChip"
}

fn generate_trace(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/program/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ impl<F: PrimeField> MachineAir<F> for ProgramChip {

type Program = Program;

fn name(&self) -> String {
"Program".to_string()
fn name(&self) -> &'static str {
"Program"
}

fn preprocessed_width(&self) -> usize {
Expand Down
32 changes: 17 additions & 15 deletions crates/core/machine/src/riscv/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<F: PrimeField32> CoreShapeConfig<F> {
let allowed_height =
if allowed_log_height != 0 { 1 << allowed_log_height } else { 0 };
if *height <= allowed_height {
return Some((air.name(), allowed_log_height));
return Some((air.name().to_string(), allowed_log_height));
}
}
None
Expand Down Expand Up @@ -132,12 +132,12 @@ impl<F: PrimeField32> CoreShapeConfig<F> {
i
);
for (air, height) in heights.iter() {
if shape.inner.contains_key(&air.name()) {
if shape.inner.contains_key(air.name()) {
tracing::debug!(
"Chip {:<20}: {:<3} -> {:<3}",
air.name(),
log2_ceil_usize(*height),
shape.inner[&air.name()],
shape.inner[air.name()],
);
}
}
Expand Down Expand Up @@ -208,17 +208,19 @@ impl<F: PrimeField32> CoreShapeConfig<F> {
.rev()
.map(|rows_per_event| {
[
(air.name(), allowed_log_height),
(air.name().to_string(), allowed_log_height),
(
RiscvAir::<F>::SyscallPrecompile(SyscallChip::precompile()).name(),
RiscvAir::<F>::SyscallPrecompile(SyscallChip::precompile())
.name()
.to_string(),
((1 << allowed_log_height)
.div_ceil(&air.rows_per_event())
.next_power_of_two()
.ilog2() as usize)
.max(4),
),
(
RiscvAir::<F>::MemoryLocal(MemoryLocalChip::new()).name(),
RiscvAir::<F>::MemoryLocal(MemoryLocalChip::new()).name().to_string(),
(((1 << allowed_log_height) * mem_events_per_row)
.div_ceil(NUM_LOCAL_MEMORY_ENTRIES_PER_ROW * rows_per_event)
.next_power_of_two()
Expand Down Expand Up @@ -251,12 +253,12 @@ impl<F: PrimeField32> CoreShapeConfig<F> {
let preprocessed_heights = self
.allowed_preprocessed_log_heights
.iter()
.map(|(air, heights)| (air.name(), heights.clone()));
.map(|(air, heights)| (air.name().to_string(), heights.clone()));

let mut memory_heights = self
.memory_allowed_log_heights
.iter()
.map(|(air, heights)| (air.name(), heights.clone()))
.map(|(air, heights)| (air.name().to_string(), heights.clone()))
.collect::<HashMap<_, _>>();
memory_heights.extend(preprocessed_heights.clone());

Expand Down Expand Up @@ -288,7 +290,7 @@ impl<F: PrimeField32> CoreShapeConfig<F> {
Self::generate_all_shapes_from_allowed_log_heights({
let mut log_heights = allowed_log_heights
.iter()
.map(|(air, heights)| (air.name(), heights.clone()))
.map(|(air, heights)| (air.name().to_string(), heights.clone()))
.collect::<HashMap<_, _>>();
log_heights.extend(preprocessed_heights.clone());
log_heights
Expand All @@ -299,10 +301,10 @@ impl<F: PrimeField32> CoreShapeConfig<F> {
}

pub fn maximal_core_shapes(&self) -> Vec<CoreShape> {
let max_preprocessed = self
.allowed_preprocessed_log_heights
.iter()
.map(|(air, allowed_heights)| (air.name(), allowed_heights.last().unwrap().unwrap()));
let max_preprocessed =
self.allowed_preprocessed_log_heights.iter().map(|(air, allowed_heights)| {
(air.name().to_string(), allowed_heights.last().unwrap().unwrap())
});

let max_core_shapes = self
.allowed_core_log_heights
Expand All @@ -313,7 +315,7 @@ impl<F: PrimeField32> CoreShapeConfig<F> {
max_preprocessed
.clone()
.chain(allowed_log_heights.iter().map(|(air, allowed_heights)| {
(air.name(), allowed_heights.last().unwrap().unwrap())
(air.name().to_string(), allowed_heights.last().unwrap().unwrap())
}))
.collect::<CoreShape>()
});
Expand Down Expand Up @@ -799,7 +801,7 @@ pub mod tests {
let height_map = preprocessed_log_heights
.into_iter()
.chain(core_log_heights)
.map(|(air, log_height)| (air.name(), log_height))
.map(|(air, log_height)| (air.name().to_string(), log_height))
.collect::<HashMap<_, _>>();

let shape = CoreShape { inner: height_map };
Expand Down
7 changes: 5 additions & 2 deletions crates/core/machine/src/syscall/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ impl<F: PrimeField32> MachineAir<F> for SyscallChip {

type Program = Program;

fn name(&self) -> String {
format!("Syscall{}", self.shard_kind).to_string()
fn name(&self) -> &'static str {
match self.shard_kind {
SyscallShardKind::Core => "SyscallCore",
SyscallShardKind::Precompile => "SyscallPrecompile",
}
}

fn generate_dependencies(&self, _input: &ExecutionRecord, _output: &mut ExecutionRecord) {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/syscall/precompiles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl<F: PrimeField32> MachineAir<F> for CustomOpChip {
type Record = ExecutionRecord;
type Program = Program;

fn name(&self) -> String {
"CustomOp".to_string()
fn name(&self) -> &'static str {
"CustomOp"
}

fn generate_trace(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/machine/src/syscall/precompiles/edwards/ed_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ impl<F: PrimeField32, E: EllipticCurve + EdwardsParameters> MachineAir<F> for Ed

type Program = Program;

fn name(&self) -> String {
"EdAddAssign".to_string()
fn name(&self) -> &'static str {
"EdAddAssign"
}

fn generate_trace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ impl<F: PrimeField32, E: EdwardsParameters> MachineAir<F> for EdDecompressChip<E

type Program = Program;

fn name(&self) -> String {
"EdDecompress".to_string()
fn name(&self) -> &'static str {
"EdDecompress"
}

fn generate_trace(
Expand Down
6 changes: 3 additions & 3 deletions crates/core/machine/src/syscall/precompiles/fptower/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ impl<F: PrimeField32, P: FpOpField> MachineAir<F> for FpOpChip<P> {

type Program = Program;

fn name(&self) -> String {
fn name(&self) -> &'static str {
match P::FIELD_TYPE {
FieldType::Bn254 => "Bn254FpOpAssign".to_string(),
FieldType::Bls12381 => "Bls12381FpOpAssign".to_string(),
FieldType::Bn254 => "Bn254FpOpAssign",
FieldType::Bls12381 => "Bls12381FpOpAssign",
}
}

Expand Down
Loading

0 comments on commit c165917

Please sign in to comment.