Bitcoin-abc: Fix Transaction Malleability

Created on 24 Aug 2017  路  1Comment  路  Source: Bitcoin-ABC/bitcoin-abc

Apply the following modifications:

  • Exclude scriptsigs when computing transaction hashes in GetHash() (optionally rename to GetId() as zCash did).
  • Create a new CTransaction method getTransactionFullHash() that includes scriptSigs, similar to the GetHash() method prior this change.
  • Modify the leaves of the transaction Merkle-Tree to contain two fields {txHash,fullTxhash} instead of only the txHash.
  • When verifying a block, check that the fullTxHash corresponds to the txHash.
  • Allow scriptSigs to be padded by trailing NOPs and consider them standard scripts, and standard transactions.
  • Before signing a transaction, first estimate the amount of bytes required for each scriptSig
  • When signing and computing the transaction hash (SignatureHash), also hash the (estimated/actual) length of the scriptSig of the input being signed, to prevent on-the-wire transaction malleability.
    e.g.
    CHashWriter ss(SER_GETHASH, 0);
    // Version
    ss << txTo.nVersion;
    ss << hashPrevouts;
    ss << hashSequence;
    ss << txTo.vin[nIn].prevout;
    ss << static_cast ss << originalScriptSigLength
    ss << amount;
    ss << txTo.vin[nIn].nSequence;
    ss << hashOutputs;
    ss << txTo.nLockTime;
    ss << nHashType;
  • When packing signatures in a scriptSig, add trailing NOPs afterwards to make the actual length reach the estimated length.

Most helpful comment

Sergio; I suggest joining the bitcoin-ml list where changes to the protocol can be discussed between all stakeholders.
https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-ml

>All comments

Sergio; I suggest joining the bitcoin-ml list where changes to the protocol can be discussed between all stakeholders.
https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-ml

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cryptoapi picture cryptoapi  路  5Comments

karelbilek picture karelbilek  路  8Comments

NickTh1 picture NickTh1  路  7Comments

prusnak picture prusnak  路  4Comments

afk11 picture afk11  路  6Comments