Page MenuHomePhabricator

[Iguana] Implement interpreter + human readable formatter
ClosedPublic

Authored by tobias_ruck on Sep 24 2024, 22:10.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC6fd3064b6d7e: [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

Diff Detail

Repository
rABC Bitcoin ABC
Branch
iguana-implement-human-readable
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 30410
Build 60340: Build Difflint-circular-dependencies · check-iguana · build-without-wallet · build-diff · build-debug · build-clang-tidy · build-clang
Build 60339: arc lint + arc unit

Event Timeline

Tail of the build log:

[585/644] Generating forms/ui_intro.h
[586/644] Generating forms/ui_openuridialog.h
[587/644] Generating forms/ui_modaloverlay.h
[588/644] Generating forms/ui_optionsdialog.h
[589/644] Generating forms/ui_overviewpage.h
[590/644] Generating forms/ui_receivecoinsdialog.h
[591/644] Generating forms/ui_receiverequestdialog.h
[592/644] Generating forms/ui_debugwindow.h
[593/644] Generating forms/ui_sendcoinsdialog.h
[594/644] Generating forms/ui_sendcoinsentry.h
[595/644] Generating forms/ui_signverifymessagedialog.h
[596/644] Generating forms/ui_transactiondescdialog.h
[597/644] Generating qrc_bitcoin.cpp
[598/644] Linking CXX executable src/bitcoind
[599/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bitcoinaddressvalidator.cpp.o
[600/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bitcoinamountfield.cpp.o
[601/644] Building CXX object src/bench/CMakeFiles/bitcoin-bench.dir/crypto_aes.cpp.o
[602/644] Building CXX object src/bench/CMakeFiles/bitcoin-bench.dir/checkblock.cpp.o
[603/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bitcoinunits.cpp.o
[604/644] Building CXX object src/bench/CMakeFiles/bitcoin-bench.dir/load_external.cpp.o
[605/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/csvmodelwriter.cpp.o
[606/644] Building CXX object src/bench/CMakeFiles/bitcoin-bench.dir/block_assemble.cpp.o
[607/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/modaloverlay.cpp.o
[608/644] Building CXX object src/bench/CMakeFiles/bitcoin-bench.dir/peer_eviction.cpp.o
[609/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/networkstyle.cpp.o
[610/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/notificator.cpp.o
[611/644] Building CXX object src/bench/CMakeFiles/bitcoin-bench.dir/duplicate_inputs.cpp.o
[612/644] Building CXX object src/bench/CMakeFiles/bitcoin-bench.dir/rpc_blockchain.cpp.o
[613/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/platformstyle.cpp.o
[614/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qvalidatedlineedit.cpp.o
[615/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qvaluecombobox.cpp.o
[616/644] Building CXX object src/bench/CMakeFiles/bitcoin-bench.dir/mempool_stress.cpp.o
[617/644] Building CXX object src/CMakeFiles/bitcoinkernel.dir/validation.cpp.o
[618/644] Linking CXX static library src/libbitcoinkernel.a
[619/644] Building CXX object src/bench/CMakeFiles/bitcoin-bench.dir/chained_tx.cpp.o
[620/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bantablemodel.cpp.o
[621/644] Linking CXX executable src/bitcoin-chainstate
[622/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/utilitydialog.cpp.o
[623/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bitcoin-qt-base_autogen/mocs_compilation.cpp.o
[624/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qrc_bitcoin_locale.cpp.o
[625/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qrc_bitcoin.cpp.o
[626/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/clientmodel.cpp.o
[627/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bitcoingui.cpp.o
[628/644] Linking CXX executable src/bench/bitcoin-bench
[629/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/intro.cpp.o
[630/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bitcoin.cpp.o
[631/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/optionsmodel.cpp.o
[632/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/optionsdialog.cpp.o
[633/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/splashscreen.cpp.o
[634/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/guiutil.cpp.o
[635/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/trafficgraphwidget.cpp.o
[636/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/peertablemodel.cpp.o
[637/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/rpcconsole.cpp.o
[638/644] Linking CXX static library src/qt/libbitcoin-qt-base.a
[639/644] Automatic MOC for target bitcoin-qt
[640/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt.dir/bitcoin-qt_autogen/mocs_compilation.cpp.o
[641/644] Building CXX object src/qt/CMakeFiles/bitcoin-qt.dir/main.cpp.o
[642/644] Linking CXX executable src/qt/bitcoin-qt
ninja: build stopped: cannot make progress due to previous errors.
Build build-without-wallet failed with exit code 1

Tail of the build log:

[517/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bantablemodel.cpp.o
[518/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/modaloverlay.cpp.o
[519/576] Building CXX object src/bench/CMakeFiles/bitcoin-bench.dir/coin_selection.cpp.o
[520/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/platformstyle.cpp.o
[521/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/notificator.cpp.o
[522/576] Building CXX object src/bench/CMakeFiles/bitcoin-bench.dir/wallet_balance.cpp.o
[523/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/clientmodel.cpp.o
[524/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qvalidatedlineedit.cpp.o
[525/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bitcoin-qt-base_autogen/mocs_compilation.cpp.o
[526/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qvaluecombobox.cpp.o
[527/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/intro.cpp.o
[528/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qrc_bitcoin.cpp.o
[529/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bitcoin.cpp.o
[530/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bitcoingui.cpp.o
[531/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/optionsmodel.cpp.o
[532/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/guiutil.cpp.o
[533/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/utilitydialog.cpp.o
[534/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/optionsdialog.cpp.o
[535/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/addressbookpage.cpp.o
[536/576] Linking CXX executable src/bench/bitcoin-bench
[537/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/coincontroltreewidget.cpp.o
[538/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/createwalletdialog.cpp.o
[539/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/trafficgraphwidget.cpp.o
[540/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/peertablemodel.cpp.o
[541/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/editaddressdialog.cpp.o
[542/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/splashscreen.cpp.o
[543/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/askpassphrasedialog.cpp.o
[544/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qrc_bitcoin_locale.cpp.o
[545/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qrimagewidget.cpp.o
[546/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/openuridialog.cpp.o
[547/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/overviewpage.cpp.o
[548/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/addresstablemodel.cpp.o
[549/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactionfilterproxy.cpp.o
[550/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/receiverequestdialog.cpp.o
[551/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactiondescdialog.cpp.o
[552/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/recentrequeststablemodel.cpp.o
[553/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/sendcoinsentry.cpp.o
[554/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/receivecoinsdialog.cpp.o
[555/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactionrecord.cpp.o
[556/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/rpcconsole.cpp.o
[557/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/coincontroldialog.cpp.o
[558/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletframe.cpp.o
[559/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactionview.cpp.o
[560/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletmodeltransaction.cpp.o
[561/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactiontablemodel.cpp.o
[562/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/signverifymessagedialog.cpp.o
[563/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactiondesc.cpp.o
[564/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/paymentrequestplus.cpp.o
[565/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/paymentserver.cpp.o
[566/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/sendcoinsdialog.cpp.o
[567/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletcontroller.cpp.o
[568/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletview.cpp.o
[569/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletmodel.cpp.o
[570/576] Linking CXX static library src/qt/libbitcoin-qt-base.a
[571/576] Automatic MOC for target bitcoin-qt
[572/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt.dir/bitcoin-qt_autogen/mocs_compilation.cpp.o
[573/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt.dir/main.cpp.o
[574/576] Linking CXX executable src/qt/bitcoin-qt
ninja: build stopped: cannot make progress due to previous errors.
Build build-diff failed with exit code 1

Tail of the build log:

[517/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/modaloverlay.cpp.o
[518/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bantablemodel.cpp.o
[519/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/notificator.cpp.o
[520/576] Building CXX object src/bench/CMakeFiles/bitcoin-bench.dir/coin_selection.cpp.o
[521/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/platformstyle.cpp.o
[522/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qvalidatedlineedit.cpp.o
[523/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bitcoin-qt-base_autogen/mocs_compilation.cpp.o
[524/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/clientmodel.cpp.o
[525/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qvaluecombobox.cpp.o
[526/576] Building CXX object src/bench/CMakeFiles/bitcoin-bench.dir/wallet_balance.cpp.o
[527/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qrc_bitcoin.cpp.o
[528/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bitcoin.cpp.o
[529/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/bitcoingui.cpp.o
[530/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/intro.cpp.o
[531/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/optionsmodel.cpp.o
[532/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/guiutil.cpp.o
[533/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/optionsdialog.cpp.o
[534/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/addressbookpage.cpp.o
[535/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/utilitydialog.cpp.o
[536/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/peertablemodel.cpp.o
[537/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/coincontroltreewidget.cpp.o
[538/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/createwalletdialog.cpp.o
[539/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/editaddressdialog.cpp.o
[540/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/askpassphrasedialog.cpp.o
[541/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/trafficgraphwidget.cpp.o
[542/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qrimagewidget.cpp.o
[543/576] Linking CXX executable src/bench/bitcoin-bench
[544/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/splashscreen.cpp.o
[545/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/openuridialog.cpp.o
[546/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qrc_bitcoin_locale.cpp.o
[547/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/overviewpage.cpp.o
[548/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/addresstablemodel.cpp.o
[549/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactionfilterproxy.cpp.o
[550/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactiondescdialog.cpp.o
[551/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/receiverequestdialog.cpp.o
[552/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/recentrequeststablemodel.cpp.o
[553/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/sendcoinsentry.cpp.o
[554/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/receivecoinsdialog.cpp.o
[555/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/coincontroldialog.cpp.o
[556/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/rpcconsole.cpp.o
[557/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactionrecord.cpp.o
[558/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactionview.cpp.o
[559/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactiontablemodel.cpp.o
[560/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactiondesc.cpp.o
[561/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/signverifymessagedialog.cpp.o
[562/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletmodeltransaction.cpp.o
[563/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletframe.cpp.o
[564/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/paymentrequestplus.cpp.o
[565/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/paymentserver.cpp.o
[566/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/sendcoinsdialog.cpp.o
[567/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletcontroller.cpp.o
[568/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletview.cpp.o
[569/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletmodel.cpp.o
[570/576] Linking CXX static library src/qt/libbitcoin-qt-base.a
[571/576] Automatic MOC for target bitcoin-qt
[572/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt.dir/bitcoin-qt_autogen/mocs_compilation.cpp.o
[573/576] Building CXX object src/qt/CMakeFiles/bitcoin-qt.dir/main.cpp.o
[574/576] Linking CXX executable src/qt/bitcoin-qt
ninja: build stopped: cannot make progress due to previous errors.
Build build-debug failed with exit code 1

fix lint, fix compilation for gcc, keep include

Fabien requested changes to this revision.Sep 25 2024, 12:32

One nit, otherwise looks good

iguana/iguana.cpp
77

make strMissingArgs a vector and use Join from util/string.h to avoid the extra comma

This revision now requires changes to proceed.Sep 25 2024, 12:32
This revision is now accepted and ready to land.Sep 28 2024, 18:20