Skip to content

Michelson: Add AND, OR, XOR, NOT, LSL, and LSR for bytes

Jun Furuse requested to merge dailambda/tezos:jun@bytes-bit-ops into master

This should fix #3523 (closed)

Adds bytes support of AND, OR, XOR, NOT, LSL, and LSR.

AND, OR, XOR

Logical binary ops left-0-pad the shorter bytes to match its length with the longer one. They return a bytes of the same length of the longer bytes:

  • 0xff00 OR 0xff = 0xff00 OR 0x00ff = 0xffff
  • 0x0000ff AND 0x0011 = 0x00ff AND 0x0011 = 0x0011 (neither 0x11 nor 0x000011)

NOT

NOT returns a bytes of the same length of the input:

  • NOT 0xff00 = 0x00ff (instead of 0xff)

LSL

LSL returns a longer bytes than the input if the shift is not 0:

  • 0x12 LSL 1 = 0x0024 (instead of 0x24)
  • 0x0012 LSL 1 = 0x000024 (instead of 0x0024 or 0x24)
  • 0x12 LSL 8 = 0x1200
  • 0x0012 LSL 9 = 0x00002400 (instead of 0x002400 or 0x2400)

LSR

LSR may return a shorter bytes:

  • 0x1234 LSR 1 = 0x091a
  • 0x1234 LSR 8 = 0x12 (instead of 0x0012)
  • 0x001234 LSR 9 = 0x0009

The shift for LSL and LSR must be between 0 and 256, just like LSL and LSR for nat. Otherwise they fail.

Milestone checklist

  • Implement the bytes support of the opcodes
    • Document of the interfaces
  • Write Michelson unit tests
  • Define their gas model
  • Determine the gas parameters
    • Jun now understands how to run snoop
  • Write the documents
    • The first draft is committed.
  • Add an item in the appropriate changelog (docs/protocols/alpha.rst for the protocol and the environment, CHANGES.rst at the root of the repository for everything else).
  • Select suitable reviewers using the Reviewers field below.
  • Select as Assignee the next person who should take action on that MR
  • Should have some text in L preview document: https://hackmd.io/MbJyOl6qScyb559OnRcuaA
Edited by Jun Furuse

Merge request reports