Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-7594 implementation #267

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
9 changes: 9 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM mcr.microsoft.com/devcontainers/rust:1-1-bullseye

RUN apt-get update && \
apt-get install -y curl xz-utils gcc openssl ca-certificates git && \
curl https://nim-lang.org/choosenim/init.sh -sSf | bash -s -- -y && \
apt -y autoremove && \
apt -y clean && \
rm -r /tmp/*
ENV PATH=/root/.nimble/bin:$PATH
39 changes: 39 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/rust
{
"name": "Rust",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"build": {
"dockerfile": "Dockerfile"
},

// Use 'mounts' to make the cargo cache persistent in a Docker Volume.
// "mounts": [
// {
// "source": "devcontainer-cargo-cache-${devcontainerId}",
// "target": "/usr/local/cargo",
// "type": "volume"
// }
// ]

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "rustc --version",

// Configure tool-specific properties.
// "customizations": {
// "vscode": {
// "extensions": [

// ]
// }
// },

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
5 changes: 3 additions & 2 deletions arkworks/benches/eip_4844.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use criterion::{criterion_group, criterion_main, Criterion};
use kzg::eip_4844::{
blob_to_kzg_commitment_rust, bytes_to_blob, compute_blob_kzg_proof_rust,
compute_kzg_proof_rust, verify_blob_kzg_proof_batch_rust, verify_blob_kzg_proof_rust,
verify_kzg_proof_rust,
compute_cells_and_kzg_proofs_rust, compute_kzg_proof_rust, verify_blob_kzg_proof_batch_rust,
verify_blob_kzg_proof_rust, verify_kzg_proof_rust,
};
use kzg_bench::benches::eip_4844::bench_eip_4844;
use rust_kzg_arkworks::eip_4844::load_trusted_setup_filename_rust;
Expand All @@ -21,6 +21,7 @@ fn bench_eip_4844_(c: &mut Criterion) {
&compute_blob_kzg_proof_rust,
&verify_blob_kzg_proof_rust,
&verify_blob_kzg_proof_batch_rust,
&compute_cells_and_kzg_proofs_rust,
);
}

Expand Down
20 changes: 17 additions & 3 deletions arkworks/src/eip_4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use kzg::eip_4844::{
blob_to_kzg_commitment_rust, compute_blob_kzg_proof_rust, compute_kzg_proof_rust,
load_trusted_setup_rust, verify_blob_kzg_proof_batch_rust, verify_blob_kzg_proof_rust,
verify_kzg_proof_rust, Blob, Bytes32, Bytes48, CKZGSettings, KZGCommitment, KZGProof,
PrecomputationTableManager, BYTES_PER_FIELD_ELEMENT, BYTES_PER_G1, BYTES_PER_G2, C_KZG_RET,
C_KZG_RET_BADARGS, C_KZG_RET_OK, FIELD_ELEMENTS_PER_BLOB, TRUSTED_SETUP_NUM_G1_POINTS,
TRUSTED_SETUP_NUM_G2_POINTS,
PrecomputationTableManager, BYTES_PER_BLOB, BYTES_PER_FIELD_ELEMENT, BYTES_PER_G1,
BYTES_PER_G2, C_KZG_RET, C_KZG_RET_BADARGS, C_KZG_RET_OK, FIELD_ELEMENTS_PER_BLOB,
TRUSTED_SETUP_NUM_G1_POINTS, TRUSTED_SETUP_NUM_G2_POINTS,
};
use kzg::{cfg_into_iter, Fr, G1};
use std::ptr::null_mut;
Expand Down Expand Up @@ -423,3 +423,17 @@ pub unsafe extern "C" fn compute_kzg_proof(
(*y_out).bytes = fry_tmp.to_bytes();
C_KZG_RET_OK
}

/// # Safety
#[no_mangle]
pub unsafe extern "C" fn compute_cells_and_kzg_proofs(
cells: *mut Cell,
proofs: *mut KZGProof,
blob: *const Blob,
s: &CKZGSettings,
) -> CKZGSettings {
// Check for null pointers
if cells.is_null() || proofs.is_null() || blob.is_null() || s.is_null() {
return C_KZG_RET_BADARGS;
}
}
30 changes: 0 additions & 30 deletions arkworks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,3 @@ pub mod poly;
pub mod recover;
pub mod utils;
pub mod zero_poly;

trait Eq<T> {
fn equals(&self, other: &T) -> bool;
}

trait Inverse<T> {
fn inverse(&self) -> T;
}

trait Zero<T> {
fn is_zero(&self) -> bool;
}

impl Eq<P1> for P1 {
fn equals(&self, other: &P1) -> bool {
self.x.l.eq(&other.x.l) && self.y.l.eq(&other.x.l) && self.z.l.eq(&other.x.l)
}
}

impl Eq<Fr> for Fr {
fn equals(&self, other: &Fr) -> bool {
self.l.eq(&other.l)
}
}

impl Zero<Fr> for Fr {
fn is_zero(&self) -> bool {
self.l[0] == 0 && self.l[1] == 0 && self.l[2] == 0 && self.l[3] == 0
}
}
19 changes: 5 additions & 14 deletions arkworks/tests/eip_4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ mod tests {
compute_and_verify_blob_kzg_proof_fails_with_incorrect_proof_test,
compute_and_verify_blob_kzg_proof_test,
compute_and_verify_kzg_proof_fails_with_incorrect_proof_test,
compute_and_verify_kzg_proof_round_trip_test, compute_kzg_proof_test, compute_powers_test,
verify_kzg_proof_batch_fails_with_incorrect_proof_test, verify_kzg_proof_batch_test,
};
#[cfg(not(feature = "minimal-spec"))]
use kzg_bench::tests::eip_4844::{
compute_and_verify_kzg_proof_within_domain_test, test_vectors_blob_to_kzg_commitment,
compute_and_verify_kzg_proof_round_trip_test,
compute_and_verify_kzg_proof_within_domain_test, compute_kzg_proof_test,
compute_powers_test, test_vectors_blob_to_kzg_commitment,
test_vectors_compute_blob_kzg_proof, test_vectors_compute_kzg_proof,
test_vectors_verify_blob_kzg_proof, test_vectors_verify_blob_kzg_proof_batch,
test_vectors_verify_kzg_proof,
test_vectors_verify_kzg_proof, verify_kzg_proof_batch_fails_with_incorrect_proof_test,
verify_kzg_proof_batch_test,
};
use rust_kzg_arkworks::consts::SCALE2_ROOT_OF_UNITY;
use rust_kzg_arkworks::eip_4844::load_trusted_setup_filename_rust;
Expand Down Expand Up @@ -96,7 +94,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn compute_and_verify_kzg_proof_within_domain_test_() {
compute_and_verify_kzg_proof_within_domain_test::<
Expand Down Expand Up @@ -221,7 +218,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_blob_to_kzg_commitment_() {
test_vectors_blob_to_kzg_commitment::<
Expand All @@ -240,7 +236,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_compute_kzg_proof_() {
test_vectors_compute_kzg_proof::<
Expand All @@ -259,7 +254,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_compute_blob_kzg_proof_() {
test_vectors_compute_blob_kzg_proof::<
Expand All @@ -278,7 +272,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_verify_kzg_proof_() {
test_vectors_verify_kzg_proof::<
Expand All @@ -293,7 +286,6 @@ mod tests {
>(&load_trusted_setup_filename_rust, &verify_kzg_proof_rust);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_verify_blob_kzg_proof_() {
test_vectors_verify_blob_kzg_proof::<
Expand All @@ -312,7 +304,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_verify_blob_kzg_proof_batch_() {
test_vectors_verify_blob_kzg_proof_batch::<
Expand Down
30 changes: 0 additions & 30 deletions arkworks3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,3 @@ pub mod poly;
pub mod recover;
pub mod utils;
pub mod zero_poly;

trait Eq<T> {
fn equals(&self, other: &T) -> bool;
}

trait Inverse<T> {
fn inverse(&self) -> T;
}

trait Zero<T> {
fn is_zero(&self) -> bool;
}

impl Eq<P1> for P1 {
fn equals(&self, other: &P1) -> bool {
self.x.l.eq(&other.x.l) && self.y.l.eq(&other.x.l) && self.z.l.eq(&other.x.l)
}
}

impl Eq<Fr> for Fr {
fn equals(&self, other: &Fr) -> bool {
self.l.eq(&other.l)
}
}

impl Zero<Fr> for Fr {
fn is_zero(&self) -> bool {
self.l[0] == 0 && self.l[1] == 0 && self.l[2] == 0 && self.l[3] == 0
}
}
19 changes: 5 additions & 14 deletions arkworks3/tests/eip_4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ mod tests {
compute_and_verify_blob_kzg_proof_fails_with_incorrect_proof_test,
compute_and_verify_blob_kzg_proof_test,
compute_and_verify_kzg_proof_fails_with_incorrect_proof_test,
compute_and_verify_kzg_proof_round_trip_test, compute_kzg_proof_test, compute_powers_test,
verify_kzg_proof_batch_fails_with_incorrect_proof_test, verify_kzg_proof_batch_test,
};
#[cfg(not(feature = "minimal-spec"))]
use kzg_bench::tests::eip_4844::{
compute_and_verify_kzg_proof_within_domain_test, test_vectors_blob_to_kzg_commitment,
compute_and_verify_kzg_proof_round_trip_test,
compute_and_verify_kzg_proof_within_domain_test, compute_kzg_proof_test,
compute_powers_test, test_vectors_blob_to_kzg_commitment,
test_vectors_compute_blob_kzg_proof, test_vectors_compute_kzg_proof,
test_vectors_verify_blob_kzg_proof, test_vectors_verify_blob_kzg_proof_batch,
test_vectors_verify_kzg_proof,
test_vectors_verify_kzg_proof, verify_kzg_proof_batch_fails_with_incorrect_proof_test,
verify_kzg_proof_batch_test,
};
use rust_kzg_arkworks3::consts::SCALE2_ROOT_OF_UNITY;
use rust_kzg_arkworks3::eip_4844::load_trusted_setup_filename_rust;
Expand Down Expand Up @@ -96,7 +94,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn compute_and_verify_kzg_proof_within_domain_test_() {
compute_and_verify_kzg_proof_within_domain_test::<
Expand Down Expand Up @@ -221,7 +218,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_blob_to_kzg_commitment_() {
test_vectors_blob_to_kzg_commitment::<
Expand All @@ -240,7 +236,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_compute_kzg_proof_() {
test_vectors_compute_kzg_proof::<
Expand All @@ -259,7 +254,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_compute_blob_kzg_proof_() {
test_vectors_compute_blob_kzg_proof::<
Expand All @@ -278,7 +272,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_verify_kzg_proof_() {
test_vectors_verify_kzg_proof::<
Expand All @@ -293,7 +286,6 @@ mod tests {
>(&load_trusted_setup_filename_rust, &verify_kzg_proof_rust);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_verify_blob_kzg_proof_() {
test_vectors_verify_blob_kzg_proof::<
Expand All @@ -312,7 +304,6 @@ mod tests {
);
}

#[cfg(not(feature = "minimal-spec"))]
#[test]
pub fn test_vectors_verify_blob_kzg_proof_batch_() {
test_vectors_verify_blob_kzg_proof_batch::<
Expand Down
19 changes: 19 additions & 0 deletions blst/out.txt

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions blst/out2.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions blst/src/data_availability_sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl FsFFTSettings {
Ordering::Equal => {
let x = evens[0].add(&evens[1]);
let y = evens[0].sub(&evens[1]);
let y_times_root = y.mul(&self.expanded_roots_of_unity[stride]);
let y_times_root = y.mul(&self.roots_of_unity[stride]);

evens[0] = x.add(&y_times_root);
evens[1] = x.sub(&y_times_root);
Expand Down Expand Up @@ -63,7 +63,7 @@ impl FsFFTSettings {
for i in 0..half {
let x = evens[i];
let y = evens[half + i];
let y_times_root: FsFr = y.mul(&self.expanded_roots_of_unity[(1 + 2 * i) * stride]);
let y_times_root: FsFr = y.mul(&self.roots_of_unity[(1 + 2 * i) * stride]);

evens[i] = x.add(&y_times_root);
evens[half + i] = x.sub(&y_times_root);
Expand Down
Loading