Skip to content

Feature/output indexing#106

Open
mpolitzer wants to merge 8 commits into
mainfrom
feature/output-indexing
Open

Feature/output indexing#106
mpolitzer wants to merge 8 commits into
mainfrom
feature/output-indexing

Conversation

@mpolitzer

@mpolitzer mpolitzer commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Changes since main.

  • removal of rollup-http

  • removal of GIO support

  • libcmt v2.

  • updated: ioctl-echo-loop, rollup and yield tools.

  • TODO: remove openapi-interfaces


feature/output-indexing Changes

Branch: feature/output-indexingorigin/main
Commits: 8 | Files changed: 78 | +1,934 / −8,478


Removed

rollup-http/ — HTTP rollup server, client, echo-dapp, tests (−8,451 lines)

The Rust actix-web HTTP server and all associated components:

Component Description
rollup-http-server/ actix-web server with libcmt FFI bindings, build.rs
rollup-http-client/ HTTP client library and rollup types
echo-dapp/ Example echo DApp
rollup-init/ rollup-init shell script
tests/rollup-http-server-tests.rs End-to-end integration tests (466 lines)

CI (main.yml) and Dockerfile also drop rollup-http build/test steps.

GIO (Generic I/O) Support (−172 lines)

Removed From
cmt_gio_request() rollup.h, rollup.c
cmt_gio_t struct rollup.h
gio_seq mock field io-mock.c
gio_request() Rust wrapper rollup-http (already removed)
tests/gio.c test suite

Old ABI Functions

Removed Replaced by
cmt_abi_put_bytes_s() cmt_abi_put_dyn_head()
cmt_abi_put_bytes_d() cmt_abi_put_dyn_tail()
cmt_abi_reserve_bytes_d() cmt_abi_reserve_dyn_tail() + cmt_abi_commit_dyn_tail()
cmt_abi_get_bytes_s() cmt_abi_get_dyn_head()
cmt_abi_get_bytes_d() cmt_abi_view_dyn_tail() / cmt_abi_get_dyn_tail()
cmt_abi_bytes_t type (removed, no replacement needed)

Old Rollup Functions

Removed Replaced by
cmt_rollup_emit_voucher() cmt_rollup_emit_output() (codec encodes, rollup hashes)
cmt_rollup_emit_delegate_call_voucher() same pattern
cmt_rollup_emit_notice() same pattern
cmt_rollup_read_advance_state() removed, replaced by: decode rx from wait_for_input
cmt_rollup_read_inspect_state() removed, replaced by: direct access to rx from wait_for_input
cmt_rollup_finish() cmt_rollup_wait_for_input()
cmt_rollup_load_merkle() removed (user accesses merkle directly via cmt_rollup_get_merkle())
cmt_rollup_save_merkle() removed
cmt_rollup_reset_merkle() removed
cmt_merkle_reset() removed from merkle.h

Old Types

Removed Replaced by
cmt_rollup_advance_t cmt_evmadvance_args_t (in codec.h)
cmt_rollup_inspect_t (inspect payload now returned directly via cmt_buf_t)
cmt_rollup_finish_t / cmt_rollup_finish_s cmt_rollup_wait_for_input() parameters
cmt_io_driver_t cmt_io_t
cmt_io_driver_ioctl_t cmt_io_ioctl_t
cmt_io_driver_mock_t cmt_io_mock_t

ioctl-echo-loop CLI Flag

Removed Reason
--delegate-call-vouchers Delegate call voucher support dropped from tool

Added

Codec Module (codec.h, codec.c, tests/codec.c) — +494 lines

Encoding and decoding for defined output types. Each type gets a struct, encode, and decode function:

Type Struct Funsel
CallVoucher cmt_callvoucher_args_t 0xbcc29146
Notice cmt_notice_args_t 0xe5d658c2
EvmAdvance cmt_evmadvance_args_t 0xbf0e3a23
ERC1155BatchTransfer cmt_erc1155batchtransfer_args_t 0x2f97382c
ERC1155SingleTransfer cmt_erc1155singletransfer_args_t 0x98b5768c
ERC20Transfer cmt_erc20transfer_args_t 0x36dd9fe5
ERC721Transfer cmt_erc721transfer_args_t 0xa0470e2b

Pattern: codec encodes into TX buffer, rollup hashes and emits. Separation of encode (ABI) from proof (merkle).

New ABI API — dyn_head/dyn_tail pattern

Function Purpose
cmt_abi_put_dyn_head() Encode static section offset for a dynamic value
cmt_abi_put_dyn_tail() Encode dynamic section contents
cmt_abi_reserve_dyn_tail() Reserve tail space for streaming writes
cmt_abi_commit_dyn_tail() Commit reserved tail after writing
cmt_abi_get_dyn_head() Decode static section offset
cmt_abi_view_dyn_tail() View (zero-copy) dynamic contents
cmt_abi_get_dyn_tail() Copy dynamic contents

