Skip to content

Commit

Permalink
feat: c-kzg bump, cleanup on kzgsetting (#1719)
Browse files Browse the repository at this point in the history
* chore: bump c-kzg v2.0.0

* feat: cleanup c-kzg kzgsetting

* rm kzg-rs from no_std check
  • Loading branch information
rakita authored Aug 26, 2024
1 parent d29e132 commit a46a88b
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 4,433 deletions.
7 changes: 3 additions & 4 deletions Cargo.lock

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

8 changes: 0 additions & 8 deletions bins/revme/src/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod bytecode;
pub mod eofvalidation;
pub mod evmrunner;
pub mod format_kzg_setup;
pub mod statetest;

use structopt::{clap::AppSettings, StructOpt};
Expand All @@ -14,10 +13,6 @@ pub enum MainCmd {
Statetest(statetest::Cmd),
#[structopt(about = "Execute eof validation tests")]
EofValidation(eofvalidation::Cmd),
#[structopt(
about = "Format kzg settings from a trusted setup file (.txt) into binary format (.bin)"
)]
FormatKzgSetup(format_kzg_setup::Cmd),
#[structopt(
about = "Evm runner command allows running arbitrary evm bytecode.\nBytecode can be provided from cli or from file with --path option."
)]
Expand All @@ -31,8 +26,6 @@ pub enum Error {
#[error(transparent)]
Statetest(#[from] statetest::Error),
#[error(transparent)]
KzgErrors(#[from] format_kzg_setup::KzgErrors),
#[error(transparent)]
EvmRunnerErrors(#[from] evmrunner::Errors),
#[error("Eof validation failed: {:?}/{total_tests}", total_tests-failed_test)]
EofValidation {
Expand All @@ -48,7 +41,6 @@ impl MainCmd {
match self {
Self::Statetest(cmd) => cmd.run().map_err(Into::into),
Self::EofValidation(cmd) => cmd.run().map_err(Into::into),
Self::FormatKzgSetup(cmd) => cmd.run().map_err(Into::into),
Self::Evm(cmd) => cmd.run().map_err(Into::into),
Self::Bytecode(cmd) => {
cmd.run();
Expand Down
59 changes: 0 additions & 59 deletions bins/revme/src/cmd/format_kzg_setup.rs

This file was deleted.

4 changes: 3 additions & 1 deletion crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ aurora-engine-modexp = { version = "1.1", default-features = false }
bn = { package = "substrate-bn", version = "0.6", default-features = false }

# KZG point evaluation precompile
c-kzg = { version = "1.0.2", default-features = false, optional = true }
c-kzg = { version = "1.0.3", default-features = false, optional = true, features = [
"ethereum_kzg_settings",
] }

# Optionally use `kzg-rs` for a pure Rust implementation of KZG point evaluation.
kzg-rs = { version = "0.1", default-features = false, features = [
Expand Down
13 changes: 7 additions & 6 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ bitvec = { version = "1", default-features = false, features = ["alloc"] }
bitflags = { version = "2.6.0", default-features = false }

# For setting the CfgEnv KZGSettings. Enabled by c-kzg flag.
c-kzg = { version = "1.0.2", default-features = false, optional = true }
once_cell = { version = "1.19", default-features = false, optional = true }
c-kzg = { version = "1.0.3", default-features = false, optional = true, features = [
"ethereum_kzg_settings",
] }

# Optionally use `kzg-rs` for a pure Rust implementation of KZG.
kzg-rs = { version = "0.1", default-features = false, features = [
Expand All @@ -42,7 +43,6 @@ kzg-rs = { version = "0.1", default-features = false, features = [

# utility
enumn = "0.1"
derive_more = { version = "0.99", optional = true }
cfg-if = "1"
dyn-clone = "1.0"

Expand Down Expand Up @@ -110,6 +110,7 @@ optional_beneficiary_reward = []
rand = ["alloy-primitives/rand"]

# See comments in `revm-precompile`
c-kzg = ["dep:c-kzg", "dep:once_cell", "dep:derive_more"]
# `kzg-rs` is not audited but useful for `no_std` environment, use it with causing and default to `c-kzg` if possible.
kzg-rs = ["dep:kzg-rs", "dep:once_cell", "dep:derive_more"]
c-kzg = ["dep:c-kzg"]
# `kzg-rs` is not audited but useful for `no_std` environment.
# use it with causing and default to `c-kzg` if possible!
kzg-rs = ["dep:kzg-rs"]
35 changes: 25 additions & 10 deletions crates/primitives/src/kzg.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
mod env_settings;
mod trusted_setup_points;

cfg_if::cfg_if! {
if #[cfg(feature = "c-kzg")] {
pub use c_kzg::KzgSettings;
/// KZG Settings that allow us to specify a custom trusted setup.
/// or use hardcoded default settings.
#[derive(Debug, Clone, Default, PartialEq, Eq )]
pub enum EnvKzgSettings {
/// Default mainnet trusted setup
#[default]
Default,
/// Custom trusted setup.
Custom(std::sync::Arc<c_kzg::KzgSettings>),
}

impl EnvKzgSettings {
/// Return set KZG settings.
///
/// In will initialize the default settings if it is not already loaded.
pub fn get(&self) -> &c_kzg::KzgSettings {
match self {
Self::Default => {
c_kzg::ethereum_kzg_settings()
}
Self::Custom(settings) => settings,
}
}
}
} else if #[cfg(feature = "kzg-rs")] {
pub use kzg_rs::KzgSettings;
pub use kzg_rs::{KzgSettings,EnvKzgSettings};
}
}

pub use env_settings::EnvKzgSettings;
pub use trusted_setup_points::{
parse_kzg_trusted_setup, G1Points, G2Points, KzgErrors, BYTES_PER_G1_POINT, BYTES_PER_G2_POINT,
G1_POINTS, G2_POINTS, NUM_G1_POINTS, NUM_G2_POINTS,
};
43 changes: 0 additions & 43 deletions crates/primitives/src/kzg/env_settings.rs

This file was deleted.

Binary file removed crates/primitives/src/kzg/g1_points.bin
Binary file not shown.
Binary file removed crates/primitives/src/kzg/g2_points.bin
Binary file not shown.
Loading

0 comments on commit a46a88b

Please sign in to comment.