bitd icon indicating copy to clipboard operation
bitd copied to clipboard

Handling Invalid Scripts

Open unwriter opened this issue 7 years ago • 0 comments

In some cases a script is invalid but can exist on the blockchain. For example:

6a04534c500001010747454e455349534c004c004c004c0001004c000800000000000064

when deserialized is:

{ script:
   { b1: 'U0xQAA==',
     s1: 'SLP\u0000',
     b2: 'AQ==',
     s2: '\u0001',
     b3: 'R0VORVNJUw==',
     s3: 'GENESIS',
     b4: '',
     s4: '',
     b5: '',
     s5: '',
     b6: '',
     s6: '',
     b7: '',
     s7: '',
     b8: 'AA==',
     s8: '\u0000',
     b9: '',
     s9: '',
     b10: 'AAAAAAAAZA==',
     s10: '\u0000\u0000\u0000\u0000\u0000\u0000d' },
  scriptString: <Script: OP_RETURN 4 0x534c5000 1 0x01 7 0x47454e45534953 OP_PUSHDATA1 OP_PUSHDATA1 OP_PUSHDATA1 OP_PUSHDATA1 1 0x00 OP_PUSHDATA1 8 0x00000000000064> }

The last part says "push 8 bytes", but the actual bytes only contain 7 bytes.

Need to look further into this, but two possible solutions could be:

  1. Don't index these invalid scripts at all
  2. Store them but add an invalid flag so that it preserves all the information (even if it's invalid)

Example: https://www.blockchain.com/btc/tx/ebc9fa1196a59e192352d76c0f6e73167046b9d37b8302b6bb6968dfd279b767

Reference (how others implement this)

  • https://github.com/fyookball/electrum/blob/master/lib/address.py#L533
  • https://github.com/bitpay/bitcore-lib/blob/master/lib/script/script.js#L53
  • https://github.com/Bitcoin-ABC/bitcoin-abc/blob/master/src/script/script.h#L522

unwriter avatar Aug 20 '18 21:08 unwriter