@@ -21,6 +21,13 @@ pub use rust_eth_kzg::{
2121 Cell , CellIndex as CellID , CellRef , TrustedSetup as PeerDASTrustedSetup ,
2222} ;
2323
24+ /// Disables the fixed-base multi-scalar multiplication optimization for computing
25+ /// cell KZG proofs, because `rust-eth-kzg` already handles the precomputation.
26+ ///
27+ /// Details about `precompute` parameter can be found here:
28+ /// <https://github.com/ethereum/c-kzg-4844/pull/545/files>
29+ pub const NO_PRECOMPUTE : u64 = 0 ;
30+
2431// Note: `spec.number_of_columns` is a config and should match `CELLS_PER_EXT_BLOB` - however this
2532// is a constant in the KZG library - be aware that overriding `number_of_columns` will break KZG
2633// operations.
@@ -65,8 +72,10 @@ impl Kzg {
6572
6673 Ok ( Self {
6774 trusted_setup : KzgSettings :: load_trusted_setup (
68- & trusted_setup. g1_points ( ) ,
69- & trusted_setup. g2_points ( ) ,
75+ & trusted_setup. g1_monomial ( ) ,
76+ & trusted_setup. g1_lagrange ( ) ,
77+ & trusted_setup. g2_monomial ( ) ,
78+ NO_PRECOMPUTE ,
7079 ) ?,
7180 context,
7281 } )
@@ -85,8 +94,10 @@ impl Kzg {
8594
8695 Ok ( Self {
8796 trusted_setup : KzgSettings :: load_trusted_setup (
88- & trusted_setup. g1_points ( ) ,
89- & trusted_setup. g2_points ( ) ,
97+ & trusted_setup. g1_monomial ( ) ,
98+ & trusted_setup. g1_lagrange ( ) ,
99+ & trusted_setup. g2_monomial ( ) ,
100+ NO_PRECOMPUTE ,
90101 ) ?,
91102 context,
92103 } )
@@ -111,8 +122,10 @@ impl Kzg {
111122
112123 Ok ( Self {
113124 trusted_setup : KzgSettings :: load_trusted_setup (
114- & trusted_setup. g1_points ( ) ,
115- & trusted_setup. g2_points ( ) ,
125+ & trusted_setup. g1_monomial ( ) ,
126+ & trusted_setup. g1_lagrange ( ) ,
127+ & trusted_setup. g2_monomial ( ) ,
128+ NO_PRECOMPUTE ,
116129 ) ?,
117130 context,
118131 } )
@@ -128,7 +141,8 @@ impl Kzg {
128141 blob : & Blob ,
129142 kzg_commitment : KzgCommitment ,
130143 ) -> Result < KzgProof , Error > {
131- c_kzg:: KzgProof :: compute_blob_kzg_proof ( blob, & kzg_commitment. into ( ) , & self . trusted_setup )
144+ self . trusted_setup
145+ . compute_blob_kzg_proof ( blob, & kzg_commitment. into ( ) )
132146 . map ( |proof| KzgProof ( proof. to_bytes ( ) . into_inner ( ) ) )
133147 . map_err ( Into :: into)
134148 }
@@ -140,11 +154,10 @@ impl Kzg {
140154 kzg_commitment : KzgCommitment ,
141155 kzg_proof : KzgProof ,
142156 ) -> Result < ( ) , Error > {
143- if !c_kzg :: KzgProof :: verify_blob_kzg_proof (
157+ if !self . trusted_setup . verify_blob_kzg_proof (
144158 blob,
145159 & kzg_commitment. into ( ) ,
146160 & kzg_proof. into ( ) ,
147- & self . trusted_setup ,
148161 ) ? {
149162 Err ( Error :: KzgVerificationFailed )
150163 } else {
@@ -172,11 +185,10 @@ impl Kzg {
172185 . map ( |proof| Bytes48 :: from ( * proof) )
173186 . collect :: < Vec < _ > > ( ) ;
174187
175- if !c_kzg :: KzgProof :: verify_blob_kzg_proof_batch (
188+ if !self . trusted_setup . verify_blob_kzg_proof_batch (
176189 blobs,
177190 & commitments_bytes,
178191 & proofs_bytes,
179- & self . trusted_setup ,
180192 ) ? {
181193 Err ( Error :: KzgVerificationFailed )
182194 } else {
@@ -186,7 +198,8 @@ impl Kzg {
186198
187199 /// Converts a blob to a kzg commitment.
188200 pub fn blob_to_kzg_commitment ( & self , blob : & Blob ) -> Result < KzgCommitment , Error > {
189- c_kzg:: KzgCommitment :: blob_to_kzg_commitment ( blob, & self . trusted_setup )
201+ self . trusted_setup
202+ . blob_to_kzg_commitment ( blob)
190203 . map ( |commitment| KzgCommitment ( commitment. to_bytes ( ) . into_inner ( ) ) )
191204 . map_err ( Into :: into)
192205 }
@@ -197,7 +210,8 @@ impl Kzg {
197210 blob : & Blob ,
198211 z : & Bytes32 ,
199212 ) -> Result < ( KzgProof , Bytes32 ) , Error > {
200- c_kzg:: KzgProof :: compute_kzg_proof ( blob, z, & self . trusted_setup )
213+ self . trusted_setup
214+ . compute_kzg_proof ( blob, z)
201215 . map ( |( proof, y) | ( KzgProof ( proof. to_bytes ( ) . into_inner ( ) ) , y) )
202216 . map_err ( Into :: into)
203217 }
@@ -210,14 +224,9 @@ impl Kzg {
210224 y : & Bytes32 ,
211225 kzg_proof : KzgProof ,
212226 ) -> Result < bool , Error > {
213- c_kzg:: KzgProof :: verify_kzg_proof (
214- & kzg_commitment. into ( ) ,
215- z,
216- y,
217- & kzg_proof. into ( ) ,
218- & self . trusted_setup ,
219- )
220- . map_err ( Into :: into)
227+ self . trusted_setup
228+ . verify_kzg_proof ( & kzg_commitment. into ( ) , z, y, & kzg_proof. into ( ) )
229+ . map_err ( Into :: into)
221230 }
222231
223232 /// Computes the cells and associated proofs for a given `blob`.
0 commit comments