arkscript: Tighten custom policy validation - #1144
Conversation
Opaque condition predicates were assumed to only add restrictions, but OP_SUCCESS makes tapscript succeed before the typed inner clause executes. A partial data push can also consume that inner clause as push data. Require predicates to parse as complete fragments, reject OP_SUCCESS, and compile each leaf during direct policy validation so every admission path fails closed.
|
@claude please review |
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
Pull request overview
This PR hardens the lib/arkscript Condition.Predicate escape hatch so opaque predicate bytes cannot (a) short-circuit tapscript execution via OP_SUCCESSx or (b) change parsing boundaries via incomplete pushes that consume the typed inner clause.
Changes:
- Validate
Condition.Predicateas a complete standalone script fragment and reject any tapscriptOP_SUCCESSxopcodes duringCondition.Script()compilation. - Make
ValidatePolicyfail closed by compiling every leaf upfront (and rejecting nil leaves) before applying structural policy invariants. - Add regression tests for
OP_SUCCESSxopcodes, “OP_SUCCESS byte in pushdata”, and incomplete-push boundary smuggling; update predicate bytes in existing tests to remain valid under the new rules.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| lib/arkscript/validate.go | Compiles/leaves upfront (and rejects nil) so admission fails closed on unsafe/invalid predicate fragments. |
| lib/arkscript/validate_test.go | Adds policy-level regression for OP_SUCCESS predicate rejection; updates predicate bytes to avoid incomplete pushes. |
| lib/arkscript/policy_template_test.go | Updates test predicates to use a valid opcode (OP_NOP) under the new predicate completeness rules. |
| lib/arkscript/node.go | Adds predicate safety validation (complete fragment + reject OP_SUCCESSx) to Condition.Script(). |
| lib/arkscript/node_test.go | Adds comprehensive predicate-safety regressions (all OP_SUCCESSx, pushed bytes, incomplete pushes). |
| docs/policy_arkscript_review_guide.md | Documents the predicate safety boundary and the new bypass prevention guarantees. |
| docs/arkscript_spec.md | Updates spec text to describe predicate validation constraints and removes brittle line references. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
Policy validation compared raw CSV operands even though consensus masks reserved bits and treats the disable bit as a no-op. Restrict typed CSV locks to canonical non-zero block delays so structural validation and script execution enforce the same value.
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
What changed
VTXO, vHTLC, and checkpoint builders
encodings
Why
Policy templates should have one interpretation across semantic validation,
script generation, persistence, and recovery. These changes align compiler and
validator behavior so malformed or ambiguous custom templates fail closed.
Compatibility and rollout
Built-in policy templates and canonical production delays are unchanged.
Persisted custom templates that use unsupported predicate fragments or
noncanonical CSV values will no longer compile and should be audited before
rollout.
Checks
go test ./lib/arkscript ./lib/tx/checkpoint ./lib/tx/oormake lint-changed-localmake buildmake fmt-changedmake tidy-module-checkmake commitmsg-lint range="origin/main..HEAD"git diff --check