Skip to content

Instantly share code, notes, and snippets.

@dexX7
Last active January 24, 2018 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dexX7/3012bb9e1d0906db38b32edbbe8ac5ff to your computer and use it in GitHub Desktop.
Save dexX7/3012bb9e1d0906db38b32edbbe8ac5ff to your computer and use it in GitHub Desktop.
Optimizing Omni Layer transactions calculations
Base transaction:
Container: 10 byte
Input: 148 byte
Change output: 34 byte
Reference output: 34 byte
Payload: 31 byte (8 value, 2 push, 1 OP_RETURN, 4 marker, 16 payload)

Transaction size:

= 10+148+34+34+31 = 257 byte

Stage 1 (shorter marker: -2 byte):
Container: 10 byte
Input: 148 byte
Change output: 34 byte
Reference output: 34 byte
Payload: 29 byte (8 value, 2 push, 1 OP_RETURN, 2 marker, 16 payload)

Transaction size:

= 10+148+34+34+29 = 255 byte

Stage 2 (merged type and version fields: -3 byte):
Container: 10 byte
Input: 148 byte
Change output: 34 byte
Reference output: 34 byte
Payload: 26 byte (8 value, 2 push, 1 OP_RETURN, 2 marker, 13 payload)

Transaction size:

= 10+148+34+34+26 = 252 byte

Stage 3 (var-length encoding: -5 byte):
Container: 10 byte
Input: 148 byte
Change output: 34 byte
Reference output: 34 byte
Payload: 21 byte (8 value, 2 push, 1 OP_RETURN, 2 marker, 8 payload)

Transaction size:

= 10+148+34+34+21 = 247 byte

##### Stage 4 (move reference into payload: -34 byte +21 byte):

Container: 10 byte
Input: 148 byte
Change output: 34 byte
Payload: 34 byte (8 value, 2 push, 1 OP_RETURN, 2 marker, 21 payload)

Transaction size:

= 10+148+34+34 = 226 byte

Result:

From 257 byte down to 226 byte is a 12.06 % cost saving.

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