feat: port to libcmt v2 — new @deroll/rollup binding + @deroll/codec packages - #183
Draft
tuler wants to merge 1 commit into
Draft
feat: port to libcmt v2 — new @deroll/rollup binding + @deroll/codec packages#183tuler wants to merge 1 commit into
tuler wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 18e2854 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
… stack redesign Track machine-guest-tools 2fefcb1 (the libcmt v2 "output indexing" overhaul). The binding is renamed @deroll/cmio -> @deroll/rollup and reduced to a thin, raw rollup.h wrapper (waitForInput/emitOutput/emitReport/emitException/ progress/close/run); all EVM-ABI wire formats move to the new pure-JS, browser-compatible @deroll/codec package (dual ESM+CJS, ox + abitype only, argument types derived from the ABI, verified byte-for-byte against libcmt's cast-generated golden vectors). Formats follow upstream: a bytes32 appContext leads every output (optional, zero-hash default), Erc*-cased names, no data payload on ERC-721/1155 transfers, (uint256,uint256)[] items batch pairs; delegate-call vouchers and gio are gone. The app pillar is redesigned on top: advance handlers receive the codec's flat Advance object (Hex payloads, bigint numbers) and return booleans, inspect handlers get the raw Hex query, and the App's output methods are synchronous and typed (createNotice, createCallVoucher, createErc*Transfer, createOutput as escape hatch) with an app-wide appContext default. The wallet parses portal deposits from Hex and its withdrawErc* methods return typed transfer objects for the matching create method; the router reports plain strings. Examples, docs (new /codec and /rollup sections, reworked /app section with a v1->v2 migration guide) and changesets are updated; tests cover the golden vectors, exact output byte layouts, and the full request loop against the libcmt mock. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FLcy7oTUN1sLhJLG4tHMSB
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.
Ports the stack to the libcmt v2 API overhaul ("output indexing" era), tracking machine-guest-tools
2fefcb1, and redesigns the whole app pillar (@deroll/core,@deroll/app,@deroll/wallet,@deroll/router) on top of it. Breaking change, covered by thecmio-libcmt-v2,codec-initialandapp-native-redesignchangesets.Design
libcmt v2 split its rollup layer (raw I/O) from a codec module (EVM-ABI wire formats). This PR mirrors that split as two packages, and rebuilds the app stack on them:
@deroll/rollup(renamed from@deroll/cmio,packages/bindings/rollup) — exclusively the nativerollup.hbinding, hence the name.waitForInput({ accept })returns{ type, payload }undecoded,emitOutput(bytes)returns the output index, plusemitReport/emitException/progress/close/run. It knows nothing about ABI formats, so wire-format changes never require a native rebuild. No longer depends onox.@deroll/codec(new,packages/app/codec) — pure JavaScript EVM-ABI codecs, dual ESM + CommonJS, browser-compatible (no Node.js APIs; verified zeroBuffer/node:references in the bundle). Dependencies:ox+abitype(types only).@deroll/core/@deroll/app/@deroll/wallet/@deroll/router— rebuilt on the two packages above (see next section).References to the Cartesi Machine's own CMIO interface (
--cmio-*flags,@deroll/cmconfig) are intentionally untouched.Naming follows upstream throughout: the transfer wire formats are
Erc*-cased, and so is deroll's API — codec types/encoders (Erc20Transfer,encodeErc20Transfer, …), App methods (createErc20Transfer, …) and the whole wallet surface (withdrawErc20,transferErc721,isErc20Deposit,parseErc1155SingleDeposit,Erc20Deposit, …). Cartesi contract names in prose (ERC20Portal,ERC1155SinglePortal) and standard references ("ERC-20") keep their canonical spelling.App stack redesign
@deroll/coreis now a single hand-authoredindex.tswhose request/output vocabulary comes straight from the codec:Advanceobject (chainId,appContract,msgSender,blockNumber,blockTimestamp,prevRandao,index,payload) with nometadatanesting; all payloads are 0x-hexHex, notBuffers.true/falseinstead of"accept"/"reject", matching the binding. Inspect handlers receive the raw query payload (Hex) directly, andcreateReport/registerExceptiontake the payload directly. TheAdvanceRequestData,InspectRequestData,Report,ExceptionandRequestHandlerResultwrapper types are gone.create*,registerExceptionandstop()no longer return promises;createNoticeetc. return the output index (number) directly. Onlystart()remains async.createCallVoucherreplacescreateVoucher(the rollup'sCallVoucherformat;valueandpayloadrequired), andcreateDelegateCallVoucheris removed (format dropped by libcmt v2).createErc20Transfer/createErc721Transfer/createErc1155Transfer/createErc1155BatchTransfermethods emit the dedicated transfer formats without manual ABI encoding, pluscreateOutput(payload)as an escape hatch for already-encoded outputs.appContexteverywhere — every output takes an optionalbytes32tag (default zero hash);createApp({ appContext })sets an application-wide default, per-output values win.NativeAppdrives the loop viawaitForInput, decodes advances with the codec, reports+rejects undecodable inputs, skips unknown request types with a warning (upstream forward-compat extension point), and handles the libcmt mock's errno quirks when testing on the host.Hexpayloads, detectors use the flatmsgSender, andwithdraw*debit the ledger and return the typed output object (CallVoucherfromwithdrawEther, the correspondingErc*Transferfrom the others) to emit with the matching App method:app.createErc20Transfer(wallet.withdrawErc20(token, user, amount)). This routes withdrawals through the App's encoders so the app-wideappContextdefault applies; the wallet has no codec dependency. The ERC-721/1155 withdrawals drop thedappparameter, and thecreate*TransferVoucherhelpers are removed.handler(payload: Hex), still plugs straight intoaddInspectHandler.@deroll/codec highlights
Abi.from([...])with all seven wire formats; each encode/decode function is a one-lineAbiFunction.encodeData/decodeDataover it, and the argument types are derived from the ABI via abitype (a 6-lineNamedArgsmapped type) — types can never drift from the signatures. Theabiitself is exported for direct use with viem/ox.bigint, no conversions inside, invalid values raise ox's own errors. Callers convert at the boundary (Hex.fromBytes(request.payload)).cast-generated golden vectors (tests/data.h), plus encode/decode roundtrips.Wire formats (machine-guest-tools
2fefcb1)Every output carries
appContext— a free-formbytes32applications use to tag outputs (recipients can filter by it) — as its first parameter. It's optional in the encoders and defaults to the zero hash (exported aszeroHash), matching upstream's own tooling. Following upstream, the single ERC-1155 transfer dropped "Single" from its name, thedatapayload was removed from the ERC-721/1155 transfers, and the batch pairs are a(uint256,uint256)[]tuple array nameditems.decodeAdvance/encodeAdvanceEvmAdvance(uint64,address,address,uint64,uint64,uint256,uint64,bytes)encodeNoticeNotice(bytes32,bytes)encodeCallVoucherCallVoucher(bytes32,address,uint256,bytes)encodeErc20TransferErc20Transfer(bytes32,address,address,uint256)encodeErc721TransferErc721Transfer(bytes32,address,address,uint256)encodeErc1155TransferErc1155Transfer(bytes32,address,address,uint256,uint256)encodeErc1155BatchTransferErc1155BatchTransfer(bytes32,address,address,(uint256,uint256)[])Removed
finish(),emitNotice(),emitVoucher(),emitDelegateCallVoucher()and the decoded advance fields on the request — use@deroll/codecwith the raw API insteadOutput1..Output4envelope + type-tag design)gio()andloadMerkle/saveMerkle/resetMerkle(no longer part of the libcmt rollup API)@deroll/core(Voucher,DelegateCallVoucher,RequestMetadata, …)dataforwarding payload on ERC-721/1155 transfer outputs (dropped by the upstream wire formats)Tests & docs
@deroll/codec: vitest suite with upstream golden vectors, roundtrips, default-appContextequivalence, and ox error propagation;attwgreen across all resolution modes@deroll/rollup: unit tests exercise the binding through the codec package and assert the exact byte layouts of every output format; the in-machine test packs and installs both tarballs into the guest rootfs@deroll/app: vitest suite drives the real native binding through the libcmt mock (CMT_INPUTS) — dispatch, output bytes vs codec encoders, short-circuit vs broadcast, handler-throw survival, undecodable-advance report+reject, inspect payload,appContextdefaulting, unknown-request-type skip@deroll/wallet(40 tests) and@deroll/router(5) updated to the new API/codecsection; the binding docs moved to/rollup; the whole/appsection reworked (create-voucher→create-call-voucher, typed transfer +createOutputpages, wallet reference on the new signatures, rewritten v1→v2 migration guide); examples updated; docs build is fully green (twoslash type-checks every snippet against the built packages)testnow depends on^buildso cross-package tests get built distsKnown follow-ups (not in this PR)
@cartesi/viemstill ships pre-output-indexing ABIs/portal addresses; bump when output-indexing contracts publish (deposit input encodings verified unchanged)decodeNotice,decodeCallVoucher, …) if the explorer pillar needs them🤖 Generated with Claude Code
https://claude.ai/code/session_01FLcy7oTUN1sLhJLG4tHMSB