Skip to content

Commit

Permalink
add edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
coderofstuff committed Dec 17, 2023
1 parent 50d5233 commit 273ad9a
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions crypto/txscript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,4 +1120,51 @@ mod bitcoind_tests {
panic!("{}/{} json tests failed", had_errors, total_tests)
}
}

#[test]
fn test_tx_edge_case() {
let sig_cache = Cache::new(10_000);
let mut reused_values = SigHashReusedValues::new();

// Ensure encapsulation of variables (no leaking between tests)
let input = TransactionInput {
previous_outpoint: TransactionOutpoint {
transaction_id: TransactionId::from_bytes([
0x67, 0x4c, 0x73, 0xce, 0x22, 0x46, 0x36, 0x4d, 0xc7, 0xdd, 0x23, 0xa1, 0x37, 0xa1, 0xf2, 0x1d, 0x9c, 0xdc, 0x5b, 0x05, 0x4f, 0x4e, 0xe8, 0xc0, 0x81, 0xce, 0xc7, 0x8e, 0x10, 0x5f, 0x3d, 0x73
]),
index: 0,
},
signature_script: vec![
0x41, 0x29, 0x79, 0xf3, 0xc6, 0xa7, 0xef, 0x51, 0x3e, 0xc6, 0x6d, 0x2e, 0xaf, 0x9d, 0x56, 0xd8, 0x47, 0xad, 0xc3, 0xe7, 0x1f, 0x78, 0xf0, 0xb9, 0x54, 0xa1, 0x36, 0x87, 0x74, 0xf8, 0x6a, 0xfc, 0x46, 0x13, 0x90, 0xc9, 0x14, 0x1a, 0x2a, 0xe8, 0x9f, 0xdb, 0xf6, 0x88, 0x4f, 0xb5, 0x65, 0x7c, 0x44, 0x88, 0x7d, 0x56, 0x86, 0xc4, 0x5a, 0xdc, 0xe2, 0x21, 0x34, 0xdf, 0xe6, 0x32, 0x84, 0xd0, 0xff, 0x01, 0x20, 0x75, 0x5f, 0xaa, 0xf7, 0x75, 0xab, 0xa0, 0xdf, 0x4f, 0xc6, 0xb6, 0x0a, 0x6c, 0x5b, 0x3b, 0x94, 0xc1, 0x96, 0xc8, 0x68, 0xf3, 0xfa, 0x83, 0xd1, 0x43, 0xda, 0xe3, 0xfe, 0x49, 0x0a, 0x84, 0x42, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x51, 0x4c, 0x70, 0x63, 0xa8, 0x20, 0x2b, 0xb8, 0x0d, 0x53, 0x7b, 0x1d, 0xa3, 0xe3, 0x8b, 0xd3, 0x03, 0x61, 0xaa, 0x85, 0x56, 0x86, 0xbd, 0xe0, 0xea, 0xcd, 0x71, 0x62, 0xfe, 0xf6, 0xa2, 0x5f, 0xe9, 0x7b, 0xf5, 0x27, 0xa2, 0x5b, 0x88, 0x76, 0x20, 0x75, 0x5f, 0xaa, 0xf7, 0x75, 0xab, 0xa0, 0xdf, 0x4f, 0xc6, 0xb6, 0x0a, 0x6c, 0x5b, 0x3b, 0x94, 0xc1, 0x96, 0xc8, 0x68, 0xf3, 0xfa, 0x83, 0xd1, 0x43, 0xda, 0xe3, 0xfe, 0x49, 0x0a, 0x84, 0x42, 0x88, 0xac, 0x67, 0x51, 0xb0, 0x76, 0x20, 0x6f, 0x53, 0x82, 0x82, 0xa9, 0x33, 0x45, 0x3c, 0x85, 0x32, 0x16, 0xe0, 0xa9, 0x98, 0xe5, 0x67, 0xb4, 0xbd, 0x55, 0x94, 0x27, 0x3d, 0xb9, 0x19, 0x49, 0xda, 0xf9, 0x9c, 0x1d, 0xc1, 0xb4, 0x3d, 0x88, 0xac, 0x68
],
sequence: 0,
sig_op_count: 2,
};

let outputs = vec![
TransactionOutput { value: 400000000, script_public_key: ScriptPublicKey::new(0, vec![
0x20, 0x6f, 0x53, 0x82, 0x82, 0xa9, 0x33, 0x45, 0x3c, 0x85, 0x32, 0x16, 0xe0, 0xa9, 0x98, 0xe5, 0x67,
0xb4, 0xbd, 0x55, 0x94, 0x27, 0x3d, 0xb9, 0x19, 0x49, 0xda, 0xf9, 0x9c, 0x1d, 0xc1, 0xb4, 0x3d, 0xac].into()) },
TransactionOutput { value: 99996793, script_public_key: ScriptPublicKey::new(0, vec![
0xaa, 0x20, 0xe1, 0xbe, 0xea, 0xf5, 0xce, 0x71, 0xee, 0x7f, 0xc2, 0xbc, 0x89, 0x34, 0x63, 0x86, 0x2c,
0x4f, 0x28, 0x6f, 0xd0, 0x67, 0x72, 0x2f, 0xf8, 0x33, 0x7b, 0x19, 0x38, 0x2e, 0x96, 0x67, 0x26, 0x8e, 0x87].into()) },
];

let tx = Transaction::new(0, vec![input.clone()], outputs.clone(), 0, Default::default(), 0, vec![]);

let prev_output = TransactionOutput { value: 500000000, script_public_key: ScriptPublicKey::new(0, vec![
0xaa, 0x20, 0xe1, 0xbe, 0xea, 0xf5, 0xce, 0x71, 0xee, 0x7f, 0xc2, 0xbc, 0x89, 0x34, 0x63, 0x86, 0x2c, 0x4f, 0x28, 0x6f, 0xd0, 0x67, 0x72, 0x2f, 0xf8, 0x33, 0x7b, 0x19, 0x38, 0x2e, 0x96, 0x67, 0x26, 0x8e, 0x87
].into())};
let utxo_entry = UtxoEntry::new(prev_output.clone().value, prev_output.script_public_key.clone(), 0, tx.is_coinbase());

let populated_tx = PopulatedTransaction::new(&tx, vec![utxo_entry.clone()]);

let mut vm = TxScriptEngine::from_transaction_input(&populated_tx, &input, 0, &utxo_entry, &mut reused_values, &sig_cache)
.expect("Script creation failed");
let r = vm.execute();
if r.is_err() {
println!("Error: {:?}", r);
}
assert_eq!(r, Ok(()));
}
}

0 comments on commit 273ad9a

Please sign in to comment.