openvm_sha2_circuit/sha2_chips/block_hasher_chip/
mod.rs

1mod air;
2mod columns;
3
4mod config;
5mod trace;
6
7use std::{
8    marker::PhantomData,
9    sync::{Arc, Mutex},
10};
11
12pub use air::*;
13pub use columns::*;
14pub use config::*;
15use openvm_circuit::system::memory::SharedMemoryHelper;
16use openvm_circuit_primitives::bitwise_op_lookup::SharedBitwiseOperationLookupChip;
17use openvm_instructions::riscv::RV32_CELL_BITS;
18use openvm_sha2_air::{Sha2BlockHasherFillerHelper, Sha2BlockHasherSubairConfig};
19
20pub use super::{config::*, Sha2SharedRecords};
21
22pub struct Sha2BlockHasherChip<F, C: Sha2BlockHasherSubairConfig> {
23    pub inner: Sha2BlockHasherFillerHelper<C>,
24    pub bitwise_lookup_chip: SharedBitwiseOperationLookupChip<RV32_CELL_BITS>,
25    pub pointer_max_bits: usize,
26    pub mem_helper: SharedMemoryHelper<F>,
27    // This Arc<Mutex<Option<RA>>> is shared with the main chip (Sha2MainChip).
28    // When the main chip's tracegen is done, it will set the value of the mutex to Some(records)
29    // and then the block hasher chip can see the records and use it to generate its trace.
30    // The arc mutex is not strictly necessary (we could just use a Cell) because tracegen is done
31    // sequentially over the list of chips (although it is parallelized within each chip), but the
32    // overhead of using a thread-safe type is negligible since we only access the 'records' field
33    // twice (once to set the value and once to get the value).
34    // So, we will just use an arc mutex to avoid overcomplicating things.
35    pub records: Arc<Mutex<Option<Sha2SharedRecords<F>>>>,
36    _phantom: PhantomData<C>,
37}
38
39impl<F, C: Sha2BlockHasherSubairConfig> Sha2BlockHasherChip<F, C> {
40    pub fn new(
41        bitwise_lookup_chip: SharedBitwiseOperationLookupChip<RV32_CELL_BITS>,
42        pointer_max_bits: usize,
43        mem_helper: SharedMemoryHelper<F>,
44        records: Arc<Mutex<Option<Sha2SharedRecords<F>>>>,
45    ) -> Self {
46        Self {
47            inner: Sha2BlockHasherFillerHelper::new(),
48            bitwise_lookup_chip,
49            pointer_max_bits,
50            mem_helper,
51            records,
52            _phantom: PhantomData,
53        }
54    }
55}