Skip to content

Commit 6331995

Browse files
WIP: update vm chip to support sha512
1 parent 816edcc commit 6331995

File tree

11 files changed

+353
-263
lines changed

11 files changed

+353
-263
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ rrs-lib = "0.1.0"
212212
rand = { version = "0.8.5", default-features = false }
213213
hex = { version = "0.4.3", default-features = false }
214214
serde-big-array = "0.5.1"
215+
ndarray = "0.16"
215216

216217
# default-features = false for no_std for use in guest programs
217218
itertools = { version = "0.14.0", default-features = false }

crates/circuits/sha-macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ fn get_const_cols_ref_fields(
292292
let slice_var = format_ident!("{}_slice", f.ident.clone().unwrap());
293293

294294
if f.attrs.iter().any(|attr| attr.path().is_ident("plain")) {
295-
// treat the field as a struct that derives AlignedBorrow
295+
// treat the field as a struct that derives AlignedBorrow (and doesn't depend on the config)
296296
let f_ty = &f.ty;
297297
return Ok(FieldInfo {
298298
ty: parse_quote! {

extensions/sha256/circuit/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ openvm-instructions = { workspace = true }
1616
openvm-sha256-transpiler = { workspace = true }
1717
openvm-rv32im-circuit = { workspace = true }
1818
openvm-sha-air = { workspace = true }
19+
openvm-sha-macros = { workspace = true }
1920

2021
derive-new.workspace = true
2122
derive_more = { workspace = true, features = ["from"] }
2223
rand.workspace = true
2324
serde.workspace = true
2425
sha2 = { version = "0.10", default-features = false }
2526
strum = { workspace = true }
27+
ndarray.workspace = true
2628

2729
[dev-dependencies]
2830
openvm-stark-sdk = { workspace = true }

extensions/sha256/circuit/src/extension.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ use openvm_rv32im_circuit::{
1717
Rv32MExecutor, Rv32MPeriphery,
1818
};
1919
use openvm_sha256_transpiler::Rv32Sha256Opcode;
20+
use openvm_sha_air::Sha256Config;
2021
use openvm_stark_backend::p3_field::PrimeField32;
2122
use serde::{Deserialize, Serialize};
2223
use strum::IntoEnumIterator;
2324

2425
use crate::*;
2526

2627
#[derive(Clone, Debug, VmConfig, derive_new::new, Serialize, Deserialize)]
27-
pub struct Sha256Rv32Config {
28+
pub struct Sha2Rv32Config {
2829
#[system]
2930
pub system: SystemConfig,
3031
#[extension]
@@ -34,38 +35,39 @@ pub struct Sha256Rv32Config {
3435
#[extension]
3536
pub io: Rv32Io,
3637
#[extension]
37-
pub sha256: Sha256,
38+
pub sha2: Sha2,
3839
}
3940

40-
impl Default for Sha256Rv32Config {
41+
impl Default for Sha2Rv32Config {
4142
fn default() -> Self {
4243
Self {
4344
system: SystemConfig::default().with_continuations(),
4445
rv32i: Rv32I,
4546
rv32m: Rv32M::default(),
4647
io: Rv32Io,
47-
sha256: Sha256,
48+
sha2: Sha2,
4849
}
4950
}
5051
}
5152

5253
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
53-
pub struct Sha256;
54+
pub struct Sha2;
5455

5556
#[derive(ChipUsageGetter, Chip, InstructionExecutor, From, AnyEnum)]
56-
pub enum Sha256Executor<F: PrimeField32> {
57-
Sha256(Sha256VmChip<F>),
57+
pub enum Sha2Executor<F: PrimeField32> {
58+
Sha256(ShaVmChip<F, Sha256Config>),
59+
Sha512(ShaVmChip<F, Sha512Config>),
5860
}
5961

6062
#[derive(From, ChipUsageGetter, Chip, AnyEnum)]
61-
pub enum Sha256Periphery<F: PrimeField32> {
63+
pub enum ShaPeriphery<F: PrimeField32> {
6264
BitwiseOperationLookup(SharedBitwiseOperationLookupChip<8>),
6365
Phantom(PhantomChip<F>),
6466
}
6567

66-
impl<F: PrimeField32> VmExtension<F> for Sha256 {
67-
type Executor = Sha256Executor<F>;
68-
type Periphery = Sha256Periphery<F>;
68+
impl<F: PrimeField32> VmExtension<F> for Sha2 {
69+
type Executor = ShaExecutor<F>;
70+
type Periphery = ShaPeriphery<F>;
6971

7072
fn build(
7173
&self,
@@ -84,7 +86,7 @@ impl<F: PrimeField32> VmExtension<F> for Sha256 {
8486
chip
8587
};
8688

87-
let sha256_chip = Sha256VmChip::new(
89+
let sha256_chip = ShaVmChip::new(
8890
builder.system_port(),
8991
builder.system_config().memory_config.pointer_max_bits,
9092
bitwise_lu_chip,

0 commit comments

Comments
 (0)