2024 01 11 bip68 bip112 txversion bug (#5346)

* Fix bug where number needed to be interpreted as a UInt32 rather than Int32 by the ScriptInterpreter in the case of OP_CSV

* Add static test vector, fix another occurrence of bug
This commit is contained in:
Chris Stewart 2024-01-12 06:44:18 -06:00 committed by GitHub
parent 748121fe8a
commit 421970dcf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 3 deletions

View file

@ -65,4 +65,10 @@ class Int32Test extends BitcoinSUnitTest {
it must "have the correct maximum number representation" in {
Int32.max.toInt must be(2147483647)
}
it must "convert to UInt32" in {
Int32.zero.toUInt32 must be(UInt32.zero)
Int32.negOne.toUInt32 must be(UInt32.max)
Int32.two.toUInt32 must be(UInt32.two)
}
}

File diff suppressed because one or more lines are too long

View file

@ -167,6 +167,7 @@ sealed abstract class Int32 extends SignedNumber[Int32] {
override def apply: A => Int32 = Int32(_)
override val andMask = 0xffffffff
override val bytes: ByteVector = ByteVector.fromInt(i = toInt, size = 4)
def toUInt32: UInt32 = UInt32.fromBytes(bytes)
}
/** Represents a int64_t in C

View file

@ -8,6 +8,7 @@ trait TransactionConstants {
lazy val version = Int32.one
lazy val validLockVersion = Int32.two
lazy val validLockVersionU32 = validLockVersion.toUInt32
lazy val lockTime = UInt32.zero
lazy val sequence = UInt32.max
lazy val disableRBFSequence = sequence - UInt32.one

View file

@ -99,7 +99,7 @@ sealed abstract class LockTimeInterpreter {
program.updateScript(program.script.tail)
case s: ScriptNumber
if isLockTimeBitOff(
s) && program.txSignatureComponent.transaction.version < TransactionConstants.validLockVersion =>
s) && program.txSignatureComponent.transaction.version.toUInt32 < TransactionConstants.validLockVersion.toUInt32 =>
program.failExecution(ScriptErrorUnsatisfiedLocktime)
case s: ScriptNumber =>
if (s.bytes.size > 5) {
@ -144,7 +144,7 @@ sealed abstract class LockTimeInterpreter {
// Fail if the transaction's version number is not set high
// enough to trigger BIP 68 rules.
if (
program.txSignatureComponent.transaction.version < TransactionConstants.validLockVersion
program.txSignatureComponent.transaction.version.toUInt32 < TransactionConstants.validLockVersion.toUInt32
) {
return false
}