// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include "consensus/validation.h"
#include "data/sighash.json.h"
#include "main.h"
#include "random.h"
-#include "serialize.h"
-#include "script/script.h"
#include "script/interpreter.h"
+#include "script/script.h"
+#include "serialize.h"
+#include "test/test_bitcoin.h"
#include "util.h"
#include "version.h"
+#include "sodium.h"
#include <iostream>
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
if (nIn >= txTo.vin.size())
{
- printf("ERROR: SignatureHash() : nIn=%d out of range\n", nIn);
+ printf("ERROR: SignatureHash(): nIn=%d out of range\n", nIn);
return one;
}
CMutableTransaction txTmp(txTo);
- // In case concatenating two scripts ends up with two codeseparators,
- // or an extra one at the end, this prevents all those possible incompatibilities.
- scriptCode.FindAndDelete(CScript(OP_CODESEPARATOR));
-
// Blank out other inputs' signatures
for (unsigned int i = 0; i < txTmp.vin.size(); i++)
txTmp.vin[i].scriptSig = CScript();
unsigned int nOut = nIn;
if (nOut >= txTmp.vout.size())
{
- printf("ERROR: SignatureHash() : nOut=%d out of range\n", nOut);
+ printf("ERROR: SignatureHash(): nOut=%d out of range\n", nOut);
return one;
}
txTmp.vout.resize(nOut+1);
txTmp.vin.resize(1);
}
+ // Blank out the joinsplit signature.
+ memset(&txTmp.joinSplitSig[0], 0, txTmp.joinSplitSig.size());
+
// Serialize and hash
CHashWriter ss(SER_GETHASH, 0);
ss << txTmp << nHashType;
tx.nLockTime = (insecure_rand() % 2) ? insecure_rand() : 0;
int ins = (insecure_rand() % 4) + 1;
int outs = fSingle ? ins : (insecure_rand() % 4) + 1;
+ int joinsplits = (insecure_rand() % 4);
for (int in = 0; in < ins; in++) {
tx.vin.push_back(CTxIn());
CTxIn &txin = tx.vin.back();
txout.nValue = insecure_rand() % 100000000;
RandomScript(txout.scriptPubKey);
}
+ if (tx.nVersion >= 2) {
+ for (int js = 0; js < joinsplits; js++) {
+ JSDescription jsdesc;
+ if (insecure_rand() % 2 == 0) {
+ jsdesc.vpub_old = insecure_rand() % 100000000;
+ } else {
+ jsdesc.vpub_new = insecure_rand() % 100000000;
+ }
+
+ jsdesc.anchor = GetRandHash();
+ jsdesc.nullifiers[0] = GetRandHash();
+ jsdesc.nullifiers[1] = GetRandHash();
+ jsdesc.ephemeralKey = GetRandHash();
+ jsdesc.randomSeed = GetRandHash();
+ randombytes_buf(jsdesc.ciphertexts[0].begin(), jsdesc.ciphertexts[0].size());
+ randombytes_buf(jsdesc.ciphertexts[1].begin(), jsdesc.ciphertexts[1].size());
+ jsdesc.proof = libzcash::ZCProof::random_invalid();
+ jsdesc.macs[0] = GetRandHash();
+ jsdesc.macs[1] = GetRandHash();
+
+ tx.vjoinsplit.push_back(jsdesc);
+ }
+
+ unsigned char joinSplitPrivKey[crypto_sign_SECRETKEYBYTES];
+ crypto_sign_keypair(tx.joinSplitPubKey.begin(), joinSplitPrivKey);
+
+ // Empty output script.
+ CScript scriptCode;
+ CTransaction signTx(tx);
+ uint256 dataToBeSigned = SignatureHash(scriptCode, signTx, NOT_AN_INPUT, SIGHASH_ALL);
+
+ assert(crypto_sign_detached(&tx.joinSplitSig[0], NULL,
+ dataToBeSigned.begin(), 32,
+ joinSplitPrivKey
+ ) == 0);
+ }
}
-BOOST_AUTO_TEST_SUITE(sighash_tests)
+BOOST_FIXTURE_TEST_SUITE(sighash_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(sighash_test)
{
stream >> tx;
CValidationState state;
- BOOST_CHECK_MESSAGE(CheckTransaction(tx, state), strTest);
+ BOOST_CHECK_MESSAGE(CheckTransactionWithoutProofVerification(tx, state), strTest);
BOOST_CHECK(state.IsValid());
std::vector<unsigned char> raw = ParseHex(raw_script);