@ -147,10 +147,14 @@ CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CMu
void DoTest ( const CScript & scriptPubKey , const CScript & scriptSig , int flags , const std : : string & message , int scriptError )
void DoTest ( const CScript & scriptPubKey , const CScript & scriptSig , int flags , const std : : string & message , int scriptError )
{
{
bool expect = ( scriptError = = SCRIPT_ERR_OK ) ;
bool expect = ( scriptError = = SCRIPT_ERR_OK ) ;
if ( flags & SCRIPT_VERIFY_CLEANSTACK ) {
flags | = SCRIPT_VERIFY_P2SH ;
flags | = SCRIPT_VERIFY_WITNESS ;
}
ScriptError err ;
ScriptError err ;
CMutableTransaction tx = BuildSpendingTransaction ( scriptSig , BuildCreditingTransaction ( scriptPubKey ) ) ;
CMutableTransaction tx = BuildSpendingTransaction ( scriptSig , BuildCreditingTransaction ( scriptPubKey ) ) ;
CMutableTransaction tx2 = tx ;
CMutableTransaction tx2 = tx ;
BOOST_CHECK_MESSAGE ( VerifyScript ( scriptSig , scriptPubKey , flags , MutableTransactionSignatureChecker ( & tx , 0 ) , & err ) = = expect , message ) ;
BOOST_CHECK_MESSAGE ( VerifyScript ( scriptSig , scriptPubKey , NULL , flags , MutableTransactionSignatureChecker ( & tx , 0 ) , & err ) = = expect , message ) ;
BOOST_CHECK_MESSAGE ( err = = scriptError , std : : string ( FormatScriptError ( err ) ) + " where " + std : : string ( FormatScriptError ( ( ScriptError_t ) scriptError ) ) + " expected: " + message ) ;
BOOST_CHECK_MESSAGE ( err = = scriptError , std : : string ( FormatScriptError ( err ) ) + " where " + std : : string ( FormatScriptError ( ( ScriptError_t ) scriptError ) ) + " expected: " + message ) ;
# if defined(HAVE_CONSENSUS_LIB)
# if defined(HAVE_CONSENSUS_LIB)
CDataStream stream ( SER_NETWORK , PROTOCOL_VERSION ) ;
CDataStream stream ( SER_NETWORK , PROTOCOL_VERSION ) ;
@ -799,18 +803,18 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG12)
CMutableTransaction txTo12 = BuildSpendingTransaction ( CScript ( ) , txFrom12 ) ;
CMutableTransaction txTo12 = BuildSpendingTransaction ( CScript ( ) , txFrom12 ) ;
CScript goodsig1 = sign_multisig ( scriptPubKey12 , key1 , txTo12 ) ;
CScript goodsig1 = sign_multisig ( scriptPubKey12 , key1 , txTo12 ) ;
BOOST_CHECK ( VerifyScript ( goodsig1 , scriptPubKey12 , flags , MutableTransactionSignatureChecker ( & txTo12 , 0 ) , & err ) ) ;
BOOST_CHECK ( VerifyScript ( goodsig1 , scriptPubKey12 , NULL , flags , MutableTransactionSignatureChecker ( & txTo12 , 0 ) , & err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
txTo12 . vout [ 0 ] . nValue = 2 ;
txTo12 . vout [ 0 ] . nValue = 2 ;
BOOST_CHECK ( ! VerifyScript ( goodsig1 , scriptPubKey12 , flags , MutableTransactionSignatureChecker ( & txTo12 , 0 ) , & err ) ) ;
BOOST_CHECK ( ! VerifyScript ( goodsig1 , scriptPubKey12 , NULL , flags , MutableTransactionSignatureChecker ( & txTo12 , 0 ) , & err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
CScript goodsig2 = sign_multisig ( scriptPubKey12 , key2 , txTo12 ) ;
CScript goodsig2 = sign_multisig ( scriptPubKey12 , key2 , txTo12 ) ;
BOOST_CHECK ( VerifyScript ( goodsig2 , scriptPubKey12 , flags , MutableTransactionSignatureChecker ( & txTo12 , 0 ) , & err ) ) ;
BOOST_CHECK ( VerifyScript ( goodsig2 , scriptPubKey12 , NULL , flags , MutableTransactionSignatureChecker ( & txTo12 , 0 ) , & err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
CScript badsig1 = sign_multisig ( scriptPubKey12 , key3 , txTo12 ) ;
CScript badsig1 = sign_multisig ( scriptPubKey12 , key3 , txTo12 ) ;
BOOST_CHECK ( ! VerifyScript ( badsig1 , scriptPubKey12 , flags , MutableTransactionSignatureChecker ( & txTo12 , 0 ) , & err ) ) ;
BOOST_CHECK ( ! VerifyScript ( badsig1 , scriptPubKey12 , NULL , flags , MutableTransactionSignatureChecker ( & txTo12 , 0 ) , & err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
}
}
@ -832,54 +836,54 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG23)
std : : vector < CKey > keys ;
std : : vector < CKey > keys ;
keys . push_back ( key1 ) ; keys . push_back ( key2 ) ;
keys . push_back ( key1 ) ; keys . push_back ( key2 ) ;
CScript goodsig1 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
CScript goodsig1 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
BOOST_CHECK ( VerifyScript ( goodsig1 , scriptPubKey23 , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK ( VerifyScript ( goodsig1 , scriptPubKey23 , NULL , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
keys . clear ( ) ;
keys . clear ( ) ;
keys . push_back ( key1 ) ; keys . push_back ( key3 ) ;
keys . push_back ( key1 ) ; keys . push_back ( key3 ) ;
CScript goodsig2 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
CScript goodsig2 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
BOOST_CHECK ( VerifyScript ( goodsig2 , scriptPubKey23 , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK ( VerifyScript ( goodsig2 , scriptPubKey23 , NULL , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
keys . clear ( ) ;
keys . clear ( ) ;
keys . push_back ( key2 ) ; keys . push_back ( key3 ) ;
keys . push_back ( key2 ) ; keys . push_back ( key3 ) ;
CScript goodsig3 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
CScript goodsig3 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
BOOST_CHECK ( VerifyScript ( goodsig3 , scriptPubKey23 , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK ( VerifyScript ( goodsig3 , scriptPubKey23 , NULL , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
keys . clear ( ) ;
keys . clear ( ) ;
keys . push_back ( key2 ) ; keys . push_back ( key2 ) ; // Can't re-use sig
keys . push_back ( key2 ) ; keys . push_back ( key2 ) ; // Can't re-use sig
CScript badsig1 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
CScript badsig1 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
BOOST_CHECK ( ! VerifyScript ( badsig1 , scriptPubKey23 , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK ( ! VerifyScript ( badsig1 , scriptPubKey23 , NULL , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
keys . clear ( ) ;
keys . clear ( ) ;
keys . push_back ( key2 ) ; keys . push_back ( key1 ) ; // sigs must be in correct order
keys . push_back ( key2 ) ; keys . push_back ( key1 ) ; // sigs must be in correct order
CScript badsig2 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
CScript badsig2 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
BOOST_CHECK ( ! VerifyScript ( badsig2 , scriptPubKey23 , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK ( ! VerifyScript ( badsig2 , scriptPubKey23 , NULL , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
keys . clear ( ) ;
keys . clear ( ) ;
keys . push_back ( key3 ) ; keys . push_back ( key2 ) ; // sigs must be in correct order
keys . push_back ( key3 ) ; keys . push_back ( key2 ) ; // sigs must be in correct order
CScript badsig3 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
CScript badsig3 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
BOOST_CHECK ( ! VerifyScript ( badsig3 , scriptPubKey23 , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK ( ! VerifyScript ( badsig3 , scriptPubKey23 , NULL , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
keys . clear ( ) ;
keys . clear ( ) ;
keys . push_back ( key4 ) ; keys . push_back ( key2 ) ; // sigs must match pubkeys
keys . push_back ( key4 ) ; keys . push_back ( key2 ) ; // sigs must match pubkeys
CScript badsig4 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
CScript badsig4 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
BOOST_CHECK ( ! VerifyScript ( badsig4 , scriptPubKey23 , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK ( ! VerifyScript ( badsig4 , scriptPubKey23 , NULL , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
keys . clear ( ) ;
keys . clear ( ) ;
keys . push_back ( key1 ) ; keys . push_back ( key4 ) ; // sigs must match pubkeys
keys . push_back ( key1 ) ; keys . push_back ( key4 ) ; // sigs must match pubkeys
CScript badsig5 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
CScript badsig5 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
BOOST_CHECK ( ! VerifyScript ( badsig5 , scriptPubKey23 , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK ( ! VerifyScript ( badsig5 , scriptPubKey23 , NULL , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_EVAL_FALSE , ScriptErrorString ( err ) ) ;
keys . clear ( ) ; // Must have signatures
keys . clear ( ) ; // Must have signatures
CScript badsig6 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
CScript badsig6 = sign_multisig ( scriptPubKey23 , keys , txTo23 ) ;
BOOST_CHECK ( ! VerifyScript ( badsig6 , scriptPubKey23 , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK ( ! VerifyScript ( badsig6 , scriptPubKey23 , NULL , flags , MutableTransactionSignatureChecker ( & txTo23 , 0 ) , & err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_INVALID_STACK_OPERATION , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_INVALID_STACK_OPERATION , ScriptErrorString ( err ) ) ;
}
}
@ -999,7 +1003,7 @@ BOOST_AUTO_TEST_CASE(script_standard_push)
CScript script ;
CScript script ;
script < < i ;
script < < i ;
BOOST_CHECK_MESSAGE ( script . IsPushOnly ( ) , " Number " < < i < < " is not pure push. " ) ;
BOOST_CHECK_MESSAGE ( script . IsPushOnly ( ) , " Number " < < i < < " is not pure push. " ) ;
BOOST_CHECK_MESSAGE ( VerifyScript ( script , CScript ( ) < < OP_1 , SCRIPT_VERIFY_MINIMALDATA , BaseSignatureChecker ( ) , & err ) , " Number " < < i < < " push is not minimal data. " ) ;
BOOST_CHECK_MESSAGE ( VerifyScript ( script , CScript ( ) < < OP_1 , NULL , SCRIPT_VERIFY_MINIMALDATA , BaseSignatureChecker ( ) , & err ) , " Number " < < i < < " push is not minimal data. " ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
}
}
@ -1008,7 +1012,7 @@ BOOST_AUTO_TEST_CASE(script_standard_push)
CScript script ;
CScript script ;
script < < data ;
script < < data ;
BOOST_CHECK_MESSAGE ( script . IsPushOnly ( ) , " Length " < < i < < " is not pure push. " ) ;
BOOST_CHECK_MESSAGE ( script . IsPushOnly ( ) , " Length " < < i < < " is not pure push. " ) ;
BOOST_CHECK_MESSAGE ( VerifyScript ( script , CScript ( ) < < OP_1 , SCRIPT_VERIFY_MINIMALDATA , BaseSignatureChecker ( ) , & err ) , " Length " < < i < < " push is not minimal data. " ) ;
BOOST_CHECK_MESSAGE ( VerifyScript ( script , CScript ( ) < < OP_1 , NULL , SCRIPT_VERIFY_MINIMALDATA , BaseSignatureChecker ( ) , & err ) , " Length " < < i < < " push is not minimal data. " ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
BOOST_CHECK_MESSAGE ( err = = SCRIPT_ERR_OK , ScriptErrorString ( err ) ) ;
}
}
}
}