Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

User request: invoke hash-committed functions provided in the unlocking script #479

Backlog

Description

@mr-zwets

BitcoinCashAutist asked:

btw, is there a way to make a contract where function body is provided in unlocking script and verified against constructor hash?

This is not currently possible: OP_DEFINE/OP_INVOKE are only emitted for functions known at compile time.

How this differs from #348

Most users will just want the MAST-like constructions tracked in #348, where the compiler handles this for all of a contract's functions and only the spending path that is used goes on-chain.

This request is the lower-level, opt-in version aimed at power users and script wizards: the contract author chooses which function is committed by hash and only revealed when used, and keeps control over exactly how that is done.

What it would need

  • Compiler: a way to define and invoke runtime-supplied bytecode after a hash check, with a declared signature so type checking still works, and a function ID that doesn't collide with compiler-allocated ones.
  • Compiler/SDK: compile a standalone function to deterministic bytecode so it can be hashed (related to Investigate compilation of 'cashscript snippets' to CashASM #256).
  • SDK (optional, later): the bytecode can already be passed as a regular bytes unlocking argument. Follow-ups could add debugging support for the invoked code and accepting a compiled function artifact directly.

Related

Activity

  1. added
    javascript-sdk
    cashc-compiler
    and removed
    javascript-sdk
    on Nov 29, 2026
  2. A60AB5450353F40E commented on Nov 29, 2026

    @A60AB5450353F40E

    Maybe something like external function Name(int m, int n) in declarations and any contract that calls it just calls it by Name but must also have the Name in contract function arguments e.g.:

    function Settle(bytes unused padding, function Name, int m, int n) {
         require(NameHash == sha256(Name));
         Name(m, n);
    }
    

    functions without the function Name argument can't call it, only those that are listed can (and SDK would auto-generate the input's data push, and it would auto-assign the correct definition index -- still tracked globally per contract's functions)

    This also lets contract writer manually implement the exact MAST shape they want.

    This doesn't prescribe function validation. Actually, we could go further and allow function body to be declared/defined anywhere as a variable, and calling it depends on it being in the scope.

    external function Name(int m, int n);
    external function NameMutated(int m, int n);
    
    function Settle(bytes unused padding, function Name, int m, int n) {
         require(NameHash == sha256(Name));
         function NameMutated = Name + 0x0075;
         Name(m, n);
         NameMutated(m, n);
    }
    

    Declaration just tells the compiler the expected function signature, which the SDK can validate just before calling OP_DEFINE when stack item will be known.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cashc-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions