Skip to content

Commit

Permalink
fix: Compute EigenDA preimage hash using preimage length - rust fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
epociask committed Aug 14, 2024
1 parent 0d0bde1 commit cbcb177
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 1 addition & 2 deletions arbitrator/prover/src/kzgbn254.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ pub fn prove_kzg_preimage_bn254(
blob.to_polynomial(PolynomialFormat::InCoefficientForm)?;
let blob_commitment = kzg.commit(&blob_polynomial_evaluation_form)?;


let commitment_x_bigint: BigUint = blob_commitment.x.into();
let commitment_y_bigint: BigUint = blob_commitment.y.into();
let length_bigint: BigUint = blob.len().into();

let mut commitment_encoded_length_bytes = Vec::with_capacity(69);
let mut commitment_encoded_length_bytes = Vec::with_capacity(68);
append_left_padded_biguint_be(&mut commitment_encoded_length_bytes, &commitment_x_bigint);
append_left_padded_biguint_be(&mut commitment_encoded_length_bytes, &commitment_y_bigint);
append_left_padded_biguint_be(&mut commitment_encoded_length_bytes, &length_bigint);
Expand Down
8 changes: 8 additions & 0 deletions arbitrator/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@ unsafe fn handle_preimage_resolution(
Some(data)
}

#[no_mangle]
pub unsafe extern "C" fn arbitrator_get_opcode(mach: *mut Machine) -> u16 {
match (*mach).get_next_instruction() {
Some(instruction) => return instruction.opcode.repr(),
None => panic!("Failed to get next opcode for Machine"),
}
}

#[no_mangle]
#[cfg(feature = "native")]
pub unsafe extern "C" fn arbitrator_set_preimage_resolver(
Expand Down
11 changes: 8 additions & 3 deletions arbitrator/prover/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,15 @@ pub fn hash_preimage(preimage: &[u8], ty: PreimageType) -> Result<[u8; 32]> {
// 25 bits for length considering 32mb blobs padded to nearest power of 2 (2^25)
// pad to 32 bits or 4 bytes so 68 bytes total
let mut commitment_length_encoded_bytes = Vec::with_capacity(68);
append_left_padded_biguint_be(&mut commitment_length_encoded_bytes, &commitment_x_bigint);
append_left_padded_biguint_be(&mut commitment_length_encoded_bytes, &commitment_y_bigint);
append_left_padded_biguint_be(
&mut commitment_length_encoded_bytes,
&commitment_x_bigint,
);
append_left_padded_biguint_be(
&mut commitment_length_encoded_bytes,
&commitment_y_bigint,
);
append_left_padded_biguint_be(&mut commitment_length_encoded_bytes, &length_bigint);


let mut keccak256_hasher = Keccak256::new();
keccak256_hasher.update(&commitment_length_encoded_bytes);
Expand Down

0 comments on commit cbcb177

Please sign in to comment.