From 137bcf1c6325a54b327b194996ec78fbded13cdf Mon Sep 17 00:00:00 2001 From: Michael Zhu Date: Fri, 22 Nov 2024 12:41:29 -0500 Subject: [PATCH] clippy --- common/src/rv_trace.rs | 7 +++---- examples/memory-ops/guest/src/lib.rs | 5 +++-- jolt-core/src/jolt/vm/bytecode.rs | 2 ++ jolt-core/src/jolt/vm/instruction_lookups.rs | 3 +++ jolt-core/src/jolt/vm/mod.rs | 2 ++ jolt-core/src/jolt/vm/read_write_memory.rs | 21 +++++++++++-------- .../src/jolt/vm/timestamp_range_check.rs | 3 +++ jolt-core/src/lib.rs | 1 + jolt-core/src/msm/mod.rs | 8 +++---- jolt-core/src/poly/dense_interleaved_poly.rs | 1 + jolt-core/src/poly/opening_proof.rs | 2 ++ jolt-core/src/poly/sparse_interleaved_poly.rs | 1 + jolt-core/src/r1cs/builder.rs | 4 ++-- jolt-core/src/subprotocols/grand_product.rs | 1 + jolt-core/src/utils/instruction_utils.rs | 4 ++-- jolt-core/src/utils/mod.rs | 2 +- tracer/src/emulator/device/uart.rs | 18 +++++++--------- .../src/emulator/device/virtio_block_disk.rs | 2 +- 18 files changed, 52 insertions(+), 35 deletions(-) diff --git a/common/src/rv_trace.rs b/common/src/rv_trace.rs index d12e8d50c..cd8255b2d 100644 --- a/common/src/rv_trace.rs +++ b/common/src/rv_trace.rs @@ -575,6 +575,7 @@ impl RV32IM { } } +#[allow(clippy::too_long_first_doc_paragraph)] /// Represented as a "peripheral device" in the RISC-V emulator, this captures /// all reads from the reserved memory address space for program inputs and all writes /// to the reserved memory address space for program outputs. @@ -706,7 +707,7 @@ impl MemoryLayout { let panic = output_end; let termination = panic + 4; - let layout = Self { + Self { max_input_size, max_output_size, input_start, @@ -715,8 +716,6 @@ impl MemoryLayout { output_end, panic, termination, - }; - - layout + } } } diff --git a/examples/memory-ops/guest/src/lib.rs b/examples/memory-ops/guest/src/lib.rs index 64dc2fca1..ab62a4709 100644 --- a/examples/memory-ops/guest/src/lib.rs +++ b/examples/memory-ops/guest/src/lib.rs @@ -1,4 +1,5 @@ #![cfg_attr(feature = "guest", no_std)] +#![allow(unused_assignments, asm_sub_register)] #[jolt::provable] fn memory_ops() -> (i32, u32, i32, u32) { @@ -12,7 +13,7 @@ fn memory_ops() -> (i32, u32, i32, u32) { asm!( "sb {value}, 0({ptr})", ptr = in(reg) ptr, - value = in(reg) 0x12u8, + value = in(reg) 0x12, ); // Load Byte Signed (LB instruction) @@ -35,7 +36,7 @@ fn memory_ops() -> (i32, u32, i32, u32) { asm!( "sh {value}, 2({ptr})", ptr = in(reg) ptr, - value = in(reg) 0x3456u16, + value = in(reg) 0x3456, ); // Load Halfword Signed (LH instruction) diff --git a/jolt-core/src/jolt/vm/bytecode.rs b/jolt-core/src/jolt/vm/bytecode.rs index 8368bc5a4..156950fa1 100644 --- a/jolt-core/src/jolt/vm/bytecode.rs +++ b/jolt-core/src/jolt/vm/bytecode.rs @@ -47,11 +47,13 @@ pub struct BytecodeStuff { } /// Note –– F: JoltField bound is not enforced. +/// /// See issue #112792 . /// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break /// `alloy_sol_types`. pub type BytecodePolynomials = BytecodeStuff>; /// Note –– F: JoltField bound is not enforced. +/// /// See issue #112792 . /// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break /// `alloy_sol_types`. diff --git a/jolt-core/src/jolt/vm/instruction_lookups.rs b/jolt-core/src/jolt/vm/instruction_lookups.rs index a7017c60a..c8478383b 100644 --- a/jolt-core/src/jolt/vm/instruction_lookups.rs +++ b/jolt-core/src/jolt/vm/instruction_lookups.rs @@ -65,16 +65,19 @@ pub struct InstructionLookupStuff } /// Note –– F: JoltField bound is not enforced. +/// /// See issue #112792 . /// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break /// `alloy_sol_types`. pub type InstructionLookupPolynomials = InstructionLookupStuff>; /// Note –– F: JoltField bound is not enforced. +/// /// See issue #112792 . /// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break /// `alloy_sol_types`. pub type InstructionLookupOpenings = InstructionLookupStuff; /// Note –– PCS: CommitmentScheme bound is not enforced. +/// /// See issue #112792 . /// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break /// `alloy_sol_types`. diff --git a/jolt-core/src/jolt/vm/mod.rs b/jolt-core/src/jolt/vm/mod.rs index fc28b2528..46177850e 100644 --- a/jolt-core/src/jolt/vm/mod.rs +++ b/jolt-core/src/jolt/vm/mod.rs @@ -193,11 +193,13 @@ impl StructuredPolynomialDa } /// Note –– F: JoltField bound is not enforced. +/// /// See issue #112792 . /// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break /// `alloy_sol_types`. pub type JoltPolynomials = JoltStuff>; /// Note –– PCS: CommitmentScheme bound is not enforced. +/// /// See issue #112792 . /// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break /// `alloy_sol_types`. diff --git a/jolt-core/src/jolt/vm/read_write_memory.rs b/jolt-core/src/jolt/vm/read_write_memory.rs index 6f1c6afea..511d94d71 100644 --- a/jolt-core/src/jolt/vm/read_write_memory.rs +++ b/jolt-core/src/jolt/vm/read_write_memory.rs @@ -183,16 +183,19 @@ impl StructuredPolynomialData } /// Note –– F: JoltField bound is not enforced. +/// /// See issue #112792 . /// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break /// `alloy_sol_types`. pub type ReadWriteMemoryPolynomials = ReadWriteMemoryStuff>; /// Note –– F: JoltField bound is not enforced. +/// /// See issue #112792 . /// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break /// `alloy_sol_types`. pub type ReadWriteMemoryOpenings = ReadWriteMemoryStuff; /// Note –– PCS: CommitmentScheme bound is not enforced. +/// /// See issue #112792 . /// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break /// `alloy_sol_types`. @@ -246,7 +249,7 @@ impl ReadWriteMemoryPolynomials { pub fn generate_witness( program_io: &JoltDevice, preprocessing: &ReadWriteMemoryPreprocessing, - trace: &Vec>, + trace: &[JoltTraceStep], ) -> (Self, [Vec; MEMORY_OPS_PER_INSTRUCTION]) { assert!(program_io.inputs.len() <= program_io.memory_layout.max_input_size as usize); assert!(program_io.outputs.len() <= program_io.memory_layout.max_output_size as usize); @@ -284,7 +287,7 @@ impl ReadWriteMemoryPolynomials { for (i, byte) in chunk.iter().enumerate() { word[i] = *byte; } - let word = u32::from_le_bytes(word.try_into().unwrap()); + let word = u32::from_le_bytes(word); v_init[v_init_index] = word as u64; v_init_index += 1; } @@ -710,19 +713,19 @@ where let mut v_init: Vec = vec![0; memory_size]; // Copy bytecode let mut v_init_index = - memory_address_to_witness_index(preprocessing.min_bytecode_address, &memory_layout); + memory_address_to_witness_index(preprocessing.min_bytecode_address, memory_layout); for word in preprocessing.bytecode_words.iter() { v_init[v_init_index] = *word as u64; v_init_index += 1; } // Copy input bytes - v_init_index = memory_address_to_witness_index(memory_layout.input_start, &memory_layout); + v_init_index = memory_address_to_witness_index(memory_layout.input_start, memory_layout); for chunk in preprocessing.program_io.as_ref().unwrap().inputs.chunks(4) { let mut word = [0u8; 4]; for (i, byte) in chunk.iter().enumerate() { word[i] = *byte; } - let word = u32::from_le_bytes(word.try_into().unwrap()); + let word = u32::from_le_bytes(word); v_init[v_init_index] = word as u64; v_init_index += 1; } @@ -867,7 +870,7 @@ where for (i, byte) in chunk.iter().enumerate() { word[i] = *byte; } - let word = u32::from_le_bytes(word.try_into().unwrap()); + let word = u32::from_le_bytes(word); v_io[input_index] = word as u64; input_index += 1; } @@ -881,7 +884,7 @@ where for (i, byte) in chunk.iter().enumerate() { word[i] = *byte; } - let word = u32::from_le_bytes(word.try_into().unwrap()); + let word = u32::from_le_bytes(word); v_io[output_index] = word as u64; output_index += 1; } @@ -993,7 +996,7 @@ where for (i, byte) in chunk.iter().enumerate() { word[i] = *byte; } - let word = u32::from_le_bytes(word.try_into().unwrap()); + let word = u32::from_le_bytes(word); v_io[input_index] = word as u64; input_index += 1; } @@ -1005,7 +1008,7 @@ where for (i, byte) in chunk.iter().enumerate() { word[i] = *byte; } - let word = u32::from_le_bytes(word.try_into().unwrap()); + let word = u32::from_le_bytes(word); v_io[output_index] = word as u64; output_index += 1; } diff --git a/jolt-core/src/jolt/vm/timestamp_range_check.rs b/jolt-core/src/jolt/vm/timestamp_range_check.rs index 77ba4883a..933e742f7 100644 --- a/jolt-core/src/jolt/vm/timestamp_range_check.rs +++ b/jolt-core/src/jolt/vm/timestamp_range_check.rs @@ -70,17 +70,20 @@ impl StructuredPolynomialDa } /// Note –– F: JoltField bound is not enforced. +/// /// See issue #112792 . /// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break /// `alloy_sol_types`. pub type TimestampRangeCheckPolynomials = TimestampRangeCheckStuff>; /// Note –– F: JoltField bound is not enforced. +/// /// See issue #112792 . /// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break /// `alloy_sol_types`. pub type TimestampRangeCheckOpenings = TimestampRangeCheckStuff; /// Note –– PCS: CommitmentScheme bound is not enforced. +/// /// See issue #112792 . /// Adding #![feature(lazy_type_alias)] to the crate attributes seem to break /// `alloy_sol_types`. diff --git a/jolt-core/src/lib.rs b/jolt-core/src/lib.rs index 86559a07c..70455baad 100644 --- a/jolt-core/src/lib.rs +++ b/jolt-core/src/lib.rs @@ -10,6 +10,7 @@ #![allow(long_running_const_eval)] #![allow(clippy::len_without_is_empty)] #![allow(type_alias_bounds)] +#![allow(clippy::too_long_first_doc_paragraph)] #[cfg(feature = "host")] pub mod benches; diff --git a/jolt-core/src/msm/mod.rs b/jolt-core/src/msm/mod.rs index edf3b48c9..0577bbb12 100644 --- a/jolt-core/src/msm/mod.rs +++ b/jolt-core/src/msm/mod.rs @@ -78,7 +78,7 @@ fn msm_bigint_wnaf( }; let num_bits = max_num_bits; - let digits_count = (num_bits + c - 1) / c; + let digits_count = num_bits.div_ceil(c); let scalar_digits = scalars .into_par_iter() .flat_map_iter(|s| make_digits_bigint(s, c, num_bits)) @@ -235,7 +235,7 @@ fn make_digits_bigint( } else { num_bits }; - let digits_count = (num_bits + w - 1) / w; + let digits_count = num_bits.div_ceil(w); (0..digits_count).map(move |i| { // Construct a buffer of bits of the scalar, starting at `bit_offset`. let bit_offset = i * w; @@ -277,7 +277,7 @@ fn msm_u64_wnaf( ln_without_floats(bases.len()) + 2 }; - let digits_count = (max_num_bits + c - 1) / c; + let digits_count = max_num_bits.div_ceil(c); let scalar_digits = scalars .into_par_iter() .flat_map_iter(|s| make_digits_u64(*s, c, max_num_bits)) @@ -451,7 +451,7 @@ fn make_digits_u64(scalar: u64, w: usize, num_bits: usize) -> impl Iterator { } /// An opening that the verifier must verify. +/// /// May be a batched opening, where multiple polynomials opened /// at the *same* point are reduced to a single polynomial opened /// at the (same) point. diff --git a/jolt-core/src/poly/sparse_interleaved_poly.rs b/jolt-core/src/poly/sparse_interleaved_poly.rs index cd95e456c..2eb9a7908 100644 --- a/jolt-core/src/poly/sparse_interleaved_poly.rs +++ b/jolt-core/src/poly/sparse_interleaved_poly.rs @@ -28,6 +28,7 @@ impl From<(usize, F)> for SparseCoefficient { } /// Represents a single layer of a sparse grand product circuit. +/// /// A layer is assumed to be arranged in "interleaved" order, i.e. the natural /// order in the visual representation of the circuit: /// Λ Λ Λ Λ diff --git a/jolt-core/src/r1cs/builder.rs b/jolt-core/src/r1cs/builder.rs index 39c8efeeb..85be551c5 100644 --- a/jolt-core/src/r1cs/builder.rs +++ b/jolt-core/src/r1cs/builder.rs @@ -136,7 +136,7 @@ impl AuxComputation { let mut aux_poly: Vec = unsafe_allocate_zero_vec(batch_size); let num_threads = rayon::current_num_threads(); - let chunk_size = (batch_size + num_threads - 1) / num_threads; + let chunk_size = batch_size.div_ceil(num_threads); aux_poly .par_chunks_mut(chunk_size) @@ -180,7 +180,7 @@ impl AuxComputation { // in the batch to a buffer owend by each thread's chunk to minimize allocs. let num_threads = rayon::current_num_threads(); - let chunk_size = (batch_size + num_threads - 1) / num_threads; + let chunk_size = batch_size.div_ceil(num_threads); let mut results: Vec = unsafe_allocate_zero_vec(batch_size); results diff --git a/jolt-core/src/subprotocols/grand_product.rs b/jolt-core/src/subprotocols/grand_product.rs index 059364776..531ab0eb6 100644 --- a/jolt-core/src/subprotocols/grand_product.rs +++ b/jolt-core/src/subprotocols/grand_product.rs @@ -236,6 +236,7 @@ where } /// A batched grand product circuit. +/// /// Note that the circuit roots are not included in `self.layers` /// o o /// / \ / \ diff --git a/jolt-core/src/utils/instruction_utils.rs b/jolt-core/src/utils/instruction_utils.rs index be7087594..fbae2f708 100644 --- a/jolt-core/src/utils/instruction_utils.rs +++ b/jolt-core/src/utils/instruction_utils.rs @@ -48,7 +48,7 @@ pub fn concatenate_lookups(vals: &[F], C: usize, operand_bits: usi /// /// ``` /// use jolt_core::utils::instruction_utils::chunk_operand; - +/// /// // Normal usage /// let x = 0b1100_1010_1111_0000; /// assert_eq!(chunk_operand(x, 4, 4), vec![12, 10, 15, 0]); @@ -76,7 +76,7 @@ pub fn chunk_operand(x: u64, C: usize, chunk_len: usize) -> Vec { /// /// ``` /// use jolt_core::utils::instruction_utils::chunk_operand_usize; - +/// /// // Normal usage /// let x = 0b1100_1010_1111_0000; /// assert_eq!(chunk_operand_usize(x, 4, 4), vec![12, 10, 15, 0]); diff --git a/jolt-core/src/utils/mod.rs b/jolt-core/src/utils/mod.rs index ba4fca1db..8a0e30cbd 100644 --- a/jolt-core/src/utils/mod.rs +++ b/jolt-core/src/utils/mod.rs @@ -85,7 +85,7 @@ pub fn mul_0_optimized(likely_zero: &F, x: &F) -> F { /// Checks if `num` is a power of 2. pub fn is_power_of_two(num: usize) -> bool { - num != 0 && (num & (num - 1)) == 0 + num != 0 && num.is_power_of_two() } /// Take the first two `num_bits` chunks of `item` (from the right / LSB) and return them as a tuple `(high_chunk, low_chunk)`. diff --git a/tracer/src/emulator/device/uart.rs b/tracer/src/emulator/device/uart.rs index 562c49ffc..f7aa2e615 100644 --- a/tracer/src/emulator/device/uart.rs +++ b/tracer/src/emulator/device/uart.rs @@ -152,16 +152,15 @@ impl Uart { //println!("UART Store AD:{:X} VAL:{:X}", address, value); match address { // Transfer Holding Register - 0x10000000 => match (self.lcr >> 7) == 0 { - true => { + 0x10000000 => { + if (self.lcr >> 7) == 0 { self.thr = value; self.lsr &= !LSR_THR_EMPTY; self.update_iir(); - } - false => {} // @TODO: Implement properly - }, - 0x10000001 => match (self.lcr >> 7) == 0 { - true => { + } // @TODO: Implement else properly + } + 0x10000001 => { + if (self.lcr >> 7) == 0 { // This bahavior isn't written in the data sheet // but some drivers seem to rely on it. if (self.ier & IER_THREINT_BIT) == 0 @@ -172,9 +171,8 @@ impl Uart { } self.ier = value; self.update_iir(); - } - false => {} // @TODO: Implement properly - }, + } // @TODO: Implement else properly + } 0x10000003 => { self.lcr = value; } diff --git a/tracer/src/emulator/device/virtio_block_disk.rs b/tracer/src/emulator/device/virtio_block_disk.rs index 7d5d3a9aa..a6d5c551a 100644 --- a/tracer/src/emulator/device/virtio_block_disk.rs +++ b/tracer/src/emulator/device/virtio_block_disk.rs @@ -450,7 +450,7 @@ impl VirtioBlockDisk { fn get_base_used_address(&self) -> u64 { let align = self.queue_align as u64; let queue_size = self.queue_size as u64; - ((self.get_base_avail_address() + 4 + queue_size * 2 + align - 1) / align) * align + (self.get_base_avail_address() + 4 + queue_size * 2).div_ceil(align) * align } // @TODO: Follow the virtio block specification more propertly.