Enforce MAX_PUSH_SIZE for taproot (#4486)

This commit is contained in:
benthecarman 2022-07-11 06:41:37 -05:00 committed by GitHub
parent db63b286b3
commit ef50becf1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -670,7 +670,6 @@ sealed abstract class ScriptInterpreter {
scriptPubKeyExecutedProgram.flags.exists(
_ == ScriptVerifyDiscourageUpgradableTaprootVersion)
if (controlBlock.isTapLeafMask) {
//drop the control block & script in the witness
val stackNoControlBlockOrScript = {
if (scriptPubKeyExecutedProgram.getAnnexHashOpt.isDefined) {
@ -682,17 +681,27 @@ sealed abstract class ScriptInterpreter {
stack.tail.tail
}
}
val newProgram = PreExecutionScriptProgram(
txSignatureComponent = taprootTxSigComponent,
stack = stackNoControlBlockOrScript.toList,
script = rebuiltSPK.asm.toList,
originalScript = rebuiltSPK.asm.toList,
altStack = Nil,
flags = taprootTxSigComponent.flags
)
val evaluated = executeProgram(newProgram)
val segwitChecks = postSegWitProgramChecks(evaluated)
Success(segwitChecks)
if (
stackNoControlBlockOrScript.exists(
_.bytes.length > MAX_PUSH_SIZE)
) {
val fail =
scriptPubKeyExecutedProgram.failExecution(
ScriptErrorPushSize)
Success(fail)
} else {
val newProgram = PreExecutionScriptProgram(
txSignatureComponent = taprootTxSigComponent,
stack = stackNoControlBlockOrScript.toList,
script = rebuiltSPK.asm.toList,
originalScript = rebuiltSPK.asm.toList,
altStack = Nil,
flags = taprootTxSigComponent.flags
)
val evaluated = executeProgram(newProgram)
val segwitChecks = postSegWitProgramChecks(evaluated)
Success(segwitChecks)
}
} else if (isDiscouragedTaprootVersion) {
val p = scriptPubKeyExecutedProgram.failExecution(
ScriptErrorDiscourageUpgradableTaprootVersion)