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
Lint
Lint Not Applicable
Unit
Tests Not Applicable

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 ↗(On Diff #55211)

This ensures we reset any previous script_error in case of success

src/script/interpreter.h
145–148 ↗(On Diff #55211)

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

src/script/script.h
215–225 ↗(On Diff #55211)
This revision now requires changes to proceed.Aug 12 2025, 13:27
src/script/interpreter.cpp
212 ↗(On Diff #55211)

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