fix serialization issue affecting single byte witness elements with a value of zero

This commit is contained in:
Craig Raw 2025-08-04 13:37:41 +02:00
parent 0ce32e4314
commit 92c57d276c

View file

@ -89,13 +89,9 @@ public class TransactionWitness extends ChildMessage {
int length = new VarInt(pushes.size()).getSizeInBytes(); int length = new VarInt(pushes.size()).getSizeInBytes();
for (int i = 0; i < pushes.size(); i++) { for (int i = 0; i < pushes.size(); i++) {
byte[] push = pushes.get(i); byte[] push = pushes.get(i);
if(push.length == 1 && push[0] == 0) {
length++;
} else {
length += new VarInt(push.length).getSizeInBytes(); length += new VarInt(push.length).getSizeInBytes();
length += push.length; length += push.length;
} }
}
return length; return length;
} }
@ -104,14 +100,10 @@ public class TransactionWitness extends ChildMessage {
stream.write(new VarInt(pushes.size()).encode()); stream.write(new VarInt(pushes.size()).encode());
for(int i = 0; i < pushes.size(); i++) { for(int i = 0; i < pushes.size(); i++) {
byte[] push = pushes.get(i); byte[] push = pushes.get(i);
if(push.length == 1 && push[0] == 0) {
stream.write(push);
} else {
stream.write(new VarInt(push.length).encode()); stream.write(new VarInt(push.length).encode());
stream.write(push); stream.write(push);
} }
} }
}
public byte[] toByteArray() { public byte[] toByteArray() {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();