Skip to content

Add BCH helper functions and non-spendable library imports#400

Open
lightswarm124 wants to merge 11 commits intoCashScript:nextfrom
lightswarm124:review/bch-functions-next
Open

Add BCH helper functions and non-spendable library imports#400
lightswarm124 wants to merge 11 commits intoCashScript:nextfrom
lightswarm124:review/bch-functions-next

Conversation

@lightswarm124
Copy link
Copy Markdown

This PR adds BCH function support on top of current next by introducing contract-local helper functions and non-spendable imported helper libraries. It treats OP_DEFINE / OP_INVOKE as first-class compiler outputs, keeps spend surfaces explicit, and adds the debug/runtime metadata needed to make helper execution reviewable.

Main changes:

  • Adds public and internal function support inside contract.
  • Adds first-class library containers for imported helper-only code.
  • Supports contract -> library and transitive library -> library imports.
  • Canonicalizes shared transitive libraries by resolved file identity to avoid duplicate shared-leaf codegen.
  • Adds helper-aware debug metadata and SDK attribution for nested helper logs and failures.
  • Rejects unsafe helper patterns:
    • recursion and mutual recursion
    • signature-check builtins in helpers
    • contract-constructor capture in helpers
    • imported contract files
    • public functions inside library

Why this matters:

  • Enables reusable BCH helper functions both locally and across imported helper libraries.
  • Keeps imported helper files non-spendable by construction.
  • Makes nested helper execution inspectable enough for maintainers and downstream teams to audit.

Examples included:

Local internal helpers:

  • examples/helper-functions.cash
  • examples/helper-functions.ts

Imported helper libraries:

  • examples/imported-helper-functions.cash
  • examples/math-helpers.cash
  • examples/parity-helpers.cash
  • examples/imported-helper-functions.ts

Testing-suite helper example:

  • examples/testing-suite/contracts/internal_functions.cash
  • examples/testing-suite/test/internal_functions.test.ts

Docs for review:

  • docs/proposals/bch-functions-team-review.md
  • docs/proposals/functions-vs-next-review.md
  • docs/proposals/functions-implementation-spec.md
  • docs/proposals/functions-security-and-release-review.md

@lightswarm124 lightswarm124 marked this pull request as ready for review April 3, 2026 22:39
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