Skip to content

Introduce portable SilverScript ABI artifacts - #232

Merged
someone235 merged 21 commits into
kaspanet:masterfrom
someone235:abi
Aug 28, 2026
Merged

Introduce portable SilverScript ABI artifacts#232
someone235 merged 21 commits into
kaspanet:masterfrom
someone235:abi

Conversation

@someone235

Copy link
Copy Markdown
Contributor

This PR introduces a portable, versioned ABI artifact shared by the compiler, debugger, and external tooling.

There are no intentional SilverScript syntax, bytecode, or runtime-semantics changes. The practical change is that compiled contract metadata and signature-script encoding no longer depend on the compiler’s
internal AST representation.

Artifact and Tooling Changes

  • Add SilAbiArtifact, containing:

    • Compiler and schema versions
    • Struct definitions
    • Contracts and runtime-state layouts
    • Entrypoint parameters and dispatch tags
    • Covenant declaration entrypoint metadata
    • Compiled bytecode and script hex
    • Template hashes and state spans
  • Add ArtifactValue as the portable representation for constructor and entrypoint arguments.

  • Add typed encoders for:

    • Regular entrypoint signature scripts
    • Covenant declaration calls
    • Struct and struct-array arguments
    • Runtime-state scripts
  • Add artifact validation for schema versions, dispatch-tag collisions, bytecode encodings, runtime-state spans, and template hashes.

  • Preserve compiler-generated dispatch tags in CompiledContract, while moving the complete public ABI representation into SilAbiArtifact.

  • Add SilDebugArtifact, which combines a portable ABI artifact with per-contract debug information.

  • Migrate the debugger to use portable ABI types for argument parsing, entrypoint selection, signature-script generation, and covenant metadata.

CLI Changes

silverc now emits a SilAbiArtifact JSON document instead of serializing the compiler’s internal CompiledContract.

Constructor argument files now use portable artifact values:

[
  {
    "kind": "bytes",
    "value": [1, 2, 3, 4]
  },
  {
    "kind": "int",
    "value": 12345
  }
]

The generated artifact has the following general shape:

{
  "schema_version": 1,
  "compiler_version": "0.1.0",
  "structs": [],
  "contracts": [
    {
      "name": "Example",
      "runtime_state": {
        "source": "State",
        "fields": []
      },
      "entries": [
        {
          "name": "main",
          "dispatch_tag": "01234567",
          "params": [
            {
              "name": "amount",
              "type": {
                "kind": "int"
              }
            }
          ]
        }
      ],
      "compiled": {
        "bytecode": [],
        "script_hex": "",
        "template_hash": [],
        "template_hash_hex": "",
        "state_span": {
          "offset": 0,
          "len": 0
        }
      }
    }
  ]
}

Programmatic Usage

Contracts can be compiled directly into portable artifacts:

use silverscript_lang::compiler::compile_to_sil_abi_artifact;

let artifact = compile_to_sil_abi_artifact(
    source,
    &[100.into()],
)?;

let contract = artifact.contract("Example").expect("contract exists");

Signature scripts are generated from the portable ABI:

use silverscript_abi::encode_contract_entry_sig_script;

let sigscript = encode_contract_entry_sig_script(
    &artifact,
    "Example",
    "main",
    &[100.into()],
)?;

@someone235
someone235 merged commit db9e1ba into kaspanet:master Aug 28, 2026
4 checks passed
@someone235
someone235 deleted the abi branch August 28, 2026 20:30
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