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

feat: Arbitrator 2mb blob test #26

Open
wants to merge 4 commits into
base: eigenda-v3.0.3
Choose a base branch
from
Open
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
24 changes: 10 additions & 14 deletions arbitrator/prover/src/kzgbn254.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ pub fn prove_kzg_preimage_bn254(
kzg.calculate_roots_of_unity(preimage.len() as u64)?;

// preimage is already padded and is the actual blob data, NOT the IFFT'd form.
let blob = Blob::from_padded_bytes_unchecked(&preimage);

let blob_polynomial_evaluation_form =
blob.to_polynomial(PolynomialFormat::InCoefficientForm)?;
let blob_commitment = kzg.commit(&blob_polynomial_evaluation_form)?;
let blob_polynomial = Blob::from_padded_bytes_unchecked(&preimage)
.to_polynomial(PolynomialFormat::InCoefficientForm)?;
let blob_commitment = kzg.commit(&blob_polynomial)?;

let commitment_x_bigint: BigUint = blob_commitment.x.into();
let commitment_y_bigint: BigUint = blob_commitment.y.into();
Expand Down Expand Up @@ -97,7 +95,7 @@ pub fn prove_kzg_preimage_bn254(
let mut proving_offset = offset;
let length_usize = preimage.len() as u64;

assert!(length_usize / 32 == blob_polynomial_evaluation_form.len() as u64);
assert!(length_usize / 32 == blob_polynomial.len() as u64);

// address proving past end edge case later
let proving_past_end = offset as u64 >= length_usize;
Expand All @@ -115,15 +113,15 @@ pub fn prove_kzg_preimage_bn254(
"Index ({}) out of bounds for preimage of length {} with data of ({} field elements x 32 bytes)",
proving_offset,
length_usize,
blob_polynomial_evaluation_form.len()
blob_polynomial.len()
)
})?;

let z_fr = kzg
.get_nth_root_of_unity(proving_offset as usize / 32)
.ok_or_else(|| eyre::eyre!("Failed to get nth root of unity"))?;

let proven_y = proven_y_fr.into_bigint().to_bytes_be();
let y = y_fr.into_bigint().to_bytes_be();
let z = z_fr.into_bigint().to_bytes_be();

