Skip to content

Commit

Permalink
fix bitcoin da tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eyusufatik committed Feb 4, 2025
1 parent 760ee30 commit c6959ca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 162 deletions.
6 changes: 2 additions & 4 deletions crates/bitcoin-da/tests/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ impl TestCase for BitcoinServiceTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&txs,
inclusion_proof,
completeness_proof,
DaNamespace::ToBatchProver
),
Ok(())
Ok(txs)
);
}

Expand Down Expand Up @@ -127,12 +126,11 @@ impl TestCase for BitcoinServiceTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&txs,
inclusion_proof,
completeness_proof,
DaNamespace::ToLightClientProver
),
Ok(())
Ok(txs)
);
}

Expand Down
161 changes: 3 additions & 158 deletions crates/bitcoin-da/tests/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof.clone(),
b_completeness_proof.clone(),
DaNamespace::ToBatchProver,
),
Ok(()),
Ok(b_txs.clone()),
);
}

Expand All @@ -84,12 +83,11 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&l_txs,
l_inclusion_proof.clone(),
l_completeness_proof.clone(),
DaNamespace::ToLightClientProver,
),
Ok(()),
Ok(l_txs.clone()),
);
}

Expand All @@ -99,7 +97,6 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof.clone(),
b_completeness_proof.clone(),
DaNamespace::ToLightClientProver,
Expand All @@ -111,7 +108,6 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&l_txs,
l_inclusion_proof.clone(),
l_completeness_proof.clone(),
DaNamespace::ToBatchProver,
Expand Down Expand Up @@ -142,12 +138,11 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&nonsegwit_block.header,
&[],
inclusion_proof,
vec![],
DaNamespace::ToBatchProver,
),
Ok(())
Ok(Vec::new())
);
}

Expand Down Expand Up @@ -179,7 +174,6 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
inclusion_proof,
b_completeness_proof.clone(),
DaNamespace::ToBatchProver,
Expand Down Expand Up @@ -229,7 +223,6 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
inclusion_proof,
b_completeness_proof.clone(),
DaNamespace::ToBatchProver,
Expand Down Expand Up @@ -286,7 +279,6 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&txs,
inclusion_proof,
completeness_proof,
DaNamespace::ToBatchProver,
Expand All @@ -305,7 +297,6 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
inclusion_proof,
b_completeness_proof.clone(),
DaNamespace::ToBatchProver,
Expand All @@ -319,7 +310,6 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
inclusion_proof,
b_completeness_proof.clone(),
DaNamespace::ToBatchProver,
Expand All @@ -336,7 +326,6 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof,
b_completeness_proof.clone(),
DaNamespace::ToBatchProver,
Expand All @@ -353,7 +342,6 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof,
b_completeness_proof.clone(),
DaNamespace::ToBatchProver,
Expand All @@ -370,7 +358,6 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof,
b_completeness_proof.clone(),
DaNamespace::ToBatchProver,
Expand All @@ -387,7 +374,6 @@ impl TestCase for BitcoinVerifierTest {
assert_panic!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof.clone(),
b_completeness_proof,
DaNamespace::ToBatchProver,
Expand All @@ -404,7 +390,6 @@ impl TestCase for BitcoinVerifierTest {
assert_panic!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof.clone(),
b_completeness_proof,
DaNamespace::ToBatchProver,
Expand All @@ -427,7 +412,6 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof.clone(),
b_completeness_proof.clone(),
DaNamespace::ToBatchProver,
Expand All @@ -444,7 +428,6 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof.clone(),
b_completeness_proof,
DaNamespace::ToBatchProver,
Expand All @@ -453,23 +436,6 @@ impl TestCase for BitcoinVerifierTest {
);
}

// Break tx order should fail
{
let mut b_txs = b_txs.clone();

b_txs.swap(0, 1);
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof.clone(),
b_completeness_proof.clone(),
DaNamespace::ToBatchProver,
),
Err(ValidationError::BlobWasTamperedWith),
);
}

// Break tx order and completeness proof order should fail
{
let mut b_completeness_proof = b_completeness_proof.clone();
Expand All @@ -480,7 +446,6 @@ impl TestCase for BitcoinVerifierTest {
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof.clone(),
b_completeness_proof,
DaNamespace::ToBatchProver,
Expand All @@ -489,126 +454,6 @@ impl TestCase for BitcoinVerifierTest {
);
}

// Missing tx should fail
{
let mut b_txs = b_txs.clone();

b_txs.pop();
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof.clone(),
b_completeness_proof.clone(),
DaNamespace::ToBatchProver,
),
Err(ValidationError::ValidBlobNotFoundInBlobs),
);
}

// Tamper tx content of batch proof should fail
{
let mut b_txs = b_txs.clone();

b_txs[0] =
BlobWithSender::new(vec![2; 152], b_txs[0].sender.0.clone(), b_txs[0].hash, None);
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof.clone(),
b_completeness_proof.clone(),
DaNamespace::ToBatchProver,
),
Err(ValidationError::BlobContentWasModified),
);
}

// Tamper tx content of light client proof should fail
{
let mut l_txs = l_txs.clone();

l_txs[0] =
BlobWithSender::new(vec![2; 152], l_txs[0].sender.0.clone(), l_txs[0].hash, None);
assert_eq!(
verifier.verify_transactions(
&block.header,
&l_txs,
l_inclusion_proof.clone(),
l_completeness_proof.clone(),
DaNamespace::ToLightClientProver,
),
Err(ValidationError::BlobContentWasModified),
);
}

// Tamper tx sender of batch proof should fail
{
let mut b_txs = b_txs.clone();

let mut blob = b_txs[0].blob.clone();
blob.advance(blob.total_len());
let blob = blob.accumulator().to_vec();

b_txs[0] = BlobWithSender::new(blob, vec![2; 33], b_txs[0].hash, None);
assert_eq!(
verifier.verify_transactions(
&block.header,
&b_txs,
b_inclusion_proof,
b_completeness_proof,
DaNamespace::ToBatchProver,
),
Err(ValidationError::IncorrectSenderInBlob),
);
}

// Tamper tx sender of light client proof should fail
{
let mut l_txs = l_txs.clone();

let mut blob = l_txs[0].blob.clone();
blob.advance(blob.total_len());
let blob = blob.accumulator().to_vec();

l_txs[0] = BlobWithSender::new(blob, vec![2; 33], l_txs[0].hash, None);
assert_eq!(
verifier.verify_transactions(
&block.header,
&l_txs,
l_inclusion_proof.clone(),
l_completeness_proof.clone(),
DaNamespace::ToLightClientProver,
),
Err(ValidationError::IncorrectSenderInBlob),
);
}

// Non-decompressed light client proof blob should fail
{
let mut l_txs = l_txs.clone();

let body = {
let parsed = parse_light_client_transaction(&l_completeness_proof[1]).unwrap();
match parsed {
ParsedLightClientTransaction::Complete(complete) => complete.body, // normally we should decompress the tx body
_ => panic!("Should not select zk proof tx other than complete"),
}
};

l_txs[0] = BlobWithSender::new(body, l_txs[0].sender.0.clone(), l_txs[0].hash, None);
assert_eq!(
verifier.verify_transactions(
&block.header,
&l_txs,
l_inclusion_proof,
l_completeness_proof,
DaNamespace::ToLightClientProver,
),
Err(ValidationError::BlobContentWasModified),
);
}

task_manager.abort().await;
Ok(())
}
Expand Down

0 comments on commit c6959ca

Please sign in to comment.