Skip to content

Port cmio binding to libcmt v2 codec API#182

Merged
tuler merged 1 commit into
feature/libcmt-v2from
claude/machine-guest-tools-update-tvdjd3
Jul 2, 2026
Merged

Port cmio binding to libcmt v2 codec API#182
tuler merged 1 commit into
feature/libcmt-v2from
claude/machine-guest-tools-update-tvdjd3

Conversation

@tuler

@tuler tuler commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Port the @deroll/cmio binding to libcmt v2's refactored API, which splits the rollup layer (raw I/O) from the codec layer (EVM-ABI encoding/decoding).

Summary

This is a breaking change that mirrors libcmt v2's architectural split:

  • The Rollup class is now a thin, synchronous raw I/O wrapper
  • EVM-ABI encoding/decoding moved to standalone JS helpers, one per libcmt codec entry
  • All helpers are implemented with ox and verified byte-for-byte against libcmt's C encoders

Key Changes

Rollup API:

  • finish()waitForInput({ accept }) returns { type, payload } with raw, undecoded bytes
  • emitNotice(), emitVoucher()emitOutput(bytes) (returns output index)
  • emitReport(), emitException(), progress(), close(), run() unchanged in spirit

New codec helpers (mirror libcmt's codec.h):

  • decodeAdvance(input) — decode raw EvmAdvance input to structured fields
  • encodeAdvance(args) — encode structured fields to EvmAdvance input (inverse of decode)
  • encodeNotice(payload)Notice(bytes) output
  • encodeCallVoucher({ destination, value, payload })CallVoucher(address,uint256,bytes) output
  • encodeERC20Transfer({ recipient, token, value })ERC20Transfer(address,address,uint256) output
  • encodeERC721Transfer({ recipient, token, tokenId, data })ERC721Transfer(address,address,uint256,bytes) output
  • encodeERC1155SingleTransfer({ recipient, token, tokenId, value, data })ERC1155SingleTransfer(address,address,uint256,uint256,bytes) output
  • encodeERC1155BatchTransfer({ recipient, token, tokenIdsAndValues, data })ERC1155BatchTransfer(address,address,uint256[2][],bytes) output

Removed:

  • encodeDelegateCallVoucher() — no longer part of libcmt v2 codec
  • Output envelope wrappers (Output1, Output2) and type tags — replaced by direct function selectors

Type changes:

  • New U64Like type for 64-bit fields in encodeAdvance
  • New AdvanceArgs interface for encodeAdvance parameters
  • Renamed VoucherCallVoucher, DelegateCallVoucher removed
  • New ERC20Transfer, ERC721Transfer, ERC1155SingleTransfer, ERC1155BatchTransfer interfaces

Implementation details:

  • EvmAdvance signature updated: uint256uint64 for chainId, blockNumber, blockTimestamp, index
  • Generalized toU256() to toUint(value, name, bits) supporting arbitrary bit widths
  • Helper toAddressHex() and encodeData() for cleaner encoder implementations
  • All encoders use ox's AbiFunction.encodeData() for battle-tested EVM-ABI word packing
  • Function selectors in comments match libcmt's codec.h (little-endian uint32 byte order)

Documentation:

  • Updated guides and reference pages to reflect new API
  • Removed encode-delegate-call-voucher.mdx
  • Added encode-asset-transfers.mdx for the new typed transfer outputs
  • Updated testing guide with encodeAdvance example
  • Updated type reference and emitting-outputs guide

Tests:

  • Updated rollup.test.mjs to use new helpers and verify against hand-rolled encoders
  • Added cross-check: library encodeAdvance vs. hand-rolled implementation
  • Updated machine test app to

https://claude.ai/code/session_01FLcy7oTUN1sLhJLG4tHMSB

Repoint the machine-guest-tools submodule from the feature-branch squash
(9933904) to the upstream landing of libcmt v2 (7ffb2da), which changed
the wire formats:

- EvmAdvance narrows chainId/blockNumber/blockTimestamp/index to uint64
  (new selector 0x233a0ebf)
- outputs use plain per-type selectors instead of the Output1..Output4
  envelope with 32-byte type tags: Notice(bytes) and
  CallVoucher(address,uint256,bytes) (encodeVoucher is renamed to
  encodeCallVoucher to match)
- delegate-call vouchers are gone from the codec
- new typed asset-transfer outputs: ERC20Transfer, ERC721Transfer,
  ERC1155SingleTransfer, ERC1155BatchTransfer, exposed as encode*
  helpers
- new encodeAdvance helper (inverse of decodeAdvance) for crafting mock
  inputs

The native addon needed no changes: the rollup.h surface it consumes is
unchanged (upstream also fixed the merkle root-hash caching in
wait_for_input). All JS encoders are verified byte-for-byte against the
C codec. Docs, README and the changeset are updated to the new formats.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FLcy7oTUN1sLhJLG4tHMSB
@changeset-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 785031e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 4 packages
Name Type
@deroll/cmio Minor
@deroll/docs Patch
@deroll/app Patch
@deroll/examples Patch

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
deroll Ready Ready Preview, Comment Jul 2, 2026 9:16pm
deroll-explorer Ready Ready Preview, Comment Jul 2, 2026 9:16pm

@tuler tuler merged commit 62bd7a6 into feature/libcmt-v2 Jul 2, 2026
5 checks passed
@tuler tuler deleted the claude/machine-guest-tools-update-tvdjd3 branch July 2, 2026 21:45
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