Bitcoinjs-lib: OP_RETURN scriptPubkey can be up to 80 bytes

Created on 22 Aug 2017  路  5Comments  路  Source: bitcoinjs/bitcoinjs-lib

https://github.com/bitcoinjs/bitcoinjs-lib/blob/b552c63fb0a76e82d55a8d562cf6df76a25f3fc5/src/templates/nulldata.js#L25

This assumes OP_RETURN then PUSHDATA (1 Byte) and slices 2 bytes off the head.

If you push 77 bytes, the PUSHDATA is 2 bytes long, so decode will give the second byte of the PUSHDATA on the head of the decoded buffer.

Since OP_RETURN allows for multiple pushes as long as the scriptPubkey is 80 bytes or lower, the decode should be

  1. slice 1 byte
  2. read PUSHDATA and slice it
  3. slice the number of bytes in 2
  4. If ended, return Buffer.
  5. If not ended read PUSHDATA again
  6. slice off the number of bytes in 5
  7. convert the return value into an array of buffers and push the result of 6
  8. repeat 5-7 until end of buffer reached.
bug breaking change

All 5 comments

@junderw could you submit a PR that uses .decompile and returns stack[1]?

And could you add a test fixture?

Sure. But wouldn't that just return the data of the first push?

ex:

> var b = require('bitcoinjs-lib')
> b.script.decompile(Buffer.from('6a010202030403040304','hex'))
[ 106, <Buffer 02>, <Buffer 03 04>, <Buffer 04 03 04> ]
// stack[1] === <Buffer 02>

I am wondering whether the result of bscript.nullData.output.decode should be

A: [ <Buffer 02>, <Buffer 03 04>, <Buffer 04 03 04> ]
B: <Buffer 01 02 02 03 04 03 04 03 04>

The rules for standardness are:

  1. PUSHDATA only (but no limit on number of pushes)
  2. whole scriptPubkey less than or equal to 80 bytes

Maybe .compile(bscript.decompile(buffer).slice(1))?

I'll see if I can't put up some fixtures and fix it.

I'm working on it. I'm also going to modify encode a little.

Closing in favour of #859

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hoshsadiq picture hoshsadiq  路  3Comments

silence-may picture silence-may  路  3Comments

itsMikeLowrey picture itsMikeLowrey  路  3Comments

zhaozhiming picture zhaozhiming  路  3Comments

coingeek picture coingeek  路  4Comments