Introduce vpour to CTransaction.
Transactions of version 2 and above contain a `vpour` field which is a vector of `CPourTx` objects that embody our protocol. We introduce serialization primitives for boost::array (we intend for changing the amount of inputs and outputs in the circuit to be simple). SIGHASH_* operations hash this field like any other for now.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -6,6 +6,7 @@
|
||||
#include "streams.h"
|
||||
#include "hash.h"
|
||||
#include "test/test_bitcoin.h"
|
||||
#include "utilstrencodings.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -15,6 +16,39 @@ using namespace std;
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(serialize_tests, BasicTestingSetup)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(boost_arrays)
|
||||
{
|
||||
boost::array<std::string, 2> test_case = {string("zub"), string("baz")};
|
||||
CDataStream ss(SER_DISK, 0);
|
||||
ss << test_case;
|
||||
|
||||
auto hash = Hash(ss.begin(), ss.end());
|
||||
|
||||
BOOST_CHECK_MESSAGE("037a75620362617a" == HexStr(ss.begin(), ss.end()), HexStr(ss.begin(), ss.end()));
|
||||
BOOST_CHECK_MESSAGE(hash == uint256S("13cb12b2dd098dced0064fe4897c97f907ba3ed36ae470c2e7fc2b1111eba35a"), "actually got: " << hash.ToString());
|
||||
|
||||
{
|
||||
// note: boost array of size 2 should serialize to be the same as a tuple
|
||||
std::pair<std::string, std::string> test_case_2 = {string("zub"), string("baz")};
|
||||
|
||||
CDataStream ss2(SER_DISK, 0);
|
||||
ss2 << test_case_2;
|
||||
|
||||
auto hash2 = Hash(ss2.begin(), ss2.end());
|
||||
|
||||
BOOST_CHECK(hash == hash2);
|
||||
}
|
||||
|
||||
boost::array<std::string, 2> decoded_test_case;
|
||||
ss >> decoded_test_case;
|
||||
|
||||
BOOST_CHECK(decoded_test_case == test_case);
|
||||
|
||||
boost::array<int32_t, 2> test = {100, 200};
|
||||
|
||||
BOOST_CHECK_EQUAL(GetSerializeSize(test, 0, 0), 8);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(sizes)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(sizeof(char), GetSerializeSize(char(0), 0));
|
||||
|
||||
@@ -101,6 +101,7 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
|
||||
tx.nLockTime = (insecure_rand() % 2) ? insecure_rand() : 0;
|
||||
int ins = (insecure_rand() % 4) + 1;
|
||||
int outs = fSingle ? ins : (insecure_rand() % 4) + 1;
|
||||
int pours = (insecure_rand() % 4);
|
||||
for (int in = 0; in < ins; in++) {
|
||||
tx.vin.push_back(CTxIn());
|
||||
CTxIn &txin = tx.vin.back();
|
||||
@@ -115,6 +116,32 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
|
||||
txout.nValue = insecure_rand() % 100000000;
|
||||
RandomScript(txout.scriptPubKey);
|
||||
}
|
||||
if (tx.nVersion >= 2) {
|
||||
for (int pour = 0; pour < pours; pour++) {
|
||||
CPourTx pourtx;
|
||||
pourtx.vpub_old = insecure_rand() % 100000000;
|
||||
pourtx.vpub_new = insecure_rand() % 100000000;
|
||||
RandomScript(pourtx.scriptPubKey);
|
||||
RandomScript(pourtx.scriptSig);
|
||||
pourtx.anchor = GetRandHash();
|
||||
pourtx.serials[0] = GetRandHash();
|
||||
pourtx.serials[1] = GetRandHash();
|
||||
pourtx.ciphertexts[0] = {insecure_rand() % 100, insecure_rand() % 100};
|
||||
pourtx.ciphertexts[1] = {insecure_rand() % 100, insecure_rand() % 100};
|
||||
pourtx.macs[0] = GetRandHash();
|
||||
pourtx.macs[1] = GetRandHash();
|
||||
{
|
||||
std::vector<unsigned char> txt;
|
||||
int prooflen = insecure_rand() % 1000;
|
||||
for (int i = 0; i < prooflen; i++) {
|
||||
txt.push_back(insecure_rand() % 256);
|
||||
}
|
||||
pourtx.proof = std::string(txt.begin(), txt.end());
|
||||
}
|
||||
|
||||
tx.vpour.push_back(pourtx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(sighash_tests, BasicTestingSetup)
|
||||
|
||||
Reference in New Issue
Block a user