mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-24 06:57:51 +01:00
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:
parent
748121fe8a
commit
421970dcf5
5 changed files with 11 additions and 3 deletions
|
@ -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
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue