Skip to content

Commit 052ef7a

Browse files
WIP: update vm chip to support sha512
1 parent 3d3dc2e commit 052ef7a

File tree

11 files changed

+350
-262
lines changed

11 files changed

+350
-262
lines changed

Cargo.lock

Lines changed: 3 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
@@ -230,6 +230,7 @@ rrs-lib = "0.1.0"
230230
rand = { version = "0.8.5", default-features = false }
231231
hex = { version = "0.4.3", default-features = false }
232232
serde-big-array = "0.5.1"
233+
ndarray = "0.16"
233234

234235
# default-features = false for no_std for use in guest programs
235236
itertools = { version = "0.13.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
@@ -294,7 +294,7 @@ fn get_const_cols_ref_fields(
294294
let slice_var = format_ident!("{}_slice", f.ident.clone().unwrap());
295295

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

extensions/sha256/circuit/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ 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"] }
@@ -24,6 +25,7 @@ serde.workspace = true
2425
sha2 = { version = "0.10", default-features = false }
2526
strum = { workspace = true }
2627
bitcode.workspace = true
28+
ndarray.workspace = true
2729

2830
[dev-dependencies]
2931
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, BytesStateful)]
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, BytesStateful)]
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)