npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

michelson-interpreter

v1.0.5

Published

Michelson interpreter with step-by-step output

Downloads

1

Readme

michelson-interpreter

michelson-interpreter is a step-by-step interpreter for the stack based language Michelson. Michelson is used for smart contracts in Tezos.

This tool was written for explaining Michelson scripts: it considers each instruction as a step and documents the following:

  • instruction (obviously) with its original line number in the file,
  • elements added to and removed from the stack,
  • full dump of the stack after the execution of the instruction is finished.

Requirements

  • Node.js (development was done with v18, however it might work with earlier versions too)

Installation

npm

npm i michelson-interpreter

Afterwards, you can use michelson-interpreter as a command from your terminal.

Usage

michelson-interpreter takes some required and some optional parameters and prints out the result to stdout. Overview of the parameters where bold ones are required:

  • -f, --file: Path of the file to interpret
  • -p, --parameter: Parameter value for the script
  • -s, --storage: Storage value for the script
  • --account: Account as a string
  • --address: Address as a string
  • --amount: Amount as an int
  • --entrypoint: Entrypoint as a string
  • --gas_limit: Gas limit as an int
  • --id: id as an int
  • --timestamp: Timestamp as a string in RFC3339 notation or an int as an Unix time
  • --version: Show version
  • --help: Show this information

Required parameters are needed to be able to do the basic simulated interpretation. Optional parameters however define the state of the execution, which is normally gotten from the blockchain. Some scripts may need these definitions in order to present correct execution traces, but simple ones tend to not.

After a successful execution, a JSON array with all the steps is printed out, which then can be inspected in a tool like fx.

After an unsuccessful execution (due to reasons like getting a FAILWITH, programming error, etc.) five pieces of information is printed out:

  • error/exception message,
  • content of the error/exception, which is usually the instruction that raised the error/exception,
  • state at the time of exception,
  • stack at the time of exception,
  • recorded steps up to and including the error/exception raising instruction.

This information comes in a user-readable form; if it should be outputted as a JSON object for programmatic use, you will be able to use a flag to indicate it hopefully sooner than later.

Limitations

  • Instruction set implemented to work with this interpreter are the ones up to and including protocol Babylon.
  • Some instructions have not been implemented (mostly due to being a blockchain operation instruction):
    • APPLY
    • CHAIN_ID
    • CHECK_SIGNATURE
    • CREATE_CONTRACT
    • EXEC
    • ITER
    • LAMBDA
    • SET_DELEGATE
    • TRANSFER_TOKENS
  • For parameter and storage inputs, only some types can be parsed (more details below).

Inputs

Michelson scripts take parameters when their execution is submitted, and they also use a storage which stays on the blockchain. As this is a simulated environment, both parameter and storage values need to be provided. Both values' types are defined in the script, and the actual inputs need to adhere to them for successful execution.

List of input types which have been implemented to successfully parse:

  • address: "..." (within double-quotes)
  • big_map: { Elt a b ; Elt c d }
  • bool: True or False
  • bytes: 0x123...def
  • int: -1, 0, 1, ..., n
  • key: "..." (within double-quotes)
  • key_hash: "..." (within double-quotes)
  • list: { a ; b }
  • map: { Elt a b ; Elt c d }
  • mutez: 0, 1, ..., n
  • nat: 0, 1, ..., n
  • option: (Some a) or (None)
  • or: (Left a) or (Right b)
  • pair: (Pair a b)
  • set: { a ; b }
  • signature: ... (without double-quotes)
  • string: "..." (within double-quotes)
  • timestamp: 0, 1, ..., n or 1970-01-01T00:00:00Z
  • unit: Unit

These types are possible to nest within others where applicable (map, list, set, etc.).