2014-03-18 10:11:00 +01:00
|
|
|
// Copyright (c) 2012-2013 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "script.h"
|
|
|
|
|
|
|
|
#include "key.h"
|
|
|
|
#include "keystore.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "script.h"
|
2012-01-05 03:40:52 +01:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
2012-01-05 03:40:52 +01:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
// Test routines internal to script.cpp:
|
|
|
|
extern uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType);
|
|
|
|
|
|
|
|
// Helpers:
|
|
|
|
static std::vector<unsigned char>
|
|
|
|
Serialize(const CScript& s)
|
|
|
|
{
|
|
|
|
std::vector<unsigned char> sSerialized(s);
|
|
|
|
return sSerialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
Verify(const CScript& scriptSig, const CScript& scriptPubKey, bool fStrict)
|
|
|
|
{
|
|
|
|
// Create dummy to/from transactions:
|
|
|
|
CTransaction txFrom;
|
|
|
|
txFrom.vout.resize(1);
|
|
|
|
txFrom.vout[0].scriptPubKey = scriptPubKey;
|
|
|
|
|
|
|
|
CTransaction txTo;
|
|
|
|
txTo.vin.resize(1);
|
|
|
|
txTo.vout.resize(1);
|
|
|
|
txTo.vin[0].prevout.n = 0;
|
|
|
|
txTo.vin[0].prevout.hash = txFrom.GetHash();
|
|
|
|
txTo.vin[0].scriptSig = scriptSig;
|
|
|
|
txTo.vout[0].nValue = 1;
|
|
|
|
|
2012-11-13 23:03:25 +01:00
|
|
|
return VerifyScript(scriptSig, scriptPubKey, txTo, 0, fStrict ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE, 0);
|
2012-01-05 03:40:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(script_P2SH_tests)
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(sign)
|
|
|
|
{
|
|
|
|
// Pay-to-script-hash looks like this:
|
|
|
|
// scriptSig: <sig> <sig...> <serialized_script>
|
|
|
|
// scriptPubKey: HASH160 <hash> EQUAL
|
|
|
|
|
|
|
|
// Test SignSignature() (and therefore the version of Solver() that signs transactions)
|
|
|
|
CBasicKeyStore keystore;
|
|
|
|
CKey key[4];
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
2012-02-20 18:32:33 +01:00
|
|
|
key[i].MakeNewKey(true);
|
2012-01-05 03:40:52 +01:00
|
|
|
keystore.AddKey(key[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 8 Scripts: checking all combinations of
|
|
|
|
// different keys, straight/P2SH, pubkey/pubkeyhash
|
|
|
|
CScript standardScripts[4];
|
|
|
|
standardScripts[0] << key[0].GetPubKey() << OP_CHECKSIG;
|
2012-05-14 23:44:52 +02:00
|
|
|
standardScripts[1].SetDestination(key[1].GetPubKey().GetID());
|
2012-01-05 03:40:52 +01:00
|
|
|
standardScripts[2] << key[1].GetPubKey() << OP_CHECKSIG;
|
2012-05-14 23:44:52 +02:00
|
|
|
standardScripts[3].SetDestination(key[2].GetPubKey().GetID());
|
2012-01-05 03:40:52 +01:00
|
|
|
CScript evalScripts[4];
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
keystore.AddCScript(standardScripts[i]);
|
2012-05-14 23:44:52 +02:00
|
|
|
evalScripts[i].SetDestination(standardScripts[i].GetID());
|
2012-01-05 03:40:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CTransaction txFrom; // Funding transaction:
|
2013-06-23 08:05:25 +02:00
|
|
|
string reason;
|
2012-01-05 03:40:52 +01:00
|
|
|
txFrom.vout.resize(8);
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
txFrom.vout[i].scriptPubKey = evalScripts[i];
|
2013-04-25 00:27:00 +02:00
|
|
|
txFrom.vout[i].nValue = COIN;
|
2012-01-05 03:40:52 +01:00
|
|
|
txFrom.vout[i+4].scriptPubKey = standardScripts[i];
|
2013-04-25 00:27:00 +02:00
|
|
|
txFrom.vout[i+4].nValue = COIN;
|
2012-01-05 03:40:52 +01:00
|
|
|
}
|
2013-06-23 08:05:25 +02:00
|
|
|
BOOST_CHECK(IsStandardTx(txFrom, reason));
|
2012-01-05 03:40:52 +01:00
|
|
|
|
|
|
|
CTransaction txTo[8]; // Spending transactions
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
txTo[i].vin.resize(1);
|
|
|
|
txTo[i].vout.resize(1);
|
|
|
|
txTo[i].vin[0].prevout.n = i;
|
|
|
|
txTo[i].vin[0].prevout.hash = txFrom.GetHash();
|
|
|
|
txTo[i].vout[0].nValue = 1;
|
|
|
|
BOOST_CHECK_MESSAGE(IsMine(keystore, txFrom.vout[i].scriptPubKey), strprintf("IsMine %d", i));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
BOOST_CHECK_MESSAGE(SignSignature(keystore, txFrom, txTo[i], 0), strprintf("SignSignature %d", i));
|
|
|
|
}
|
|
|
|
// All of the above should be OK, and the txTos have valid signatures
|
|
|
|
// Check to make sure signature verification fails if we use the wrong ScriptSig:
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
for (int j = 0; j < 8; j++)
|
|
|
|
{
|
|
|
|
CScript sigSave = txTo[i].vin[0].scriptSig;
|
|
|
|
txTo[i].vin[0].scriptSig = txTo[j].vin[0].scriptSig;
|
2012-11-13 23:03:25 +01:00
|
|
|
bool sigOK = VerifySignature(CCoins(txFrom, 0), txTo[i], 0, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC, 0);
|
2012-01-05 03:40:52 +01:00
|
|
|
if (i == j)
|
|
|
|
BOOST_CHECK_MESSAGE(sigOK, strprintf("VerifySignature %d %d", i, j));
|
|
|
|
else
|
|
|
|
BOOST_CHECK_MESSAGE(!sigOK, strprintf("VerifySignature %d %d", i, j));
|
|
|
|
txTo[i].vin[0].scriptSig = sigSave;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(norecurse)
|
|
|
|
{
|
|
|
|
// Make sure only the outer pay-to-script-hash does the
|
|
|
|
// extra-validation thing:
|
|
|
|
CScript invalidAsScript;
|
|
|
|
invalidAsScript << OP_INVALIDOPCODE << OP_INVALIDOPCODE;
|
|
|
|
|
|
|
|
CScript p2sh;
|
2012-05-14 23:44:52 +02:00
|
|
|
p2sh.SetDestination(invalidAsScript.GetID());
|
2012-01-05 03:40:52 +01:00
|
|
|
|
|
|
|
CScript scriptSig;
|
|
|
|
scriptSig << Serialize(invalidAsScript);
|
|
|
|
|
|
|
|
// Should not verify, because it will try to execute OP_INVALIDOPCODE
|
|
|
|
BOOST_CHECK(!Verify(scriptSig, p2sh, true));
|
|
|
|
|
2012-07-26 02:48:39 +02:00
|
|
|
// Try to recur, and verification should succeed because
|
2012-01-05 03:40:52 +01:00
|
|
|
// the inner HASH160 <> EQUAL should only check the hash:
|
|
|
|
CScript p2sh2;
|
2012-05-14 23:44:52 +02:00
|
|
|
p2sh2.SetDestination(p2sh.GetID());
|
2012-01-05 03:40:52 +01:00
|
|
|
CScript scriptSig2;
|
|
|
|
scriptSig2 << Serialize(invalidAsScript) << Serialize(p2sh);
|
|
|
|
|
|
|
|
BOOST_CHECK(Verify(scriptSig2, p2sh2, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(set)
|
|
|
|
{
|
|
|
|
// Test the CScript::Set* methods
|
|
|
|
CBasicKeyStore keystore;
|
|
|
|
CKey key[4];
|
2013-05-01 06:52:05 +02:00
|
|
|
std::vector<CPubKey> keys;
|
2012-01-05 03:40:52 +01:00
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
2012-02-20 18:32:33 +01:00
|
|
|
key[i].MakeNewKey(true);
|
2012-01-05 03:40:52 +01:00
|
|
|
keystore.AddKey(key[i]);
|
2013-05-01 06:52:05 +02:00
|
|
|
keys.push_back(key[i].GetPubKey());
|
2012-01-05 03:40:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CScript inner[4];
|
2012-05-14 23:44:52 +02:00
|
|
|
inner[0].SetDestination(key[0].GetPubKey().GetID());
|
2013-05-01 06:52:05 +02:00
|
|
|
inner[1].SetMultisig(2, std::vector<CPubKey>(keys.begin(), keys.begin()+2));
|
|
|
|
inner[2].SetMultisig(1, std::vector<CPubKey>(keys.begin(), keys.begin()+2));
|
|
|
|
inner[3].SetMultisig(2, std::vector<CPubKey>(keys.begin(), keys.begin()+3));
|
2012-01-05 03:40:52 +01:00
|
|
|
|
|
|
|
CScript outer[4];
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
2012-05-14 23:44:52 +02:00
|
|
|
outer[i].SetDestination(inner[i].GetID());
|
2012-01-05 03:40:52 +01:00
|
|
|
keystore.AddCScript(inner[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
CTransaction txFrom; // Funding transaction:
|
2013-06-23 08:05:25 +02:00
|
|
|
string reason;
|
2012-01-05 03:40:52 +01:00
|
|
|
txFrom.vout.resize(4);
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
txFrom.vout[i].scriptPubKey = outer[i];
|
2013-04-25 00:27:00 +02:00
|
|
|
txFrom.vout[i].nValue = CENT;
|
2012-01-05 03:40:52 +01:00
|
|
|
}
|
2013-06-23 08:05:25 +02:00
|
|
|
BOOST_CHECK(IsStandardTx(txFrom, reason));
|
2012-01-05 03:40:52 +01:00
|
|
|
|
|
|
|
CTransaction txTo[4]; // Spending transactions
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
txTo[i].vin.resize(1);
|
|
|
|
txTo[i].vout.resize(1);
|
|
|
|
txTo[i].vin[0].prevout.n = i;
|
|
|
|
txTo[i].vin[0].prevout.hash = txFrom.GetHash();
|
2013-04-25 00:27:00 +02:00
|
|
|
txTo[i].vout[0].nValue = 1*CENT;
|
2012-01-05 03:40:52 +01:00
|
|
|
txTo[i].vout[0].scriptPubKey = inner[i];
|
|
|
|
BOOST_CHECK_MESSAGE(IsMine(keystore, txFrom.vout[i].scriptPubKey), strprintf("IsMine %d", i));
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
BOOST_CHECK_MESSAGE(SignSignature(keystore, txFrom, txTo[i], 0), strprintf("SignSignature %d", i));
|
2013-06-23 08:05:25 +02:00
|
|
|
BOOST_CHECK_MESSAGE(IsStandardTx(txTo[i], reason), strprintf("txTo[%d].IsStandard", i));
|
2012-01-05 03:40:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(is)
|
|
|
|
{
|
|
|
|
// Test CScript::IsPayToScriptHash()
|
|
|
|
uint160 dummy;
|
|
|
|
CScript p2sh;
|
|
|
|
p2sh << OP_HASH160 << dummy << OP_EQUAL;
|
|
|
|
BOOST_CHECK(p2sh.IsPayToScriptHash());
|
|
|
|
|
|
|
|
// Not considered pay-to-script-hash if using one of the OP_PUSHDATA opcodes:
|
|
|
|
static const unsigned char direct[] = { OP_HASH160, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUAL };
|
|
|
|
BOOST_CHECK(CScript(direct, direct+sizeof(direct)).IsPayToScriptHash());
|
|
|
|
static const unsigned char pushdata1[] = { OP_HASH160, OP_PUSHDATA1, 20, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUAL };
|
|
|
|
BOOST_CHECK(!CScript(pushdata1, pushdata1+sizeof(pushdata1)).IsPayToScriptHash());
|
|
|
|
static const unsigned char pushdata2[] = { OP_HASH160, OP_PUSHDATA2, 20,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUAL };
|
|
|
|
BOOST_CHECK(!CScript(pushdata2, pushdata2+sizeof(pushdata2)).IsPayToScriptHash());
|
|
|
|
static const unsigned char pushdata4[] = { OP_HASH160, OP_PUSHDATA4, 20,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, OP_EQUAL };
|
|
|
|
BOOST_CHECK(!CScript(pushdata4, pushdata4+sizeof(pushdata4)).IsPayToScriptHash());
|
|
|
|
|
|
|
|
CScript not_p2sh;
|
|
|
|
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
|
|
|
|
|
|
|
not_p2sh.clear(); not_p2sh << OP_HASH160 << dummy << dummy << OP_EQUAL;
|
|
|
|
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
|
|
|
|
|
|
|
not_p2sh.clear(); not_p2sh << OP_NOP << dummy << OP_EQUAL;
|
|
|
|
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
|
|
|
|
|
|
|
not_p2sh.clear(); not_p2sh << OP_HASH160 << dummy << OP_CHECKSIG;
|
|
|
|
BOOST_CHECK(!not_p2sh.IsPayToScriptHash());
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(switchover)
|
|
|
|
{
|
2012-07-26 02:48:39 +02:00
|
|
|
// Test switch over code
|
2012-01-05 03:40:52 +01:00
|
|
|
CScript notValid;
|
|
|
|
notValid << OP_11 << OP_12 << OP_EQUALVERIFY;
|
|
|
|
CScript scriptSig;
|
|
|
|
scriptSig << Serialize(notValid);
|
|
|
|
|
|
|
|
CScript fund;
|
2012-05-14 23:44:52 +02:00
|
|
|
fund.SetDestination(notValid.GetID());
|
2012-01-05 03:40:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Validation should succeed under old rules (hash is correct):
|
|
|
|
BOOST_CHECK(Verify(scriptSig, fund, false));
|
|
|
|
// Fail under new:
|
|
|
|
BOOST_CHECK(!Verify(scriptSig, fund, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(AreInputsStandard)
|
|
|
|
{
|
Ultraprune
This switches bitcoin's transaction/block verification logic to use a
"coin database", which contains all unredeemed transaction output scripts,
amounts and heights.
The name ultraprune comes from the fact that instead of a full transaction
index, we only (need to) keep an index with unspent outputs. For now, the
blocks themselves are kept as usual, although they are only necessary for
serving, rescanning and reorganizing.
The basic datastructures are CCoins (representing the coins of a single
transaction), and CCoinsView (representing a state of the coins database).
There are several implementations for CCoinsView. A dummy, one backed by
the coins database (coins.dat), one backed by the memory pool, and one
that adds a cache on top of it. FetchInputs, ConnectInputs, ConnectBlock,
DisconnectBlock, ... now operate on a generic CCoinsView.
The block switching logic now builds a single cached CCoinsView with
changes to be committed to the database before any changes are made.
This means no uncommitted changes are ever read from the database, and
should ease the transition to another database layer which does not
support transactions (but does support atomic writes), like LevelDB.
For the getrawtransaction() RPC call, access to a txid-to-disk index
would be preferable. As this index is not necessary or even useful
for any other part of the implementation, it is not provided. Instead,
getrawtransaction() uses the coin database to find the block height,
and then scans that block to find the requested transaction. This is
slow, but should suffice for debug purposes.
2012-07-01 18:54:00 +02:00
|
|
|
CCoinsView coinsDummy;
|
|
|
|
CCoinsViewCache coins(coinsDummy);
|
2012-01-05 03:40:52 +01:00
|
|
|
CBasicKeyStore keystore;
|
|
|
|
CKey key[3];
|
2013-05-01 06:52:05 +02:00
|
|
|
vector<CPubKey> keys;
|
2012-01-05 03:40:52 +01:00
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
2012-02-20 18:32:33 +01:00
|
|
|
key[i].MakeNewKey(true);
|
2012-01-05 03:40:52 +01:00
|
|
|
keystore.AddKey(key[i]);
|
2013-05-01 06:52:05 +02:00
|
|
|
keys.push_back(key[i].GetPubKey());
|
2012-01-05 03:40:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CTransaction txFrom;
|
2012-01-20 23:07:40 +01:00
|
|
|
txFrom.vout.resize(6);
|
2012-01-05 03:40:52 +01:00
|
|
|
|
|
|
|
// First three are standard:
|
2012-05-14 23:44:52 +02:00
|
|
|
CScript pay1; pay1.SetDestination(key[0].GetPubKey().GetID());
|
2012-01-05 03:40:52 +01:00
|
|
|
keystore.AddCScript(pay1);
|
2012-05-14 23:44:52 +02:00
|
|
|
CScript payScriptHash1; payScriptHash1.SetDestination(pay1.GetID());
|
2012-01-05 03:40:52 +01:00
|
|
|
CScript pay1of3; pay1of3.SetMultisig(1, keys);
|
|
|
|
|
|
|
|
txFrom.vout[0].scriptPubKey = payScriptHash1;
|
Ultraprune
This switches bitcoin's transaction/block verification logic to use a
"coin database", which contains all unredeemed transaction output scripts,
amounts and heights.
The name ultraprune comes from the fact that instead of a full transaction
index, we only (need to) keep an index with unspent outputs. For now, the
blocks themselves are kept as usual, although they are only necessary for
serving, rescanning and reorganizing.
The basic datastructures are CCoins (representing the coins of a single
transaction), and CCoinsView (representing a state of the coins database).
There are several implementations for CCoinsView. A dummy, one backed by
the coins database (coins.dat), one backed by the memory pool, and one
that adds a cache on top of it. FetchInputs, ConnectInputs, ConnectBlock,
DisconnectBlock, ... now operate on a generic CCoinsView.
The block switching logic now builds a single cached CCoinsView with
changes to be committed to the database before any changes are made.
This means no uncommitted changes are ever read from the database, and
should ease the transition to another database layer which does not
support transactions (but does support atomic writes), like LevelDB.
For the getrawtransaction() RPC call, access to a txid-to-disk index
would be preferable. As this index is not necessary or even useful
for any other part of the implementation, it is not provided. Instead,
getrawtransaction() uses the coin database to find the block height,
and then scans that block to find the requested transaction. This is
slow, but should suffice for debug purposes.
2012-07-01 18:54:00 +02:00
|
|
|
txFrom.vout[0].nValue = 1000;
|
2012-01-05 03:40:52 +01:00
|
|
|
txFrom.vout[1].scriptPubKey = pay1;
|
Ultraprune
This switches bitcoin's transaction/block verification logic to use a
"coin database", which contains all unredeemed transaction output scripts,
amounts and heights.
The name ultraprune comes from the fact that instead of a full transaction
index, we only (need to) keep an index with unspent outputs. For now, the
blocks themselves are kept as usual, although they are only necessary for
serving, rescanning and reorganizing.
The basic datastructures are CCoins (representing the coins of a single
transaction), and CCoinsView (representing a state of the coins database).
There are several implementations for CCoinsView. A dummy, one backed by
the coins database (coins.dat), one backed by the memory pool, and one
that adds a cache on top of it. FetchInputs, ConnectInputs, ConnectBlock,
DisconnectBlock, ... now operate on a generic CCoinsView.
The block switching logic now builds a single cached CCoinsView with
changes to be committed to the database before any changes are made.
This means no uncommitted changes are ever read from the database, and
should ease the transition to another database layer which does not
support transactions (but does support atomic writes), like LevelDB.
For the getrawtransaction() RPC call, access to a txid-to-disk index
would be preferable. As this index is not necessary or even useful
for any other part of the implementation, it is not provided. Instead,
getrawtransaction() uses the coin database to find the block height,
and then scans that block to find the requested transaction. This is
slow, but should suffice for debug purposes.
2012-07-01 18:54:00 +02:00
|
|
|
txFrom.vout[1].nValue = 2000;
|
2012-01-05 03:40:52 +01:00
|
|
|
txFrom.vout[2].scriptPubKey = pay1of3;
|
Ultraprune
This switches bitcoin's transaction/block verification logic to use a
"coin database", which contains all unredeemed transaction output scripts,
amounts and heights.
The name ultraprune comes from the fact that instead of a full transaction
index, we only (need to) keep an index with unspent outputs. For now, the
blocks themselves are kept as usual, although they are only necessary for
serving, rescanning and reorganizing.
The basic datastructures are CCoins (representing the coins of a single
transaction), and CCoinsView (representing a state of the coins database).
There are several implementations for CCoinsView. A dummy, one backed by
the coins database (coins.dat), one backed by the memory pool, and one
that adds a cache on top of it. FetchInputs, ConnectInputs, ConnectBlock,
DisconnectBlock, ... now operate on a generic CCoinsView.
The block switching logic now builds a single cached CCoinsView with
changes to be committed to the database before any changes are made.
This means no uncommitted changes are ever read from the database, and
should ease the transition to another database layer which does not
support transactions (but does support atomic writes), like LevelDB.
For the getrawtransaction() RPC call, access to a txid-to-disk index
would be preferable. As this index is not necessary or even useful
for any other part of the implementation, it is not provided. Instead,
getrawtransaction() uses the coin database to find the block height,
and then scans that block to find the requested transaction. This is
slow, but should suffice for debug purposes.
2012-07-01 18:54:00 +02:00
|
|
|
txFrom.vout[2].nValue = 3000;
|
2012-01-05 03:40:52 +01:00
|
|
|
|
2012-01-20 23:07:40 +01:00
|
|
|
// Last three non-standard:
|
2012-01-05 03:40:52 +01:00
|
|
|
CScript empty;
|
|
|
|
keystore.AddCScript(empty);
|
|
|
|
txFrom.vout[3].scriptPubKey = empty;
|
Ultraprune
This switches bitcoin's transaction/block verification logic to use a
"coin database", which contains all unredeemed transaction output scripts,
amounts and heights.
The name ultraprune comes from the fact that instead of a full transaction
index, we only (need to) keep an index with unspent outputs. For now, the
blocks themselves are kept as usual, although they are only necessary for
serving, rescanning and reorganizing.
The basic datastructures are CCoins (representing the coins of a single
transaction), and CCoinsView (representing a state of the coins database).
There are several implementations for CCoinsView. A dummy, one backed by
the coins database (coins.dat), one backed by the memory pool, and one
that adds a cache on top of it. FetchInputs, ConnectInputs, ConnectBlock,
DisconnectBlock, ... now operate on a generic CCoinsView.
The block switching logic now builds a single cached CCoinsView with
changes to be committed to the database before any changes are made.
This means no uncommitted changes are ever read from the database, and
should ease the transition to another database layer which does not
support transactions (but does support atomic writes), like LevelDB.
For the getrawtransaction() RPC call, access to a txid-to-disk index
would be preferable. As this index is not necessary or even useful
for any other part of the implementation, it is not provided. Instead,
getrawtransaction() uses the coin database to find the block height,
and then scans that block to find the requested transaction. This is
slow, but should suffice for debug purposes.
2012-07-01 18:54:00 +02:00
|
|
|
txFrom.vout[3].nValue = 4000;
|
2012-01-05 03:40:52 +01:00
|
|
|
// Can't use SetPayToScriptHash, it checks for the empty Script. So:
|
|
|
|
txFrom.vout[4].scriptPubKey << OP_HASH160 << Hash160(empty) << OP_EQUAL;
|
Ultraprune
This switches bitcoin's transaction/block verification logic to use a
"coin database", which contains all unredeemed transaction output scripts,
amounts and heights.
The name ultraprune comes from the fact that instead of a full transaction
index, we only (need to) keep an index with unspent outputs. For now, the
blocks themselves are kept as usual, although they are only necessary for
serving, rescanning and reorganizing.
The basic datastructures are CCoins (representing the coins of a single
transaction), and CCoinsView (representing a state of the coins database).
There are several implementations for CCoinsView. A dummy, one backed by
the coins database (coins.dat), one backed by the memory pool, and one
that adds a cache on top of it. FetchInputs, ConnectInputs, ConnectBlock,
DisconnectBlock, ... now operate on a generic CCoinsView.
The block switching logic now builds a single cached CCoinsView with
changes to be committed to the database before any changes are made.
This means no uncommitted changes are ever read from the database, and
should ease the transition to another database layer which does not
support transactions (but does support atomic writes), like LevelDB.
For the getrawtransaction() RPC call, access to a txid-to-disk index
would be preferable. As this index is not necessary or even useful
for any other part of the implementation, it is not provided. Instead,
getrawtransaction() uses the coin database to find the block height,
and then scans that block to find the requested transaction. This is
slow, but should suffice for debug purposes.
2012-07-01 18:54:00 +02:00
|
|
|
txFrom.vout[4].nValue = 5000;
|
2012-01-20 23:07:40 +01:00
|
|
|
CScript oneOfEleven;
|
|
|
|
oneOfEleven << OP_1;
|
|
|
|
for (int i = 0; i < 11; i++)
|
|
|
|
oneOfEleven << key[0].GetPubKey();
|
|
|
|
oneOfEleven << OP_11 << OP_CHECKMULTISIG;
|
2012-05-14 23:44:52 +02:00
|
|
|
txFrom.vout[5].scriptPubKey.SetDestination(oneOfEleven.GetID());
|
Ultraprune
This switches bitcoin's transaction/block verification logic to use a
"coin database", which contains all unredeemed transaction output scripts,
amounts and heights.
The name ultraprune comes from the fact that instead of a full transaction
index, we only (need to) keep an index with unspent outputs. For now, the
blocks themselves are kept as usual, although they are only necessary for
serving, rescanning and reorganizing.
The basic datastructures are CCoins (representing the coins of a single
transaction), and CCoinsView (representing a state of the coins database).
There are several implementations for CCoinsView. A dummy, one backed by
the coins database (coins.dat), one backed by the memory pool, and one
that adds a cache on top of it. FetchInputs, ConnectInputs, ConnectBlock,
DisconnectBlock, ... now operate on a generic CCoinsView.
The block switching logic now builds a single cached CCoinsView with
changes to be committed to the database before any changes are made.
This means no uncommitted changes are ever read from the database, and
should ease the transition to another database layer which does not
support transactions (but does support atomic writes), like LevelDB.
For the getrawtransaction() RPC call, access to a txid-to-disk index
would be preferable. As this index is not necessary or even useful
for any other part of the implementation, it is not provided. Instead,
getrawtransaction() uses the coin database to find the block height,
and then scans that block to find the requested transaction. This is
slow, but should suffice for debug purposes.
2012-07-01 18:54:00 +02:00
|
|
|
txFrom.vout[5].nValue = 6000;
|
2012-01-05 03:40:52 +01:00
|
|
|
|
Ultraprune
This switches bitcoin's transaction/block verification logic to use a
"coin database", which contains all unredeemed transaction output scripts,
amounts and heights.
The name ultraprune comes from the fact that instead of a full transaction
index, we only (need to) keep an index with unspent outputs. For now, the
blocks themselves are kept as usual, although they are only necessary for
serving, rescanning and reorganizing.
The basic datastructures are CCoins (representing the coins of a single
transaction), and CCoinsView (representing a state of the coins database).
There are several implementations for CCoinsView. A dummy, one backed by
the coins database (coins.dat), one backed by the memory pool, and one
that adds a cache on top of it. FetchInputs, ConnectInputs, ConnectBlock,
DisconnectBlock, ... now operate on a generic CCoinsView.
The block switching logic now builds a single cached CCoinsView with
changes to be committed to the database before any changes are made.
This means no uncommitted changes are ever read from the database, and
should ease the transition to another database layer which does not
support transactions (but does support atomic writes), like LevelDB.
For the getrawtransaction() RPC call, access to a txid-to-disk index
would be preferable. As this index is not necessary or even useful
for any other part of the implementation, it is not provided. Instead,
getrawtransaction() uses the coin database to find the block height,
and then scans that block to find the requested transaction. This is
slow, but should suffice for debug purposes.
2012-07-01 18:54:00 +02:00
|
|
|
coins.SetCoins(txFrom.GetHash(), CCoins(txFrom, 0));
|
2012-01-05 03:40:52 +01:00
|
|
|
|
|
|
|
CTransaction txTo;
|
|
|
|
txTo.vout.resize(1);
|
2012-05-14 23:44:52 +02:00
|
|
|
txTo.vout[0].scriptPubKey.SetDestination(key[1].GetPubKey().GetID());
|
2012-01-05 03:40:52 +01:00
|
|
|
|
|
|
|
txTo.vin.resize(3);
|
|
|
|
txTo.vin[0].prevout.n = 0;
|
|
|
|
txTo.vin[0].prevout.hash = txFrom.GetHash();
|
|
|
|
BOOST_CHECK(SignSignature(keystore, txFrom, txTo, 0));
|
|
|
|
txTo.vin[1].prevout.n = 1;
|
|
|
|
txTo.vin[1].prevout.hash = txFrom.GetHash();
|
|
|
|
BOOST_CHECK(SignSignature(keystore, txFrom, txTo, 1));
|
|
|
|
txTo.vin[2].prevout.n = 2;
|
|
|
|
txTo.vin[2].prevout.hash = txFrom.GetHash();
|
|
|
|
BOOST_CHECK(SignSignature(keystore, txFrom, txTo, 2));
|
|
|
|
|
2013-01-08 13:17:15 +01:00
|
|
|
BOOST_CHECK(::AreInputsStandard(txTo, coins));
|
|
|
|
BOOST_CHECK_EQUAL(GetP2SHSigOpCount(txTo, coins), 1U);
|
2012-01-05 03:40:52 +01:00
|
|
|
|
2012-01-19 19:30:54 +01:00
|
|
|
// Make sure adding crap to the scriptSigs makes them non-standard:
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
CScript t = txTo.vin[i].scriptSig;
|
|
|
|
txTo.vin[i].scriptSig = (CScript() << 11) + t;
|
2013-01-08 13:17:15 +01:00
|
|
|
BOOST_CHECK(!::AreInputsStandard(txTo, coins));
|
2012-01-19 19:30:54 +01:00
|
|
|
txTo.vin[i].scriptSig = t;
|
|
|
|
}
|
|
|
|
|
2012-01-05 03:40:52 +01:00
|
|
|
CTransaction txToNonStd;
|
|
|
|
txToNonStd.vout.resize(1);
|
2012-05-14 23:44:52 +02:00
|
|
|
txToNonStd.vout[0].scriptPubKey.SetDestination(key[1].GetPubKey().GetID());
|
Ultraprune
This switches bitcoin's transaction/block verification logic to use a
"coin database", which contains all unredeemed transaction output scripts,
amounts and heights.
The name ultraprune comes from the fact that instead of a full transaction
index, we only (need to) keep an index with unspent outputs. For now, the
blocks themselves are kept as usual, although they are only necessary for
serving, rescanning and reorganizing.
The basic datastructures are CCoins (representing the coins of a single
transaction), and CCoinsView (representing a state of the coins database).
There are several implementations for CCoinsView. A dummy, one backed by
the coins database (coins.dat), one backed by the memory pool, and one
that adds a cache on top of it. FetchInputs, ConnectInputs, ConnectBlock,
DisconnectBlock, ... now operate on a generic CCoinsView.
The block switching logic now builds a single cached CCoinsView with
changes to be committed to the database before any changes are made.
This means no uncommitted changes are ever read from the database, and
should ease the transition to another database layer which does not
support transactions (but does support atomic writes), like LevelDB.
For the getrawtransaction() RPC call, access to a txid-to-disk index
would be preferable. As this index is not necessary or even useful
for any other part of the implementation, it is not provided. Instead,
getrawtransaction() uses the coin database to find the block height,
and then scans that block to find the requested transaction. This is
slow, but should suffice for debug purposes.
2012-07-01 18:54:00 +02:00
|
|
|
txToNonStd.vout[0].nValue = 1000;
|
2012-01-20 23:07:40 +01:00
|
|
|
txToNonStd.vin.resize(2);
|
2012-01-05 03:40:52 +01:00
|
|
|
txToNonStd.vin[0].prevout.n = 4;
|
|
|
|
txToNonStd.vin[0].prevout.hash = txFrom.GetHash();
|
|
|
|
txToNonStd.vin[0].scriptSig << Serialize(empty);
|
2012-01-20 23:07:40 +01:00
|
|
|
txToNonStd.vin[1].prevout.n = 5;
|
|
|
|
txToNonStd.vin[1].prevout.hash = txFrom.GetHash();
|
|
|
|
txToNonStd.vin[1].scriptSig << OP_0 << Serialize(oneOfEleven);
|
2012-01-05 03:40:52 +01:00
|
|
|
|
2013-01-08 13:17:15 +01:00
|
|
|
BOOST_CHECK(!::AreInputsStandard(txToNonStd, coins));
|
|
|
|
BOOST_CHECK_EQUAL(GetP2SHSigOpCount(txToNonStd, coins), 11U);
|
2012-01-05 03:40:52 +01:00
|
|
|
|
|
|
|
txToNonStd.vin[0].scriptSig.clear();
|
2013-01-08 13:17:15 +01:00
|
|
|
BOOST_CHECK(!::AreInputsStandard(txToNonStd, coins));
|
2012-01-05 03:40:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|