From ed66937d01b3ff5530c0561cd2e4351b8c856717 Mon Sep 17 00:00:00 2001 From: Chris Stewart Date: Mon, 3 Mar 2025 06:32:14 -0600 Subject: [PATCH] core: Fix bug when converting OP_0 to long (#5948) --- .../org/bitcoins/core/script/constant/ScriptNumberUtil.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/org/bitcoins/core/script/constant/ScriptNumberUtil.scala b/core/src/main/scala/org/bitcoins/core/script/constant/ScriptNumberUtil.scala index 3bda637567..087c7255e4 100644 --- a/core/src/main/scala/org/bitcoins/core/script/constant/ScriptNumberUtil.scala +++ b/core/src/main/scala/org/bitcoins/core/script/constant/ScriptNumberUtil.scala @@ -54,7 +54,10 @@ trait ScriptNumberUtil { */ def toLong(bytes: ByteVector): Long = { val reversedBytes = bytes.reverse - if (bytes.size == 1 && bytes.head == -128) { + + if (bytes.isEmpty) { + 0 + } else if (bytes.size == 1 && bytes.head == -128) { // the case for negative zero 0 } else if (isPositive(bytes)) {