Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024 01 11 bip68 bip112 txversion bug #5346

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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)
}
}

Large diffs are not rendered by default.

Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down