Page MenuHomePhabricator

[interpreter] Return `INTEGER_OVERFLOW` or `BAD_INTEGER_ENCODING` instead of UNKNOWN
ClosedPublic

Authored by tobias_ruck on Aug 12 2025, 12:01.

Details

Summary

Currently, the Script interpreter returns UNKNOWN when it encountered an integer overflow or a non-minimally encoded integer.

This has been a nuisance for new Script devs for a while, because "unknown error" sounds like the interpreter is broken, but it's actually expected behavior.

Also, this makes script number tests more brittle.

Instead, we return INTEGER_OVERFLOW if there's been any kind of integer overflow, e.g. when parsing operands, or when executing an operation like OP_ADD, OP_BIN2NUM, etc.

Test Plan

ninja check && ninja check-functional

Diff Detail

Repository
rABC Bitcoin ABC
Branch
interpreter-better-scriptnum-errors
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 34129
Build 67726: Build Difflint-circular-dependencies · build-without-wallet · build-fuzzer · build-diff · build-debug · build-clang-tidy · build-clang
Build 67725: arc lint + arc unit

Event Timeline

rebase onto master, fix comment

Fabien requested changes to this revision.Aug 12 2025, 13:27
Fabien added inline comments.
src/script/interpreter.cpp
212

This ensures we reset any previous script_error in case of success

src/script/interpreter.h
145–148

If it can't throw, let's mark it noexcept

src/script/script.h
215–225
This revision now requires changes to proceed.Aug 12 2025, 13:27
src/script/interpreter.cpp
212

but that changes the behavior of RunNextOp, it previously did not do that. And a Script is not successful after just one opcode, it must run all of them to be successful

src/script/interpreter.h
146 ↗(On Diff #55214)

remove redundant "will not throw" comment

This revision is now accepted and ready to land.Aug 12 2025, 15:41