Skip to content

Commit

Permalink
Reuse TxFilterConfig in L1-Scan Guest code (#611)
Browse files Browse the repository at this point in the history
reuse TxFilterConfig in all the l1 batch
  • Loading branch information
MdTeach authored Jan 15, 2025
1 parent f96448d commit 89578af
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions crates/proof-impl/btc-blockspace/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ use strata_tx_parser::filter::{filter_protocol_op_tx_refs, TxFilterConfig};
pub fn extract_relevant_info(
block: &Block,
rollup_params: &RollupParams,
filter_config: &TxFilterConfig,
) -> (Vec<DepositInfo>, Option<BatchCheckpoint>) {
let filter_config =
TxFilterConfig::derive_from(rollup_params).expect("derive tx-filter config");

let mut deposits = Vec::new();
let mut prev_checkpoint = None;

let relevant_txs = filter_protocol_op_tx_refs(block, &filter_config);
let relevant_txs = filter_protocol_op_tx_refs(block, filter_config);

for tx in relevant_txs {
match tx.proto_op() {
Expand Down
5 changes: 4 additions & 1 deletion crates/proof-impl/btc-blockspace/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bitcoin::{consensus::deserialize, Block};
use borsh::{BorshDeserialize, BorshSerialize};
use strata_primitives::params::RollupParams;
use strata_state::{batch::BatchCheckpoint, l1::L1TxProof, tx::DepositInfo};
use strata_tx_parser::filter::TxFilterConfig;
use strata_zkvm::ZkVmEnv;

use crate::scan::process_blockscan;
Expand All @@ -29,7 +30,9 @@ pub fn process_blockspace_proof_outer(zkvm: &impl ZkVmEnv) {
let serialized_block = zkvm.read_buf();
let inclusion_proof: Option<L1TxProof> = zkvm.read_borsh();
let block: Block = deserialize(&serialized_block).unwrap();
let output = process_blockscan(&block, &inclusion_proof, &rollup_params);
let filter_config =
TxFilterConfig::derive_from(&rollup_params).expect("derive tx-filter config");
let output = process_blockscan(&block, &inclusion_proof, &rollup_params, &filter_config);
zkvm.commit_borsh(&output);
}

Expand Down
4 changes: 3 additions & 1 deletion crates/proof-impl/btc-blockspace/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use bitcoin::{consensus::serialize, Block};
use strata_primitives::params::RollupParams;
use strata_state::l1::L1TxProof;
use strata_tx_parser::filter::TxFilterConfig;

use crate::{block::check_integrity, filter::extract_relevant_info, logic::BlockScanResult};

Expand All @@ -11,10 +12,11 @@ pub fn process_blockscan(
block: &Block,
inclusion_proof: &Option<L1TxProof>,
rollup_params: &RollupParams,
filter_config: &TxFilterConfig,
) -> BlockScanResult {
assert!(check_integrity(block, inclusion_proof));

let (deposits, prev_checkpoint) = extract_relevant_info(block, rollup_params);
let (deposits, prev_checkpoint) = extract_relevant_info(block, rollup_params, filter_config);

BlockScanResult {
header_raw: serialize(&block.header),
Expand Down
1 change: 1 addition & 0 deletions crates/proof-impl/l1-batch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ serde.workspace = true
strata-primitives.workspace = true
strata-proofimpl-btc-blockspace.workspace = true
strata-state.workspace = true
strata-tx-parser.workspace = true
strata-zkvm.workspace = true

[dev-dependencies]
Expand Down
7 changes: 6 additions & 1 deletion crates/proof-impl/l1-batch/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use strata_state::{
l1::{get_btc_params, HeaderVerificationState, HeaderVerificationStateSnapshot, L1TxProof},
tx::DepositInfo,
};
use strata_tx_parser::filter::TxFilterConfig;
use strata_zkvm::ZkVmEnv;

/// Represents the public parameters of the L1BlockScan batch proof.
Expand All @@ -29,6 +30,9 @@ pub fn process_l1_batch_proof(zkvm: &impl ZkVmEnv) {
let mut state: HeaderVerificationState = zkvm.read_borsh();

let rollup_params: RollupParams = zkvm.read_serde();
let filter_config =
TxFilterConfig::derive_from(&rollup_params).expect("derive tx-filter config");

let num_inputs: u32 = zkvm.read_serde();
assert!(num_inputs > 0);

Expand All @@ -41,7 +45,8 @@ pub fn process_l1_batch_proof(zkvm: &impl ZkVmEnv) {
let inclusion_proof: Option<L1TxProof> = zkvm.read_borsh();

let block: Block = deserialize(&serialized_block).unwrap();
let blockscan_result = process_blockscan(&block, &inclusion_proof, &rollup_params);
let blockscan_result =
process_blockscan(&block, &inclusion_proof, &rollup_params, &filter_config);
state.check_and_update_continuity(&block.header, &get_btc_params());
deposits.extend(blockscan_result.deposits);
prev_checkpoint = prev_checkpoint.or(blockscan_result.prev_checkpoint);
Expand Down

0 comments on commit 89578af

Please sign in to comment.