wallet|cj|tests: Adjust Dash-specific code to create signatures with Low R too

This commit is contained in:
UdjinM6 2021-07-04 04:35:53 +03:00
parent 90154c6074
commit e7d5f4087b
No known key found for this signature in database
GPG Key ID: 83592BD1400D58D9
3 changed files with 11 additions and 32 deletions

View File

@ -135,19 +135,9 @@ CTransactionBuilder::CTransactionBuilder(std::shared_ptr<CWallet> pwalletIn, con
CPubKey dummyPubkey = pwallet->GenerateNewKey(dummyBatch, 0, false); CPubKey dummyPubkey = pwallet->GenerateNewKey(dummyBatch, 0, false);
dummyBatch.TxnAbort(); dummyBatch.TxnAbort();
dummyScript = ::GetScriptForDestination(dummyPubkey.GetID()); dummyScript = ::GetScriptForDestination(dummyPubkey.GetID());
// Create dummy signatures for all inputs // Calculate required bytes for the dummy signed tx with tallyItem's inputs only
int nIn = 0; nBytesBase = CalculateMaximumSignedTxSize(dummyTx, pwallet.get(), false);
for (const auto& coin : tallyItem.vecInputCoins) {
const CScript& scriptPubKey = coin.txout.scriptPubKey;
SignatureData sigdata;
bool res = ProduceSignature(*pwallet, DUMMY_SIGNATURE_CREATOR, scriptPubKey, sigdata);
assert(res);
UpdateInput(dummyTx.vin[nIn], sigdata);
nIn++;
}
} }
// Calculate required bytes for the dummy tx with tallyItem's inputs only
nBytesBase = ::GetSerializeSize(dummyTx, SER_NETWORK, PROTOCOL_VERSION);
// Calculate the output size // Calculate the output size
nBytesOutput = ::GetSerializeSize(CTxOut(0, dummyScript), SER_NETWORK, PROTOCOL_VERSION); nBytesOutput = ::GetSerializeSize(CTxOut(0, dummyScript), SER_NETWORK, PROTOCOL_VERSION);
// Just to make sure.. // Just to make sure..

View File

@ -107,20 +107,20 @@ public:
BOOST_FIXTURE_TEST_CASE(CTransactionBuilderTest, CTransactionBuilderTestSetup) BOOST_FIXTURE_TEST_CASE(CTransactionBuilderTest, CTransactionBuilderTestSetup)
{ {
// NOTE: Mock wallet version is FEATURE_BASE which means that it uses uncompressed pubkeys // NOTE: Mock wallet version is FEATURE_BASE which means that it uses uncompressed pubkeys
// (65 bytes instead of 33 bytes), so CTxIn size is 180 bytes, not 148 bytes as one might expect. // (65 bytes instead of 33 bytes), so CTxIn size is 179 bytes, not 147 bytes as one might expect.
// Each output is 34 bytes, vin and vout compact sizes are 1 byte each. // Each output is 34 bytes, vin and vout compact sizes are 1 byte each.
// Therefore base size (i.e. for a tx with 1 input, 0 outputs) is expected to be // Therefore base size (i.e. for a tx with 1 input, 0 outputs) is expected to be
// 4(n32bitVersion) + 1(vin size) + 180(vin[0]) + 1(vout size) + 4(nLockTime) = 190 bytes. // 4(n32bitVersion) + 1(vin size) + 179(vin[0]) + 1(vout size) + 4(nLockTime) = 189 bytes.
minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE); minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
// Tests with single outpoint tallyItem // Tests with single outpoint tallyItem
{ {
CompactTallyItem tallyItem = GetTallyItem({5000}); CompactTallyItem tallyItem = GetTallyItem({4999});
CTransactionBuilder txBuilder(wallet, tallyItem); CTransactionBuilder txBuilder(wallet, tallyItem);
BOOST_CHECK_EQUAL(txBuilder.CountOutputs(), 0); BOOST_CHECK_EQUAL(txBuilder.CountOutputs(), 0);
BOOST_CHECK_EQUAL(txBuilder.GetAmountInitial(), tallyItem.nAmount); BOOST_CHECK_EQUAL(txBuilder.GetAmountInitial(), tallyItem.nAmount);
BOOST_CHECK_EQUAL(txBuilder.GetAmountLeft(), 4810); // 5000 - 190 BOOST_CHECK_EQUAL(txBuilder.GetAmountLeft(), 4810); // 4999 - 189
BOOST_CHECK(txBuilder.CouldAddOutput(4776)); // 4810 - 34 BOOST_CHECK(txBuilder.CouldAddOutput(4776)); // 4810 - 34
BOOST_CHECK(!txBuilder.CouldAddOutput(4777)); BOOST_CHECK(!txBuilder.CouldAddOutput(4777));
@ -131,7 +131,7 @@ BOOST_FIXTURE_TEST_CASE(CTransactionBuilderTest, CTransactionBuilderTestSetup)
BOOST_CHECK(txBuilder.CouldAddOutputs({1000, 1000, 2708})); // (4810 - 34 * 3) split in 3 outputs BOOST_CHECK(txBuilder.CouldAddOutputs({1000, 1000, 2708})); // (4810 - 34 * 3) split in 3 outputs
BOOST_CHECK(!txBuilder.CouldAddOutputs({1000, 1000, 2709})); BOOST_CHECK(!txBuilder.CouldAddOutputs({1000, 1000, 2709}));
BOOST_CHECK_EQUAL(txBuilder.AddOutput(5000), nullptr); BOOST_CHECK_EQUAL(txBuilder.AddOutput(4999), nullptr);
BOOST_CHECK_EQUAL(txBuilder.AddOutput(-1), nullptr); BOOST_CHECK_EQUAL(txBuilder.AddOutput(-1), nullptr);
CTransactionBuilderOutput* output = txBuilder.AddOutput(); CTransactionBuilderOutput* output = txBuilder.AddOutput();

View File

@ -3719,23 +3719,12 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
} }
auto calculateFee = [&](CAmount& nFee) -> bool { auto calculateFee = [&](CAmount& nFee) -> bool {
// Fill in dummy signatures for fee calculation. nBytes = CalculateMaximumSignedTxSize(txNew, this, coin_control.fAllowWatchOnly);
int nIn = 0; if (nBytes < 0) {
for (const auto& coin : vecCoins) { strFailReason = _("Signing transaction failed");
const CScript& scriptPubKey = coin.txout.scriptPubKey; return false;
SignatureData sigdata;
if (!ProduceSignature(*this, DUMMY_SIGNATURE_CREATOR, scriptPubKey, sigdata)) {
strFailReason = _("Signing transaction failed");
return false;
} else {
UpdateInput(txNew.vin[nIn], sigdata);
}
nIn++;
} }
nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION);
if (nExtraPayloadSize != 0) { if (nExtraPayloadSize != 0) {
// account for extra payload in fee calculation // account for extra payload in fee calculation
nBytes += GetSizeOfCompactSize(nExtraPayloadSize) + nExtraPayloadSize; nBytes += GetSizeOfCompactSize(nExtraPayloadSize) + nExtraPayloadSize;