Newer
Older
let checker = TransactionSignatureChecker {
signer: signer,
input_index: 1,
};
let input: Script = "00483045022015BD0139BCCCF990A6AF6EC5C1C52ED8222E03A0D51C334DF139968525D2FCD20221009F9EFE325476EB64C3958E4713E9EEFE49BF1D820ED58D2112721B134E2A1A53034930460221008431BDFA72BC67F9D41FE72E94C88FB8F359FFA30B33C72C121C5A877D922E1002210089EF5FC22DD8BFC6BF9FFDB01A9862D27687D424D1FEFBAB9E9C7176844A187A014C9052483045022015BD0139BCCCF990A6AF6EC5C1C52ED8222E03A0D51C334DF139968525D2FCD20221009F9EFE325476EB64C3958E4713E9EEFE49BF1D820ED58D2112721B134E2A1A5303210378D430274F8C5EC1321338151E9F27F4C676A008BDF8638D07C0B6BE9AB35C71210378D430274F8C5EC1321338151E9F27F4C676A008BDF8638D07C0B6BE9AB35C7153AE".into();
let output: Script = "A914D8DACDADB7462AE15CD906F1878706D0DA8660E687".into();
let flags = VerificationFlags::default()
.verify_p2sh(true);
assert_eq!(verify_script(&input, &output, &flags, &checker, SignatureVersion::Base), Ok(()));
Marek Kotewicz
committed
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
#[test]
fn test_script_with_forkid_signature() {
use keys::{KeyPair, Private, Network};
use sign::UnsignedTransactionInput;
use chain::{OutPoint, TransactionOutput};
let key_pair = KeyPair::from_private(Private { network: Network::Mainnet, secret: 1.into(), compressed: false, }).unwrap();
let redeem_script = Builder::default()
.push_data(key_pair.public())
.push_opcode(Opcode::OP_CHECKSIG)
.into_script();
let amount = 12345000000000;
let sighashtype = 0x41; // All + ForkId
let checker = TransactionSignatureChecker {
input_index: 0,
input_amount: amount,
signer: TransactionInputSigner {
version: 1,
inputs: vec![
UnsignedTransactionInput {
previous_output: OutPoint {
hash: 0u8.into(),
index: 0xffffffff,
},
sequence: 0xffffffff,
},
],
outputs: vec![
TransactionOutput {
value: amount,
script_pubkey: redeem_script.to_bytes(),
},
],
lock_time: 0,
},
};
let script_pubkey = redeem_script;
let flags = VerificationFlags::default();
// valid signature
{
let signed_input = checker.signer.signed_input(&key_pair, 0, amount, &script_pubkey, SignatureVersion::ForkId, sighashtype);
let script_sig = signed_input.script_sig.into();
assert_eq!(verify_script(&script_sig, &script_pubkey, &flags, &checker, SignatureVersion::ForkId), Ok(()));
}
// signature with wrong amount
{
let signed_input = checker.signer.signed_input(&key_pair, 0, amount + 1, &script_pubkey, SignatureVersion::ForkId, sighashtype);
let script_sig = signed_input.script_sig.into();
assert_eq!(verify_script(&script_sig, &script_pubkey, &flags, &checker, SignatureVersion::ForkId), Err(Error::EvalFalse));
}
// fork-id signature passed when not expected
{
let signed_input = checker.signer.signed_input(&key_pair, 0, amount + 1, &script_pubkey, SignatureVersion::ForkId, sighashtype);
let script_sig = signed_input.script_sig.into();
assert_eq!(verify_script(&script_sig, &script_pubkey, &flags, &checker, SignatureVersion::Base), Err(Error::EvalFalse));
}
// non-fork-id signature passed when expected
{
let signed_input = checker.signer.signed_input(&key_pair, 0, amount + 1, &script_pubkey, SignatureVersion::Base, 1);
let script_sig = signed_input.script_sig.into();
assert_eq!(verify_script(&script_sig, &script_pubkey, &flags.verify_strictenc(true), &checker, SignatureVersion::ForkId), Err(Error::SignatureMustUseForkId));