Plugin/Michelson: run_step RPC to execute arbitrary Michelson code on arbitrary stack
Context
Stacked on !9946 (merged).
This MR adds a new RPC to call the Michelson interpreter at a low level. It takes arbitrary code and stack (in the format of the existing normalize_stack RPC).
This MR was extracted from the !4474 (merged) which adds client support for the TZT format. It is part of %Support for Michelson unit tests in TZT format but may also be useful to simplify the implementation of off-chain views in TzComet.
This MR also provides a client command to call this RPC; the syntax is octez-client run michelson code <code> on stack <stack>
:
Bonus
Here is a small bash script building a Michelson REPL using the new client command (requires !9944 (merged) on which this MR is stacked):
#! /bin/bash
CLIENT='octez-client --mode mockup --base-dir /tmp/mockup'
STACK='{}'
while :
do
read -p "> " COMMAND || exit 0
if [ "$COMMAND" = "" ]
then
COMMAND='{}'
fi
NEWSTACK=$($CLIENT run michelson code "$COMMAND" on stack "$STACK" | head -n -2 | tail -n +2)
if [ "$NEWSTACK" = "" ]
then
NEWSTACK="$STACK"
else
STACK="$NEWSTACK"
echo "$STACK"
fi
done
Manually testing the MR
$ octez-client run michelson code COMPARE on stack '{Stack_elt nat 2; Stack_elt nat 5}'
Result
{Stack_elt int -1}
Gas remaining: 1039597.951 units remaining
$ echo '{PAIR}' > test
$ octez-client run michelson code test on stack '{Stack_elt nat 2; Stack_elt nat 5}'
Result
{Stack_elt (pair nat nat) (Pair 2 5)}
Gas remaining: 1039597.514 units remaining
$ octez-client run michelson code FAIL on stack '{}'
At (unshown) location 3, script reached FAILWITH instruction
with Unit
Fatal error:
error running script
$ octez-client run michelson code ADD on stack '{Stack_elt mutez 5000000000000000000; Stack_elt mutez 5000000000000000000}'
Overflowing addition of 5000000000000 tez and 5000000000000 tez
Fatal error:
error running script
Checklist
-
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