Skip to content

Commit 8552867

Browse files
afk11dcousens
authored andcommitted
bscript.compie - minimal encoding of -1 stack element
1 parent ff68116 commit 8552867

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/script.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function compile (chunks) {
3939
// data chunk
4040
if (Buffer.isBuffer(chunk)) {
4141
// adhere to BIP62.3, minimal push policy
42-
if (chunk.length === 1 && chunk[0] >= 1 && chunk[0] <= 16) {
42+
if (chunk.length === 1 && (chunk[0] === 0x81 || chunk[0] >= 1 && chunk[0] <= 16)) {
4343
return accum + 1
4444
}
4545

@@ -64,6 +64,12 @@ function compile (chunks) {
6464
return
6565
}
6666

67+
if (chunk.length === 1 && chunk[0] === 0x81) {
68+
buffer.writeUInt8(OPS.OP_1NEGATE, offset)
69+
offset += 1
70+
return
71+
}
72+
6773
offset += bufferutils.writePushDataInt(buffer, chunk.length, offset)
6874

6975
chunk.copy(buffer, offset)

test/fixtures/script.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
"valid": [
3+
{
4+
"asm": "OP_1NEGATE",
5+
"script": "4f",
6+
"stack": [
7+
"81"
8+
]
9+
},
310
{
411
"asm": "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801",
512
"script": "47304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801",

0 commit comments

Comments
 (0)