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

4844 support + Move host to raiko-hosts #48

Merged
merged 21 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
some fixes to make blobs work
  • Loading branch information
Brechtpd committed Mar 5, 2024
commit ee1d37c1ed7a318bc372953985f1b727bf77d05b
50 changes: 23 additions & 27 deletions lib/src/host/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn taiko_run_preflight(
let l1_state_root_block = tp.l1_provider.get_partial_block(&BlockQuery {
block_no: l1_state_block_no,
})?;
println!("l1_state_root_block: {:?}", l1_state_root_block);
//println!("l1_state_root_block: {:?}", l1_state_root_block);
println!(
"l1_state_root_block hash: {:?}",
l1_state_root_block.hash.unwrap()
Expand All @@ -115,69 +115,65 @@ pub fn taiko_run_preflight(
"tx list bytes must be not more than MAX_TX_LIST_BYTES"
);

let mut l2_tx_list: Vec<EthersTransaction> = Rlp::new(&proposal_call.txList).as_list()?;
ensure!(
l2_tx_list.len() <= MAX_TX_LIST,
"tx list size must be not more than MAX_TX_LISTs"
);

// blobUsed == (txList.length == 0) according to TaikoL1
let blob_used = proposal_call.txList.is_empty();
let (l2_tx_list_blob, tx_blob_hash) = if blob_used {
let BlockMetadata {
blobHash: _proposed_blob_hash,
txListByteOffset: offset,
txListByteSize: size,
..
} = decode_propose_block_call_params(&proposal_call.params)
let (tx_list, tx_blob_hash) = if blob_used {
println!("blob active");
let metadata = decode_propose_block_call_params(&proposal_call.params)
.expect("valid propose_block_call_params");
println!("metadata: {:?}", metadata);

let blob_hashs = proposal_tx.blob_versioned_hashes.unwrap();
// TODO: multiple blob hash support
assert!(blob_hashs.len() == 1);
let blob_hash = blob_hashs[0];
// TODO: check _proposed_blob_hash with blob_hash if _proposed_blob_hash is not None

let blobs = tp.l1_provider.get_blob_data(l1_state_block_no + 1)?;
let blobs = tp.l1_provider.get_blob_data(l1_inclusion_block_no)?;
let tx_blobs: Vec<GetBlobData> = blobs
.data
.iter()
.filter(|blob| blob_hash.as_fixed_bytes() == &calc_blob_hash(&blob.kzg_commitment))
.cloned()
.collect::<Vec<GetBlobData>>();
let blob_data = decode_blob_data(&tx_blobs[0].blob);
let offset = metadata.txListByteOffset as usize;
let size = metadata.txListByteSize as usize;
(
blob_data.as_slice()[offset as usize..(offset + size) as usize].to_vec(),
blob_data.as_slice()[offset..(offset + size)].to_vec(),
Some(from_ethers_h256(blob_hash)),
)
} else {
(proposal_call.txList.clone(), None)
};

// TODO(Cecilia): reset to empty necessary if wrong?
// tracing::log for particular reason instead of uniform error handling?
// txs.clear();
//println!("tx_list: {:?}", tx_list);

info!(
"Inserted anchor {:?} in tx_list decoded from {:?}",
anchor_tx.hash, proposal_call.txList
);
l2_tx_list.insert(0, anchor_tx);
block.transactions = l2_tx_list;
// Create the transactions for the proposed tx list
let mut transactions: Vec<EthersTransaction> = Rlp::new(&tx_list).as_list()?;
println!("Transaction count pre anchor: {:?}", transactions.len());
// Insert the anchor transactions generated by the node (which will be verified)
transactions.insert(0, anchor_tx);

println!("Block valid transactions: {:?}", block.transactions.len());
assert!(transactions.len() >= block.transactions.len(), "unexpected number of transactions");

//
block.transactions = transactions;

info!(
"Final block number: {:?} ({:?})",
block.number.unwrap(),
block.hash.unwrap()
);
info!("Transaction count: {:?}", block.transactions.len());
println!("Transaction count: {:?}", block.transactions.len());

let taiko_sys_info = TaikoSystemInfo {
chain_spec_name: chain_spec_name.to_string(),
l1_header: l1_state_root_block
.try_into()
.expect("Failed to convert ethers block to zeth block"),
tx_list: l2_tx_list_blob,
tx_list,
tx_blob_hash,
block_proposed: proposal_event,
prover_data,
Expand Down
23 changes: 21 additions & 2 deletions lib/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,25 @@ sol! {
bytes32 parentMetaHash; // slot 8
}

#[derive(Debug, Default, Deserialize, Serialize)]
struct BlockParams {
address assignedProver;
address coinbase;
bytes32 extraData;
bytes32 blobHash;
uint24 txListByteOffset;
uint24 txListByteSize;
bool cacheBlobForReuse;
bytes32 parentMetaHash;
HookCall[] hookCalls;
}

#[derive(Debug, Default, Deserialize, Serialize)]
struct HookCall {
address hook;
bytes data;
}

#[derive(Debug)]
struct Transition {
bytes32 parentHash;
Expand Down Expand Up @@ -146,8 +165,8 @@ sol! {
function proveBlock(uint64 blockId, bytes calldata input) {}
}

pub fn decode_propose_block_call_params(data: &[u8]) -> Result<BlockMetadata> {
let propose_block_params = BlockMetadata::abi_decode(data, false)
pub fn decode_propose_block_call_params(data: &[u8]) -> Result<BlockParams> {
let propose_block_params = BlockParams::abi_decode(data, false)
.map_err(|e| anyhow!("failed to decode propose block call: {e}"))?;
Ok(propose_block_params)
}
Expand Down
1 change: 1 addition & 0 deletions pullblock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ do
\"type\": \"native\",
\"l2Rpc\": \"https://rpc.katla.taiko.xyz\",
\"l1Rpc\": \"https://l1rpc.katla.taiko.xyz\",
\"beaconRpc\": \"https://l1beacon.internal.taiko.xyz\",
\"l2Contracts\": \"testnet\",
\"proofInstance\": \"native\",
\"blockNumber\": $block,
Expand Down
2 changes: 1 addition & 1 deletion raiko-host/src/prover/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub async fn prepare_input(
graffiti: req.graffiti,
prover: req.prover,
},
None,
Some(req.beacon_rpc),
)
.expect("Init taiko failed")
})
Expand Down
2 changes: 2 additions & 0 deletions raiko-host/src/prover/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct ProofRequest {
pub l2_rpc: String,
/// l1 node for signal root verify and get txlist info from proposed transaction.
pub l1_rpc: String,
/// beacon node for data blobs
pub beacon_rpc: String,
/// l2 contracts selection
pub l2_contracts: String,
// graffiti
Expand Down
Loading