Skip to content

Commit

Permalink
Merge branch 'taiko/unstable' into prover-config-loading-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Brechtpd authored May 10, 2024
2 parents eded602 + 7b8b15c commit 6196036
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 39 deletions.
120 changes: 83 additions & 37 deletions host/src/preflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,9 @@ pub async fn preflight<BDP: BlockDataProvider>(
chain_spec.genesis_time,
chain_spec.seconds_per_slot,
)?;
let blobs = get_blob_data(&beacon_rpc_url.clone().unwrap(), slot_id).await?;
assert!(!blobs.data.is_empty(), "blob data not available anymore");
// Get the blob data for the blob storing the tx list
let tx_blob = blobs
.data
.iter()
.find(|blob| {
// calculate from plain blob
blob_hash == calc_blob_versioned_hash(&blob.blob)
})
.cloned();
assert!(tx_blob.is_some());
(blob_to_bytes(&tx_blob.unwrap().blob), Some(blob_hash))
// Fetch the blob data
let blob = get_blob_data(&beacon_rpc_url.clone().unwrap(), slot_id, blob_hash).await?;
(blob, Some(blob_hash))
} else {
// Get the tx list data directly from the propose transaction data
let proposal_call = proposeBlockCall::abi_decode(&proposal_tx.input, false).unwrap();
Expand Down Expand Up @@ -282,15 +272,66 @@ fn calc_blob_versioned_hash(blob_str: &str) -> [u8; 32] {
version_hash
}

async fn get_blob_data(beacon_rpc_url: &str, block_id: u64) -> Result<GetBlobsResponse> {
async fn get_blob_data(
beacon_rpc_url: &str,
block_id: u64,
blob_hash: FixedBytes<32>,
) -> Result<Vec<u8>> {
if beacon_rpc_url.contains("blobscan.com") {
get_blob_data_blobscan(beacon_rpc_url, block_id, blob_hash).await
} else {
get_blob_data_beacon(beacon_rpc_url, block_id, blob_hash).await
}
}

async fn get_blob_data_beacon(
beacon_rpc_url: &str,
block_id: u64,
blob_hash: FixedBytes<32>,
) -> Result<Vec<u8>> {
// Blob data from the beacon chain
// type Sidecar struct {
// Index string `json:"index"`
// Blob string `json:"blob"`
// SignedBeaconBlockHeader *SignedBeaconBlockHeader `json:"signed_block_header"`
// KzgCommitment string `json:"kzg_commitment"`
// KzgProof string `json:"kzg_proof"`
// CommitmentInclusionProof []string
// `json:"kzg_commitment_inclusion_proof"` }
#[derive(Clone, Debug, Deserialize, Serialize)]
struct GetBlobData {
pub index: String,
pub blob: String,
// pub signed_block_header: SignedBeaconBlockHeader, // ignore for now
pub kzg_commitment: String,
pub kzg_proof: String,
pub kzg_commitment_inclusion_proof: Vec<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
struct GetBlobsResponse {
pub data: Vec<GetBlobData>,
}

let url = format!(
"{}/eth/v1/beacon/blob_sidecars/{block_id}",
beacon_rpc_url.trim_end_matches('/'),
);
let response = reqwest::get(url.clone()).await?;
if response.status().is_success() {
let blob_response: GetBlobsResponse = response.json().await?;
Ok(blob_response)
let blobs: GetBlobsResponse = response.json().await?;
assert!(!blobs.data.is_empty(), "blob data not available anymore");
// Get the blob data for the blob storing the tx list
let tx_blob = blobs
.data
.iter()
.find(|blob| {
// calculate from plain blob
blob_hash == calc_blob_versioned_hash(&blob.blob)
})
.cloned();
assert!(tx_blob.is_some());
Ok(blob_to_bytes(&tx_blob.unwrap().blob))
} else {
println!(
"Request {url} failed with status code: {}",
Expand All @@ -303,28 +344,33 @@ async fn get_blob_data(beacon_rpc_url: &str, block_id: u64) -> Result<GetBlobsRe
}
}

// Blob data from the beacon chain
// type Sidecar struct {
// Index string `json:"index"`
// Blob string `json:"blob"`
// SignedBeaconBlockHeader *SignedBeaconBlockHeader `json:"signed_block_header"`
// KzgCommitment string `json:"kzg_commitment"`
// KzgProof string `json:"kzg_proof"`
// CommitmentInclusionProof []string
// `json:"kzg_commitment_inclusion_proof"` }
#[derive(Clone, Debug, Deserialize, Serialize)]
struct GetBlobData {
pub index: String,
pub blob: String,
// pub signed_block_header: SignedBeaconBlockHeader, // ignore for now
pub kzg_commitment: String,
pub kzg_proof: String,
pub kzg_commitment_inclusion_proof: Vec<String>,
}
async fn get_blob_data_blobscan(
beacon_rpc_url: &str,
_block_id: u64,
blob_hash: FixedBytes<32>,
) -> Result<Vec<u8>> {
// https://api.blobscan.com/#/
#[derive(Clone, Debug, Deserialize, Serialize)]
struct BlobScanData {
pub commitment: String,
pub data: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
struct GetBlobsResponse {
pub data: Vec<GetBlobData>,
let url = format!("{}/blobs/{blob_hash}", beacon_rpc_url.trim_end_matches('/'),);
let response = reqwest::get(url.clone()).await?;
if response.status().is_success() {
let blob: BlobScanData = response.json().await?;
Ok(blob_to_bytes(&blob.data))
} else {
println!(
"Request {url} failed with status code: {}",
response.status()
);
Err(anyhow::anyhow!(
"Request failed with status code: {}",
response.status()
))
}
}

async fn get_block_proposed_event(
Expand Down
2 changes: 1 addition & 1 deletion host/src/raiko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ mod tests {
block_number,
rpc: "https://rpc.hekla.taiko.xyz".to_string(),
l1_rpc: "https://ethereum-holesky-rpc.publicnode.com".to_string(),
beacon_rpc: "https://l1beacon.hekla.taiko.xyz".to_string(),
beacon_rpc: "https://api.holesky.blobscan.com".to_string(),
network,
graffiti: B256::ZERO,
prover: Address::ZERO,
Expand Down
2 changes: 1 addition & 1 deletion script/prove-block.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ elif [ "$chain" == "taiko_a6" ]; then
elif [ "$chain" == "taiko_a7" ]; then
rpc="https://rpc.hekla.taiko.xyz"
l1Rpc="https://ethereum-holesky-rpc.publicnode.com"
beaconRpc="https://l1beacon.hekla.taiko.xyz"
beaconRpc="https://api.holesky.blobscan.com"
else
echo "Invalid chain name. Please use 'ethereum', 'taiko_a6' or 'taiko_a7'."
exit 1
Expand Down

0 comments on commit 6196036

Please sign in to comment.