feat: gate chain-specific host functions to the emulated chain#1
Merged
Conversation
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.
There was a problem hiding this comment.
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
Blockchainand define per-chain host-function availability viaCHAIN_SPECIFIC_HOST_FUNCTIONS. - In
VM, remove (withhold) all chain-specific host functions fromimports.envunless 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
wax-vert registers
verify_rsa_sha256_sigfor everyBlockchain. 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
Blockchainis generic Antelope by default and exposes none;new Blockchain({ chain: 'wax' })adds the WAX set. The VM deletes any withheld function from itsenvimports before instantiating, so a contract importing one fails to instantiate under the wrong chain, mirroring howsetcoderejects 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
waxblockchain. New tests assertverify_rsa_sha256_sigis absent by default, present underwax, absent under an unknown chain name, and that withholding it leaves shared host functions likerecover_keyintact. Verified directly that a default VM exposesundefinedfor it while awaxVM 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.