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

Add eip_7594.rs to zkcrypto with "compute_weighted_sum_of_commitments" #268

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions zkcrypto/src/eip_7594.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
extern crate alloc;

use alloc::vec::Vec;
use crate::kzg_types::{Fr, G1, Bytes48, C_KZG_OK, C_KZG_RET};

Check failure on line 4 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, zkcrypto)

unresolved imports `crate::kzg_types::Fr`, `crate::kzg_types::Bytes48`, `crate::kzg_types::C_KZG_OK`, `crate::kzg_types::C_KZG_RET`

Check failure on line 4 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, zkcrypto)

trait import `G1` is private

Check failure on line 4 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / benchmarks (ubuntu-latest, zkcrypto)

unresolved imports `crate::kzg_types::Fr`, `crate::kzg_types::Bytes48`, `crate::kzg_types::C_KZG_OK`, `crate::kzg_types::C_KZG_RET`

Check failure on line 4 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / benchmarks (ubuntu-latest, zkcrypto)

trait import `G1` is private

Check failure on line 4 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / benchmarks (windows-latest, zkcrypto)

unresolved imports `crate::kzg_types::Fr`, `crate::kzg_types::Bytes48`, `crate::kzg_types::C_KZG_OK`, `crate::kzg_types::C_KZG_RET`

Check failure on line 4 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / benchmarks (windows-latest, zkcrypto)

trait import `G1` is private

Check failure on line 4 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / backend_ci (windows-latest, zkcrypto)

unresolved imports `crate::kzg_types::Fr`, `crate::kzg_types::Bytes48`, `crate::kzg_types::C_KZG_OK`, `crate::kzg_types::C_KZG_RET`

Check failure on line 4 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / backend_ci (windows-latest, zkcrypto)

trait import `G1` is private

Check failure on line 4 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / backend_ci (macos-latest, zkcrypto)

unresolved imports `crate::kzg_types::Fr`, `crate::kzg_types::Bytes48`, `crate::kzg_types::C_KZG_OK`, `crate::kzg_types::C_KZG_RET`

Check failure on line 4 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / backend_ci (macos-latest, zkcrypto)

trait import `G1` is private

Check failure on line 4 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / benchmarks (macos-latest, zkcrypto)

unresolved imports `crate::kzg_types::Fr`, `crate::kzg_types::Bytes48`, `crate::kzg_types::C_KZG_OK`, `crate::kzg_types::C_KZG_RET`

Check failure on line 4 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / benchmarks (macos-latest, zkcrypto)

trait import `G1` is private
use crate::kzg_proofs::g1_lincomb_fast;

Check failure on line 5 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, zkcrypto)

unresolved import `crate::kzg_proofs::g1_lincomb_fast`

Check failure on line 5 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / benchmarks (ubuntu-latest, zkcrypto)

unresolved import `crate::kzg_proofs::g1_lincomb_fast`

Check failure on line 5 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / benchmarks (windows-latest, zkcrypto)

unresolved import `crate::kzg_proofs::g1_lincomb_fast`

Check failure on line 5 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / backend_ci (windows-latest, zkcrypto)

unresolved import `crate::kzg_proofs::g1_lincomb_fast`

Check failure on line 5 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / backend_ci (macos-latest, zkcrypto)

unresolved import `crate::kzg_proofs::g1_lincomb_fast`

Check failure on line 5 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / benchmarks (macos-latest, zkcrypto)

unresolved import `crate::kzg_proofs::g1_lincomb_fast`
use crate::common_utils::bytes_to_kzg_commitment;

Check failure on line 6 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, zkcrypto)

unresolved import `crate::common_utils`

Check failure on line 6 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / benchmarks (ubuntu-latest, zkcrypto)

unresolved import `crate::common_utils`

Check failure on line 6 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / benchmarks (windows-latest, zkcrypto)

unresolved import `crate::common_utils`

Check failure on line 6 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / backend_ci (windows-latest, zkcrypto)

unresolved import `crate::common_utils`

Check failure on line 6 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / backend_ci (macos-latest, zkcrypto)

unresolved import `crate::common_utils`

Check failure on line 6 in zkcrypto/src/eip_7594.rs

View workflow job for this annotation

GitHub Actions / benchmarks (macos-latest, zkcrypto)

unresolved import `crate::common_utils`

pub fn compute_weighted_sum_of_commitments(
sum_of_commitments_out: &mut G1,
unique_commitments: &[Bytes48],
commitment_indices: &[u64],
r_powers: &[Fr],
num_commitments: usize,
num_cells: u64,
) -> C_KZG_RET {
let mut commitments_g1: Vec<G1> = Vec::with_capacity(num_commitments);
let mut commitment_weights: Vec<Fr> = vec![Fr::zero(); num_commitments];

// Convert unique commitments to G1 points and validate them
for i in 0..num_commitments {
let commitment = bytes_to_kzg_commitment(&unique_commitments[i]);
match commitment {
Ok(g1) => commitments_g1.push(g1),
Err(ret) => return ret,
}
}

// Update commitment weights based on commitment_indices and r_powers
for i in 0..num_cells as usize {
let idx = commitment_indices[i] as usize;
commitment_weights[idx] += r_powers[i];
}

// Compute the linear combination of commitments with the calculated weights
match g1_lincomb_fast(sum_of_commitments_out, &commitments_g1, &commitment_weights, num_commitments) {
Ok(_) => C_KZG_OK,
Err(ret) => ret,
}
}
1 change: 1 addition & 0 deletions zkcrypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ pub mod poly;
pub mod recover;
pub mod utils;
pub mod zero_poly;
pub mod eip_7594;
Loading