Skip to content

Commit 1f44957

Browse files
Updated names
1 parent 4f1038a commit 1f44957

File tree

22 files changed

+53
-81
lines changed

22 files changed

+53
-81
lines changed

.github/workflows/primitives.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
paths:
99
- "crates/circuits/primitives/**"
1010
- "crates/circuits/poseidon2-air/**"
11-
- "crates/circuits/sha256-air/**"
11+
- "crates/circuits/sha-air/**"
1212
- "Cargo.toml"
1313

1414
concurrency:
@@ -45,7 +45,7 @@ jobs:
4545
run: |
4646
cargo nextest run --cargo-profile fast --features parallel
4747
48-
- name: Run tests for sha256-air
49-
working-directory: crates/circuits/sha256-air
48+
- name: Run tests for sha-air
49+
working-directory: crates/circuits/sha-air
5050
run: |
5151
cargo nextest run --cargo-profile fast --features parallel

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ openvm-stark-sdk = { git = "https://github.com/openvm-org/stark-backend.git", re
112112
openvm-sdk = { path = "crates/sdk", default-features = false }
113113
openvm-mod-circuit-builder = { path = "crates/circuits/mod-builder", default-features = false }
114114
openvm-poseidon2-air = { path = "crates/circuits/poseidon2-air", default-features = false }
115-
openvm-sha256-air = { path = "crates/circuits/sha256-air", default-features = false }
115+
openvm-sha-air = { path = "crates/circuits/sha-air", default-features = false }
116116
openvm-sha-macros = { path = "crates/circuits/sha-macros", default-features = false }
117117
openvm-circuit-primitives = { path = "crates/circuits/primitives", default-features = false }
118118
openvm-circuit-primitives-derive = { path = "crates/circuits/primitives/derive", default-features = false }

crates/circuits/sha256-air/Cargo.toml renamed to crates/circuits/sha-air/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "openvm-sha256-air"
2+
name = "openvm-sha-air"
33
version.workspace = true
44
authors.workspace = true
55
edition.workspace = true
File renamed without changes.

crates/circuits/sha256-air/src/columns.rs renamed to crates/circuits/sha-air/src/columns.rs

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,18 @@ use openvm_stark_backend::p3_field::FieldAlgebra;
66

77
use crate::ShaConfig;
88

9-
/// In each SHA256 block:
10-
/// - First 16 rows use Sha256RoundCols
11-
/// - Final row uses Sha256DigestCols
9+
/// In each SHA block:
10+
/// - First C::ROUND_ROWS rows use ShaRoundCols
11+
/// - Final row uses ShaDigestCols
1212
///
13-
/// Note that for soundness, we require that there is always a padding row after the last digest row in the trace.
14-
/// Right now, this is true because the unpadded height is a multiple of 17, and thus not a power of 2.
15-
///
16-
/// Sha256RoundCols and Sha256DigestCols share the same first 3 fields:
13+
/// ShaRoundCols and ShaDigestCols share the same first 3 fields:
1714
/// - flags
1815
/// - work_vars/hash (same type, different name)
1916
/// - schedule_helper
2017
///
2118
/// This design allows for:
2219
/// 1. Common constraints to work on either struct type by accessing these shared fields
2320
/// 2. Specific constraints to use the appropriate struct, with flags helping to do conditional constraints
24-
///
25-
/// Note that the `Sha256WorkVarsCols` field it is used for different purposes in the two structs.
2621
#[repr(C)]
2722
#[derive(Clone, Copy, Debug, ColsRef)]
2823
pub struct ShaRoundCols<
@@ -35,7 +30,6 @@ pub struct ShaRoundCols<
3530
const ROW_VAR_CNT: usize,
3631
> {
3732
pub flags: ShaFlagsCols<T, ROW_VAR_CNT>,
38-
/// Stores the current state of the working variables
3933
pub work_vars: ShaWorkVarsCols<T, WORD_BITS, ROUNDS_PER_ROW, WORD_U16S>,
4034
pub schedule_helper:
4135
ShaMessageHelperCols<T, WORD_U16S, ROUNDS_PER_ROW, ROUNDS_PER_ROW_MINUS_ONE>,
@@ -55,11 +49,7 @@ pub struct ShaDigestCols<
5549
const ROW_VAR_CNT: usize,
5650
> {
5751
pub flags: ShaFlagsCols<T, ROW_VAR_CNT>,
58-
/// Will serve as previous hash values for the next block.
59-
/// - on non-last blocks, this is the final hash of the current block
60-
/// - on last blocks, this is the initial state constants, SHA256_H.
61-
/// The work variables constraints are applied on all rows, so `carry_a` and `carry_e`
62-
/// must be filled in with dummy values to ensure these constraints hold.
52+
/// Will serve as previous hash values for the next block
6353
pub hash: ShaWorkVarsCols<T, WORD_BITS, ROUNDS_PER_ROW, WORD_U16S>,
6454
pub schedule_helper:
6555
ShaMessageHelperCols<T, WORD_U16S, ROUNDS_PER_ROW, ROUNDS_PER_ROW_MINUS_ONE>,
@@ -79,11 +69,10 @@ pub struct ShaMessageScheduleCols<
7969
const ROUNDS_PER_ROW: usize,
8070
const WORD_U8S: usize,
8171
> {
82-
/// The message schedule words as C::WORD_BITS-bit integers
83-
/// The first 16 rows will be the message data
72+
/// The message schedule words as 32-bit intergers
8473
pub w: [[T; WORD_BITS]; ROUNDS_PER_ROW],
8574
/// Will be message schedule carries for rows 4..C::ROUND_ROWS and a buffer for rows 0..4 to be used freely by wrapper chips
86-
/// Note: carries are 2 bit numbers represented using 2 cells as individual bits
75+
/// Note: carries are represented as 2 bit numbers
8776
pub carry_or_buffer: [[T; WORD_U8S]; ROUNDS_PER_ROW],
8877
}
8978

@@ -114,12 +103,10 @@ pub struct ShaMessageHelperCols<
114103
const ROUNDS_PER_ROW_MINUS_ONE: usize,
115104
> {
116105
/// The following are used to move data forward to constrain the message schedule additions
117-
/// The value of `w` (message schedule word) from 3 rounds ago
118-
/// In general, `w_i` means `w` from `i` rounds ago
106+
/// The value of `w` from 3 rounds ago
119107
pub w_3: [[T; WORD_U16S]; ROUNDS_PER_ROW_MINUS_ONE],
120108
/// Here intermediate(i) = w_i + sig_0(w_{i+1})
121109
/// Intermed_t represents the intermediate t rounds ago
122-
/// This is needed to constrain the message schedule, since we can only constrain on two rows at a time
123110
pub intermed_4: [[T; WORD_U16S]; ROUNDS_PER_ROW],
124111
pub intermed_8: [[T; WORD_U16S]; ROUNDS_PER_ROW],
125112
pub intermed_12: [[T; WORD_U16S]; ROUNDS_PER_ROW],
@@ -128,38 +115,27 @@ pub struct ShaMessageHelperCols<
128115
#[repr(C)]
129116
#[derive(Clone, Copy, Debug, ColsRef)]
130117
pub struct ShaFlagsCols<T, const ROW_VAR_CNT: usize> {
131-
/// A flag that indicates if the current row is among the first C::ROUND_ROWS rows of a block.
132118
pub is_round_row: T,
133-
/// A flag that indicates if the current row is among the first 4 rows of a block.
119+
/// A flag that indicates if the current row is among the first 4 rows of a block
134120
pub is_first_4_rows: T,
135-
/// A flag that indicates if the current row is the last (17th) row of a block.
136121
pub is_digest_row: T,
137-
// A flag that indicates if the current row is the last block of the message.
138-
// This flag is only used in digest rows.
139122
pub is_last_block: T,
140123
/// We will encode the row index [0..17) using 5 cells
141124
//#[length(ROW_VAR_CNT)]
142125
pub row_idx: [T; ROW_VAR_CNT],
143-
/// The index of the current block in the trace starting at 1.
144-
/// Set to 0 on padding rows.
126+
/// The global index of the current block
145127
pub global_block_idx: T,
146-
/// The index of the current block in the current message starting at 0.
147-
/// Resets after every message.
148-
/// Set to 0 on padding rows.
128+
/// Will store the index of the current block in the current message starting from 0
149129
pub local_block_idx: T,
150130
}
151131

152132
impl<O, T: Copy + core::ops::Add<Output = O>, const ROW_VAR_CNT: usize>
153133
ShaFlagsCols<T, ROW_VAR_CNT>
154134
{
155-
// This refers to the padding rows that are added to the air to make the trace length a power of 2.
156-
// Not to be confused with the padding added to messages as part of the SHA hash function.
157135
pub fn is_not_padding_row(&self) -> O {
158136
self.is_round_row + self.is_digest_row
159137
}
160138

161-
// This refers to the padding rows that are added to the air to make the trace length a power of 2.
162-
// Not to be confused with the padding added to messages as part of the SHA hash function.
163139
pub fn is_padding_row(&self) -> O
164140
where
165141
O: FieldAlgebra,
@@ -168,14 +144,11 @@ impl<O, T: Copy + core::ops::Add<Output = O>, const ROW_VAR_CNT: usize>
168144
}
169145
}
170146

171-
// We need to implement this for the ColsRef type as well
172147
impl<'a, O, T: Copy + core::ops::Add<Output = O>> ShaFlagsColsRef<'a, T> {
173148
pub fn is_not_padding_row(&self) -> O {
174149
*self.is_round_row + *self.is_digest_row
175150
}
176151

177-
// This refers to the padding rows that are added to the air to make the trace length a power of 2.
178-
// Not to be confused with the padding added to messages as part of the SHA hash function.
179152
pub fn is_padding_row(&self) -> O
180153
where
181154
O: FieldAlgebra,

crates/circuits/sha256-air/src/config.rs renamed to crates/circuits/sha-air/src/config.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ pub trait ShaConfig: Send + Sync + Clone {
8181
};
8282
}
8383

84+
/// We can notice that `carry_a`'s and `carry_e`'s are always the same on invalid rows
85+
/// To optimize the trace generation of invalid rows, we precompute those values.
86+
/// This trait also stores the constants K and H for the given SHA config.
8487
pub trait ShaPrecomputedValues<T> {
8588
// these should be appropirately sized for the config
8689
fn get_invalid_carry_a(round_num: usize) -> &'static [u32];
@@ -111,8 +114,6 @@ impl ShaConfig for Sha256Config {
111114
const ROW_VAR_CNT: usize = 5;
112115
}
113116

114-
/// We can notice that `carry_a`'s and `carry_e`'s are always the same on invalid rows
115-
/// To optimize the trace generation of invalid rows, we have those values precomputed here
116117
pub const SHA256_INVALID_CARRY_A: [[u32; Sha256Config::WORD_U16S]; Sha256Config::ROUNDS_PER_ROW] = [
117118
[1230919683, 1162494304],
118119
[266373122, 1282901987],
@@ -179,8 +180,6 @@ impl ShaConfig for Sha512Config {
179180
const ROW_VAR_CNT: usize = 6;
180181
}
181182

182-
/// We can notice that `carry_a`'s and `carry_e`'s are always the same on invalid rows
183-
/// To optimize the trace generation of invalid rows, we have those values precomputed here
184183
pub(crate) const SHA512_INVALID_CARRY_A: [[u32; Sha512Config::WORD_U16S];
185184
Sha512Config::ROUNDS_PER_ROW] = [
186185
[55971842, 827997017, 993005918, 512731953],
@@ -308,7 +307,7 @@ impl ShaPrecomputedValues<u64> for Sha512Config {
308307
}
309308

310309
// Needed to avoid compile errors in utils.rs
311-
// don't ask me why this doesn't inf loop
310+
// not sure why this doesn't inf loop
312311
pub trait RotateRight {
313312
fn rotate_right(self, n: u32) -> Self;
314313
}

crates/circuits/sha256-air/src/lib.rs renamed to crates/circuits/sha-air/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Implementation of the SHA256 compression function without padding
1+
//! Implementation of the SHA256/SHA512 compression function without padding
22
//! This this AIR doesn't constrain any of the message padding
33
44
mod air;
File renamed without changes.

crates/circuits/sha256-air/src/trace.rs renamed to crates/circuits/sha-air/src/trace.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{
1919
ShaRoundColsRef, WrappingAdd,
2020
};
2121

22-
/// The trace generation of SHA256 should be done in two passes.
22+
/// The trace generation of SHA should be done in two passes.
2323
/// The first pass should do `get_block_trace` for every block and generate the invalid rows through `get_default_row`
2424
/// The second pass should go through all the blocks and call `generate_missing_cells`
2525
impl<C: ShaConfig + ShaPrecomputedValues<C::Word>> ShaAir<C> {
@@ -455,7 +455,7 @@ impl<C: ShaConfig + ShaPrecomputedValues<C::Word>> ShaAir<C> {
455455
/// This function should be called only after `generate_block_trace` was called for all blocks
456456
/// And [`Self::generate_default_row`] is called for all invalid rows
457457
/// Will populate the missing values of `trace`, where the width of the trace is `trace_width`
458-
/// and the starting column for the `Sha256Air` is `trace_start_col`.
458+
/// and the starting column for the `ShaAir` is `trace_start_col`.
459459
/// Note: `trace` needs to be the rows 1..C::ROWS_PER_BLOCK of a block and the first row of the next block
460460
pub fn generate_missing_cells<F: PrimeField32>(
461461
&self,
@@ -748,11 +748,8 @@ pub fn generate_trace<F: PrimeField32, C: ShaConfig + ShaPrecomputedValues<C::Wo
748748
debug_assert!(input.len() == C::BLOCK_U8S);
749749
}
750750

751-
println!("records.len(): {}", records.len());
752751
let non_padded_height = records.len() * C::ROWS_PER_BLOCK;
753-
println!("non_padded_height: {}", non_padded_height);
754752
let height = next_power_of_two_or_zero(non_padded_height);
755-
println!("height: {}", height);
756753
let width = <ShaAir<C> as BaseAir<F>>::width(sub_air);
757754
let mut values = F::zero_vec(height * width);
758755

0 commit comments

Comments
 (0)