Skip to content

Commit a5d95e6

Browse files
Merge pull request #76 from IamLupo/master
fix: signature checking that caused exploit.
2 parents a0fb5d7 + 763daa0 commit a5d95e6

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/ctransaction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "util.h"
2020
#include "cautofile.h"
2121
#include "cdatastream.h"
22+
#include "checkpoints.h"
2223

2324
#include "ctransaction.h"
2425

@@ -494,7 +495,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs, std::map<uint256
494495
// Skip ECDSA signature verification when connecting blocks (fBlock=true)
495496
// before the last blockchain checkpoint. This is safe because block merkle hashes are
496497
// still computed and checked, and any change will be caught at the next checkpoint.
497-
if (!(fBlock && !IsInitialBlockDownload()))
498+
if (!(fBlock && (nBestHeight < Checkpoints::GetTotalBlocksEstimate())))
498499
{
499500
// Verify signature
500501
if (!VerifySignature(txPrev, *this, i, flags, 0))

src/script.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3843,6 +3843,13 @@ bool SignSignature(const CKeyStore &keystore, const CTransaction& txFrom, CTrans
38433843

38443844
bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType)
38453845
{
3846+
std::string _txFrom, _txTo;
3847+
3848+
_txFrom = txFrom.GetHash().ToString();
3849+
_txTo = txTo.GetHash().ToString();
3850+
3851+
LogPrintf("VerifySignature from %s to %s\n", _txFrom.c_str(), _txTo.c_str());
3852+
38463853
assert(nIn < txTo.vin.size());
38473854

38483855
const CTxIn& txin = txTo.vin[nIn];
@@ -3859,6 +3866,29 @@ bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsig
38593866
return false;
38603867
}
38613868

3869+
/*
3870+
Exploit happpend on 31st Aug 2021 17:17:26
3871+
3872+
Reference:
3873+
https://xdn-explorer.com/block/00000000000371f620dba8ef1576407b558686d8b00ca275c3debbfaee6a3db8
3874+
*/
3875+
if(
3876+
(
3877+
(
3878+
_txFrom == "81140f106083298143e0e0bd044705b83a891bf2072721dfa43f7237be5931fb" ||
3879+
_txFrom == "164a0151731efc1536fd75e7d5c4a61e17ef67df1d0f4649b3689d604a41a955"
3880+
) &&
3881+
_txTo == "2a639be55df3d7789c73e05aab30edce8fc867d1aae76728e2d59dd2c19b39ab"
3882+
) ||
3883+
(
3884+
_txFrom == "2a639be55df3d7789c73e05aab30edce8fc867d1aae76728e2d59dd2c19b39ab" &&
3885+
_txTo == "adb24c4a4f50bf848ded522fad8de1546bcc16f1ae838a5b51888bcd753dd25b"
3886+
)
3887+
)
3888+
{
3889+
return true;
3890+
}
3891+
38623892
return VerifyScript(txin.scriptSig, txout.scriptPubKey, txTo, nIn, flags, nHashType);
38633893
}
38643894

0 commit comments

Comments
 (0)