Skip to content

Commit

Permalink
remove logs and unused libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
afkbyte committed Jun 4, 2024
1 parent 0f692a3 commit 8eed5f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 57 deletions.
47 changes: 9 additions & 38 deletions arbitrator/prover/src/kzgbn254.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@

use crate::utils::Bytes32;
use ark_ec::{AffineRepr, CurveGroup,pairing::Pairing};
use ark_ec::{AffineRepr, CurveGroup};
use kzgbn254::{
blob::Blob, helpers::{remove_empty_byte_from_padded_bytes_unchecked, to_byte_array, to_fr_array}, kzg::Kzg, polynomial::{Polynomial, PolynomialFormat}
blob::Blob, kzg::Kzg, polynomial::PolynomialFormat
};
use hex::encode;
use eyre::{ensure, Result};
use ark_bn254::{Bn254, G1Affine, G1Projective, G2Affine, Fr};
use libc::qos_class_t;
use ark_bn254::{G2Affine, Fr};
use num::BigUint;
use sha2::{Digest, Sha256};
use std::{convert::TryFrom, io::Write, convert::TryInto};
use std::{io::Write, convert::TryInto};
use ark_serialize::CanonicalSerialize;
use num::Zero;
use ark_poly::{EvaluationDomain, GeneralEvaluationDomain};
use kzgbn254::errors::KzgError;
use byteorder::{LittleEndian, WriteBytesExt};
use ark_ff::{PrimeField, BigInteger};


Expand Down Expand Up @@ -101,43 +95,30 @@ pub fn prove_kzg_preimage_bn254(
let blob_header = blob_bytes[..32].to_vec();
println!("blob header {:?}", blob_header);

// decode blob header
let (version, length) = decode_codec_blob_header(&blob_header);
println!("version {:?}", version);
println!("length {:?}", length);
// decode blob header, version is currently unused however in the future we probabky
let (_, length) = decode_codec_blob_header(&blob_header);

let length_usize = length as usize;

let encoded_data = blob_bytes[32..].to_vec();


// we set the proving offset to offset + 1 because the first 32 bytes of the array are the header
let mut proving_offset = offset + 1;
// we set the proving offset to offset + 32 because the first 32 bytes of the array are the header
let mut proving_offset = (offset + 32) / 32;

// address proving past end edge case later
let proving_past_end = offset as usize >= length_usize;
if proving_past_end {
// Proving any offset proves the length which is all we need here,
// because we're past the end of the preimage.
proving_offset = 1;
proving_offset = 0;
}

let proving_offset_bigint = BigUint::from(proving_offset);
let proving_offset_fr = to_fr_array(&proving_offset_bigint.to_bytes_le());

let proving_offset_bytes = proving_offset.to_be_bytes();
let mut padded_proving_offset_bytes: [u8; 32] = [0u8; 32];
padded_proving_offset_bytes[32 - proving_offset_bytes.len()..].copy_from_slice(&proving_offset_bytes);

println!("proving_offset_bytes {:?}", proving_offset_bytes);
println!("proving_offset_fr {:?}", proving_offset_fr);

let proven_y_fr = blob_polynomial_coefficient_form.get_at_index(proving_offset as usize).unwrap();
let z_fr = kzg.get_nth_root_of_unity(proving_offset as usize).unwrap();

let proven_y = proven_y_fr.into_bigint().to_bytes_be();
println!("proven_y {:?}", proven_y);


let g2_generator = G2Affine::generator();
let z_g2= (g2_generator * z_fr).into_affine();
Expand All @@ -146,26 +127,16 @@ pub fn prove_kzg_preimage_bn254(
let g2_tau: G2Affine = kzg.get_g2_points().get(1).unwrap().clone();
let g2_tau_minus_g2_z = (g2_tau - z_g2).into_affine();

assert_eq!(blob_polynomial_evaluation_form.get_form(), PolynomialFormat::InEvaluationForm);
let kzg_proof = match kzg.compute_kzg_proof_with_roots_of_unity(&blob_polynomial_coefficient_form, proving_offset as u64) {
Ok(proof) => proof,
Err(err) => return Err(err.into()),
};

let verified = kzg.verify_kzg_proof(blob_commitment, kzg_proof, *proven_y_fr, *z_fr);
assert_eq!(verified, true);
println!("verified {:?}", verified);

let xminusz_x0: BigUint = g2_tau_minus_g2_z.x.c0.into();
let xminusz_x1: BigUint = g2_tau_minus_g2_z.x.c1.into();
let xminusz_y0: BigUint = g2_tau_minus_g2_z.y.c0.into();
let xminusz_y1: BigUint = g2_tau_minus_g2_z.y.c1.into();

println!("xminusz_x0 {:?}", xminusz_x0.to_string());
println!("xminusz_x1 {:?}", xminusz_x1.to_string());
println!("xminusz_y0 {:?}", xminusz_y0.to_string());
println!("xminusz_y1 {:?}", xminusz_y1.to_string());

// turn each element of xminusz into bytes, then pad each to 32 bytes, then append in order x1,x0,y1,y0
let mut xminusz_encoded_bytes = Vec::with_capacity(128);
append_left_padded_biguint_be(&mut xminusz_encoded_bytes, &xminusz_x1);
Expand Down
20 changes: 1 addition & 19 deletions arbitrator/prover/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@

use crate::kzg::ETHEREUM_KZG_SETTINGS;
use arbutil::PreimageType;
use ark_ec::AffineRepr;
use ark_bn254::{Fr, G1Affine, G1Projective, G2Affine};
use c_kzg::{Blob, KzgCommitment};
use kzgbn254::{
kzg::Kzg as KzgBN254,
blob::Blob as EigenDABlob,
helpers::remove_empty_byte_from_padded_bytes_unchecked,
polynomial::{Polynomial, PolynomialFormat},
polynomial::PolynomialFormat,
};
use digest::Digest;
use eyre::{eyre, Result};
Expand All @@ -27,8 +24,6 @@ use std::{
ops::{Deref, DerefMut},
path::Path,
};
use num::BigUint;
use ark_ff::BigInteger256;
use wasmparser::{TableType, Type};

/// cbindgen:field-names=[bytes]
Expand Down Expand Up @@ -302,30 +297,17 @@ pub fn hash_preimage(preimage: &[u8], ty: PreimageType) -> Result<[u8; 32]> {
3000
).unwrap();



let blob = EigenDABlob::from_padded_bytes_unchecked(preimage);

let blob_polynomial = blob.to_polynomial(PolynomialFormat::InEvaluationForm).unwrap();
let blob_commitment = kzg_bn254.commit(&blob_polynomial).unwrap();

let cx: num_bigint::BigUint = blob_commitment.x.into();
let cy: num_bigint::BigUint = blob_commitment.y.into();
println!("commitment x {:?}", cx);
println!("commitment y {:?}", cy);

let mut commitment_bytes = Vec::new();
blob_commitment.serialize_uncompressed(&mut commitment_bytes).unwrap();

let mut commitment_hash: [u8; 32] = Sha256::digest(&commitment_bytes).into();
commitment_hash[0] = 1;

// print the commitment hash
println!("commitment_hash UTILS.rs: {:?}", commitment_hash);

// print the commitment hash as a hex string
println!("commitment_hash UTILS.rs: {:?}", hex::encode(commitment_hash));

Ok(commitment_hash)
}
}
Expand Down

0 comments on commit 8eed5f6

Please sign in to comment.