HomePhabricator

[Iguana] Implement interpreter + human readable formatter

Description

[Iguana] Implement interpreter + human readable formatter

Summary:
The "core" of the interpreter is IguanaInterpreter::Run, which aims to exactly model the VerifyScript function.

The internal RunScript function is modelled after EvalScript, but it collects a detailled trace of every opcode, i.e. the state of the stack and altstack. It also collects errors in an as helpful as possible way.

For example, integer overflows (which bubble up as exceptions in EvalScript), now finally have a nice error message (bitcoind would report "Unknown error"). For a scriptSig, it will stop at the first non-push opcode, instead of just saying that it has some non-pushop somewhere. And other cases, e.g. invalidly encoded opcodes.

After collecting the result, a Formatter can be used to display the trace. One implementation is FormatterHumanReadable, which prints it to stdout in a somewhat verbose but easy to understand format.

The executable itself simply takes -tx, -scriptpubkey, -value and -inputindex, and runs the interpreter. This is similar to the parameters Meep takes, but named after the fields in the bitcoind codebase.

In the future, we can add a -format arg, which could allow CSV or other machine readable formats (that could be fed into Script IDEs, e.g. Bitauth IDE).

Also, we can add a -scriptflags arg, to allow e.g. standard vs. mandatory flags, or a specific custom flagset. This would also allow us to run the debugger against the script_tests.json.

Test Plan: ninja check-iguana

Reviewers: Fabien, #bitcoin_abc

Reviewed By: Fabien, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D16810

Details

Provenance
tobias_ruckAuthored on Sep 24 2024, 22:09
tobias_ruckPushed on Sep 30 2024, 07:55
Reviewer
Restricted Project
Differential Revision
D16810: [Iguana] Implement interpreter + human readable formatter
Parents
rABC8ce33ba18593: [Automated] Update seeds
Branches
Unknown
Tags
Unknown