Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use u32 based hasher for BabybearBlake3 #327

Merged
merged 7 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
57 changes: 32 additions & 25 deletions Cargo.lock

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

38 changes: 19 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ debug = true
debug-assertions = true

[workspace.dependencies]
p3-air = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-field = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-commit = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-matrix = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-baby-bear = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-util = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-challenger = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-dft = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-fri = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-goldilocks = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-keccak = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-keccak-air = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-blake3 = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-mds = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-merkle-tree = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-poseidon2 = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-symmetric = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-uni-stark = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-maybe-rayon = { git = "https://github.com/succinctlabs/plonky3.git" }
p3-air = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
kevjue marked this conversation as resolved.
Show resolved Hide resolved
p3-field = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-commit = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-matrix = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-baby-bear = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-util = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-challenger = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-dft = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-fri = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-goldilocks = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-keccak = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-keccak-air = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-blake3 = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-mds = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-merkle-tree = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-poseidon2 = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-symmetric = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-uni-stark = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
p3-maybe-rayon = { git = "https://github.com/succinctlabs/plonky3.git", branch = "kevjue/u32_related_hash_functions" }
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ petgraph = "0.6.4"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
hashbrown = "0.14.3"
num_cpus = "1.16.0"
blake3_zkvm = { git = "https://github.com/sp1-patches/BLAKE3.git", branch = "patch-blake3_zkvm/v.1.0.0" }

[dev-dependencies]
criterion = "0.5.1"
Expand Down
29 changes: 23 additions & 6 deletions core/src/utils/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ pub(super) mod baby_bear_keccak {

pub type Dft = Radix2DitParallel;

type Challenger = SerializingChallenger32<Val, HashChallenger<u8, ByteHash, 32>>;
type Challenger = SerializingChallenger32<Val, u8, HashChallenger<u8, ByteHash, 32>>;

type Pcs =
TwoAdicFriPcs<TwoAdicFriPcsConfig<Val, Challenge, Challenger, Dft, ValMmcs, ChallengeMmcs>>;
Expand Down Expand Up @@ -428,7 +428,7 @@ pub(super) mod baby_bear_blake3 {
use p3_field::extension::BinomialExtensionField;
use p3_fri::{FriConfig, TwoAdicFriPcs, TwoAdicFriPcsConfig};
use p3_merkle_tree::FieldMerkleTreeMmcs;
use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher32};
use p3_symmetric::{PseudoCompressionFunction, SerializingHasher32};
use serde::{Deserialize, Serialize};

use crate::stark::StarkGenericConfig;
Expand All @@ -442,14 +442,14 @@ pub(super) mod baby_bear_blake3 {
type ByteHash = Blake3;
type FieldHash = SerializingHasher32<ByteHash>;

type MyCompress = CompressionFunctionFromHasher<u8, ByteHash, 2, 32>;
type MyCompress = OptimizedCompressionFunction;

pub type ValMmcs = FieldMerkleTreeMmcs<Val, u8, FieldHash, MyCompress, 32>;
pub type ValMmcs = FieldMerkleTreeMmcs<Val, u32, FieldHash, MyCompress, 8>;
pub type ChallengeMmcs = ExtensionMmcs<Val, Challenge, ValMmcs>;

pub type Dft = Radix2DitParallel;

type Challenger = SerializingChallenger32<Val, HashChallenger<u8, ByteHash, 32>>;
type Challenger = SerializingChallenger32<Val, u32, HashChallenger<u32, ByteHash, 8>>;

type Pcs =
TwoAdicFriPcs<TwoAdicFriPcsConfig<Val, Challenge, Challenger, Dft, ValMmcs, ChallengeMmcs>>;
Expand Down Expand Up @@ -487,7 +487,7 @@ pub(super) mod baby_bear_blake3 {
let byte_hash = ByteHash {};
let field_hash = FieldHash::new(byte_hash);

let compress = MyCompress::new(byte_hash);
let compress = MyCompress::new();

let val_mmcs = ValMmcs::new(field_hash, compress);

Expand Down Expand Up @@ -542,4 +542,21 @@ pub(super) mod baby_bear_blake3 {
&self.pcs
}
}
#[derive(Clone)]
pub struct OptimizedCompressionFunction {}
kevjue marked this conversation as resolved.
Show resolved Hide resolved

impl OptimizedCompressionFunction {
pub fn new() -> Self {
Self {}
}
}

impl PseudoCompressionFunction<[u32; 8], 2> for OptimizedCompressionFunction {
fn compress(&self, input: [[u32; 8]; 2]) -> [u32; 8] {
let mut block_words = [0u32; blake3_zkvm::BLOCK_LEN];
block_words[0..8].copy_from_slice(&input[0]);
block_words[8..].copy_from_slice(&input[1]);
blake3_zkvm::hash_single_block(&block_words, blake3_zkvm::BLOCK_LEN)
}
}
}
Loading
Loading