Skip to content

feat: gate chain-specific host functions to the emulated chain#1

Merged
robrigo merged 1 commit into
mainfrom
feat/gate-chain-host-functions
Jul 16, 2026
Merged

feat: gate chain-specific host functions to the emulated chain#1
robrigo merged 1 commit into
mainfrom
feat/gate-chain-host-functions

Conversation

@robrigo

@robrigo robrigo commented Jul 16, 2026

Copy link
Copy Markdown

Why

wax-vert registers verify_rsa_sha256_sig for every Blockchain. It exists on WAX and not on EOS, Jungle4 or Vaulta, so a contract importing it passed the harness and would fail to load on those chains. The harness was more permissive than three of the four Antelope chains these contracts deploy to, which is a class of false-green: a contract calling a WAX-only host function looks tested when it cannot deploy.

What

Host functions unique to a chain are withheld unless the emulated chain provides them. A Blockchain is generic Antelope by default and exposes none; new Blockchain({ chain: 'wax' }) adds the WAX set. The VM deletes any withheld function from its env imports before instantiating, so a contract importing one fails to instantiate under the wrong chain, mirroring how setcode rejects it. That is a load-time failure, which is faithful to where the real chain rejects it.

The set is declared in CHAIN_SPECIFIC_HOST_FUNCTIONS, keyed by chain. Modeling a new chain-specific function is one map entry, and it is then gated everywhere automatically.

Validation

35 tests pass (31 prior plus 4 for the gate). The two existing RSA tests now run against a wax blockchain. New tests assert verify_rsa_sha256_sig is absent by default, present under wax, absent under an unknown chain name, and that withholding it leaves shared host functions like recover_key intact. Verified directly that a default VM exposes undefined for it while a wax VM exposes a function.

Version 2.2.0: this adds behavior over the 2.1.1 base and gives the fork its own version line rather than sharing upstream's.

wax-vert registers verify_rsa_sha256_sig for every Blockchain. It exists on WAX and not on EOS, Jungle4 or Vaulta, so a contract importing it passed the harness and would fail to load on those chains: the harness was more permissive than three of the four chains these contracts deploy to.

Host functions unique to a chain are now withheld unless the emulated chain provides them. A Blockchain is generic Antelope by default and exposes none; new Blockchain({ chain: 'wax' }) adds the WAX set. The VM deletes any withheld function from its env imports before instantiating, so a contract importing one fails to instantiate under the wrong chain, mirroring how setcode rejects it. The two existing RSA tests now run against a wax blockchain, and new tests assert the function is absent by default, present under wax, absent under an unknown chain name, and that withholding it leaves the shared host functions intact.

The set is declared in CHAIN_SPECIFIC_HOST_FUNCTIONS, so a new chain-specific function is one map entry. Version 2.2.0: this adds behavior over the 2.1.1 base and gives the fork its own version line.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens VeRT’s Antelope host-function parity by gating chain-specific host functions so contracts that import a function unsupported by the emulated chain fail at instantiation time (mirroring real setcode behavior), eliminating false-green test results across different Antelope chains.

Changes:

  • Add a chain selector to Blockchain and define per-chain host-function availability via CHAIN_SPECIFIC_HOST_FUNCTIONS.
  • In VM, remove (withhold) all chain-specific host functions from imports.env unless enabled for the selected chain.
  • Update and extend tests/docs/examples to validate and demonstrate the new chain-specific gating; bump version to 2.2.0.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/antelope/vm.ts Withholds chain-specific host functions from WASM imports based on the emulated chain.
src/antelope/blockchain.ts Adds chain option and exposes chain-specific host-function sets (enabled + union).
src/antelope/tests/vm.spec.ts Updates RSA tests to run under wax and adds gating assertions for default/wax/unknown chains.
examples/rsa/rsa.spec.ts Uses new Blockchain({ chain: 'wax' }) so RSA example matches WAX host-function availability.
README.md Documents the new per-chain host-function behavior and how to select a chain.
package.json Bumps package version to 2.2.0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@robrigo
robrigo merged commit a8a4160 into main Jul 16, 2026
7 checks passed
@robrigo
robrigo deleted the feat/gate-chain-host-functions branch July 16, 2026 14:05
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