// probably should be a constant on the contract.
Expand All @@ -138,16 +136,14 @@ pub fn prove_kzg_preimage_bn254(
.clone();
let g2_tau_minus_g2_z = (g2_tau - z_g2).into_affine();

let kzg_proof = kzg.compute_kzg_proof_with_roots_of_unity(
&blob_polynomial_evaluation_form,
proving_offset as u64 / 32,
)?;
let kzg_proof =
kzg.compute_kzg_proof_with_roots_of_unity(&blob_polynomial, proving_offset as u64 / 32)?;

let offset_usize = proving_offset as usize;
// This should cause failure when proving past offset.
if !proving_past_end {
ensure!(
*proven_y == preimage[offset_usize..offset_usize + 32],
*y == preimage[offset_usize..offset_usize + 32],
"KZG proof produced wrong preimage for offset {}",
offset,
);
Expand Down Expand Up @@ -177,7 +173,7 @@ pub fn prove_kzg_preimage_bn254(

out.write_all(&commitment_hash.to_vec())?; // hash [:32]
out.write_all(&*z)?; // evaluation point [32:64]
out.write_all(&*proven_y)?; // expected output [64:96]
out.write_all(&*y)?; // expected output [64:96]
out.write_all(&xminusz_encoded_bytes)?; // g2TauMinusG2z [96:224]
out.write_all(&*commitment_encoded_bytes)?; // kzg commitment [224:288]
out.write_all(&proof_encoded_bytes)?; // proof [288:352]
Expand Down
1 change: 0 additions & 1 deletion arbitrator/prover/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3044,7 +3044,6 @@ impl Machine {
.expect("Failed to generate KZG preimage proof");
}
PreimageType::EigenDAHash => {
println!("Generating proof for EigenDA preimage");
prove_kzg_preimage_bn254(hash, &preimage, offset, &mut data)
.expect("Failed to generate eigenDA KZG preimage proof");
}
Expand Down
9 changes: 9 additions & 0 deletions arbitrator/prover/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ const DELAYED_HEADER_LEN: usize = 112; // also in test-case's host-io.rs & contr

#[cfg(feature = "native")]
fn main() -> Result<()> {
use arbutil::crypto::keccak;

let opts = Opts::from_args();

let mut inbox_contents = HashMap::default();
Expand Down Expand Up @@ -170,6 +172,13 @@ fn main() -> Result<()> {
file.read_exact(&mut buf)?;

let hash = hash_preimage(&buf, preimage_ty)?;

println!(
"read preimage of type {:?} with hash 0x{} and size {}",
preimage_ty,
hex::encode(hash),
size
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably need to remove this.

preimages
.entry(preimage_ty)
.or_default()
Expand Down
6 changes: 3 additions & 3 deletions arbitrator/prover/test-cases/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ func main() {
panic(fmt.Sprintf("expected blob element %v to be %v but got %v", i, hex.EncodeToString(expectedElement), hex.EncodeToString(gotElement)))
}
}
// EIGENDA COMMIT HASH
_, err = wavmio.ResolveTypedPreimage(arbutil.EigenDaPreimageType, common.HexToHash("1c303f6af17677aa69367bea000420f4b0ee26bb2c542a8879b9791a4b43d4d0"))
// Resolve 128 byte kzg-bn254 preimage
_, err = wavmio.ResolveTypedPreimage(arbutil.EigenDaPreimageType, common.HexToHash("01605220b6928163676612ca50bbe5e0c595052876796dbedeae8ef597c9fdcf"))
if err != nil {
panic(fmt.Sprintf("failed to resolve eigenda preimage: %v", err))
panic(fmt.Sprintf("failed to resolve eigenda preimage #1: %v", err))
}

println("verified preimage resolution!\n")
Expand Down
26 changes: 20 additions & 6 deletions arbitrator/prover/test-cases/rust/src/bin/host-io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,37 @@ fn main() {
assert_eq!(bytebuffer.0, expected_hash);
}

println!("eigenda preimage");

println!("eigenda 2MB kzg-bn254 preimage");
let eigen_hash = hex!("0191c996190e53f90d077a02f247169f6704a6f870272158f88f88a4194fd7e2");
bytebuffer = Bytes32(eigen_hash);

// ensure that offset > 127KB can be successfully read
// we only read a singe 32 byte piece of this large preimage given a bug
// where multiple kzg-bn254 read_preimage proof serializations within the same execution cause
// failures. This is ok though given that a proof is only serialized for a single instruction at the
// final stage of dispute resolution.
let actual_len = wavm_read_eigen_da_hash_preimage(bytebuffer.0.as_mut_ptr(), (4096 * 32) + 32);
assert_eq!(actual_len, 32);



println!("eigenda 128b preimage");

let expected_len = 0;

for i in 0..5{
let eigen_hash = hex!("1c303f6af17677aa69367bea000420f4b0ee26bb2c542a8879b9791a4b43d4d0");
let eigen_hash = hex!("01605220b6928163676612ca50bbe5e0c595052876796dbedeae8ef597c9fdcf");
bytebuffer = Bytes32(eigen_hash);

let actual_len = wavm_read_eigen_da_hash_preimage(bytebuffer.0.as_mut_ptr(), i * 32);

if i < 4 {
assert_eq!(actual_len, 32);
} else {
assert_eq!(actual_len, 0);
}

}
}

}
println!("Done!");
}
Binary file added out
Binary file not shown.
14 changes: 11 additions & 3 deletions scripts/create-test-preimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ def kzg_test_data():
data.extend(h)
return bytes(data)

def eigen_test_data():
# the value we are returning is the same string that is returned by the old eigen_test_data but encoded in the style the high level eigenDA client would
def kzg_bn254_2mb_test_data():
# load 2MB padded blob from file
# 01bc9203a3f91276750f5fdc7241e7b09c94ae58f7f189aa292858a040bd7858
with open("scripts/eigenda_large_blob.txt", "r") as file:
data = file.read().strip()
# decode hex string to bytes
return bytes.fromhex(data[2:])

def kzg_bn254_128b_test_data():
# 00bca02094eb78126a517b206a88c73cfa9ec6f704c7030d18212cace820f025
data = bytes([0 ,0 ,0 ,0 ,0 ,64 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,48 ,48 ,98 ,99 ,97 ,48 ,50 ,48 ,57 ,52 ,101 ,98 ,55 ,56 ,49 ,50 ,54 ,97 ,53 ,49 ,55 ,98 ,50 ,48 ,54 ,97 ,56 ,56 ,99 ,55 ,51 ,0 ,99 ,102 ,97 ,57 ,101 ,99 ,54 ,102 ,55 ,48 ,52 ,99 ,55 ,48 ,51 ,48 ,100 ,49 ,56 ,50 ,49 ,50 ,99 ,97 ,99 ,101 ,56 ,50 ,48 ,102 ,48 ,0 ,50 ,53 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0])

Expand All @@ -42,7 +49,8 @@ def eigen_test_data():
(0, b'hello world'),
(1, b'hello world'),
(2, kzg_test_data()),
(3, eigen_test_data())
(3, kzg_bn254_2mb_test_data()),
(3, kzg_bn254_128b_test_data()),
]

write_data_to_file(filename, preimages)
1 change: 1 addition & 0 deletions scripts/eigenda_large_blob.txt

Large diffs are not rendered by default.

Loading