diff --git a/Cargo.lock b/Cargo.lock index 4def54a..af1a7b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4139,6 +4139,17 @@ dependencies = [ "digest 0.10.6", ] +[[package]] +name = "melo-erasure-coding" +version = "0.1.0" +dependencies = [ + "criterion", + "kzg", + "melo-primitives-crypto", + "rand 0.8.5", + "rust-kzg-blst", +] + [[package]] name = "melo-primitives-crypto" version = "0.1.0" @@ -6011,6 +6022,7 @@ dependencies = [ "libc", "num_cpus", "once_cell", + "rand 0.8.5", "rayon", "smallvec", ] diff --git a/Cargo.toml b/Cargo.toml index 4dbbd81..e0277bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "node", "primitives", + "crates/*", "pallets/template", "runtime", ] diff --git a/crates/melo-erasure-coding/Cargo.toml b/crates/melo-erasure-coding/Cargo.toml new file mode 100644 index 0000000..a74dd26 --- /dev/null +++ b/crates/melo-erasure-coding/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "melo-erasure-coding" +description = "Polynomial erasure coding implementation used in Melodot" +license = "Apache-2.0" +version = "0.1.0" +authors = ["DKLee "] +edition = "2021" + +[lib] +# Necessary for CLI options to work on benches +bench = false + +[dependencies] +melo-primitives-crypto = { version = "0.1.0", path = "../../primitives", default-features = false } +rust-kzg-blst = { git = "https://github.com/sifraitech/rust-kzg", rev = "b416f2b", default-features = false } +kzg = { git = "https://github.com/sifraitech/rust-kzg", rev = "b416f2b", default-features = false } + +[dev-dependencies] +rust-kzg-blst = { git = "https://github.com/sifraitech/rust-kzg", rev = "b416f2b"} +criterion = "0.4.0" +rand = "0.8.5" + +[features] +default = ["std", "parallel"] +std = [ + "rust-kzg-blst/std", + "kzg/std", + "melo-primitives-crypto/std", +] +parallel = ["rust-kzg-blst/parallel"] diff --git a/crates/melo-erasure-coding/src/lib.rs b/crates/melo-erasure-coding/src/lib.rs new file mode 100644 index 0000000..af5297e --- /dev/null +++ b/crates/melo-erasure-coding/src/lib.rs @@ -0,0 +1,30 @@ +// Copyright 2023 ZeroDAO +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +extern crate alloc; + +use alloc::sync::Arc; +use rust_kzg_blst::types::fft_settings::FsFFTSettings; + +#[derive(Debug, Clone)] +pub struct ErasureCoding { + fft_settings: Arc, +} + +impl ErasureCoding { + pub fn new(fft_settings: Arc) -> Self { + Self { fft_settings } + } + +} diff --git a/primitives/src/kzg.rs b/primitives/src/kzg.rs index 857b283..01d267d 100644 --- a/primitives/src/kzg.rs +++ b/primitives/src/kzg.rs @@ -25,7 +25,7 @@ use parity_scale_codec::{Decode, Encode, EncodeLike, Input, MaxEncodedLen}; use rust_kzg_blst::{ eip_4844::{ compute_blob_kzg_proof_rust, load_trusted_setup_filename_rust, - verify_blob_kzg_proof_batch_rust, verify_blob_kzg_proof_rust, + verify_blob_kzg_proof_batch_rust, verify_blob_kzg_proof_rust, blob_to_kzg_commitment_rust }, types::{ fft_settings::FsFFTSettings, fr::FsFr, g1::FsG1, kzg_settings::FsKZGSettings, poly::FsPoly, @@ -230,6 +230,11 @@ impl Blob { }) .collect() } + + #[inline] + pub fn commit(&self, kzg: &KZG) -> KZGCommitment { + KZGCommitment(blob_to_kzg_commitment_rust(&self,&kzg.settings)) + } } const TRUSTED_SETUP_FILENAME: &str = "eth-public-parameters.bin";