New types: cmt_abi_frame_t, cmt_abi_dyn_state_t.

New functions for fixed-size bytes: cmt_abi_put_bytesN(), cmt_abi_get_bytesN().

New util.h — Debug and file helpers

Symbol Purpose
CMT_DBG(X) Wrap any function call; prints file:line + errno on failure when CMT_DEBUG=yes
cmt_util_debug_enabled() Check if debug output is on
cmt_util_debug() Internal function called by CMT_DBG

New buf.h Functions

Function Purpose
cmt_buf_make() Create a buffer from data+length (value return, replaces cmt_buf_init())
cmt_buf_begin() Get pointer to buffer start

New rollup.h API

Function Purpose
cmt_rollup_emit_output() Unified emit for all on-chain outputs (vouchers, notices). Hashes into merkle tree. NULL data = zero-copy from TX buffer.
cmt_rollup_get_io() Expose internal IO driver
cmt_rollup_get_merkle() Expose internal merkle tree state
cmt_rollup_wait_for_input() Accept/reject current input + wait for next. Returns request type.
cmt_rollup_req_type_t Enum: CMT_ROLLUP_REQ_TYPE_ADVANCE (0) / CMT_ROLLUP_REQ_TYPE_INSPECT (1)

IO Driver — Yield Constants

New yield reason and reply constants in io.h.


Changed

cmt_io_init()cmt_io_t (was cmt_io_driver_t)

Renamed union: cmt_io_driver_tcmt_io_t. All IO accessor functions updated: cmt_io_get_tx(), cmt_io_get_rx(), cmt_io_init(), cmt_io_fini().

cmt_rollup_emit_report() / cmt_rollup_emit_exception() — simplified signature

// Before
int cmt_rollup_emit_report(cmt_rollup_t *me, const cmt_abi_bytes_t *payload);
// After
int cmt_rollup_emit_report(cmt_rollup_t *me, size_t length, const void *data);

Same for emit_exception. NULL data = zero-copy mode (emit directly from TX buffer).

Merkle Hash Caching

cmt_rollup_wait_for_input() now caches the merkle root hash. Recomputed only when leaf_count changes since last call. Controlled via finish_leaf_count field initialized to UINT64_C(-1).

Mock IO — CMT_INPUTS env var

Rewritten to support new input format: type:filename,... (e.g., 0:advance.bin,1:inspect.bin).

Mock Build Targets

New mock build targets in:

  • sys-utils/ioctl-echo-loop/Makefile
  • sys-utils/rollup/Makefile
  • sys-utils/yield/Makefile

Tools Updated

Tool Changes
ioctl-echo-loop Replaced direct ABI encode/decode with codec API; --vouchers--call-vouchers; dropped --delegate-call-vouchers
rollup.cpp Replaced GIO/voucher/notice/del-call-voucher functions with codec API; updated type names; output hashing now via cmt_rollup_emit_output()
yield.c cmt_io_driver_tcmt_io_t
funsel.c Updated to new API

Doc Examples Updated

All examples in doc/examples/ updated from old bytes_s/bytes_d API to new dyn_head/dyn_tail API. abi_decode_002.c added (multiple dynamic values).

pkg-config Template

libcmt.pc.in: @PREFIX@@ARG_PREFIX@ (build system fix).

Keccak Endianness

src/keccak.c: fixed endianness in hash computation (__builtin_bswap64(st[i]) instead of incorrectly casting the pointer).

cmt_rollup_progress() — NULL guard added

Returns -EINVAL when called with NULL.


Architectural Shift

┌─────────────────────────────────────────────────┐
│  BEFORE: libcmt v1                              │
│                                                 │
│  App ─→ rollup API (emit_voucher, emit_notice)  │
│           ├── encodes ABI internally            │
│           ├── hashes into merkle tree           │
│           └── reads advance/inspect internally  │
│                                                 │
│  Heavy rollup.h: ~245 lines                     │
└─────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────┐
│  AFTER: libcmt v2                               │
│                                                 │
│  App ─→ codec API (cmt_notice_encode, ...)      │
│           └── encodes ABI into TX buffer        │
│       ─→ rollup API (emit_output, wait_for_input)│
│           ├── hashes output into merkle tree    │
│           └── returns raw input buffer          │
│       ─→ codec API (cmt_evmadvance_decode, ...) │
│           └── decodes ABI from RX buffer        │
│                                                 │
│  Separated concerns:                            │
│    - codec.h   → ABI encode/decode              │
│    - rollup.h  → IO + merkle hashing            │
│    - abi.h     → low-level ABI primitives       │
│                                                 │
│  Slim rollup.h: ~153 lines                      │
└─────────────────────────────────────────────────┘

The rollup API no longer does ABI encoding/decoding — applications use the codec module directly. This gives applications full control over the encoding while keeping the merkle hashing and IO management in the rollup layer.

