From b4841b1479bf6be5958a850083052badc4c027fa Mon Sep 17 00:00:00 2001 From: Kamen Mladenov Date: Mon, 14 Apr 2025 13:23:49 +0300 Subject: feat(guests/keccak): Add SP1 and RISC0 precompile usage --- guests/keccak/Cargo.lock | 24 +++++++++++++++++++++++- guests/keccak/Cargo.toml | 7 +++++-- guests/keccak/src/lib.rs | 10 +++++++--- 3 files changed, 35 insertions(+), 6 deletions(-) (limited to 'guests') diff --git a/guests/keccak/Cargo.lock b/guests/keccak/Cargo.lock index 69063a0..5136a4d 100644 --- a/guests/keccak/Cargo.lock +++ b/guests/keccak/Cargo.lock @@ -116,7 +116,9 @@ name = "keccak" version = "0.1.0" dependencies = [ "guests_macro", - "sha3", + "sha3 0.10.6", + "sha3 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha3 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?tag=patch-sha3-0.10.8-sp1-4.0.0)", "zkm-runtime", ] @@ -250,6 +252,15 @@ dependencies = [ "digest", ] +[[package]] +name = "sha3" +version = "0.10.6" +source = "git+https://github.com/risc0/RustCrypto-hashes?tag=sha3-v0.10.6#7a187e934c1f6c68e4b4e5cf37541b7a0d64d303" +dependencies = [ + "digest", + "keccak 0.1.5", +] + [[package]] name = "sha3" version = "0.10.8" @@ -260,6 +271,15 @@ dependencies = [ "keccak 0.1.5", ] +[[package]] +name = "sha3" +version = "0.10.8" +source = "git+https://github.com/sp1-patches/RustCrypto-hashes?tag=patch-sha3-0.10.8-sp1-4.0.0#8f6d303c0861ba7e5adcc36207c0f41fe5edaabc" +dependencies = [ + "digest", + "keccak 0.1.5", +] + [[package]] name = "syn" version = "2.0.100" @@ -361,6 +381,7 @@ dependencies = [ [[package]] name = "zkm-precompiles" version = "0.2.0" +source = "git+https://github.com/zkMIPS/zkm.git#eb09cf6c81bed9717bc98e4a4c9a61f54787a351" dependencies = [ "bincode", "cfg-if", @@ -371,6 +392,7 @@ dependencies = [ [[package]] name = "zkm-runtime" version = "0.2.0" +source = "git+https://github.com/zkMIPS/zkm.git#eb09cf6c81bed9717bc98e4a4c9a61f54787a351" dependencies = [ "bincode", "bytemuck", diff --git a/guests/keccak/Cargo.toml b/guests/keccak/Cargo.toml index beaa70e..aaf3d2a 100644 --- a/guests/keccak/Cargo.toml +++ b/guests/keccak/Cargo.toml @@ -8,11 +8,14 @@ guests_macro = { version = "0.1.0", path = "../../guests_macro" } sha3 = { version = "0.10.8", default-features = false } zkm-runtime = { git = "https://github.com/zkMIPS/zkm.git", optional = true } # patched by the guest wrapper +sha3-sp1 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha3", tag = "patch-sha3-0.10.8-sp1-4.0.0", optional = true } +sha3-risc0 = { git = "https://github.com/risc0/RustCrypto-hashes", package = "sha3", tag = "sha3-v0.10.6", optional = true } + [features] no_std = [] jolt = [] nexus = [] -risc0 = [] -sp1 = [] +risc0 = ["sha3-risc0"] +sp1 = ["sha3-sp1"] zkm = ["zkm-runtime"] zkwasm = [] diff --git a/guests/keccak/src/lib.rs b/guests/keccak/src/lib.rs index 4808442..df15ae2 100644 --- a/guests/keccak/src/lib.rs +++ b/guests/keccak/src/lib.rs @@ -5,9 +5,13 @@ extern crate alloc; #[cfg(feature = "no_std")] use alloc::vec::Vec; -#[cfg(feature = "zkm")] -use zkm_runtime::*; +#[cfg(feature = "sp1")] +use sha3_sp1::{Digest, Keccak256}; +#[cfg(feature = "risc0")] +use sha3_risc0::{Digest, Keccak256}; + +#[cfg(not(any(feature = "zkm", feature = "sp1", feature = "risc0")))] use sha3::{Digest, Keccak256}; #[guests_macro::proving_entrypoint] @@ -15,7 +19,7 @@ pub fn main(secret: Vec, hash: Vec) -> bool { #[cfg(feature = "zkm")] let result = zkm_runtime::io::keccak(&secret.as_slice()); - #[cfg(not(any(feature = "zkm")))] + #[cfg(not(feature = "zkm"))] let result = { let mut hasher = Keccak256::new(); hasher.update(secret); -- cgit v1.2.3