Skip to content

Instantly share code, notes, and snippets.

@cgcardona
Last active March 16, 2020 09:01
Show Gist options
  • Save cgcardona/650894a9f801ffbf99d715a945b37e97 to your computer and use it in GitHub Desktop.
Save cgcardona/650894a9f801ffbf99d715a945b37e97 to your computer and use it in GitHub Desktop.

Intro

May 15th is bringing a network upgrade (also known as a hard fork) to the $BCH network. Along w/ a 32 MB block size we're reactivating a bunch of OP codes. Thanks to the advice of @MADinMelbourne I decided to see exactly what each new OP code was bringing to the table.

Below I list each new OP code w/ a quick description and then demonstrate how it works by showing a small validation script and then what the stack would look like after.

Please let me know if you spot errors. Thanks!

OP_CAT

Concatenates 2 strings

Validation script

'foo' 'bar' OP_CAT

Stack

  • 'foobar'

OP_AND

Boolean AND between each bit in the inputs.

Validation script

true false OP_AND

Stack

  • false

OP_OR

Boolean OR between each bit in the inputs.

Validation script

true false OP_OR

Stack

  • true

OP_XOR

Boolean XOR between each bit in the inputs.

Validation script

true true OP_XOR

Stack

  • false

OP_DIV

a is divided by b.

Validation script

10 5 OP_DIV

Stack

  • 2

OP_MOD

Returns the remainder after dividing a by b.

Validation script

11 5 OP_MOD

Stack

  • 1

OP_SPLIT

Split string at positions

Validation script

'foobar' 2 OP_SPLIT

Stack

  • 'obar'
  • 'fo'

OP_NUM2BIN

Convert the numeric value into a binary array of a certain size, taking account of the sign bit.

Validation script

12 size OP_NUM2BIN

Stack

  • binaryArray

OP_BIN2NUM

Convert the binary array into a valid numeric value, including minimal encoding.

Validation script

binaryArray OP_BIN2NUM

Stack

  • 12

OP_RETURN

increasing from 80 bytes to 220 bytes

@cgcardona
Copy link
Author

I'm getting multiple people (including Deadalnix) telling me that OP_SUBSTR isn't being enabled. I'm removing it from this doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment