Merge bitcoin/bitcoin#34381: script: return proper error for CScriptNum errors

6f7b4323cb test: remove UNKNOWN_ERROR from script_tests (Bruno Garcia)
bd31a92d67 script: use SCRIPT_ERR_SCRIPTNUM for CScriptNum errors (Bruno Garcia)
0ca4dcd786 script: add SCRIPT_ERR_SCRIPTNUM error (Bruno Garcia)

Pull request description:

  When evaluating a script, the current code is bad for analyzing some errors because it returns `SCRIPT_ERR_UNKNOWN_ERROR` for errors that are clearly known.

  `CScriptNum` has two well defined errors: number overflow and non-minimally encoded number. However, for both errors we return as unknown. This PR changes it by adding a new ScriptError that is used for any `CScriptNum` error.

ACKs for top commit:
  achow101:
    ACK 6f7b4323cb
  w0xlt:
    ACK 6f7b4323cb
  darosior:
    ACK 6f7b4323cb

Tree-SHA512: e656d9992251fbc95d33966fa18ce64bf714179d51ba6a7f429e5a55bc58e7fc08827e4ab71ace0dd385dac7e1feaea621b49503387793a30eae7a7e44aa6b0f
This commit is contained in:
Ava Chow
2026-01-30 16:22:43 -08:00
6 changed files with 77 additions and 69 deletions

View File

@@ -1223,6 +1223,10 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
return set_error(serror, SCRIPT_ERR_STACK_SIZE);
}
}
catch (const scriptnum_error&)
{
return set_error(serror, SCRIPT_ERR_SCRIPTNUM);
}
catch (...)
{
return set_error(serror, SCRIPT_ERR_UNKNOWN_ERROR);

View File

@@ -117,6 +117,8 @@ std::string ScriptErrorString(const ScriptError serror)
return "Using OP_CODESEPARATOR in non-witness script";
case SCRIPT_ERR_SIG_FINDANDDELETE:
return "Signature is found in scriptCode";
case SCRIPT_ERR_SCRIPTNUM:
return "Script number overflowed or is non-minimally encoded";
case SCRIPT_ERR_UNKNOWN_ERROR:
case SCRIPT_ERR_ERROR_COUNT:
default: break;

View File

@@ -14,6 +14,7 @@ typedef enum ScriptError_t
SCRIPT_ERR_UNKNOWN_ERROR,
SCRIPT_ERR_EVAL_FALSE,
SCRIPT_ERR_OP_RETURN,
SCRIPT_ERR_SCRIPTNUM,
/* Max sizes */
SCRIPT_ERR_SCRIPT_SIZE,