Skip to content

Commit

Permalink
Merge pull request #401 from presstab/ct_dummysigfail
Browse files Browse the repository at this point in the history
[Wallet] Use a temp keystore for signing stealth inputs.
  • Loading branch information
presstab committed Feb 20, 2019
2 parents ed96f7c + 15ea6ff commit f489177
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/veil/ringct/anonwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2213,6 +2213,25 @@ int AnonWallet::AddStandardInputs(CWalletTx &wtx, CTransactionRecord &rtx, std::
return 0;
}

bool AnonWallet::MakeSigningKeystore(CBasicKeyStore& keystore, const CScript& scriptPubKey)
{
CTxDestination dest;
if (!ExtractDestination(scriptPubKey, dest))
return error("%s: Failed to extract destination", __func__);

if (dest.type() != typeid(CKeyID))
return error("%s: Destination is not type keyid", __func__);

CKey key;
CKeyID keyID = boost::get<CKeyID>(dest);
if (!GetKey(keyID, key))
return error("%s: Failed to fetch key", __func__);

keystore.AddKey(key);

return true;
}

int AnonWallet::AddBlindedInputs_Inner(CWalletTx &wtx, CTransactionRecord &rtx, std::vector<CTempRecipient> &vecSend,
bool sign, CAmount &nFeeRet, const CCoinControl *coinControl, std::string &sError)
{
Expand Down Expand Up @@ -2417,14 +2436,18 @@ int AnonWallet::AddBlindedInputs_Inner(CWalletTx &wtx, CTransactionRecord &rtx,
const uint256 &txhash = coin.first->first;
const COutputRecord *oR = coin.first->second.GetOutput(coin.second);
const CScript &scriptPubKey = oR->scriptPubKey;
SignatureData sigdata;

CBasicKeyStore keystore;
if (!MakeSigningKeystore(keystore, scriptPubKey))
return wserrorN(1, sError, __func__, "Could not locate signing key");

// Use witness size estimate if set
COutPoint prevout(txhash, coin.second);
std::map<COutPoint, CInputData>::const_iterator it = coinControl->m_inputData.find(prevout);
SignatureData sigdata;
if (it != coinControl->m_inputData.end()) {
sigdata.scriptWitness = it->second.scriptWitness;
} else if (!ProduceSignature(*pwalletParent, DUMMY_SIGNATURE_CREATOR, scriptPubKey, sigdata)) {
} else if (!ProduceSignature(keystore, DUMMY_SIGNATURE_CREATOR, scriptPubKey, sigdata)) {
return wserrorN(1, sError, __func__, "Dummy signature failed.");
}
UpdateInput(txNew.vin[nIn], sigdata);
Expand Down Expand Up @@ -2630,6 +2653,10 @@ int AnonWallet::AddBlindedInputs_Inner(CWalletTx &wtx, CTransactionRecord &rtx,

const CScript &scriptPubKey = outputRecord->scriptPubKey;

CBasicKeyStore keystore;
if (!MakeSigningKeystore(keystore, scriptPubKey))
return wserrorN(1, sError, __func__, "Could not locate signing key");

CStoredTransaction stx;
if (!AnonWalletDB(*walletDatabase).ReadStoredTx(txhash, stx)) {
return werrorN(1, "%s: ReadStoredTx failed for %s.\n", __func__, txhash.ToString().c_str());
Expand All @@ -2639,7 +2666,7 @@ int AnonWallet::AddBlindedInputs_Inner(CWalletTx &wtx, CTransactionRecord &rtx,

SignatureData sigdata;

if (!ProduceSignature(*pwalletParent, MutableTransactionSignatureCreator(&txNew, nIn, vchAmount, SIGHASH_ALL), scriptPubKey, sigdata))
if (!ProduceSignature(keystore, MutableTransactionSignatureCreator(&txNew, nIn, vchAmount, SIGHASH_ALL), scriptPubKey, sigdata))
return wserrorN(1, sError, __func__, _("Signing transaction failed"));
UpdateInput(txNew.vin[nIn], sigdata);

Expand Down
1 change: 1 addition & 0 deletions src/veil/ringct/anonwallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class AnonWallet
bool RegenerateKey(const CKeyID& idKey, CKey& key) const;
bool RegenerateExtKey(const CKeyID& idKey, CExtKey& extkey) const;
bool RegenerateAccountExtKey(const CKeyID& idAccount, CExtKey& keyAccount) const;
bool MakeSigningKeystore(CBasicKeyStore& keystore, const CScript& scriptPubKey);

bool NewStealthKey(CStealthAddress& stealthAddress, uint32_t nPrefixBits, const char *pPrefix);

Expand Down

0 comments on commit f489177

Please sign in to comment.