From bc4aca3d8c22f6a21b32906f11968ce79f152262 Mon Sep 17 00:00:00 2001 From: nhtyy Date: Fri, 29 Nov 2024 10:38:20 -0800 Subject: [PATCH] fix: use &static str for chip names as much as possible --- crates/core/executor/src/program.rs | 2 +- crates/core/executor/src/record.rs | 2 +- crates/core/executor/src/shape.rs | 2 +- crates/core/machine/src/alu/add_sub/mod.rs | 4 +-- crates/core/machine/src/alu/bitwise/mod.rs | 4 +-- crates/core/machine/src/alu/divrem/mod.rs | 4 +-- crates/core/machine/src/alu/lt/mod.rs | 4 +-- crates/core/machine/src/alu/mul/mod.rs | 4 +-- crates/core/machine/src/alu/sll/mod.rs | 4 +-- crates/core/machine/src/alu/sr/mod.rs | 4 +-- crates/core/machine/src/bytes/trace.rs | 4 +-- crates/core/machine/src/cpu/trace.rs | 6 ++-- crates/core/machine/src/memory/global.rs | 6 ++-- crates/core/machine/src/memory/local.rs | 4 +-- crates/core/machine/src/memory/program.rs | 4 +-- .../machine/src/operations/field/field_den.rs | 4 +-- .../operations/field/field_inner_product.rs | 4 +-- .../machine/src/operations/field/field_op.rs | 9 ++++-- .../src/operations/field/field_sqrt.rs | 4 +-- crates/core/machine/src/program/mod.rs | 4 +-- crates/core/machine/src/riscv/shape.rs | 32 ++++++++++--------- crates/core/machine/src/syscall/chip.rs | 7 ++-- .../machine/src/syscall/precompiles/README.md | 4 +-- .../src/syscall/precompiles/edwards/ed_add.rs | 4 +-- .../precompiles/edwards/ed_decompress.rs | 4 +-- .../src/syscall/precompiles/fptower/fp.rs | 6 ++-- .../syscall/precompiles/fptower/fp2_addsub.rs | 6 ++-- .../syscall/precompiles/fptower/fp2_mul.rs | 6 ++-- .../syscall/precompiles/keccak256/trace.rs | 4 +-- .../precompiles/sha256/compress/trace.rs | 4 +-- .../precompiles/sha256/extend/trace.rs | 4 +-- .../syscall/precompiles/u256x2048_mul/air.rs | 4 +-- .../src/syscall/precompiles/uint256/air.rs | 4 +-- .../weierstrass/weierstrass_add.rs | 10 +++--- .../weierstrass/weierstrass_decompress.rs | 8 ++--- .../weierstrass/weierstrass_double.rs | 10 +++--- crates/core/machine/src/utils/prove.rs | 14 ++++---- crates/derive/src/lib.rs | 2 +- crates/prover/src/lib.rs | 2 +- crates/recursion/circuit/src/stark.rs | 4 +-- crates/recursion/core/src/chips/alu_base.rs | 4 +-- crates/recursion/core/src/chips/alu_ext.rs | 4 +-- crates/recursion/core/src/chips/batch_fri.rs | 4 +-- .../core/src/chips/exp_reverse_bits.rs | 4 +-- crates/recursion/core/src/chips/fri_fold.rs | 4 +-- .../recursion/core/src/chips/mem/constant.rs | 4 +-- .../recursion/core/src/chips/mem/variable.rs | 4 +-- .../core/src/chips/poseidon2_skinny/trace.rs | 13 ++++++-- .../poseidon2_wide/columns/permutation.rs | 2 +- .../core/src/chips/poseidon2_wide/trace.rs | 19 +++++++++-- .../recursion/core/src/chips/public_values.rs | 4 +-- crates/recursion/core/src/chips/select.rs | 4 +-- crates/recursion/core/src/machine.rs | 4 +-- crates/recursion/core/src/runtime/program.rs | 2 +- crates/recursion/core/src/shape.rs | 27 ++++++++++------ crates/stark/src/air/machine.rs | 2 +- crates/stark/src/chip.rs | 2 +- crates/stark/src/lookup/debug.rs | 4 +-- crates/stark/src/machine.rs | 19 ++++++----- crates/stark/src/prover.rs | 25 ++++++++------- crates/stark/src/verifier.rs | 4 +-- 61 files changed, 212 insertions(+), 169 deletions(-) diff --git a/crates/core/executor/src/program.rs b/crates/core/executor/src/program.rs index 09bb70cac4..5989310375 100644 --- a/crates/core/executor/src/program.rs +++ b/crates/core/executor/src/program.rs @@ -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() diff --git a/crates/core/executor/src/record.rs b/crates/core/executor/src/record.rs index f9e89acb4c..bf2b934ff2 100644 --- a/crates/core/executor/src/record.rs +++ b/crates/core/executor/src/record.rs @@ -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() diff --git a/crates/core/executor/src/shape.rs b/crates/core/executor/src/shape.rs index cf1477fbe4..f382473038 100644 --- a/crates/core/executor/src/shape.rs +++ b/crates/core/executor/src/shape.rs @@ -40,7 +40,7 @@ impl CoreShape { /// Determines whether the execution record contains a trace for a given chip. pub fn included>(&self, air: &A) -> bool { - self.inner.contains_key(&air.name()) + self.inner.contains_key(air.name()) } } diff --git a/crates/core/machine/src/alu/add_sub/mod.rs b/crates/core/machine/src/alu/add_sub/mod.rs index d276820755..e3aca948ef 100644 --- a/crates/core/machine/src/alu/add_sub/mod.rs +++ b/crates/core/machine/src/alu/add_sub/mod.rs @@ -68,8 +68,8 @@ impl MachineAir for AddSubChip { type Program = Program; - fn name(&self) -> String { - "AddSub".to_string() + fn name(&self) -> &'static str { + "AddSub" } fn generate_trace( diff --git a/crates/core/machine/src/alu/bitwise/mod.rs b/crates/core/machine/src/alu/bitwise/mod.rs index 88156e286c..d8ae480ac7 100644 --- a/crates/core/machine/src/alu/bitwise/mod.rs +++ b/crates/core/machine/src/alu/bitwise/mod.rs @@ -62,8 +62,8 @@ impl MachineAir for BitwiseChip { type Program = Program; - fn name(&self) -> String { - "Bitwise".to_string() + fn name(&self) -> &'static str { + "Bitwise" } fn generate_trace( diff --git a/crates/core/machine/src/alu/divrem/mod.rs b/crates/core/machine/src/alu/divrem/mod.rs index 1d4d539fc4..6d1a7ae7ef 100644 --- a/crates/core/machine/src/alu/divrem/mod.rs +++ b/crates/core/machine/src/alu/divrem/mod.rs @@ -214,8 +214,8 @@ impl MachineAir for DivRemChip { type Program = Program; - fn name(&self) -> String { - "DivRem".to_string() + fn name(&self) -> &'static str { + "DivRem" } fn generate_trace( diff --git a/crates/core/machine/src/alu/lt/mod.rs b/crates/core/machine/src/alu/lt/mod.rs index 876fdaaf8f..acdf383bb0 100644 --- a/crates/core/machine/src/alu/lt/mod.rs +++ b/crates/core/machine/src/alu/lt/mod.rs @@ -97,8 +97,8 @@ impl MachineAir for LtChip { type Program = Program; - fn name(&self) -> String { - "Lt".to_string() + fn name(&self) -> &'static str { + "Lt" } fn generate_trace( diff --git a/crates/core/machine/src/alu/mul/mod.rs b/crates/core/machine/src/alu/mul/mod.rs index 6a1ce272fe..494deb8a17 100644 --- a/crates/core/machine/src/alu/mul/mod.rs +++ b/crates/core/machine/src/alu/mul/mod.rs @@ -129,8 +129,8 @@ impl MachineAir for MulChip { type Program = Program; - fn name(&self) -> String { - "Mul".to_string() + fn name(&self) -> &'static str { + "Mul" } fn generate_trace( diff --git a/crates/core/machine/src/alu/sll/mod.rs b/crates/core/machine/src/alu/sll/mod.rs index af00dd47a5..1454c7abff 100644 --- a/crates/core/machine/src/alu/sll/mod.rs +++ b/crates/core/machine/src/alu/sll/mod.rs @@ -106,8 +106,8 @@ impl MachineAir for ShiftLeft { type Program = Program; - fn name(&self) -> String { - "ShiftLeft".to_string() + fn name(&self) -> &'static str { + "ShiftLeft" } fn generate_trace( diff --git a/crates/core/machine/src/alu/sr/mod.rs b/crates/core/machine/src/alu/sr/mod.rs index b26c949945..7a09cddfc5 100644 --- a/crates/core/machine/src/alu/sr/mod.rs +++ b/crates/core/machine/src/alu/sr/mod.rs @@ -139,8 +139,8 @@ impl MachineAir for ShiftRightChip { type Program = Program; - fn name(&self) -> String { - "ShiftRight".to_string() + fn name(&self) -> &'static str { + "ShiftRight" } fn generate_trace( diff --git a/crates/core/machine/src/bytes/trace.rs b/crates/core/machine/src/bytes/trace.rs index 6cfb81bbfc..90d40c850d 100644 --- a/crates/core/machine/src/bytes/trace.rs +++ b/crates/core/machine/src/bytes/trace.rs @@ -19,8 +19,8 @@ impl MachineAir for ByteChip { type Program = Program; - fn name(&self) -> String { - "Byte".to_string() + fn name(&self) -> &'static str { + "Byte" } fn preprocessed_width(&self) -> usize { diff --git a/crates/core/machine/src/cpu/trace.rs b/crates/core/machine/src/cpu/trace.rs index 5a43202608..8d4e6b550b 100644 --- a/crates/core/machine/src/cpu/trace.rs +++ b/crates/core/machine/src/cpu/trace.rs @@ -24,8 +24,8 @@ impl MachineAir for CpuChip { type Program = Program; - fn name(&self) -> String { - "CPU".to_string() + fn name(&self) -> &'static str { + "CPU" } fn generate_trace( @@ -35,7 +35,7 @@ impl MachineAir for CpuChip { ) -> RowMajorMatrix { let n_real_rows = input.cpu_events.len(); let padded_nb_rows = if let Some(shape) = &input.shape { - 1 << shape.inner[&MachineAir::::name(self)] + 1 << shape.inner[MachineAir::::name(self)] } else if n_real_rows < 16 { 16 } else { diff --git a/crates/core/machine/src/memory/global.rs b/crates/core/machine/src/memory/global.rs index db58e9c351..82aebd66a2 100644 --- a/crates/core/machine/src/memory/global.rs +++ b/crates/core/machine/src/memory/global.rs @@ -47,10 +47,10 @@ impl MachineAir 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", } } diff --git a/crates/core/machine/src/memory/local.rs b/crates/core/machine/src/memory/local.rs index 8be4377031..132a7a2343 100644 --- a/crates/core/machine/src/memory/local.rs +++ b/crates/core/machine/src/memory/local.rs @@ -73,8 +73,8 @@ impl MachineAir 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) { diff --git a/crates/core/machine/src/memory/program.rs b/crates/core/machine/src/memory/program.rs index 4dc8b196ad..db5050d7e0 100644 --- a/crates/core/machine/src/memory/program.rs +++ b/crates/core/machine/src/memory/program.rs @@ -66,8 +66,8 @@ impl MachineAir for MemoryProgramChip { type Program = Program; - fn name(&self) -> String { - "MemoryProgram".to_string() + fn name(&self) -> &'static str { + "MemoryProgram" } fn preprocessed_width(&self) -> usize { diff --git a/crates/core/machine/src/operations/field/field_den.rs b/crates/core/machine/src/operations/field/field_den.rs index b9bb80b306..2e3857f42c 100644 --- a/crates/core/machine/src/operations/field/field_den.rs +++ b/crates/core/machine/src/operations/field/field_den.rs @@ -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( diff --git a/crates/core/machine/src/operations/field/field_inner_product.rs b/crates/core/machine/src/operations/field/field_inner_product.rs index 30f2610e74..482ffa6b7c 100644 --- a/crates/core/machine/src/operations/field/field_inner_product.rs +++ b/crates/core/machine/src/operations/field/field_inner_product.rs @@ -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( diff --git a/crates/core/machine/src/operations/field/field_op.rs b/crates/core/machine/src/operations/field/field_op.rs index 9e16fe4db2..42d899ec9f 100644 --- a/crates/core/machine/src/operations/field/field_op.rs +++ b/crates/core/machine/src/operations/field/field_op.rs @@ -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( diff --git a/crates/core/machine/src/operations/field/field_sqrt.rs b/crates/core/machine/src/operations/field/field_sqrt.rs index a0f40c6a48..bcf84b848e 100644 --- a/crates/core/machine/src/operations/field/field_sqrt.rs +++ b/crates/core/machine/src/operations/field/field_sqrt.rs @@ -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( diff --git a/crates/core/machine/src/program/mod.rs b/crates/core/machine/src/program/mod.rs index f6c1f3bc0c..d8d83a6dab 100644 --- a/crates/core/machine/src/program/mod.rs +++ b/crates/core/machine/src/program/mod.rs @@ -56,8 +56,8 @@ impl MachineAir for ProgramChip { type Program = Program; - fn name(&self) -> String { - "Program".to_string() + fn name(&self) -> &'static str { + "Program" } fn preprocessed_width(&self) -> usize { diff --git a/crates/core/machine/src/riscv/shape.rs b/crates/core/machine/src/riscv/shape.rs index 4ef0650043..b35e24ba38 100644 --- a/crates/core/machine/src/riscv/shape.rs +++ b/crates/core/machine/src/riscv/shape.rs @@ -87,7 +87,7 @@ impl CoreShapeConfig { 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 @@ -132,12 +132,12 @@ impl CoreShapeConfig { 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()], ); } } @@ -208,9 +208,11 @@ impl CoreShapeConfig { .rev() .map(|rows_per_event| { [ - (air.name(), allowed_log_height), + (air.name().to_string(), allowed_log_height), ( - RiscvAir::::SyscallPrecompile(SyscallChip::precompile()).name(), + RiscvAir::::SyscallPrecompile(SyscallChip::precompile()) + .name() + .to_string(), ((1 << allowed_log_height) .div_ceil(&air.rows_per_event()) .next_power_of_two() @@ -218,7 +220,7 @@ impl CoreShapeConfig { .max(4), ), ( - RiscvAir::::MemoryLocal(MemoryLocalChip::new()).name(), + RiscvAir::::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() @@ -251,12 +253,12 @@ impl CoreShapeConfig { 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::>(); memory_heights.extend(preprocessed_heights.clone()); @@ -288,7 +290,7 @@ impl CoreShapeConfig { 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::>(); log_heights.extend(preprocessed_heights.clone()); log_heights @@ -299,10 +301,10 @@ impl CoreShapeConfig { } pub fn maximal_core_shapes(&self) -> Vec { - 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 @@ -313,7 +315,7 @@ impl CoreShapeConfig { 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::() }); @@ -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::>(); let shape = CoreShape { inner: height_map }; diff --git a/crates/core/machine/src/syscall/chip.rs b/crates/core/machine/src/syscall/chip.rs index 00257d46aa..c0e4a2cb37 100644 --- a/crates/core/machine/src/syscall/chip.rs +++ b/crates/core/machine/src/syscall/chip.rs @@ -70,8 +70,11 @@ impl MachineAir 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) { diff --git a/crates/core/machine/src/syscall/precompiles/README.md b/crates/core/machine/src/syscall/precompiles/README.md index a6d26bd3fe..ebf5f1ea9f 100644 --- a/crates/core/machine/src/syscall/precompiles/README.md +++ b/crates/core/machine/src/syscall/precompiles/README.md @@ -61,8 +61,8 @@ impl MachineAir for CustomOpChip { type Record = ExecutionRecord; type Program = Program; - fn name(&self) -> String { - "CustomOp".to_string() + fn name(&self) -> &'static str { + "CustomOp" } fn generate_trace( diff --git a/crates/core/machine/src/syscall/precompiles/edwards/ed_add.rs b/crates/core/machine/src/syscall/precompiles/edwards/ed_add.rs index 7488a772c3..5e59cbe5a1 100644 --- a/crates/core/machine/src/syscall/precompiles/edwards/ed_add.rs +++ b/crates/core/machine/src/syscall/precompiles/edwards/ed_add.rs @@ -109,8 +109,8 @@ impl MachineAir for Ed type Program = Program; - fn name(&self) -> String { - "EdAddAssign".to_string() + fn name(&self) -> &'static str { + "EdAddAssign" } fn generate_trace( diff --git a/crates/core/machine/src/syscall/precompiles/edwards/ed_decompress.rs b/crates/core/machine/src/syscall/precompiles/edwards/ed_decompress.rs index 51b3f32e59..25c184c9ac 100644 --- a/crates/core/machine/src/syscall/precompiles/edwards/ed_decompress.rs +++ b/crates/core/machine/src/syscall/precompiles/edwards/ed_decompress.rs @@ -207,8 +207,8 @@ impl MachineAir for EdDecompressChip String { - "EdDecompress".to_string() + fn name(&self) -> &'static str { + "EdDecompress" } fn generate_trace( diff --git a/crates/core/machine/src/syscall/precompiles/fptower/fp.rs b/crates/core/machine/src/syscall/precompiles/fptower/fp.rs index a9c21016c7..53a9d3d9ee 100644 --- a/crates/core/machine/src/syscall/precompiles/fptower/fp.rs +++ b/crates/core/machine/src/syscall/precompiles/fptower/fp.rs @@ -80,10 +80,10 @@ impl MachineAir for FpOpChip

{ 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", } } diff --git a/crates/core/machine/src/syscall/precompiles/fptower/fp2_addsub.rs b/crates/core/machine/src/syscall/precompiles/fptower/fp2_addsub.rs index 7f28309597..55f60225b6 100644 --- a/crates/core/machine/src/syscall/precompiles/fptower/fp2_addsub.rs +++ b/crates/core/machine/src/syscall/precompiles/fptower/fp2_addsub.rs @@ -83,10 +83,10 @@ impl MachineAir for Fp2AddSubAssignChip

{ type Program = Program; - fn name(&self) -> String { + fn name(&self) -> &'static str { match P::FIELD_TYPE { - FieldType::Bn254 => "Bn254Fp2AddSubAssign".to_string(), - FieldType::Bls12381 => "Bls12831Fp2AddSubAssign".to_string(), + FieldType::Bn254 => "Bn254Fp2AddSubAssign", + FieldType::Bls12381 => "Bls12831Fp2AddSubAssign", } } diff --git a/crates/core/machine/src/syscall/precompiles/fptower/fp2_mul.rs b/crates/core/machine/src/syscall/precompiles/fptower/fp2_mul.rs index 95a624cc2f..03559594c7 100644 --- a/crates/core/machine/src/syscall/precompiles/fptower/fp2_mul.rs +++ b/crates/core/machine/src/syscall/precompiles/fptower/fp2_mul.rs @@ -132,10 +132,10 @@ impl MachineAir for Fp2MulAssignChip

{ type Program = Program; - fn name(&self) -> String { + fn name(&self) -> &'static str { match P::FIELD_TYPE { - FieldType::Bn254 => "Bn254Fp2MulAssign".to_string(), - FieldType::Bls12381 => "Bls12831Fp2MulAssign".to_string(), + FieldType::Bn254 => "Bn254Fp2MulAssign", + FieldType::Bls12381 => "Bls12831Fp2MulAssign", } } diff --git a/crates/core/machine/src/syscall/precompiles/keccak256/trace.rs b/crates/core/machine/src/syscall/precompiles/keccak256/trace.rs index 020b28c9f0..48a0b001b5 100644 --- a/crates/core/machine/src/syscall/precompiles/keccak256/trace.rs +++ b/crates/core/machine/src/syscall/precompiles/keccak256/trace.rs @@ -23,8 +23,8 @@ impl MachineAir for KeccakPermuteChip { type Record = ExecutionRecord; type Program = Program; - fn name(&self) -> String { - "KeccakPermute".to_string() + fn name(&self) -> &'static str { + "KeccakPermute" } fn generate_dependencies(&self, input: &Self::Record, output: &mut Self::Record) { diff --git a/crates/core/machine/src/syscall/precompiles/sha256/compress/trace.rs b/crates/core/machine/src/syscall/precompiles/sha256/compress/trace.rs index d6b61b67f2..73d0df171a 100644 --- a/crates/core/machine/src/syscall/precompiles/sha256/compress/trace.rs +++ b/crates/core/machine/src/syscall/precompiles/sha256/compress/trace.rs @@ -23,8 +23,8 @@ impl MachineAir for ShaCompressChip { type Program = Program; - fn name(&self) -> String { - "ShaCompress".to_string() + fn name(&self) -> &'static str { + "ShaCompress" } fn generate_trace( diff --git a/crates/core/machine/src/syscall/precompiles/sha256/extend/trace.rs b/crates/core/machine/src/syscall/precompiles/sha256/extend/trace.rs index 75e1a16533..b538037920 100644 --- a/crates/core/machine/src/syscall/precompiles/sha256/extend/trace.rs +++ b/crates/core/machine/src/syscall/precompiles/sha256/extend/trace.rs @@ -18,8 +18,8 @@ impl MachineAir for ShaExtendChip { type Program = Program; - fn name(&self) -> String { - "ShaExtend".to_string() + fn name(&self) -> &'static str { + "ShaExtend" } fn generate_trace( diff --git a/crates/core/machine/src/syscall/precompiles/u256x2048_mul/air.rs b/crates/core/machine/src/syscall/precompiles/u256x2048_mul/air.rs index 43a9906581..e48a352246 100644 --- a/crates/core/machine/src/syscall/precompiles/u256x2048_mul/air.rs +++ b/crates/core/machine/src/syscall/precompiles/u256x2048_mul/air.rs @@ -92,8 +92,8 @@ impl MachineAir for U256x2048MulChip { type Record = ExecutionRecord; type Program = Program; - fn name(&self) -> String { - "U256XU2048Mul".to_string() + fn name(&self) -> &'static str { + "U256XU2048Mul" } fn generate_trace( diff --git a/crates/core/machine/src/syscall/precompiles/uint256/air.rs b/crates/core/machine/src/syscall/precompiles/uint256/air.rs index 54e0925f9e..db2458ac95 100644 --- a/crates/core/machine/src/syscall/precompiles/uint256/air.rs +++ b/crates/core/machine/src/syscall/precompiles/uint256/air.rs @@ -96,8 +96,8 @@ impl MachineAir for Uint256MulChip { type Record = ExecutionRecord; type Program = Program; - fn name(&self) -> String { - "Uint256MulMod".to_string() + fn name(&self) -> &'static str { + "Uint256MulMod" } fn generate_trace( diff --git a/crates/core/machine/src/syscall/precompiles/weierstrass/weierstrass_add.rs b/crates/core/machine/src/syscall/precompiles/weierstrass/weierstrass_add.rs index ac82fb88ce..6f46235cc2 100644 --- a/crates/core/machine/src/syscall/precompiles/weierstrass/weierstrass_add.rs +++ b/crates/core/machine/src/syscall/precompiles/weierstrass/weierstrass_add.rs @@ -147,12 +147,12 @@ impl MachineAir type Record = ExecutionRecord; type Program = Program; - fn name(&self) -> String { + fn name(&self) -> &'static str { match E::CURVE_TYPE { - CurveType::Secp256k1 => "Secp256k1AddAssign".to_string(), - CurveType::Secp256r1 => "Secp256r1AddAssign".to_string(), - CurveType::Bn254 => "Bn254AddAssign".to_string(), - CurveType::Bls12381 => "Bls12381AddAssign".to_string(), + CurveType::Secp256k1 => "Secp256k1AddAssign", + CurveType::Secp256r1 => "Secp256r1AddAssign", + CurveType::Bn254 => "Bn254AddAssign", + CurveType::Bls12381 => "Bls12381AddAssign", _ => panic!("Unsupported curve"), } } diff --git a/crates/core/machine/src/syscall/precompiles/weierstrass/weierstrass_decompress.rs b/crates/core/machine/src/syscall/precompiles/weierstrass/weierstrass_decompress.rs index da010cf81d..c06fa5a4ab 100644 --- a/crates/core/machine/src/syscall/precompiles/weierstrass/weierstrass_decompress.rs +++ b/crates/core/machine/src/syscall/precompiles/weierstrass/weierstrass_decompress.rs @@ -145,11 +145,11 @@ impl MachineAir type Record = ExecutionRecord; type Program = Program; - fn name(&self) -> String { + fn name(&self) -> &'static str { match E::CURVE_TYPE { - CurveType::Secp256k1 => "Secp256k1Decompress".to_string(), - CurveType::Secp256r1 => "Secp256r1Decompress".to_string(), - CurveType::Bls12381 => "Bls12381Decompress".to_string(), + CurveType::Secp256k1 => "Secp256k1Decompress", + CurveType::Secp256r1 => "Secp256r1Decompress", + CurveType::Bls12381 => "Bls12381Decompress", _ => panic!("Unsupported curve"), } } diff --git a/crates/core/machine/src/syscall/precompiles/weierstrass/weierstrass_double.rs b/crates/core/machine/src/syscall/precompiles/weierstrass/weierstrass_double.rs index e7a8f9600f..c4147c1f95 100644 --- a/crates/core/machine/src/syscall/precompiles/weierstrass/weierstrass_double.rs +++ b/crates/core/machine/src/syscall/precompiles/weierstrass/weierstrass_double.rs @@ -165,12 +165,12 @@ impl MachineAir type Record = ExecutionRecord; type Program = Program; - fn name(&self) -> String { + fn name(&self) -> &'static str { match E::CURVE_TYPE { - CurveType::Secp256k1 => "Secp256k1DoubleAssign".to_string(), - CurveType::Secp256r1 => "Secp256r1DoubleAssign".to_string(), - CurveType::Bn254 => "Bn254DoubleAssign".to_string(), - CurveType::Bls12381 => "Bls12381DoubleAssign".to_string(), + CurveType::Secp256k1 => "Secp256k1DoubleAssign", + CurveType::Secp256r1 => "Secp256r1DoubleAssign", + CurveType::Bn254 => "Bn254DoubleAssign", + CurveType::Bls12381 => "Bls12381DoubleAssign", _ => panic!("Unsupported curve"), } } diff --git a/crates/core/machine/src/utils/prove.rs b/crates/core/machine/src/utils/prove.rs index bca7ee88a8..51a7a721a3 100644 --- a/crates/core/machine/src/utils/prove.rs +++ b/crates/core/machine/src/utils/prove.rs @@ -205,10 +205,12 @@ where // Spawn the workers for phase 1 record generation. let p1_record_gen_sync = Arc::new(TurnBasedSync::new()); let p1_trace_gen_sync = Arc::new(TurnBasedSync::new()); - let (p1_records_and_traces_tx, p1_records_and_traces_rx) = - sync_channel::<(Vec, Vec>)>>)>( - opts.records_and_traces_channel_capacity, - ); + let (p1_records_and_traces_tx, p1_records_and_traces_rx) = sync_channel::<( + Vec, + Vec>)>>, + )>( + opts.records_and_traces_channel_capacity, + ); let p1_records_and_traces_tx = Arc::new(Mutex::new(p1_records_and_traces_tx)); let checkpoints_rx = Arc::new(Mutex::new(checkpoints_rx)); @@ -438,8 +440,8 @@ where sync_channel::<( Vec, ( - Vec>)>>, - Vec>)>>, + Vec>)>>, + Vec>)>>, ), )>(opts.records_and_traces_channel_capacity); let p2_records_and_traces_tx = Arc::new(Mutex::new(p2_records_and_traces_tx)); diff --git a/crates/derive/src/lib.rs b/crates/derive/src/lib.rs index 3721b9b93e..2e5461d5c9 100644 --- a/crates/derive/src/lib.rs +++ b/crates/derive/src/lib.rs @@ -204,7 +204,7 @@ pub fn machine_air_derive(input: TokenStream) -> TokenStream { type Program = #program_path; - fn name(&self) -> String { + fn name(&self) -> &'static str { match self { #(#name_arms,)* } diff --git a/crates/prover/src/lib.rs b/crates/prover/src/lib.rs index 75915e5bc0..9beeefad8b 100644 --- a/crates/prover/src/lib.rs +++ b/crates/prover/src/lib.rs @@ -691,7 +691,7 @@ impl SP1Prover { usize, Arc>, ExecutionRecord, - Vec<(String, RowMajorMatrix)>, + Vec<(&'static str, RowMajorMatrix)>, )>(opts.recursion_opts.records_and_traces_channel_capacity); let record_and_trace_tx = Arc::new(Mutex::new(record_and_trace_tx)); let record_and_trace_rx = Arc::new(Mutex::new(record_and_trace_rx)); diff --git a/crates/recursion/circuit/src/stark.rs b/crates/recursion/circuit/src/stark.rs index 8242ab23ab..337309f6fe 100644 --- a/crates/recursion/circuit/src/stark.rs +++ b/crates/recursion/circuit/src/stark.rs @@ -161,7 +161,7 @@ pub fn dummy_vk_and_shard_proof>( ::Challenge, ::Challenger, >>::natural_domain_for_degree(pcs, 1 << log_height); - (name.to_owned(), domain, Dimensions { width: *width, height: 1 << log_height }) + (name.to_string(), domain, Dimensions { width: *width, height: 1 << log_height }) }) .collect(); @@ -169,7 +169,7 @@ pub fn dummy_vk_and_shard_proof>( let preprocessed_chip_ordering = preprocessed_names_and_dimensions .iter() .enumerate() - .map(|(i, (name, _, _))| (name.to_owned(), i)) + .map(|(i, (name, _, _))| (name.to_string(), i)) .collect::>(); let vk = StarkVerifyingKey { diff --git a/crates/recursion/core/src/chips/alu_base.rs b/crates/recursion/core/src/chips/alu_base.rs index f587c73ce8..8827a55b5a 100644 --- a/crates/recursion/core/src/chips/alu_base.rs +++ b/crates/recursion/core/src/chips/alu_base.rs @@ -64,8 +64,8 @@ impl MachineAir for BaseAluChip { type Program = crate::RecursionProgram; - fn name(&self) -> String { - "BaseAlu".to_string() + fn name(&self) -> &'static str { + "BaseAlu" } fn preprocessed_width(&self) -> usize { diff --git a/crates/recursion/core/src/chips/alu_ext.rs b/crates/recursion/core/src/chips/alu_ext.rs index b698a5d209..9fb2ec7c45 100644 --- a/crates/recursion/core/src/chips/alu_ext.rs +++ b/crates/recursion/core/src/chips/alu_ext.rs @@ -62,8 +62,8 @@ impl> MachineAir for ExtAluChip { type Program = crate::RecursionProgram; - fn name(&self) -> String { - "ExtAlu".to_string() + fn name(&self) -> &'static str { + "ExtAlu" } fn preprocessed_width(&self) -> usize { diff --git a/crates/recursion/core/src/chips/batch_fri.rs b/crates/recursion/core/src/chips/batch_fri.rs index 6522a9881d..319044dcb3 100644 --- a/crates/recursion/core/src/chips/batch_fri.rs +++ b/crates/recursion/core/src/chips/batch_fri.rs @@ -61,8 +61,8 @@ impl MachineAir for BatchFRIChip; - fn name(&self) -> String { - "BatchFRI".to_string() + fn name(&self) -> &'static str { + "BatchFRI" } fn generate_dependencies(&self, _: &Self::Record, _: &mut Self::Record) { diff --git a/crates/recursion/core/src/chips/exp_reverse_bits.rs b/crates/recursion/core/src/chips/exp_reverse_bits.rs index b5a8655236..412bd3617e 100644 --- a/crates/recursion/core/src/chips/exp_reverse_bits.rs +++ b/crates/recursion/core/src/chips/exp_reverse_bits.rs @@ -73,8 +73,8 @@ impl MachineAir for ExpReverseBitsLenCh type Program = RecursionProgram; - fn name(&self) -> String { - "ExpReverseBitsLen".to_string() + fn name(&self) -> &'static str { + "ExpReverseBitsLen" } fn generate_dependencies(&self, _: &Self::Record, _: &mut Self::Record) { diff --git a/crates/recursion/core/src/chips/fri_fold.rs b/crates/recursion/core/src/chips/fri_fold.rs index 063037032c..174f1595e9 100644 --- a/crates/recursion/core/src/chips/fri_fold.rs +++ b/crates/recursion/core/src/chips/fri_fold.rs @@ -89,8 +89,8 @@ impl MachineAir for FriFoldChip type Program = RecursionProgram; - fn name(&self) -> String { - "FriFold".to_string() + fn name(&self) -> &'static str { + "FriFold" } fn generate_dependencies(&self, _: &Self::Record, _: &mut Self::Record) { diff --git a/crates/recursion/core/src/chips/mem/constant.rs b/crates/recursion/core/src/chips/mem/constant.rs index 9298de73ec..68d25e44c3 100644 --- a/crates/recursion/core/src/chips/mem/constant.rs +++ b/crates/recursion/core/src/chips/mem/constant.rs @@ -47,8 +47,8 @@ impl MachineAir for MemoryChip { type Program = crate::RecursionProgram; - fn name(&self) -> String { - "MemoryConst".to_string() + fn name(&self) -> &'static str { + "MemoryConst" } fn preprocessed_width(&self) -> usize { NUM_MEM_PREPROCESSED_INIT_COLS diff --git a/crates/recursion/core/src/chips/mem/variable.rs b/crates/recursion/core/src/chips/mem/variable.rs index 98ae999ba4..cb2a6dd52f 100644 --- a/crates/recursion/core/src/chips/mem/variable.rs +++ b/crates/recursion/core/src/chips/mem/variable.rs @@ -48,8 +48,8 @@ impl MachineAir for MemoryChip { type Program = crate::RecursionProgram; - fn name(&self) -> String { - "MemoryVar".to_string() + fn name(&self) -> &'static str { + "MemoryVar" } fn preprocessed_width(&self) -> usize { NUM_MEM_PREPROCESSED_INIT_COLS diff --git a/crates/recursion/core/src/chips/poseidon2_skinny/trace.rs b/crates/recursion/core/src/chips/poseidon2_skinny/trace.rs index 7e67f54362..9e4d054aba 100644 --- a/crates/recursion/core/src/chips/poseidon2_skinny/trace.rs +++ b/crates/recursion/core/src/chips/poseidon2_skinny/trace.rs @@ -2,6 +2,7 @@ use std::{ array, borrow::{Borrow, BorrowMut}, mem::size_of, + sync::OnceLock, }; use itertools::Itertools; @@ -37,8 +38,16 @@ impl MachineAir for Poseidon2SkinnyChip type Program = RecursionProgram; - fn name(&self) -> String { - format!("Poseidon2SkinnyDeg{}", DEGREE) + fn name(&self) -> &'static str { + static NAME: OnceLock<&'static str> = OnceLock::new(); + + // Leak the str only once to avoid future allocations. + // This should be cleaned up by the system when the program exits. + // OnceLock ensures its only called once. + NAME.get_or_init(|| { + let name = format!("Poseidon2SkinnyDeg{}", DEGREE); + Box::leak(name.into_boxed_str()) + }) } fn generate_dependencies(&self, _: &Self::Record, _: &mut Self::Record) { diff --git a/crates/recursion/core/src/chips/poseidon2_wide/columns/permutation.rs b/crates/recursion/core/src/chips/poseidon2_wide/columns/permutation.rs index 45fc461e29..3a3626a503 100644 --- a/crates/recursion/core/src/chips/poseidon2_wide/columns/permutation.rs +++ b/crates/recursion/core/src/chips/poseidon2_wide/columns/permutation.rs @@ -181,7 +181,7 @@ pub type PermutationNoSboxHalfExternal = PermutationNoSbox; pub fn permutation_mut<'a, 'b: 'a, T, const DEGREE: usize>( row: &'b mut [T], -) -> Box<&mut (dyn Poseidon2Mut + 'a)> +) -> Box<&'b mut (dyn Poseidon2Mut + 'a)> where T: Copy, { diff --git a/crates/recursion/core/src/chips/poseidon2_wide/trace.rs b/crates/recursion/core/src/chips/poseidon2_wide/trace.rs index e13717bfae..53a543a621 100644 --- a/crates/recursion/core/src/chips/poseidon2_wide/trace.rs +++ b/crates/recursion/core/src/chips/poseidon2_wide/trace.rs @@ -1,4 +1,4 @@ -use std::{borrow::BorrowMut, mem::size_of}; +use std::{borrow::BorrowMut, mem::size_of, sync::OnceLock}; use p3_air::BaseAir; use p3_field::PrimeField32; @@ -33,8 +33,21 @@ impl MachineAir for Poseidon2WideChip; - fn name(&self) -> String { - format!("Poseidon2WideDeg{}", DEGREE) + fn name(&self) -> &'static str { + static NAME: OnceLock<&'static str> = OnceLock::new(); + + // Note: Rust Team will eventually provide a better way to do this. + // (::to_string should be const) + // + // you could probably do this now using transpose and converting to ascii in a const fn + + // Leak the str only once to avoid future allocations. + // This should be cleaned up by the system when the program exits. + // OnceLock ensures its only called once. + NAME.get_or_init(|| { + let name = format!("Poseidon2WideDeg{}", DEGREE); + Box::leak(name.into_boxed_str()) + }) } fn generate_dependencies(&self, _: &Self::Record, _: &mut Self::Record) { diff --git a/crates/recursion/core/src/chips/public_values.rs b/crates/recursion/core/src/chips/public_values.rs index e81ed89758..b76dc9906a 100644 --- a/crates/recursion/core/src/chips/public_values.rs +++ b/crates/recursion/core/src/chips/public_values.rs @@ -53,8 +53,8 @@ impl MachineAir for PublicValuesChip { type Program = RecursionProgram; - fn name(&self) -> String { - "PublicValues".to_string() + fn name(&self) -> &'static str { + "PublicValues" } fn generate_dependencies(&self, _: &Self::Record, _: &mut Self::Record) { diff --git a/crates/recursion/core/src/chips/select.rs b/crates/recursion/core/src/chips/select.rs index d1c44d9b94..9fbb957f4f 100644 --- a/crates/recursion/core/src/chips/select.rs +++ b/crates/recursion/core/src/chips/select.rs @@ -44,8 +44,8 @@ impl MachineAir for SelectChip { type Program = crate::RecursionProgram; - fn name(&self) -> String { - "Select".to_string() + fn name(&self) -> &'static str { + "Select" } fn preprocessed_width(&self) -> usize { diff --git a/crates/recursion/core/src/machine.rs b/crates/recursion/core/src/machine.rs index b143487d1d..a22475b7da 100644 --- a/crates/recursion/core/src/machine.rs +++ b/crates/recursion/core/src/machine.rs @@ -164,7 +164,7 @@ impl, const DEGREE: usize> RecursionAi (Self::ExpReverseBitsLen(ExpReverseBitsLenChip::), 17), (Self::PublicValues(PublicValuesChip), PUB_VALUES_LOG_HEIGHT), ] - .map(|(chip, log_height)| (chip.name(), log_height)), + .map(|(chip, log_height)| (chip.name().to_string(), log_height)), ); RecursionShape { inner: shape } } @@ -201,7 +201,7 @@ impl, const DEGREE: usize> RecursionAi ), (Self::PublicValues(PublicValuesChip), PUB_VALUES_LOG_HEIGHT), ] - .map(|(chip, log_height)| (chip.name(), log_height)) + .map(|(chip, log_height)| (chip.name().to_string(), log_height)) .to_vec() } } diff --git a/crates/recursion/core/src/runtime/program.rs b/crates/recursion/core/src/runtime/program.rs index 38fb29ca8a..21cdf30dad 100644 --- a/crates/recursion/core/src/runtime/program.rs +++ b/crates/recursion/core/src/runtime/program.rs @@ -29,7 +29,7 @@ impl RecursionProgram { .map(|shape| { shape .inner - .get(&air.name()) + .get(air.name()) .unwrap_or_else(|| panic!("Chip {} not found in specified shape", air.name())) }) .copied() diff --git a/crates/recursion/core/src/shape.rs b/crates/recursion/core/src/shape.rs index 39f47cf72c..76295cd464 100644 --- a/crates/recursion/core/src/shape.rs +++ b/crates/recursion/core/src/shape.rs @@ -88,17 +88,24 @@ impl, const DEGREE: usize> Default { fn default() -> Self { // Get the names of all the recursion airs to make the shape specification more readable. - let mem_const = RecursionAir::::MemoryConst(MemoryConstChip::default()).name(); - let mem_var = RecursionAir::::MemoryVar(MemoryVarChip::default()).name(); - let base_alu = RecursionAir::::BaseAlu(BaseAluChip).name(); - let ext_alu = RecursionAir::::ExtAlu(ExtAluChip).name(); - let poseidon2_wide = - RecursionAir::::Poseidon2Wide(Poseidon2WideChip::).name(); - let batch_fri = RecursionAir::::BatchFRI(BatchFRIChip::).name(); - let select = RecursionAir::::Select(SelectChip).name(); + let mem_const = + RecursionAir::::MemoryConst(MemoryConstChip::default()).name().to_string(); + let mem_var = + RecursionAir::::MemoryVar(MemoryVarChip::default()).name().to_string(); + let base_alu = RecursionAir::::BaseAlu(BaseAluChip).name().to_string(); + let ext_alu = RecursionAir::::ExtAlu(ExtAluChip).name().to_string(); + let poseidon2_wide = RecursionAir::::Poseidon2Wide(Poseidon2WideChip::) + .name() + .to_string(); + let batch_fri = + RecursionAir::::BatchFRI(BatchFRIChip::).name().to_string(); + let select = RecursionAir::::Select(SelectChip).name().to_string(); let exp_reverse_bits_len = - RecursionAir::::ExpReverseBitsLen(ExpReverseBitsLenChip::).name(); - let public_values = RecursionAir::::PublicValues(PublicValuesChip).name(); + RecursionAir::::ExpReverseBitsLen(ExpReverseBitsLenChip::) + .name() + .to_string(); + let public_values = + RecursionAir::::PublicValues(PublicValuesChip).name().to_string(); // Specify allowed shapes. let allowed_shapes = [ diff --git a/crates/stark/src/air/machine.rs b/crates/stark/src/air/machine.rs index 0a9b0af4a8..037779e684 100644 --- a/crates/stark/src/air/machine.rs +++ b/crates/stark/src/air/machine.rs @@ -17,7 +17,7 @@ pub trait MachineAir: BaseAir + 'static + Send + Sync { type Program: MachineProgram; /// A unique identifier for this AIR as part of a machine. - fn name(&self) -> String; + fn name(&self) -> &'static str; /// Generate the trace for a given execution record. /// diff --git a/crates/stark/src/chip.rs b/crates/stark/src/chip.rs index 2d627d2ccd..1385a50ffe 100644 --- a/crates/stark/src/chip.rs +++ b/crates/stark/src/chip.rs @@ -186,7 +186,7 @@ where type Program = A::Program; - fn name(&self) -> String { + fn name(&self) -> &'static str { self.air.name() } diff --git a/crates/stark/src/lookup/debug.rs b/crates/stark/src/lookup/debug.rs index fd3e0b61ce..492ee1ce5e 100644 --- a/crates/stark/src/lookup/debug.rs +++ b/crates/stark/src/lookup/debug.rs @@ -14,7 +14,7 @@ use crate::{ #[derive(Debug)] pub struct InteractionData { /// The chip name. - pub chip_name: String, + pub chip_name: &'static str, /// The kind of interaction. pub kind: InteractionKind, /// The row of the interaction. @@ -72,7 +72,7 @@ pub fn debug_interactions>>( let trace = chip.generate_trace(record, &mut A::Record::default()); let mut pre_traces = pkey.traces.clone(); let mut preprocessed_trace = - pkey.chip_ordering.get(&chip.name()).map(|&index| pre_traces.get_mut(index).unwrap()); + pkey.chip_ordering.get(chip.name()).map(|&index| pre_traces.get_mut(index).unwrap()); let mut main = trace.clone(); let height = trace.clone().height(); diff --git a/crates/stark/src/machine.rs b/crates/stark/src/machine.rs index 5a5f5ea8db..bd47799273 100644 --- a/crates/stark/src/machine.rs +++ b/crates/stark/src/machine.rs @@ -160,13 +160,13 @@ impl>> StarkMachine { { self.chips .iter() - .filter(|chip| chip_ordering.contains_key(&chip.name())) - .sorted_by_key(|chip| chip_ordering.get(&chip.name())) + .filter(|chip| chip_ordering.contains_key(chip.name())) + .sorted_by_key(|chip| chip_ordering.get(chip.name())) } /// Returns the indices of the chips in the machine that are included in the given shard. pub fn chips_sorted_indices(&self, proof: &ShardProof) -> Vec> { - self.chips().iter().map(|chip| proof.chip_ordering.get(&chip.name()).copied()).collect() + self.chips().iter().map(|chip| proof.chip_ordering.get(chip.name()).copied()).collect() } /// The setup preprocessing phase. @@ -204,15 +204,14 @@ impl>> StarkMachine { }); // Order the chips and traces by trace size (biggest first), and get the ordering map. - named_preprocessed_traces - .sort_by_key(|(name, _, trace)| (Reverse(trace.height()), name.clone())); + named_preprocessed_traces.sort_by_key(|(name, _, trace)| (Reverse(trace.height()), *name)); let pcs = self.config.pcs(); let (chip_information, domains_and_traces): (Vec<_>, Vec<_>) = named_preprocessed_traces .iter() .map(|(name, _, trace)| { let domain = pcs.natural_domain_for_degree(trace.height()); - ((name.to_owned(), domain, trace.dimensions()), (domain, trace.to_owned())) + (((*name).to_string(), domain, trace.dimensions()), (domain, trace.to_owned())) }) .unzip(); @@ -224,7 +223,7 @@ impl>> StarkMachine { let chip_ordering = named_preprocessed_traces .iter() .enumerate() - .map(|(i, (name, _, _))| (name.to_owned(), i)) + .map(|(i, (name, _, _))| ((*name).to_string(), i)) .collect::>(); let local_only = named_preprocessed_traces @@ -264,7 +263,7 @@ impl>> StarkMachine { .iter() .filter(|chip| { if let Some(chips_filter) = chips_filter { - chips_filter.contains(&chip.name()) + chips_filter.iter().find(|name| name == &chip.name()).is_some() } else { true } @@ -399,7 +398,7 @@ impl>> StarkMachine { // Generate the main trace for each chip. let pre_traces = chips .iter() - .map(|chip| pk.chip_ordering.get(&chip.name()).map(|index| &pk.traces[*index])) + .map(|chip| pk.chip_ordering.get(chip.name()).map(|index| &pk.traces[*index])) .collect::>(); let mut traces = chips .par_iter() @@ -466,7 +465,7 @@ impl>> StarkMachine { tracing::info_span!("debug constraints").in_scope(|| { for i in 0..chips.len() { let preprocessed_trace = - pk.chip_ordering.get(&chips[i].name()).map(|index| &pk.traces[*index]); + pk.chip_ordering.get(chips[i].name()).map(|index| &pk.traces[*index]); debug_constraints::( chips[i], preprocessed_trace, diff --git a/crates/stark/src/prover.rs b/crates/stark/src/prover.rs index 95d3da46c5..5774cd01eb 100644 --- a/crates/stark/src/prover.rs +++ b/crates/stark/src/prover.rs @@ -68,7 +68,7 @@ pub trait MachineProver>: &self, record: &A::Record, interaction_scope: InteractionScope, - ) -> Vec<(String, RowMajorMatrix>)> { + ) -> Vec<(&'static str, RowMajorMatrix>)> { let shard_chips = self.shard_chips(record).collect::>(); let chips = shard_chips .iter() @@ -101,7 +101,7 @@ pub trait MachineProver>: fn commit( &self, record: &A::Record, - traces: Vec<(String, RowMajorMatrix>)>, + traces: Vec<(&'static str, RowMajorMatrix>)>, ) -> ShardMainData; /// Observe the main commitment and public values and update the challenger. @@ -334,10 +334,10 @@ where fn commit( &self, record: &A::Record, - mut named_traces: Vec<(String, RowMajorMatrix>)>, + mut named_traces: Vec<(&'static str, RowMajorMatrix>)>, ) -> ShardMainData { // Order the chips and traces by trace size (biggest first), and get the ordering map. - named_traces.sort_by_key(|(name, trace)| (Reverse(trace.height()), name.clone())); + named_traces.sort_by_key(|(name, trace)| (Reverse(trace.height()), *name)); let pcs = self.config().pcs(); @@ -353,8 +353,11 @@ where let (main_commit, main_data) = pcs.commit(domains_and_traces); // Get the chip ordering. - let chip_ordering = - named_traces.iter().enumerate().map(|(i, (name, _))| (name.to_owned(), i)).collect(); + let chip_ordering = named_traces + .iter() + .enumerate() + .map(|(i, (name, _))| ((*name).to_string(), i)) + .collect(); let traces = named_traces.into_iter().map(|(_, trace)| trace).collect::>(); @@ -457,7 +460,7 @@ where .zip(all_shard_data.par_iter()) .map(|(chip, shard_data)| { let preprocessed_trace = - pk.chip_ordering.get(&chip.name()).map(|&index| &pk.traces[index]); + pk.chip_ordering.get(chip.name()).map(|&index| &pk.traces[index]); let (perm_trace, global_sum, local_sum) = chip.generate_permutation_trace( preprocessed_trace, shard_data.trace, @@ -535,7 +538,7 @@ where tracing::debug_span!(parent: &parent_span, "compute quotient values for domain") .in_scope(|| { let preprocessed_trace_on_quotient_domains = - pk.chip_ordering.get(&chips[i].name()).map(|&index| { + pk.chip_ordering.get(chips[i].name()).map(|&index| { pcs.get_evaluations_on_domain(&pk.data, index, *quotient_domain) }); let scope = all_chip_scopes[i]; @@ -714,8 +717,8 @@ where let mut main_values = Vec::with_capacity(global_chip_ordering.len() + local_chip_ordering.len()); for chip in chips.iter() { - let global_order = global_chip_ordering.get(&chip.name()); - let local_order = local_chip_ordering.get(&chip.name()); + let global_order = global_chip_ordering.get(chip.name()); + let local_order = local_chip_ordering.get(chip.name()); match (global_order, local_order) { (Some(&global_order), None) => { let global_main_values = @@ -768,7 +771,7 @@ where .map(|(i, ((((main, permutation), quotient), cumulative_sums), log_degree))| { let preprocessed = pk .chip_ordering - .get(&chips[i].name()) + .get(chips[i].name()) .map(|&index| preprocessed_opened_values[index].clone()) .unwrap_or(AirOpenedValues { local: vec![], next: vec![] }); ChipOpenedValues { diff --git a/crates/stark/src/verifier.rs b/crates/stark/src/verifier.rs index 2fb3e8cef3..0b140300d1 100644 --- a/crates/stark/src/verifier.rs +++ b/crates/stark/src/verifier.rs @@ -497,9 +497,9 @@ pub enum VerificationError { /// Out-of-domain evaluation mismatch. /// /// `constraints(zeta)` did not match `quotient(zeta) Z_H(zeta)`. - OodEvaluationMismatch(String), + OodEvaluationMismatch(&'static str), /// The shape of the opening arguments is invalid. - OpeningShapeError(String, OpeningShapeError), + OpeningShapeError(&'static str, OpeningShapeError), /// The cpu chip is missing. MissingCpuChip, /// The length of the chip opening does not match the expected length.