Skip to content

Michelson opcodes for bytes-nat conversion

Jun Furuse requested to merge dailambda/tezos:jun@bytes-nat-conversion into master


Conversion between bytes and nat, see #1457.

Currently we have the following minimal specs:

NAT : bytes -> nat  # decode the bytes using the big endian

NAT 0x = 0
NAT 0x00 = 0
NAT 0x123456 = 1193046 (0x123456)
NAT 0x00123456 = 1193046 (0x123456)

BYTES : nat -> bytes    # encode the natural number using the big endian

BYTES 0 = 0x
BYTES 1 = 0x01
BYTES 1193046 = 0x123456
  • Users may want to have an option for the little endian
  • Users may want to have the size of the returned bytes for NAT, left-padded with 0s if necessary.
  • Maybe there are better opcode names.

Tests for the MR

  • dune exec src/lib_stdlib/test/test_tzBytes.exe
  • Python test: poetry run pytest tests_alpha/ --regtest-reset


  • Fix the specifications
  • Gas cost benchmark on my laptop
  • Official gas cost benchmark
  • Document the interface of any function added or modified (see the coding guidelines)
  • Document any change to the user interface, including configuration parameters (see node configuration)
  • Provide automatic testing (see the testing guide).
  • For new features and bug fixes, 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
Edited by Jun Furuse

Merge request reports