mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-28 19:50:20 -05:00
Ensure the size of our locking script never changes
This commit is contained in:
parent
4405dbcf9c
commit
148fdb8d0a
4 changed files with 35 additions and 8 deletions
|
|
@ -7,11 +7,11 @@ use ::bitcoin::{OutPoint, TxIn, TxOut, Txid};
|
|||
use anyhow::{bail, Result};
|
||||
use bdk::database::BatchDatabase;
|
||||
use bitcoin::Script;
|
||||
use ecdsa_fun::fun::Point;
|
||||
use miniscript::{Descriptor, DescriptorTrait};
|
||||
use rand::thread_rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const SCRIPT_SIZE: usize = 34;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct TxLock {
|
||||
inner: PartiallySignedTransaction,
|
||||
|
|
@ -112,12 +112,7 @@ impl TxLock {
|
|||
|
||||
/// Calculate the size of the script used by this transaction.
|
||||
pub fn script_size() -> usize {
|
||||
build_shared_output_descriptor(
|
||||
Point::random(&mut thread_rng()),
|
||||
Point::random(&mut thread_rng()),
|
||||
)
|
||||
.script_pubkey()
|
||||
.len()
|
||||
SCRIPT_SIZE
|
||||
}
|
||||
|
||||
pub fn script_pubkey(&self) -> Script {
|
||||
|
|
@ -245,6 +240,17 @@ mod tests {
|
|||
result.expect_err("PSBT to be invalid");
|
||||
}
|
||||
|
||||
proptest::proptest! {
|
||||
#[test]
|
||||
fn estimated_tx_lock_script_size_never_changes(a in crate::proptest::ecdsa_fun::point(), b in crate::proptest::ecdsa_fun::point()) {
|
||||
proptest::prop_assume!(a != b);
|
||||
|
||||
let computed_size = build_shared_output_descriptor(a, b).script_pubkey().len();
|
||||
|
||||
assert_eq!(computed_size, SCRIPT_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function that represents Bob's action of constructing the PSBT.
|
||||
///
|
||||
/// Extracting this allows us to keep the tests concise.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue