Skip to content

Wasm space api - #24

Merged
yapishu merged 6 commits into
masterfrom
wasm-space-api
Oct 18, 2026
Merged

yapishu merged 6 commits into
masterfrom
wasm-space-api

Conversation

@yapishu

@yapishu yapishu commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds first-class runtime selection to tx-types and migrates the crate to the upstream nockchain NounSpace/handle API, so the same source serves:

Consumer Features Runtime
ESP32 / nockster-esp default-features = false pokenoun (no_std, crypto-only)
Extension/app wallet (wasm) std,embedded vendored nockchain-minimal
Native consumer std,native upstream SWPSCO/nockchain @ 73877be

embedded and native are mutually exclusive; std requires exactly one. Both are compile errors if violated. The pokenoun re-export and the crypto-only no_std path are unchanged.

This is the point of tx-types: embedders and wasm consumers import it instead of the full nockchain tree, while native consumers still share the same wire types and hashing logic.

Runtime selection

Dependency sets are declared as aliased optional deps (nockapp-minimal / nockapp-upstream, etc.) and selected at the crate root with extern crate … as …. This keeps ::nockapp, ::nockvm, ::noun_serde, and derive-generated paths identical for both runtimes. Cargo does not allow a feature to switch dependency sources, so both sets live in this manifest.

BUILDING.md documents the matrix; the old use-local-nockchain.sh / use-git-nockchain.sh scripts and the consumer-side [patch] are removed.

Upstream API migration

  • NounDecode::from_noun(&Noun, &NounSpace) everywhere, including the derive and nockchain-minimal.
  • Handle-based traversal: noun.in_space(space).as_cell()/as_atom(), CellHandle::head()/tail(), AtomHandle.
  • noun_space() on slabs/stacks, copy_into(root, &space), and space-aware TIP5/math entry points.
  • Minimal nockvm/nockapp gained the new types/methods; existing 1-arg helpers remain where possible.

Correctness / parity fixes

From a line-by-line audit against nockchain 73877be:

  • Fee accounting: count_note_data_words now matches Hoon (2n+1 atoms per note-data entry); previously 3n+1, overcharging minimum fees.
  • Hash::from_b58: five divmods, reject non-zero high quotient and non-canonical spellings (exact re-encode).
  • Hashing errors: removed fabricated Hash { [0; 5] } / cue→0 fallbacks; hashing returns Result, unbased/oversized atoms error.
  • pokenoun hardening: checked sizes/shifts, allocation bounded by remaining input, 1<<20 walk budget, numeric atom comparisons (non-minimal spellings compare equal).
  • Schnorr verification: reject zero chal/sig and non-canonical T8 limbs.
  • Validator: V1 now returns UnsupportedVersion instead of silently Ok(()).
  • Bythos: build_lock_merkle_proof selects stub below the phase and full at/above; callers pass a page/height.
  • Decode safety: expect/assert on noun shapes replaced with errors; Witness::tim != 0 rejected; dead non-consensus TIP5 file removed.
  • ZMap/ZSet: try_* variants added; legacy helpers no longer fabricate zero digests.

Breaking changes

  • compute_tx_id_v1*, hash_noun_varlen, hash_hashable, V1 to_hash/to_hashable, and related hashing helpers return Result.
  • build_lock_merkle_proof requires a page argument.
  • Witness::from_noun rejects non-zero tim.
  • TransactionValidationError::UnsupportedVersion added.
  • embedded is the default backend; native consumers must opt out of defaults and select std,native.

Consumers updated in lockstep: siger-esp (std,embedded, host + wasm + thumb) and native consumers (std,native).

CI

  • Targets are installed for the toolchain in rust-toolchain.toml (nightly-2026-04-03) via actions-rust-lang/setup-rust-toolchain.
  • rustflags: "" so pre-existing warnings in vendored ibig are not promoted to errors.
  • The regression job now passes end-to-end (no-std lib, no-std tests, hosted tests, vanity, browser assets, GPU-init tests).

Verification

  • cargo check -p tx-types (default embedded+std)
  • cargo test -p tx-types --lib — 80 passed
  • cargo check -p tx-types --no-default-features and --target thumbv7em-none-eabihf — pass
  • cargo check -p tx-types --no-default-features --features std,embedded — pass
  • ... --features std,native — pass
  • ... --features std,embedded --target wasm32-unknown-unknown — pass
  • cargo test -p pokenoun — 11 passed
  • vanity/pkh/gpu suites and browser asset build pass; PR CI is green.

Follow-ups

  • pokenoun::jam still emits no backreferences (cue-compatible; byte size differs from nockvm::jam).
  • Firmware (nockster-fw) requires the ESP/Xtensa toolchain; no_std was verified on thumbv7em-none-eabihf in CI.

Thread the real NounSpace through noun decoding and noun-reading
helpers, switching from the removed private Cell/Atom accessors to
NounHandle/CellHandle/AtomHandle traversal.

- NounDecode::from_noun now takes (&Noun, &NounSpace)
- Hashable::from_noun and hashing::raw helpers take a space
- Tip5Hasher uses nockchain-math digests instead of door jets
  (the jets now require the num-rounds door subject)
- Copy nouns into the jet stack with their source space
- ZMap/ZSet decoding and test helpers pass the slab space

The no_std path (crypto only) is unchanged.
Declare both the vendored nockchain-minimal crates and upstream nockchain
73877be as aliased optional dependencies and select between them with the
mutually exclusive 'embedded' (default) and 'native' features. 'std' gates the
transaction/block/hashing modules and requires exactly one runtime backend, so
the crypto-only no_std path still builds with default features disabled.

Port the vendored minimal runtime to the current NounSpace/handle API:
- nockvm: NounSpace, NounHandle/CellHandle/AtomHandle, Noun/Cell/Atom
  in_space, and a default NounAllocator::noun_space.
- nockapp: space-aware copy_into plus NounAllocatorExt, and re-exports for
  NounAllocator/NounSpace.
- noun-serde/derive: two-argument NounDecode::from_noun and all impls and
  generated code.
- nockchain-math/libp2p/zkvm: space-aware TIP5 and shape entry points, and
  hash_ten_cell/hash_belts_slice shims.

Bins now require std so they are not built for no_std targets. The obsolete
consumer patch section and toggle scripts are removed.
- fee: count note-data words as Hoon rep shape (2n+1), not the z-map noun
- Hash::from_b58: five divmods, zero high quotient, canonical re-encode
- hashing: propagate Result instead of fabricating zero digests; validate leaves;
  zmap/zset expose try_{put,get,has,del} and no longer hash-fallback to zero
- schnorr: reject zero scalars and non-canonical T8 limbs
- validator: fail closed with UnsupportedVersion for V1
- block types: page-aware build_lock_merkle_proof (stub below BYTHOS_PHASE)
- v1 decode/hash: return errors instead of expect/assert; reject tim != 0
- pokenoun: hostile-jam hardening (checked sizes, bounded walks) and numeric
  atom comparisons for non-minimal encodings
- delete dead hashing/tip5_impl.rs
@yapishu
yapishu merged commit f225b52 into master Oct 18, 2026
1 check passed
@yapishu
yapishu deleted the wasm-space-api branch October 18, 2026 21:29
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