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

Improve merkle proof #5

Draft
wants to merge 3 commits into
base: m1-client
Choose a base branch
from
Draft
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
64 changes: 62 additions & 2 deletions src/blob_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ impl BlobHeader {
.map(|quorum| Token::Tuple(quorum.to_tokens()))
.collect();

vec![Token::Tuple(vec![
vec![
Token::Tuple(commitment),
data_length,
Token::Array(blob_quorum_params),
])]
]
}
}

Expand All @@ -146,6 +146,22 @@ impl From<DisperserBatchHeader> for BatchHeader {
}
}

impl BatchHeader {
pub fn to_tokens(&self) -> Vec<Token> {
let batch_root = Token::FixedBytes(self.batch_root.clone());
let quorum_numbers = Token::Bytes(self.quorum_numbers.clone());
let quorum_signed_percentages = Token::Bytes(self.quorum_signed_percentages.clone());
let reference_block_number = Token::Uint(U256::from(self.reference_block_number));

vec![
batch_root,
quorum_numbers,
quorum_signed_percentages,
reference_block_number,
]
}
}

/// Internal of BlobInfo
#[derive(Debug, PartialEq, Clone)]
pub(crate) struct BatchMetadata {
Expand Down Expand Up @@ -173,6 +189,20 @@ impl TryFrom<DisperserBatchMetadata> for BatchMetadata {
}
}

impl BatchMetadata {
pub fn to_tokens(&self) -> Vec<Token> {
let batch_header = Token::Tuple(self.batch_header.to_tokens());
let signatory_record_hash = Token::FixedBytes(self.signatory_record_hash.clone());
let confirmation_block_number = Token::Uint(U256::from(self.confirmation_block_number));

vec![
batch_header,
signatory_record_hash,
confirmation_block_number,
]
}
}

/// Internal of BlobInfo
#[derive(Debug, PartialEq, Clone)]
pub(crate) struct BlobVerificationProof {
Expand All @@ -198,6 +228,24 @@ impl TryFrom<DisperserBlobVerificationProof> for BlobVerificationProof {
}
}

impl BlobVerificationProof {
pub fn to_tokens(&self) -> Vec<Token> {
let batch_id = Token::Uint(U256::from(self.batch_id));
let blob_index = Token::Uint(U256::from(self.blob_index));
let batch_medatada = Token::Tuple(self.batch_medatada.to_tokens());
let inclusion_proof = Token::Bytes(self.inclusion_proof.clone());
let quorum_indexes = Token::Bytes(self.quorum_indexes.clone());

vec![
batch_id,
blob_index,
batch_medatada,
inclusion_proof,
quorum_indexes,
]
}
}

/// Data returned by the disperser when a blob is dispersed
#[derive(Debug, PartialEq, Clone)]
pub(crate) struct BlobInfo {
Expand All @@ -222,3 +270,15 @@ impl TryFrom<DisperserBlobInfo> for BlobInfo {
})
}
}

impl BlobInfo {
pub fn to_tokens(&self) -> Vec<Token> {
let blob_header_tokens = self.blob_header.to_tokens();
let blob_verification_proof_tokens = self.blob_verification_proof.to_tokens();

vec![Token::Tuple(vec![
Token::Tuple(blob_header_tokens),
Token::Tuple(blob_verification_proof_tokens),
])]
}
}
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pub(crate) mod client_tests;
pub mod config;
pub mod errors;
pub(crate) mod eth_client;
pub(crate) mod merkle_proof_input;
pub(crate) mod sdk;
pub(crate) mod verifier;
pub(crate) mod verifier_tests;
Expand Down
20 changes: 0 additions & 20 deletions src/merkle_proof_input.rs

This file was deleted.

19 changes: 2 additions & 17 deletions src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ use crate::{
AuthenticatedReply, BlobAuthHeader,
},
errors::{
BlobStatusError, CommunicationError, ConfigError, ConversionError, EigenClientError,
BlobStatusError, CommunicationError, ConfigError, EigenClientError,
VerificationError,
},
merkle_proof_input::MerkleProofInput,
};
use byteorder::{BigEndian, ByteOrder};
use ethereum_types::Address;
Expand Down Expand Up @@ -240,21 +239,7 @@ impl RawEigenClient {
) -> Result<Option<Vec<u8>>, EigenClientError> {
let blob_info = self.get_commitment(request_id).await?;
if let Some(blob_info) = blob_info {
let inclusion_data = MerkleProofInput {
batch_root: blob_info
.blob_verification_proof
.batch_medatada
.batch_header
.batch_root
.try_into()
.map_err(|_| ConversionError::NotPresent("a".to_string()))?,
leaf: self.keccak256(
&self.keccak256(&ethabi::encode(&blob_info.blob_header.to_tokens())),
),
index: blob_info.blob_verification_proof.blob_index.into(),
inclusion_proof: blob_info.blob_verification_proof.inclusion_proof,
};
Ok(Some(ethabi::encode(&inclusion_data.to_tokens())))
Ok(Some(ethabi::encode(&blob_info.to_tokens())))
} else {
Ok(None)
}
Expand Down