Skip to content

Commit

Permalink
add blob hash opt into taiko extra
Browse files Browse the repository at this point in the history
  • Loading branch information
smtmfft committed Feb 20, 2024
1 parent aaba77e commit e6922c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 41 deletions.
48 changes: 8 additions & 40 deletions lib/src/taiko/host.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use alloy_sol_types::sol_data::FixedBytes;
use anyhow::Result;
use ethers_core::types::{Block, Transaction as EthersTransaction, H160, H256, U256};
use reqwest;
use reth_primitives::eip4844::kzg_to_versioned_hash;
use serde::Deserialize;
use sha2::{Digest, Sha256};
use tracing::info;
use zeth_primitives::{
ethers::{from_ethers_h160, from_ethers_h256, from_ethers_u256},
Expand All @@ -30,6 +28,7 @@ pub struct TaikoExtra {
pub l1_hash: B256,
pub l1_height: u64,
pub l2_tx_list: Vec<u8>,
pub tx_blob_hash: Option<B256>,
pub prover: Address,
pub graffiti: B256,
pub l1_signal_root: B256,
Expand Down Expand Up @@ -217,13 +216,11 @@ fn execute_data<N: NetworkStrategyBundle<TxEssence = EthereumTxEssence>>(
// KzgProof string `json:"kzg_proof"`
// CommitmentInclusionProof []string
// `json:"kzg_commitment_inclusion_proof"` }

#[warn(dead_code)]
#[derive(Clone, Debug, Deserialize)]
struct GetBlobData {

Check failure on line 220 in lib/src/taiko/host.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] reported by reviewdog 🐶 error: fields `index`, `kzg_proof`, and `kzg_commitment_inclusion_proof` are never read --> lib/src/taiko/host.rs:221:9 | 220 | struct GetBlobData { | ----------- fields in this struct 221 | pub index: String, | ^^^^^ ... 225 | pub kzg_proof: String, | ^^^^^^^^^ 226 | pub kzg_commitment_inclusion_proof: Vec<String>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `GetBlobData` has derived impls for the traits `Debug` and `Clone`, but these are intentionally ignored during dead code analysis = note: `-D dead-code` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(dead_code)]` Raw Output: lib/src/taiko/host.rs:220:8:e:error: fields `index`, `kzg_proof`, and `kzg_commitment_inclusion_proof` are never read --> lib/src/taiko/host.rs:221:9 | 220 | struct GetBlobData { | ----------- fields in this struct 221 | pub index: String, | ^^^^^ ... 225 | pub kzg_proof: String, | ^^^^^^^^^ 226 | pub kzg_commitment_inclusion_proof: Vec<String>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `GetBlobData` has derived impls for the traits `Debug` and `Clone`, but these are intentionally ignored during dead code analysis = note: `-D dead-code` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(dead_code)]` __END__

Check failure on line 220 in lib/src/taiko/host.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] reported by reviewdog 🐶 error: fields `index`, `kzg_proof`, and `kzg_commitment_inclusion_proof` are never read --> lib/src/taiko/host.rs:221:9 | 220 | struct GetBlobData { | ----------- fields in this struct 221 | pub index: String, | ^^^^^ ... 225 | pub kzg_proof: String, | ^^^^^^^^^ 226 | pub kzg_commitment_inclusion_proof: Vec<String>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `GetBlobData` has derived impls for the traits `Debug` and `Clone`, but these are intentionally ignored during dead code analysis = note: `-D dead-code` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(dead_code)]` Raw Output: lib/src/taiko/host.rs:220:8:e:error: fields `index`, `kzg_proof`, and `kzg_commitment_inclusion_proof` are never read --> lib/src/taiko/host.rs:221:9 | 220 | struct GetBlobData { | ----------- fields in this struct 221 | pub index: String, | ^^^^^ ... 225 | pub kzg_proof: String, | ^^^^^^^^^ 226 | pub kzg_commitment_inclusion_proof: Vec<String>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `GetBlobData` has derived impls for the traits `Debug` and `Clone`, but these are intentionally ignored during dead code analysis = note: `-D dead-code` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(dead_code)]` __END__
pub index: String,
pub blob: String,
// pub signed_block_header: String,
// pub signed_block_header: SignedBeaconBlockHeader, // ignore for now
pub kzg_commitment: String,
pub kzg_proof: String,
pub kzg_commitment_inclusion_proof: Vec<String>,
Expand Down Expand Up @@ -342,11 +339,11 @@ pub fn get_taiko_initial_data<N: NetworkStrategyBundle<TxEssence = EthereumTxEss

// blobUsed == (txList.length == 0) according to TaikoL1
let blob_used = l2_tx_list.is_empty();
let l2_tx_list_blob = if blob_used {
let (l2_tx_list_blob, tx_blob_hash) = if blob_used {
let BlockParams {
assignedProver: _,
extraData: _,
blobHash: proposed_blob_hash,
blobHash: _proposed_blob_hash,
txListByteOffset: offset,
txListByteSize: size,
cacheBlobForReuse: _,
Expand All @@ -359,9 +356,7 @@ pub fn get_taiko_initial_data<N: NetworkStrategyBundle<TxEssence = EthereumTxEss
// TODO: multiple blob hash support
assert!(blob_hashs.len() == 1);
let blob_hash = blob_hashs[0];
// if proposed_blob_hash != [0; 32] {
// assert_eq!(proposed_blob_hash, blob_hash);
// }
//TODO: check _proposed_blob_hash with blob_hash if _proposed_blob_hash is not None

let blobs = fetch_blob_data(l1_beacon_rpc_url.unwrap(), l1_block_no + 1)?;
let tx_blobs: Vec<GetBlobData> = blobs
Expand All @@ -371,9 +366,9 @@ pub fn get_taiko_initial_data<N: NetworkStrategyBundle<TxEssence = EthereumTxEss
.cloned()
.collect::<Vec<GetBlobData>>();
let blob_data = decode_blob_data(&tx_blobs[0].blob);
blob_data.as_slice()[offset as usize..(offset + size) as usize].to_vec()
(blob_data.as_slice()[offset as usize..(offset + size) as usize].to_vec(), Some(from_ethers_h256(blob_hash)))
} else {
l2_tx_list
(l2_tx_list, None)
};

// 1. check l2 parent gas used
Expand Down Expand Up @@ -405,6 +400,7 @@ pub fn get_taiko_initial_data<N: NetworkStrategyBundle<TxEssence = EthereumTxEss
l1_hash: anchor_l1_hash,
l1_height: l1_block_no,
l2_tx_list: l2_tx_list_blob.to_vec(),
tx_blob_hash: tx_blob_hash,

Check failure on line 403 in lib/src/taiko/host.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] reported by reviewdog 🐶 error: redundant field names in struct initialization --> lib/src/taiko/host.rs:403:9 | 403 | tx_blob_hash: tx_blob_hash, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `tx_blob_hash` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names = note: `-D clippy::redundant-field-names` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_field_names)]` Raw Output: lib/src/taiko/host.rs:403:9:e:error: redundant field names in struct initialization --> lib/src/taiko/host.rs:403:9 | 403 | tx_blob_hash: tx_blob_hash, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `tx_blob_hash` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names = note: `-D clippy::redundant-field-names` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_field_names)]` __END__

Check failure on line 403 in lib/src/taiko/host.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] reported by reviewdog 🐶 error: redundant field names in struct initialization --> lib/src/taiko/host.rs:403:9 | 403 | tx_blob_hash: tx_blob_hash, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `tx_blob_hash` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names = note: `-D clippy::redundant-field-names` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_field_names)]` Raw Output: lib/src/taiko/host.rs:403:9:e:error: redundant field names in struct initialization --> lib/src/taiko/host.rs:403:9 | 403 | tx_blob_hash: tx_blob_hash, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `tx_blob_hash` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names = note: `-D clippy::redundant-field-names` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_field_names)]` __END__
prover,
graffiti,
l1_signal_root,
Expand Down Expand Up @@ -473,32 +469,4 @@ mod test {
let tx: Transaction = serde_json::from_str(response).unwrap();
println!("tx: {:?}", tx);
}

