Dynafed blocks must have sighash byte

It is not included in the signature hash.
The sighash byte MUST be SIGHASH_ALL to avoid
malleability.
This commit is contained in:
Gregory Sanders 2019-09-27 10:01:46 -04:00 committed by Steven Roose
parent 4afb69f994
commit 8d043f37af
No known key found for this signature in database
GPG key ID: 2F2A88D7F8D68E87
5 changed files with 46 additions and 18 deletions

View file

@ -21,12 +21,15 @@ bool CheckChallenge(const CBlockHeader& block, const CBlockIndex& indexLast, con
static bool CheckProofGeneric(const CBlockHeader& block, const uint32_t max_block_signature_size, const CScript& challenge, const CScript& scriptSig, const CScriptWitness& witness)
{
// scriptSig or witness will be nonempty, but not both, so just compare both limits
if (scriptSig.size() > max_block_signature_size) {
return false;
}
// Legacy blocks have empty witness, dynafed blocks have empty scriptSig
bool is_dyna = !witness.stack.empty();
if (witness.GetSerializedSize() > max_block_signature_size) {
// Check signature limits for blocks
if (scriptSig.size() > max_block_signature_size) {
assert(!is_dyna);
return false;
} else if (witness.GetSerializedSize() > max_block_signature_size) {
assert(is_dyna);
return false;
}
@ -40,7 +43,7 @@ static bool CheckProofGeneric(const CBlockHeader& block, const uint32_t max_bloc
| SCRIPT_VERIFY_SIGPUSHONLY // Witness is push-only
| SCRIPT_VERIFY_LOW_S // Stop easiest signature fiddling
| SCRIPT_VERIFY_WITNESS // Witness and to enforce cleanstack
| SCRIPT_NO_SIGHASH_BYTE; // non-Check(Multi)Sig signatures will not have sighash byte
| (is_dyna ? 0 : SCRIPT_NO_SIGHASH_BYTE); // Non-dynafed blocks do not have sighash byte
return GenericVerifyScript(scriptSig, witness, challenge, proof_flags, block);
}