Skip to content

Commit 2ed19d5

Browse files
Rename ShaChipConfig to Sha2ChipConfig for consistency with Sha2Config
1 parent 32b66e5 commit 2ed19d5

File tree

7 files changed

+37
-37
lines changed

7 files changed

+37
-37
lines changed

extensions/sha2/circuit/src/sha2_chip/air.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ use openvm_stark_backend::{
2323
rap::{BaseAirWithPublicValues, PartitionedBaseAir},
2424
};
2525

26-
use super::{Sha2VmDigestColsRef, Sha2VmRoundColsRef, ShaChipConfig};
26+
use super::{Sha2VmDigestColsRef, Sha2VmRoundColsRef, Sha2ChipConfig};
2727

2828
/// Sha2VmAir does all constraints related to message padding and
2929
/// the Sha2Air subair constrains the actual hash
3030
#[derive(Clone, Debug)]
31-
pub struct Sha2VmAir<C: ShaChipConfig> {
31+
pub struct Sha2VmAir<C: Sha2ChipConfig> {
3232
pub execution_bridge: ExecutionBridge,
3333
pub memory_bridge: MemoryBridge,
3434
/// Bus to send byte checks to
@@ -40,7 +40,7 @@ pub struct Sha2VmAir<C: ShaChipConfig> {
4040
pub(super) padding_encoder: Encoder,
4141
}
4242

43-
impl<C: ShaChipConfig> Sha2VmAir<C> {
43+
impl<C: Sha2ChipConfig> Sha2VmAir<C> {
4444
pub fn new(
4545
SystemPort {
4646
execution_bus,
@@ -63,15 +63,15 @@ impl<C: ShaChipConfig> Sha2VmAir<C> {
6363
}
6464
}
6565

66-
impl<F: Field, C: ShaChipConfig> BaseAirWithPublicValues<F> for Sha2VmAir<C> {}
67-
impl<F: Field, C: ShaChipConfig> PartitionedBaseAir<F> for Sha2VmAir<C> {}
68-
impl<F: Field, C: ShaChipConfig> BaseAir<F> for Sha2VmAir<C> {
66+
impl<F: Field, C: Sha2ChipConfig> BaseAirWithPublicValues<F> for Sha2VmAir<C> {}
67+
impl<F: Field, C: Sha2ChipConfig> PartitionedBaseAir<F> for Sha2VmAir<C> {}
68+
impl<F: Field, C: Sha2ChipConfig> BaseAir<F> for Sha2VmAir<C> {
6969
fn width(&self) -> usize {
7070
C::VM_WIDTH
7171
}
7272
}
7373

74-
impl<AB: InteractionBuilder, C: ShaChipConfig> Air<AB> for Sha2VmAir<C> {
74+
impl<AB: InteractionBuilder, C: Sha2ChipConfig> Air<AB> for Sha2VmAir<C> {
7575
fn eval(&self, builder: &mut AB) {
7676
self.eval_padding(builder);
7777
self.eval_transitions(builder);
@@ -156,7 +156,7 @@ impl PaddingFlags {
156156
}
157157

158158
use PaddingFlags::*;
159-
impl<C: ShaChipConfig> Sha2VmAir<C> {
159+
impl<C: Sha2ChipConfig> Sha2VmAir<C> {
160160
/// Implement all necessary constraints for the padding
161161
fn eval_padding<AB: InteractionBuilder>(&self, builder: &mut AB) {
162162
let main = builder.main();

extensions/sha2/circuit/src/sha2_chip/columns.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ use openvm_sha2_air::{
1212
};
1313

1414
use super::SHA_REGISTER_READS;
15-
use crate::ShaChipConfig;
15+
use crate::Sha2ChipConfig;
1616

1717
/// the first C::ROUND_ROWS rows of every SHA block will be of type ShaVmRoundCols and the last row
1818
/// will be of type ShaVmDigestCols
1919
#[repr(C)]
2020
#[derive(Clone, Copy, Debug, ColsRef)]
21-
#[config(ShaChipConfig)]
21+
#[config(Sha2ChipConfig)]
2222
pub struct Sha2VmRoundCols<
2323
T,
2424
const WORD_BITS: usize,
@@ -44,7 +44,7 @@ pub struct Sha2VmRoundCols<
4444

4545
#[repr(C)]
4646
#[derive(Clone, Copy, Debug, ColsRef)]
47-
#[config(ShaChipConfig)]
47+
#[config(Sha2ChipConfig)]
4848
pub struct Sha2VmDigestCols<
4949
T,
5050
const WORD_BITS: usize,
@@ -90,7 +90,7 @@ pub struct Sha2VmDigestCols<
9090
/// These are the columns that are used on both round and digest rows
9191
#[repr(C)]
9292
#[derive(Clone, Copy, Debug, ColsRef)]
93-
#[config(ShaChipConfig)]
93+
#[config(Sha2ChipConfig)]
9494
pub struct Sha2VmControlCols<T> {
9595
/// Note: We will use the buffer in `inner.message_schedule` as the message data
9696
/// This is the length of the entire message in bytes

extensions/sha2/circuit/src/sha2_chip/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use openvm_sha2_transpiler::Rv32Sha2Opcode;
44

55
use super::{Sha2VmControlColsRef, Sha2VmDigestColsRef, Sha2VmRoundColsRef};
66

7-
pub trait ShaChipConfig: Sha2Config {
7+
pub trait Sha2ChipConfig: Sha2Config {
88
// Name of the opcode
99
const OPCODE_NAME: &'static str;
1010
/// Width of the ShaVmControlCols
@@ -51,7 +51,7 @@ pub trait ShaChipConfig: Sha2Config {
5151
/// Register reads to get dst, src, len
5252
pub const SHA_REGISTER_READS: usize = 3;
5353

54-
impl ShaChipConfig for Sha256Config {
54+
impl Sha2ChipConfig for Sha256Config {
5555
const OPCODE_NAME: &'static str = "SHA256";
5656
const MESSAGE_LENGTH_BITS: usize = 64;
5757
const WRITE_SIZE: usize = SHA_WRITE_SIZE;
@@ -60,7 +60,7 @@ impl ShaChipConfig for Sha256Config {
6060
const DIGEST_SIZE: usize = Self::HASH_SIZE;
6161
}
6262

63-
impl ShaChipConfig for Sha512Config {
63+
impl Sha2ChipConfig for Sha512Config {
6464
const OPCODE_NAME: &'static str = "SHA512";
6565
const MESSAGE_LENGTH_BITS: usize = 128;
6666
const WRITE_SIZE: usize = SHA_WRITE_SIZE;
@@ -69,7 +69,7 @@ impl ShaChipConfig for Sha512Config {
6969
const DIGEST_SIZE: usize = Self::HASH_SIZE;
7070
}
7171

72-
impl ShaChipConfig for Sha384Config {
72+
impl Sha2ChipConfig for Sha384Config {
7373
const OPCODE_NAME: &'static str = "SHA384";
7474
const MESSAGE_LENGTH_BITS: usize = 128;
7575
const WRITE_SIZE: usize = SHA_WRITE_SIZE;

extensions/sha2/circuit/src/sha2_chip/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ mod tests;
4343

4444
pub type Sha2VmChip<F, C> = NewVmChipWrapper<F, Sha2VmAir<C>, Sha2VmStep<C>, MatrixRecordArena<F>>;
4545

46-
pub struct Sha2VmStep<C: ShaChipConfig> {
46+
pub struct Sha2VmStep<C: Sha2ChipConfig> {
4747
pub inner: Sha2StepHelper<C>,
4848
pub padding_encoder: Encoder,
4949
pub bitwise_lookup_chip: SharedBitwiseOperationLookupChip<RV32_CELL_BITS>,
5050
pub offset: usize,
5151
pub pointer_max_bits: usize,
5252
}
5353

54-
impl<C: ShaChipConfig> Sha2VmStep<C> {
54+
impl<C: Sha2ChipConfig> Sha2VmStep<C> {
5555
pub fn new(
5656
bitwise_lookup_chip: SharedBitwiseOperationLookupChip<RV32_CELL_BITS>,
5757
offset: usize,
@@ -67,7 +67,7 @@ impl<C: ShaChipConfig> Sha2VmStep<C> {
6767
}
6868
}
6969

70-
impl<F: PrimeField32, C: ShaChipConfig> StepExecutorE1<F> for Sha2VmStep<C> {
70+
impl<F: PrimeField32, C: Sha2ChipConfig> StepExecutorE1<F> for Sha2VmStep<C> {
7171
fn execute_e1<Ctx>(
7272
&self,
7373
state: &mut VmStateMut<F, GuestMemory, Ctx>,
@@ -266,7 +266,7 @@ impl<F: PrimeField32, C: ShaChipConfig> StepExecutorE1<F> for Sha2VmStep<C> {
266266
}
267267
}
268268

269-
pub fn sha2_solve<C: ShaChipConfig>(input_message: &[u8]) -> Vec<u8> {
269+
pub fn sha2_solve<C: Sha2ChipConfig>(input_message: &[u8]) -> Vec<u8> {
270270
match C::VARIANT {
271271
Sha2Variant::Sha256 => {
272272
let mut hasher = Sha256::new();

extensions/sha2/circuit/src/sha2_chip/tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use openvm_stark_backend::{interaction::BusIndex, p3_field::FieldAlgebra};
1717
use openvm_stark_sdk::{config::setup_tracing, p3_baby_bear::BabyBear, utils::create_seeded_rng};
1818
use rand::{rngs::StdRng, Rng};
1919

20-
use super::{Sha2VmAir, Sha2VmChip, Sha2VmStep, ShaChipConfig};
20+
use super::{Sha2ChipConfig, Sha2VmAir, Sha2VmChip, Sha2VmStep};
2121
use crate::{
2222
sha2_chip::trace::Sha2VmRecordLayout, sha2_solve, Sha2VmDigestColsRef, Sha2VmRoundColsRef,
2323
};
@@ -27,7 +27,7 @@ const SELF_BUS_IDX: BusIndex = 28;
2727
const MAX_INS_CAPACITY: usize = 8192;
2828
type Sha2VmChipDense<C> = NewVmChipWrapper<F, Sha2VmAir<C>, Sha2VmStep<C>, DenseRecordArena>;
2929

30-
fn create_test_chips<C: ShaChipConfig>(
30+
fn create_test_chips<C: Sha2ChipConfig>(
3131
tester: &mut VmChipTestBuilder<F>,
3232
) -> (
3333
Sha2VmChip<F, C>,
@@ -54,7 +54,7 @@ fn create_test_chips<C: ShaChipConfig>(
5454
(chip, bitwise_chip)
5555
}
5656

57-
fn set_and_execute<E: InstructionExecutor<F>, C: ShaChipConfig>(
57+
fn set_and_execute<E: InstructionExecutor<F>, C: Sha2ChipConfig>(
5858
tester: &mut VmChipTestBuilder<F>,
5959
chip: &mut E,
6060
rng: &mut StdRng,
@@ -131,7 +131,7 @@ fn set_and_execute<E: InstructionExecutor<F>, C: ShaChipConfig>(
131131
/// Randomly generate computations and execute, ensuring that the generated trace
132132
/// passes all constraints.
133133
///////////////////////////////////////////////////////////////////////////////////////
134-
fn rand_sha_test<C: ShaChipConfig + 'static>() {
134+
fn rand_sha_test<C: Sha2ChipConfig + 'static>() {
135135
setup_tracing();
136136
let mut rng = create_seeded_rng();
137137
let mut tester = VmChipTestBuilder::default();
@@ -166,7 +166,7 @@ fn rand_sha384_test() {
166166
///
167167
/// Ensure that solve functions produce the correct results.
168168
///////////////////////////////////////////////////////////////////////////////////////
169-
fn execute_roundtrip_sanity_test<C: ShaChipConfig>() {
169+
fn execute_roundtrip_sanity_test<C: Sha2ChipConfig>() {
170170
let mut rng = create_seeded_rng();
171171
let mut tester = VmChipTestBuilder::default();
172172
let (mut chip, _) = create_test_chips::<C>(&mut tester);
@@ -246,7 +246,7 @@ fn sha384_solve_sanity_check() {
246246
/// to a [MatrixRecordArena]. After transferring we generate the trace and make sure that
247247
/// all the constraints pass.
248248
///////////////////////////////////////////////////////////////////////////////////////
249-
fn create_test_chip_dense<C: ShaChipConfig>(
249+
fn create_test_chip_dense<C: Sha2ChipConfig>(
250250
tester: &mut VmChipTestBuilder<F>,
251251
) -> Sha2VmChipDense<C> {
252252
let bitwise_bus = BitwiseOperationLookupBus::new(BITWISE_OP_LOOKUP_BUS);
@@ -271,7 +271,7 @@ fn create_test_chip_dense<C: ShaChipConfig>(
271271
chip
272272
}
273273

274-
fn dense_record_arena_test<C: ShaChipConfig + 'static>() {
274+
fn dense_record_arena_test<C: Sha2ChipConfig + 'static>() {
275275
let mut rng = create_seeded_rng();
276276
let mut tester = VmChipTestBuilder::default();
277277
let (mut sparse_chip, bitwise_chip) = create_test_chips::<C>(&mut tester);

extensions/sha2/circuit/src/sha2_chip/trace.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ use openvm_stark_backend::{
3434
};
3535

3636
use super::{
37-
Sha2Variant, Sha2VmDigestColsRefMut, Sha2VmRoundColsRefMut, Sha2VmStep, ShaChipConfig,
37+
Sha2Variant, Sha2VmDigestColsRefMut, Sha2VmRoundColsRefMut, Sha2VmStep, Sha2ChipConfig,
3838
};
3939
use crate::{
4040
get_sha2_num_blocks, sha2_chip::PaddingFlags, sha2_solve, Sha2VmControlColsRefMut,
4141
MAX_SHA_NUM_WRITES, SHA_MAX_MESSAGE_LEN, SHA_REGISTER_READS, SHA_WRITE_SIZE,
4242
};
4343

4444
#[derive(Clone, Copy)]
45-
pub struct Sha2VmMetadata<C: ShaChipConfig> {
45+
pub struct Sha2VmMetadata<C: Sha2ChipConfig> {
4646
pub num_blocks: u32,
4747
_phantom: PhantomData<C>,
4848
}
4949

50-
impl<C: ShaChipConfig> MultiRowMetadata for Sha2VmMetadata<C> {
50+
impl<C: Sha2ChipConfig> MultiRowMetadata for Sha2VmMetadata<C> {
5151
#[inline(always)]
5252
fn get_num_rows(&self) -> usize {
5353
self.num_blocks as usize * C::ROWS_PER_BLOCK
@@ -87,7 +87,7 @@ pub struct Sha2VmRecordMut<'a> {
8787
/// `C::NUM_READ_ROWS * num_blocks`. Uses `align_to_mut()` to make sure the slice is properly
8888
/// aligned to `MemoryReadAuxRecord`. Has debug assertions that check the size and alignment of the
8989
/// slices.
90-
impl<'a, C: ShaChipConfig> CustomBorrow<'a, Sha2VmRecordMut<'a>, Sha2VmRecordLayout<C>> for [u8] {
90+
impl<'a, C: Sha2ChipConfig> CustomBorrow<'a, Sha2VmRecordMut<'a>, Sha2VmRecordLayout<C>> for [u8] {
9191
fn custom_borrow(&'a mut self, layout: Sha2VmRecordLayout<C>) -> Sha2VmRecordMut<'a> {
9292
let (header_buf, rest) =
9393
unsafe { self.split_at_mut_unchecked(size_of::<Sha2VmRecordHeader>()) };
@@ -123,7 +123,7 @@ impl<'a, C: ShaChipConfig> CustomBorrow<'a, Sha2VmRecordMut<'a>, Sha2VmRecordLay
123123
}
124124
}
125125

126-
impl<C: ShaChipConfig> SizedRecord<Sha2VmRecordLayout<C>> for Sha2VmRecordMut<'_> {
126+
impl<C: Sha2ChipConfig> SizedRecord<Sha2VmRecordLayout<C>> for Sha2VmRecordMut<'_> {
127127
fn size(layout: &Sha2VmRecordLayout<C>) -> usize {
128128
let mut total_len = size_of::<Sha2VmRecordHeader>();
129129
total_len += layout.metadata.num_blocks as usize * C::BLOCK_CELLS;
@@ -140,7 +140,7 @@ impl<C: ShaChipConfig> SizedRecord<Sha2VmRecordLayout<C>> for Sha2VmRecordMut<'_
140140
}
141141
}
142142

143-
impl<F: PrimeField32, CTX, C: ShaChipConfig> TraceStep<F, CTX> for Sha2VmStep<C> {
143+
impl<F: PrimeField32, CTX, C: Sha2ChipConfig> TraceStep<F, CTX> for Sha2VmStep<C> {
144144
type RecordLayout = Sha2VmRecordLayout<C>;
145145
type RecordMut<'a> = Sha2VmRecordMut<'a>;
146146

@@ -310,7 +310,7 @@ impl<F: PrimeField32, CTX, C: ShaChipConfig> TraceStep<F, CTX> for Sha2VmStep<C>
310310
}
311311
}
312312

313-
impl<F: PrimeField32, CTX, C: ShaChipConfig> TraceFiller<F, CTX> for Sha2VmStep<C> {
313+
impl<F: PrimeField32, CTX, C: Sha2ChipConfig> TraceFiller<F, CTX> for Sha2VmStep<C> {
314314
fn fill_trace(
315315
&self,
316316
mem_helper: &MemoryAuxColsFactory<F>,
@@ -450,7 +450,7 @@ impl<F: PrimeField32, CTX, C: ShaChipConfig> TraceFiller<F, CTX> for Sha2VmStep<
450450
}
451451
}
452452

453-
impl<C: ShaChipConfig> Sha2VmStep<C> {
453+
impl<C: Sha2ChipConfig> Sha2VmStep<C> {
454454
#[allow(clippy::too_many_arguments)]
455455
fn fill_block_trace<F: PrimeField32>(
456456
&self,

extensions/sha2/circuit/src/sha2_chip/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use crate::ShaChipConfig;
1+
use crate::Sha2ChipConfig;
22

33
/// Returns the number of blocks required to hash a message of length `len`
4-
pub fn get_sha2_num_blocks<C: ShaChipConfig>(len: u32) -> u32 {
4+
pub fn get_sha2_num_blocks<C: Sha2ChipConfig>(len: u32) -> u32 {
55
// need to pad with one 1 bit, 64 bits for the message length and then pad until the length
66
// is divisible by [C::BLOCK_BITS]
77
((len << 3) as usize + 1 + C::MESSAGE_LENGTH_BITS).div_ceil(C::BLOCK_BITS) as u32

0 commit comments

Comments
 (0)