Skip to content

Follow SV Node v1.2.3 Chronicle and signature rules in the interpreter - #18

Merged
rohenaz merged 4 commits into
mainfrom
interpreter-chronicle-node-rules
Nov 16, 2026
Merged

rohenaz merged 4 commits into
mainfrom
interpreter-chronicle-node-rules

Conversation

@rohenaz

@rohenaz rohenaz commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Before: the Swift interpreter differed from SV Node v1.2.3 on Chronicle rules (splice operands, shift counts, number limits, SIGHASH_CHRONICLE/OTDA, alt-stack clearing, malleability relaxation) and on some signature edge cases, so some spends verified differently in Swift than on the network.

After: the interpreter matches SV Node v1.2.3 for every rule checked, including all 21 TS vectors, and the review probes give the node's verdict.

How: each rule was ported from node source (interpreter.cpp, script_num.cpp, pubkey.cpp, big_int.cpp) with a test that fails on the old code. Details and node line references are in COMP-064.

Behaviour changes callers will see

  • New ScriptVerificationFlags.chronicle. .afterChronicle implies it; callers using .afterGenesis or .beforeGenesis for outputs spent at or after mainnet height 943,816 must pass .chronicle themselves.
  • With .enableForkID, a signature without the ForkID bit is now rejected (illegalForkID), as the node's MUST_USE_FORKID does. It used to be accepted against the legacy digest.
  • New errors illegalChronicle and scriptNumberOverflow.
  • Strict DER now runs only the node's structural check: a well-formed signature with out-of-range r or s makes CHECKSIG/CHECKMULTISIG push false instead of throwing (NULLFAIL still applies). Under .lowS, s is read the way the node's lax parser reads it, so r = 0 with a high s is rejected.
  • After Genesis, ADD, SUB, MUL, 1ADD, 1SUB and 2MUL results longer than the number limit fail.
  • Under Chronicle, a CHECKSIG in the unlocking script includes the locking script in the script code (node behaviour); an over-long script code fails as ScriptExecutionError.transaction(.scriptTooLarge).
  • .bip143SignatureHash now only requires the ForkID bit under strict encoding and no longer chooses the digest (documented and tested).

Testing

swift test in swift:6.1 (Linux): 905 tests passed, 0 failures; only live and opt-in tests skipped. Reviewed line by line against SV Node v1.2.3 source with probes, including a second review of the follow-up fixes.

Add the chronicle verification flag, implied by the afterChronicle era, and
match SV Node v1.2.3 where the interpreter differed from it:

- Splice operands use the node int64 decoding: at most 9 bytes, then
  saturate to Int32.
- LSHIFTNUM and RSHIFTNUM reject shifts the node rejects; a negative right
  shift rounds toward zero.
- The post-Chronicle number limit is 32,000,000 bytes.
- SIGHASH_CHRONICLE signatures are verified with the original digest; the
  ForkID digest is used only when ForkID is enabled.
- The original digest serializes script code as the node does after a
  failed final push, and FindAndDelete removes only exact pushes.
- Malleability rules are relaxed for version > 1 transactions under
  Chronicle.
- The alt stack is cleared between scripts.
- Public keys are checked for empty signatures.
- NULLFAIL covers every failed signature.
- Multisig counts are 4-byte numbers.

Record the change as COMP-064 and update the Go parity notes.
…rithmetic bound

- Compute the ForkID digest over raw script-code bytes, so a Chronicle
  unlocking-plus-locking script code is bounded only by the transaction
  limits and fails with a typed ScriptExecutionError.
- Apply only the node's structural DER rule under strict encoding. A
  signature with an out-of-range r or s now fails CHECKSIG without an
  error, as in SV Node.
- After Genesis, reject arithmetic results longer than the script-number
  limit, as the node's big-number operators do.
- Document the meaning of bip143SignatureHash and when callers must set
  chronicle themselves, and record the caller-visible changes in COMP-064.
- Remove the unused legacy digest overload and add tests for:
  - multisig NULLFAIL relaxation;
  - multisig in the unlocking script under Chronicle;
  - OP_0 removal for an empty signature;
  - the zero left-shift boundary.
…-node-rules

# Conflicts:
#	Documentation/Compatibility/Rulings.md
A structurally valid signature that the strict parser rejects is now
checked for LOW_S the way CPubKey::CheckLowS reads it: values longer than
32 bytes or not below the curve order read as the zero signature, otherwise
the real s is compared with half the order. So r = 0 with a high s fails
LOW_S, as in the node, instead of failing the signature check.

Fix the IsValidSignatureEncoding line range and the pre-Genesis result-size
wording, and add a 2MUL result-bound test.
@rohenaz
rohenaz merged commit 614a838 into main Nov 16, 2026
2 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant