mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: re-export c-kzg types and impl rlp traits (#4084)
This commit is contained in:
49
Cargo.lock
generated
49
Cargo.lock
generated
@ -601,6 +601,27 @@ dependencies = [
|
|||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bindgen"
|
||||||
|
version = "0.64.0"
|
||||||
|
source = "git+https://github.com/rust-lang/rust-bindgen?rev=0de11f0a521611ac8738b7b01d19dddaf3899e66#0de11f0a521611ac8738b7b01d19dddaf3899e66"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 1.3.2",
|
||||||
|
"cexpr",
|
||||||
|
"clang-sys",
|
||||||
|
"lazy_static",
|
||||||
|
"lazycell",
|
||||||
|
"log",
|
||||||
|
"peeking_take_while",
|
||||||
|
"proc-macro2 1.0.66",
|
||||||
|
"quote 1.0.32",
|
||||||
|
"regex",
|
||||||
|
"rustc-hash",
|
||||||
|
"shlex",
|
||||||
|
"syn 2.0.27",
|
||||||
|
"which",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bindgen"
|
name = "bindgen"
|
||||||
version = "0.65.1"
|
version = "0.65.1"
|
||||||
@ -909,6 +930,19 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "c-kzg"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/ethereum/c-kzg-4844#13cec820c08f45318f82ed4e0da0300042758b92"
|
||||||
|
dependencies = [
|
||||||
|
"bindgen 0.64.0 (git+https://github.com/rust-lang/rust-bindgen?rev=0de11f0a521611ac8738b7b01d19dddaf3899e66)",
|
||||||
|
"cc",
|
||||||
|
"glob",
|
||||||
|
"hex",
|
||||||
|
"libc",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "camino"
|
name = "camino"
|
||||||
version = "1.1.6"
|
version = "1.1.6"
|
||||||
@ -3703,7 +3737,7 @@ version = "0.13.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8b18cbf29f8ff3542ba22bdce9ac610fcb75d74bb4e2b306b2a2762242025b4f"
|
checksum = "8b18cbf29f8ff3542ba22bdce9ac610fcb75d74bb4e2b306b2a2762242025b4f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen 0.64.0",
|
"bindgen 0.64.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"errno 0.2.8",
|
"errno 0.2.8",
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
@ -5767,6 +5801,7 @@ dependencies = [
|
|||||||
"arbitrary",
|
"arbitrary",
|
||||||
"assert_matches",
|
"assert_matches",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
"c-kzg",
|
||||||
"crc",
|
"crc",
|
||||||
"criterion",
|
"criterion",
|
||||||
"crunchy",
|
"crunchy",
|
||||||
@ -5893,6 +5928,7 @@ dependencies = [
|
|||||||
"arrayvec",
|
"arrayvec",
|
||||||
"auto_impl",
|
"auto_impl",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
"c-kzg",
|
||||||
"criterion",
|
"criterion",
|
||||||
"ethereum-types",
|
"ethereum-types",
|
||||||
"ethnum",
|
"ethnum",
|
||||||
@ -8219,6 +8255,17 @@ dependencies = [
|
|||||||
"rustls-webpki",
|
"rustls-webpki",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "which"
|
||||||
|
version = "4.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "widestring"
|
name = "widestring"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
|
|||||||
@ -143,6 +143,8 @@ jsonrpsee-types = { version = "0.19" }
|
|||||||
|
|
||||||
## crypto
|
## crypto
|
||||||
secp256k1 = { version = "0.27.0", default-features = false, features = ["global-context", "rand-std", "recovery"] }
|
secp256k1 = { version = "0.27.0", default-features = false, features = ["global-context", "rand-std", "recovery"] }
|
||||||
|
# for eip-4844
|
||||||
|
c-kzg = { git = "https://github.com/ethereum/c-kzg-4844" }
|
||||||
|
|
||||||
### misc-testing
|
### misc-testing
|
||||||
proptest = "1.0"
|
proptest = "1.0"
|
||||||
|
|||||||
@ -22,7 +22,7 @@ crunchy = { version = "0.2.2", default-features = false, features = ["limit_256"
|
|||||||
ruint = { version = "1.9.0", features = ["primitive-types", "rlp"] }
|
ruint = { version = "1.9.0", features = ["primitive-types", "rlp"] }
|
||||||
|
|
||||||
# Bloom
|
# Bloom
|
||||||
fixed-hash = { version = "0.8", default-features = false, features = ["rustc-hex"] }
|
fixed-hash = { version = "0.8", default-features = false, features = ["rustc-hex"] }
|
||||||
|
|
||||||
# crypto
|
# crypto
|
||||||
secp256k1 = { workspace = true, default-features = false, features = [
|
secp256k1 = { workspace = true, default-features = false, features = [
|
||||||
@ -31,6 +31,9 @@ secp256k1 = { workspace = true, default-features = false, features = [
|
|||||||
"recovery",
|
"recovery",
|
||||||
] }
|
] }
|
||||||
|
|
||||||
|
# for eip-4844
|
||||||
|
c-kzg = { workspace = true }
|
||||||
|
|
||||||
# used for forkid
|
# used for forkid
|
||||||
crc = "3"
|
crc = "3"
|
||||||
|
|
||||||
|
|||||||
@ -142,6 +142,11 @@ pub mod utils {
|
|||||||
pub use ethers_core::types::serde_helpers;
|
pub use ethers_core::types::serde_helpers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// EIP-4844 + KZG helpers
|
||||||
|
pub mod kzg {
|
||||||
|
pub use c_kzg::*;
|
||||||
|
}
|
||||||
|
|
||||||
/// Helpers for working with serde
|
/// Helpers for working with serde
|
||||||
pub mod serde_helper;
|
pub mod serde_helper;
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,9 @@ ethereum-types = { version = "0.14", features = ["codec"], optional = true }
|
|||||||
revm-primitives = { workspace = true, features = ["serde"] }
|
revm-primitives = { workspace = true, features = ["serde"] }
|
||||||
reth-rlp-derive = { path = "./rlp-derive", optional = true }
|
reth-rlp-derive = { path = "./rlp-derive", optional = true }
|
||||||
|
|
||||||
|
# for eip-4844
|
||||||
|
c-kzg = { workspace = true, optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
reth-rlp = { workspace = true, features = [
|
reth-rlp = { workspace = true, features = [
|
||||||
"derive",
|
"derive",
|
||||||
@ -31,9 +34,11 @@ criterion = "0.5.0"
|
|||||||
pprof = { version = "0.12", features = ["flamegraph", "frame-pointer", "criterion"] }
|
pprof = { version = "0.12", features = ["flamegraph", "frame-pointer", "criterion"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
default = ["kzg"]
|
||||||
alloc = []
|
alloc = []
|
||||||
derive = ["reth-rlp-derive"]
|
derive = ["reth-rlp-derive"]
|
||||||
std = ["alloc"]
|
std = ["alloc"]
|
||||||
|
kzg = ["c-kzg"]
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "bench"
|
name = "bench"
|
||||||
|
|||||||
@ -413,6 +413,77 @@ pub fn encode_fixed_size<E: MaxEncodedLen<LEN>, const LEN: usize>(v: &E) -> Arra
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "kzg")]
|
||||||
|
mod kzg_support {
|
||||||
|
extern crate c_kzg;
|
||||||
|
|
||||||
|
use super::BufMut;
|
||||||
|
use crate::{Decodable, DecodeError, Encodable};
|
||||||
|
use c_kzg::{Blob, Bytes48, KzgCommitment, KzgProof, BYTES_PER_BLOB, BYTES_PER_COMMITMENT};
|
||||||
|
use core::ops::Deref;
|
||||||
|
|
||||||
|
impl Encodable for Blob {
|
||||||
|
fn encode(&self, out: &mut dyn BufMut) {
|
||||||
|
// Deref is implemented to get the underlying bytes
|
||||||
|
self.deref().encode(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn length(&self) -> usize {
|
||||||
|
self.deref().length()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Decodable for Blob {
|
||||||
|
fn decode(buf: &mut &[u8]) -> Result<Self, DecodeError> {
|
||||||
|
let bytes: [u8; BYTES_PER_BLOB] = Decodable::decode(buf)?;
|
||||||
|
Ok(Blob::from(bytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Encodable for Bytes48 {
|
||||||
|
fn encode(&self, out: &mut dyn BufMut) {
|
||||||
|
self.deref().encode(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn length(&self) -> usize {
|
||||||
|
self.deref().length()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Decodable for Bytes48 {
|
||||||
|
fn decode(buf: &mut &[u8]) -> Result<Self, DecodeError> {
|
||||||
|
let bytes: [u8; BYTES_PER_COMMITMENT] = Decodable::decode(buf)?;
|
||||||
|
Ok(Bytes48::from(bytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Only [Encodable] is implemented for [KzgCommitment] because this is a validated type - it
|
||||||
|
/// should be decoded using [Decodable] into a [Bytes48] type, validated, _then_ converted
|
||||||
|
/// into a [KzgCommitment].
|
||||||
|
impl Encodable for KzgCommitment {
|
||||||
|
fn encode(&self, out: &mut dyn BufMut) {
|
||||||
|
self.deref().encode(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn length(&self) -> usize {
|
||||||
|
self.deref().length()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Only [Encodable] is implemented for [KzgProof] because this is a validated type - it should
|
||||||
|
/// be decoded using [Decodable] into a [Bytes48] type, validated, _then_ converted into a
|
||||||
|
/// [KzgProof].
|
||||||
|
impl Encodable for KzgProof {
|
||||||
|
fn encode(&self, out: &mut dyn BufMut) {
|
||||||
|
self.deref().encode(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn length(&self) -> usize {
|
||||||
|
self.deref().length()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|||||||
@ -84,6 +84,13 @@ name = "rustls-webpki"
|
|||||||
expression = "LicenseRef-rustls-webpki"
|
expression = "LicenseRef-rustls-webpki"
|
||||||
license-files = [{ path = "LICENSE", hash = 0x001c7e6c }]
|
license-files = [{ path = "LICENSE", hash = 0x001c7e6c }]
|
||||||
|
|
||||||
|
[[licenses.clarify]]
|
||||||
|
name = "c-kzg"
|
||||||
|
expression = "Apache-2.0"
|
||||||
|
# The crate is in `bindings/rust` so we have to go up two directories for the
|
||||||
|
# license
|
||||||
|
license-files = [{ path = "../../LICENSE", hash = 0x13cec820 }]
|
||||||
|
|
||||||
# This section is considered when running `cargo deny check sources`.
|
# This section is considered when running `cargo deny check sources`.
|
||||||
# More documentation about the 'sources' section can be found here:
|
# More documentation about the 'sources' section can be found here:
|
||||||
# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html
|
# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html
|
||||||
|
|||||||
Reference in New Issue
Block a user