Skip to content

Covenant Declarations#47

Merged
someone235 merged 40 commits intokaspanet:masterfrom
michaelsutton:decl
Mar 9, 2026
Merged

Covenant Declarations#47
someone235 merged 40 commits intokaspanet:masterfrom
michaelsutton:decl

Conversation

@michaelsutton
Copy link
Contributor

This PR introduces covenant declarations for silverscript, with compiler integration and thorough test coverage.

Included:

  • New covenant declaration support via #[covenant(...)], including singleton and fanout sugar.
  • Inference/defaults for binding and mode, plus validation of groups and termination rules.
  • Dedicated test suites for:
    • declaration semantics (covenant_compiler_tests.rs)
    • generated wrapper AST shape (covenant_declaration_ast_tests.rs)
    • tx/script-engine security behavior (covenant_declaration_security_tests.rs)
  • New proposal/spec document: DECL.md.
  • Supporting compiler correctness fixes needed by this feature path:
    • selector dispatch and field-prolog execution order in multi-entrypoint contracts
    • correct debug entrypoint offset in selector mode
    • readInputState state-segment offset calculation from the current script layout
    • validateOutputState full script reconstruction around updated state segment
    • inline-call synthetic argument mapping for identifier-backed args and returned expr rewrites

…elds

Background
A pre-existing compiler bug caused selector-based multi-entrypoint contracts to fail when contract fields were present. The failure was not caused by covenant declaration macros; it existed in general script composition logic.

Bug shape
- Contract has multiple entrypoints (selector dispatch enabled)
- Contract also has state fields (field prolog emitted)
- Runtime fails with VerifyError when dispatching entrypoints

Root cause (compiler-level, macro-independent)
The dispatch selector was effectively disrupted by how field prolog and dispatch logic were composed. This is core entrypoint compilation behavior and applies to any contract using selector dispatch + fields, regardless of whether covenant macros are used.

Fix context
The underlying fix is to ensure selector dispatch executes before branch-local field prolog consumption, preserving correct selector semantics for all branches.

What this commit adds
- New regression test: runs_selector_dispatch_with_contract_fields
- Test constructs a non-covenant contract with two entrypoints and two fields
- Test executes both entrypoints via VM and asserts success

Why this matters
This test would have caught the original bug early and protects against future regressions in compiler dispatch/prolog composition outside the covenant macro feature set.
someone235
someone235 previously approved these changes Mar 9, 2026
@someone235 someone235 merged commit f85d221 into kaspanet:master Mar 9, 2026
4 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.

2 participants