#[tokio::test]
async fn test_decode_propose_block_call_params() {
tokio::task::spawn_blocking(|| {
let l1_block_no = 3;
let mut l1_provider = new_provider(None, Some("http://127.0.0.1:8545".to_owned()))
.expect("valid provider");

let l1_next_block = l1_provider
.get_full_block(&BlockQuery {
block_no: l1_block_no + 1,
})
.expect("get l1_next_block success");
println!("l1_next_block: {:?}", l1_next_block);

let (propose_tx, _) = l1_provider
.get_blob_tx_propose(&ProposeQuery {
l1_contract: H160::default(),
l1_block_no: l1_block_no,
l2_block_no: 0,
})
.expect("valid get_blob_tx_propose");

println!("propose_tx: {:?}", propose_tx);
})
.await
.unwrap();
}
}
4 changes: 3 additions & 1 deletion lib/src/taiko/protocol_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use zeth_primitives::{
use crate::taiko::host::TaikoExtra;

pub fn assemble_protocol_instance(extra: &TaikoExtra, header: &Header) -> Result<ProtocolInstance> {
let tx_list_hash = TxHash::from(keccak::keccak(extra.l2_tx_list.as_slice()));
let tx_list_hash = extra
.tx_blob_hash
.unwrap_or(TxHash::from(keccak::keccak(extra.l2_tx_list.as_slice())));
let deposits: Vec<EthDeposit> = extra
.l2_withdrawals
.iter()
Expand Down

0 comments on commit e6922c3

Please sign in to comment.