Skip to content

Commit

Permalink
feat: Arbitrator 2mb blob test - split into two test blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
epociask committed Aug 12, 2024
1 parent d681b91 commit b40ef81
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
7 changes: 0 additions & 7 deletions arbitrator/prover/src/kzgbn254.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ pub fn prove_kzg_preimage_bn254(
proving_offset = 0;
}

println!("offset / 32: {}", proving_offset / 32);
// Y = ϕ(offset) --> evaluation point for computing quotient proof
// confirming if this is actually ok ?
let y_fr = blob_polynomial
Expand All @@ -89,15 +88,11 @@ pub fn prove_kzg_preimage_bn254(
)
})?;

println!("y_fr: {:?}", y_fr);

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 y = y_fr.into_bigint().to_bytes_be();
println!("y: {:?}", y_fr);

let z = z_fr.into_bigint().to_bytes_be();

// probably should be a constant on the contract.
Expand All @@ -118,8 +113,6 @@ pub fn prove_kzg_preimage_bn254(
let offset_usize = proving_offset as usize;
// This should cause failure when proving past offset.
if !proving_past_end {
println!("y {:?}", y);
println!("preimage {:?}", &preimage[0..32]);
ensure!(
*y == preimage[offset_usize..offset_usize + 32],
"KZG proof produced wrong preimage for offset {}",
Expand Down
4 changes: 2 additions & 2 deletions arbitrator/prover/test-cases/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ func main() {
panic(fmt.Sprintf("expected blob element %v to be %v but got %v", i, hex.EncodeToString(expectedElement), hex.EncodeToString(gotElement)))
}
}
// Ensure 2MB padded iFFT bytes (2^21) of data can be resolved
_, err = wavmio.ResolveTypedPreimage(arbutil.EigenDaPreimageType, common.HexToHash("004f3a0db52c6f708ec9bde76570c1fcf3c0eefdf4841b7686d2aa13c38232a9"))
// 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 #1: %v", err))
}
Expand Down
34 changes: 28 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,15 +104,37 @@ fn main() {
assert_eq!(bytebuffer.0, expected_hash);
}

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

// ensure that offset > (4096 * 32) can be successfully read
// let actual_len = wavm_read_eigen_da_hash_preimage(bytebuffer.0.as_mut_ptr(), (4096 * 32) + 32);
// assert_eq!(actual_len, 32);
// 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!("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!");
}
11 changes: 9 additions & 2 deletions scripts/create-test-preimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ def kzg_test_data():
data.extend(h)
return bytes(data)

def kzg_bn254_test_data():
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])

return data

if len(sys.argv) < 2:
print("Usage: python3 create-test-preimages.py <filename>")
sys.exit(1)
Expand All @@ -43,7 +49,8 @@ def kzg_bn254_test_data():
(0, b'hello world'),
(1, b'hello world'),
(2, kzg_test_data()),
(3, kzg_bn254_test_data()),
(3, kzg_bn254_2mb_test_data()),
(3, kzg_bn254_128b_test_data()),
]

write_data_to_file(filename, preimages)

0 comments on commit b40ef81

Please sign in to comment.