Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 154 additions & 31 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ members = [
"crypto/math-cuda",
"bin/cli",
]
# Riscv-only bare-metal crate, path-dependent from crypto/crypto (target-gated),
# ethrex-crypto, and guest programs. Without this exclude, Cargo auto-adopts it as
# a member (nothing else claims it), so `cargo test` runs its unit tests on host,
# which link against riscv-only symbols and abort.
exclude = ["syscalls"]

resolver = "2"

Expand Down
3 changes: 2 additions & 1 deletion bench_vs/lambda/recursion/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crypto/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ memmap2 = { version = "0.9", optional = true }
tempfile = { version = "3", optional = true }
libc = { version = "0.2", optional = true }

[target.'cfg(target_arch = "riscv64")'.dependencies]
lambda-vm-syscalls = { path = "../../syscalls" }

[dev-dependencies]
math = { path = "../math", features = ["test-utils"] }
rand = "0.8.5"
Expand Down
3 changes: 2 additions & 1 deletion crypto/crypto/src/fiat_shamir/default_transcript.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::fiat_shamir::is_transcript::{IsStarkTranscript, IsTranscript};

use crate::hash::platform_keccak::PlatformKeccak256 as Keccak256;
use core::marker::PhantomData;
use digest::Digest;
use math::{
field::{
element::FieldElement,
Expand All @@ -9,7 +11,6 @@ use math::{
traits::ByteConversion,
};
use rand_chacha::{ChaCha20Rng, rand_core::SeedableRng};
use sha3::{Digest, Keccak256};

pub struct DefaultTranscript<F: HasDefaultTranscript> {
hasher: Keccak256,
Expand Down
1 change: 1 addition & 0 deletions crypto/crypto/src/hash/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod platform_keccak;
pub mod poseidon;
pub mod sha3;
58 changes: 58 additions & 0 deletions crypto/crypto/src/hash/platform_keccak.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! Keccak-256 implementation selected per target: the `keccak_permute`
//! precompile on the riscv64 guest, plain software `sha3::Keccak256` on host.
//! Wraps `lambda_vm_syscalls::keccak::Keccak256` with the `digest` crate
//! traits so it's a drop-in replacement anywhere a `D: Digest` is expected
//! (Merkle tree backends, Fiat-Shamir transcript).

#[cfg(target_arch = "riscv64")]
mod imp {
use digest::{
FixedOutput, FixedOutputReset, HashMarker, Output, OutputSizeUser, Reset, Update,
};
use lambda_vm_syscalls::keccak::Keccak256 as SyscallKeccak256;

#[derive(Clone, Default)]
pub struct PlatformKeccak256(SyscallKeccak256);

impl HashMarker for PlatformKeccak256 {}

impl OutputSizeUser for PlatformKeccak256 {
type OutputSize = digest::typenum::U32;
}

impl Update for PlatformKeccak256 {
fn update(&mut self, data: &[u8]) {
self.0.update(data);
}
}

impl FixedOutput for PlatformKeccak256 {
fn finalize_into(self, out: &mut Output<Self>) {
let mut bytes = [0u8; 32];
self.0.finalize(&mut bytes);
out.copy_from_slice(&bytes);
}
}

impl Reset for PlatformKeccak256 {
fn reset(&mut self) {
*self = Self::default();
}
}

impl FixedOutputReset for PlatformKeccak256 {
fn finalize_into_reset(&mut self, out: &mut Output<Self>) {
let mut bytes = [0u8; 32];
self.0.clone().finalize(&mut bytes);
out.copy_from_slice(&bytes);
Reset::reset(self);
}
}
}

#[cfg(not(target_arch = "riscv64"))]
mod imp {
pub type PlatformKeccak256 = sha3::Keccak256;
}

pub use imp::PlatformKeccak256;
2 changes: 1 addition & 1 deletion crypto/crypto/src/merkle_tree/backends/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sha3::Keccak256;
use crate::hash::platform_keccak::PlatformKeccak256 as Keccak256;

use super::{
field_element::FieldElementBackend,
Expand Down
2 changes: 1 addition & 1 deletion crypto/stark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ math = { path = "../math", features = [
crypto = { path = "../crypto", features = ["std", "serde"] }
thiserror = "1.0.38"
log = "0.4.17"
sha3 = "0.10.8"
digest = "0.10.7"
serde = { version = "1.0", features = ["derive"] }
itertools = "0.11.0"

Expand Down
3 changes: 2 additions & 1 deletion crypto/stark/src/grinding.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crypto::hash::platform_keccak::PlatformKeccak256 as Keccak256;
use digest::Digest;
#[cfg(feature = "parallel")]
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
use sha3::{Digest, Keccak256};

const PREFIX: [u8; 8] = [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xed];

Expand Down
5 changes: 5 additions & 0 deletions executor/programs/rust/keccak_precompile/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.riscv64im-lambda-vm-elf]
rustflags = [
"--cfg", "getrandom_backend=\"custom\"",
"-C", "passes=lower-atomic"
]
Loading
Loading