This reverts commit 20eba47.
@mpolitzer mpolitzer force-pushed the feature/output-indexing branch from 8f162a0 to 61a08cd Compare June 25, 2026 06:12
@mpolitzer mpolitzer self-assigned this Jun 25, 2026
@mpolitzer mpolitzer added the enhancement New feature or request label Jun 25, 2026
@mpolitzer mpolitzer moved this from Todo to In Progress in Machine Unit Jun 25, 2026
@mpolitzer mpolitzer force-pushed the feature/output-indexing branch 7 times, most recently from 023f62a to b140fa0 Compare June 26, 2026 18:18
@mpolitzer mpolitzer force-pushed the feature/output-indexing branch from b140fa0 to 97d2a2a Compare June 26, 2026 18:33
@mpolitzer mpolitzer marked this pull request as ready for review June 29, 2026 14:14
@mpolitzer mpolitzer requested review from lynoferraz and vfusco June 29, 2026 22:35
@mpolitzer mpolitzer force-pushed the feature/output-indexing branch 5 times, most recently from a1a6354 to 704b787 Compare July 2, 2026 18:10
This is the first of two commits that restructure the library into
independent modules: rollup, io, abi, buf, and (upcoming) codec.

Rollup module
- Remove `cmt_rollup_advance_t`, `cmt_rollup_inspect_t`, and
  `cmt_rollup_finish_t` — `cmt_rollup_advance_t` gets reintroduced in
  the codec module (next commit).
- Replace typed emit functions (`emit_voucher`, `emit_delegate_call_voucher`,
  `emit_notice`) with a single generic `cmt_rollup_emit_output()` that
  takes raw length+data. The ABI envelope encoding is deferred to the
  codec layer.
- Simplify `emit_report()` and `emit_exception()` to take `(size_t, const
  void*)` instead of `cmt_abi_bytes_t`.
- Collapse `cmt_rollup_finish()` + `cmt_rollup_read_advance_state()` +
  `cmt_rollup_read_inspect_state()` into a single blocking call:
  `cmt_rollup_wait_for_input(bool accept, cmt_buf_t *out)`.
- Expose internal io and merkle handles via `cmt_rollup_get_io()` and
  `cmt_rollup_get_merkle()` accessors.
- Remove `load_merkle()`, `save_merkle()`, and `reset_merkle()` wrappers.
- Drop `fromhost_data` field; buffer sizing is now done at yield time.

IO module
- Rename types for brevity: `cmt_io_driver_t` → `cmt_io_t`,
  `cmt_io_driver_ioctl_t` → `cmt_io_ioctl_t`,
  `cmt_io_driver_mock_t` → `cmt_io_mock_t`.
- Mock: tighter input-type parsing (sscanf → strtoul with bounds check),
  separate error codes for rejected input (-ENOSYS) vs end-of-inputs
  (-ENODATA).

ABI module
- Replace `cmt_abi_bytes_t {length, data}` with raw `cmt_buf_t` usage
  throughout.
- Rename dynamic-section calls for clarity:
  `put_bytes_s/d` → `put_dyn_head/tail`,
  `get_bytes_s/d` → `get_dyn_head` / `view_dyn_tail` / `get_dyn_tail`.
- Add `cmt_abi_dyn_state_t` helper struct, `cmt_abi_frame_t` wrapper,
  `cmt_abi_reserve_dyn_tail()` / `cmt_abi_commit_dyn_tail()` for
  zero-copy dynamic encoding.
- Add `cmt_abi_put_bytesN()` / `cmt_abi_get_bytesN()` for fixed-size
  byte arrays (Solidity `bytes<M>`).
- Rename iterator parameters: `me` → `wr`/`rd` throughout.

Buffer module
- `cmt_buf_init()` → `cmt_buf_make()`, returns value instead of using
  out-parameter.
- `cmt_buf_split()`: make `lhs` and `rhs` optional (nullable),
  change length parameter to unsigned.
- Add `cmt_buf_begin()` convenience accessor.

Merkle module
- Remove `cmt_merkle_reset()`

Debug & utilities
- Hoist the `DBG()` trace macro out of `rollup.c` into the public
  `util.h` header as `CMT_DBG()`, so all modules can use it.

Documentation
- Update README and all doc examples to reflect the new API surfaces
  (rollup, io, abi, and the upcoming codec module).
@mpolitzer mpolitzer force-pushed the feature/output-indexing branch from 704b787 to 7ffb2da Compare July 2, 2026 18:21
- EvmAdvance
- Notice
- CallVoucher
- DelegateCallVoucher (removed)
- ERC20Transfer
- ERC721Transfer
- ERC1155SingleTransfer
- ERC1155BatchTransfer
@mpolitzer mpolitzer force-pushed the feature/output-indexing branch from 7ffb2da to 91dc33e Compare July 2, 2026 19:54
@mpolitzer mpolitzer force-pushed the feature/output-indexing branch from 91dc33e to 861db43 Compare July 2, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant