-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c02ad4
commit a4bd0d3
Showing
40 changed files
with
1,908 additions
and
1,073 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...97e3313dd9ee63c1f1edd812a2d3095c720d.json → ...ff1ceb985eb38321fe5760ef02dfa40e3b3f.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
.sqlx/query-dbd4dc48ee0c62be2690c7894bfd111cfe64383add2ae8d78f90975b74af6b57.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[package] | ||
name = "fuel-block-committer-encoding" | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
repository = { workspace = true } | ||
rust-version = { workspace = true } | ||
publish = true | ||
|
||
[dependencies] | ||
# alloy only really needed when generating proofs, and since the core doesn't | ||
# need to do that we've gated it behing the `kzg` feature flag. | ||
alloy = { workspace = true, features = ["consensus", "eips"], optional = true } | ||
anyhow = { workspace = true } | ||
bitvec = { workspace = true, features = ["default"] } | ||
c-kzg = { workspace = true } | ||
flate2 = { workspace = true, features = ["default"] } | ||
hex = { workspace = true } | ||
itertools = { workspace = true, features = ["use_std"] } | ||
postcard = { workspace = true, features = ["alloc"] } | ||
serde = { workspace = true } | ||
static_assertions = { workspace = true } | ||
|
||
[dev-dependencies] | ||
alloy = { workspace = true, features = ["consensus", "eips", "kzg"] } | ||
fuel-block-committer-encoding = { workspace = true, features = [ | ||
"default", | ||
"kzg", | ||
] } | ||
itertools = { workspace = true, features = ["use_alloc"] } | ||
proptest = { workspace = true, features = ["default"] } | ||
rand = { workspace = true, features = ["std", "std_rng", "small_rng"] } | ||
test-case = { workspace = true } | ||
|
||
[features] | ||
default = [] | ||
kzg = ["alloy/kzg"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
mod decoder; | ||
mod encoder; | ||
mod header; | ||
|
||
pub use decoder::Decoder; | ||
pub use encoder::Encoder; | ||
pub use header::*; | ||
|
||
use crate::constants::BYTES_PER_BLOB; | ||
|
||
pub type Blob = Box<[u8; BYTES_PER_BLOB]>; | ||
|
||
#[cfg(feature = "kzg")] | ||
pub fn generate_sidecar( | ||
blobs: impl IntoIterator<Item = Blob>, | ||
) -> anyhow::Result<alloy::consensus::BlobTransactionSidecar> { | ||
let blobs = blobs | ||
.into_iter() | ||
.map(|blob| alloy::eips::eip4844::Blob::from(*blob)) | ||
.collect::<Vec<_>>(); | ||
let mut commitments = Vec::with_capacity(blobs.len()); | ||
let mut proofs = Vec::with_capacity(blobs.len()); | ||
let settings = alloy::consensus::EnvKzgSettings::default(); | ||
|
||
for blob in &blobs { | ||
// SAFETY: same size | ||
let blob = | ||
unsafe { core::mem::transmute::<&alloy::eips::eip4844::Blob, &c_kzg::Blob>(blob) }; | ||
let commitment = c_kzg::KzgCommitment::blob_to_kzg_commitment(blob, settings.get())?; | ||
let proof = | ||
c_kzg::KzgProof::compute_blob_kzg_proof(blob, &commitment.to_bytes(), settings.get())?; | ||
|
||
// SAFETY: same size | ||
unsafe { | ||
commitments.push(core::mem::transmute::< | ||
c_kzg::Bytes48, | ||
alloy::eips::eip4844::Bytes48, | ||
>(commitment.to_bytes())); | ||
proofs.push(core::mem::transmute::< | ||
c_kzg::Bytes48, | ||
alloy::eips::eip4844::Bytes48, | ||
>(proof.to_bytes())); | ||
} | ||
} | ||
|
||
Ok(alloy::consensus::BlobTransactionSidecar::new( | ||
blobs, | ||
commitments, | ||
proofs, | ||
)) | ||
} |
Oops, something went wrong.