Skip to content
Open
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
2 changes: 1 addition & 1 deletion bin/citrea/tests/bitcoin/bitcoin_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ impl BitcoinVerifierTest {
new_header,
block.header.tx_count(),
block.header.height(),
block.header.txs_commitment().to_byte_array(),
block.header.txs_commitment(),
);

// The verifier should still successfully extract the relevant txs
Expand Down
4 changes: 2 additions & 2 deletions crates/bitcoin-da/src/spec/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ impl BlockHeaderTrait for HeaderWrapper {
self.hash() == BlockHashWrapper(self.block_hash())
}

fn txs_commitment(&self) -> Self::Hash {
BlockHashWrapper::from(self.txs_commitment)
fn txs_commitment(&self) -> [u8; 32] {
self.txs_commitment
}

fn height(&self) -> u64 {
Expand Down
11 changes: 5 additions & 6 deletions crates/bitcoin-da/src/spec/short_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ impl VerifiableShortHeaderProof for BitcoinHeaderShortProof {
// If non-segwit block, claimed tx commitment should equal to
// header.merkle_root if there are more than one tx
if self.header.tx_count > 1
&& self.header.merkle_root()
!= Into::<[u8; 32]>::into(self.header.txs_commitment())
&& self.header.merkle_root() != self.header.txs_commitment()
{
return Err(ShortHeaderProofVerificationError::WrongTxCommitment {
expected: self.header.merkle_root(),
actual: Into::<[u8; 32]>::into(self.header.txs_commitment()),
actual: self.header.txs_commitment(),
});
}
}
Expand All @@ -99,7 +98,7 @@ impl VerifiableShortHeaderProof for BitcoinHeaderShortProof {

let mut vec_merkle = Vec::with_capacity(input_witness_value.len() + 32);

vec_merkle.extend_from_slice(&self.header.txs_commitment().to_byte_array());
vec_merkle.extend_from_slice(&self.header.txs_commitment());
vec_merkle.extend_from_slice(input_witness_value);

// check with sha256(sha256(<merkle root><witness value>))
Expand All @@ -110,7 +109,7 @@ impl VerifiableShortHeaderProof for BitcoinHeaderShortProof {
expected: script_pubkey[6..38]
.try_into()
.expect("Must have hash in witness commitment output"),
actual: Into::<[u8; 32]>::into(self.header.txs_commitment()),
actual: self.header.txs_commitment(),
});
}
}
Expand Down Expand Up @@ -154,7 +153,7 @@ impl VerifiableShortHeaderProof for BitcoinHeaderShortProof {
.prev_blockhash
.as_raw_hash()
.to_byte_array(),
tx_commitment: self.header.txs_commitment().into(),
tx_commitment: self.header.txs_commitment(),
coinbase_txid_merkle_proof_height: self.coinbase_tx_txid_merkle_proof.len() as u8,
block_height: height,
})
Expand Down
6 changes: 3 additions & 3 deletions crates/sequencer/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,11 +1281,11 @@ where
let bridge_init_param = hex::decode(self.config.bridge_initialize_params.clone())
.expect("should deserialize");

info!("Initializing Bitcoin Light Client with L1 block: #{} with hash {}, tx commitment {}, and coinbase depth {}. Using {:?} for bridge initialization params.", l1_block.header().height(), hex::encode(Into::<[u8; 32]>::into(l1_block.header().txs_commitment())), hex::encode(l1_block.hash()), l1_block.header().coinbase_txid_merkle_proof_height(), bridge_init_param);
info!("Initializing Bitcoin Light Client with L1 block: #{} with hash {}, tx commitment {}, and coinbase depth {}. Using {:?} for bridge initialization params.", l1_block.header().height(), hex::encode(l1_block.header().txs_commitment()), hex::encode(l1_block.hash()), l1_block.header().coinbase_txid_merkle_proof_height(), bridge_init_param);

let initialize_events = create_initial_system_events(
l1_block.header().hash().into(),
l1_block.header().txs_commitment().into(),
l1_block.header().txs_commitment(),
l1_block.header().coinbase_txid_merkle_proof_height(),
l1_block.header().height(),
bridge_init_param,
Expand All @@ -1300,7 +1300,7 @@ where

let set_block_info_event = populate_set_block_info_event(
da_block_header.hash().into(),
da_block_header.txs_commitment().into(),
da_block_header.txs_commitment(),
coinbase_depth,
);
system_events.push(set_block_info_event);
Expand Down
4 changes: 2 additions & 2 deletions crates/sovereign-sdk/adapters/mock-da/src/db_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl DbConnector {
params![
block.header.prev_hash.0,
block.header.hash.0,
block.header.txs_commitment.0,
block.header.txs_commitment,
block.header.height,
serde_json::to_string(&block.header.time)
.expect("DbConnector: Failed to serialize time"),
Expand Down Expand Up @@ -129,7 +129,7 @@ impl DbConnector {
header: MockBlockHeader {
prev_hash: MockHash(row.get(0).unwrap()),
hash: MockHash(row.get(1).unwrap()),
txs_commitment: MockHash(row.get(2).unwrap()),
txs_commitment: row.get(2).unwrap(),
height: row.get(3).unwrap(),
time: serde_json::from_str(row.get::<_, String>(4).unwrap().as_str()).unwrap(),
bits: 0,
Expand Down
6 changes: 3 additions & 3 deletions crates/sovereign-sdk/adapters/mock-da/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{MockBlockHeader, MockHash};
const GENESIS_HEADER: MockBlockHeader = MockBlockHeader {
prev_hash: MockHash([0; 32]),
hash: MockHash([1; 32]),
txs_commitment: MockHash([1; 32]),
txs_commitment: [1; 32],
height: 0,
// 2023-01-01T00:00:00Z
time: Time::from_secs(1672531200),
Expand Down Expand Up @@ -219,7 +219,7 @@ impl MockDaService {
let header = MockBlockHeader {
prev_hash: previous_block_hash,
hash: block_hash,
txs_commitment: block_hash,
txs_commitment: block_hash.into(),
height,
time: Time::from_secs(10000000000), // TODO: had to mock this for now, causes different state roots
bits: 0,
Expand Down Expand Up @@ -496,7 +496,7 @@ impl DaService for MockDaService {
MockShortHeaderProof {
header_hash: block.header.hash.0,
prev_header_hash: block.header.prev_hash.0,
txs_commitment: block.header.txs_commitment.0,
txs_commitment: block.header.txs_commitment,
height: block.header.height,
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/sovereign-sdk/adapters/mock-da/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub struct MockBlockHeader {
/// The hash of this block.
pub hash: MockHash,
/// The transactions commitment of this block.
pub txs_commitment: MockHash,
pub txs_commitment: [u8; 32],
/// The height of this block
pub height: u64,
/// The time at which this block was created
Expand All @@ -93,7 +93,7 @@ impl MockBlockHeader {
MockBlockHeader {
prev_hash: MockHash(prev_hash),
hash: MockHash(hash),
txs_commitment: MockHash(txs_commitment),
txs_commitment,
height,
time: Time::now(),
bits,
Expand Down Expand Up @@ -130,7 +130,7 @@ impl BlockHeaderTrait for MockBlockHeader {
self.hash
}

fn txs_commitment(&self) -> Self::Hash {
fn txs_commitment(&self) -> [u8; 32] {
self.txs_commitment
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ pub trait BlockHeaderTrait:
fn verify_hash(&self) -> bool;

/// Transactions commitment of the block.
fn txs_commitment(&self) -> Self::Hash;
fn txs_commitment(&self) -> [u8; 32];

/// The current header height
fn height(&self) -> u64;
Expand Down
Loading