Skip to content
Merged
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
3 changes: 2 additions & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ hex-literal.workspace = true
[features]
default = []
c-kzg = ["ethrex-crypto/c-kzg"]

risc0 = ["ethrex-crypto/risc0"]

[lib]
path = "./common.rs"

Expand Down
1 change: 1 addition & 0 deletions crates/common/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ thiserror.workspace = true
[features]
default = []
c-kzg = ["dep:c-kzg"]
risc0 = ["c-kzg"]
23 changes: 17 additions & 6 deletions crates/common/crypto/kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ pub const FIELD_ELEMENTS_PER_EXT_BLOB: usize = 2 * FIELD_ELEMENTS_PER_BLOB;
pub const FIELD_ELEMENTS_PER_CELL: usize = 64;
pub const BYTES_PER_CELL: usize = FIELD_ELEMENTS_PER_CELL * BYTES_PER_FIELD_ELEMENT;
pub const CELLS_PER_EXT_BLOB: usize = FIELD_ELEMENTS_PER_EXT_BLOB / FIELD_ELEMENTS_PER_CELL;

// https://github.com/ethereum/c-kzg-4844?tab=readme-ov-file#precompute
// For Risc0 we need this parameter to be 0.
// For the rest we keep the value 8 due to optimizations.
#[cfg(not(feature = "risc0"))]
pub const KZG_PRECOMPUTE: u64 = 8;
#[cfg(feature = "risc0")]
pub const KZG_PRECOMPUTE: u64 = 0;

type Bytes48 = [u8; 48];
type Blob = [u8; BYTES_PER_BLOB];
type Commitment = Bytes48;
Expand Down Expand Up @@ -54,7 +63,7 @@ pub fn verify_cell_kzg_proof_batch(
)));
#[cfg(feature = "c-kzg")]
{
let c_kzg_settings = c_kzg::ethereum_kzg_settings(8);
let c_kzg_settings = c_kzg::ethereum_kzg_settings(KZG_PRECOMPUTE);
let mut cells = Vec::new();
for blob in blobs {
cells.extend(c_kzg_settings.compute_cells(&(*blob).into())?.into_iter());
Expand Down Expand Up @@ -98,7 +107,7 @@ pub fn verify_blob_kzg_proof(
#[cfg(feature = "c-kzg")]
{
c_kzg::KzgSettings::verify_blob_kzg_proof(
c_kzg::ethereum_kzg_settings(8),
c_kzg::ethereum_kzg_settings(KZG_PRECOMPUTE),
&blob.into(),
&commitment.into(),
&proof.into(),
Expand Down Expand Up @@ -128,7 +137,7 @@ pub fn verify_kzg_proof(
#[cfg(feature = "c-kzg")]
{
c_kzg::KzgSettings::verify_kzg_proof(
c_kzg::ethereum_kzg_settings(8),
c_kzg::ethereum_kzg_settings(KZG_PRECOMPUTE),
&commitment_bytes.into(),
&z.into(),
&y.into(),
Expand All @@ -142,12 +151,14 @@ pub fn verify_kzg_proof(
pub fn blob_to_kzg_commitment_and_proof(blob: &Blob) -> Result<(Commitment, Proof), KzgError> {
let blob: c_kzg::Blob = (*blob).into();

let commitment =
c_kzg::KzgSettings::blob_to_kzg_commitment(c_kzg::ethereum_kzg_settings(8), &blob)?;
let commitment = c_kzg::KzgSettings::blob_to_kzg_commitment(
c_kzg::ethereum_kzg_settings(KZG_PRECOMPUTE),
&blob,
)?;
let commitment_bytes = commitment.to_bytes();

let proof = c_kzg::KzgSettings::compute_blob_kzg_proof(
c_kzg::ethereum_kzg_settings(8),
c_kzg::ethereum_kzg_settings(KZG_PRECOMPUTE),
&blob,
&commitment_bytes,
)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/l2/prover/src/guest_program/src/risc0/Cargo.toml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to update RISC0's guest Cargo.lock?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there is no need. I ran cargo check inside risc0 guest program and nothing change

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ guest_program = { path = "../../", default-features = false, features = [
rkyv = { version = "0.8.10", features = ["unaligned"] }


ethrex-common = { path = "../../../../../../common", default-features = false }
ethrex-common = { path = "../../../../../../common", default-features = false, features = ["risc0"] }
ethrex-storage = { path = "../../../../../../storage", default-features = false }
ethrex-rlp = { path = "../../../../../../common/rlp" }
ethrex-vm = { path = "../../../../../../vm", default-features = false, features = [
Expand Down
Loading