Corpus Core Docs

Unified RPC API

The unified RPC API combines method type detection, proof generation (local or remote), and verification into a single context. This eliminates the need for bindings to implement the orchestration logic (method type check, prover/verifier decision, proof flow).

The host system only needs to:

  1. Create an RPC context with c4_create_rpc_ctx()
  2. Call c4_rpc_execute_json_status() in a loop
  3. Handle pending data requests (same as with prover/verifier APIs)
  4. Free the context with c4_free_rpc_ctx()

The existing c4_create_prover_ctx() and c4_verify_create_ctx() APIs remain available for use cases that need separate proof generation and verification (e.g. proof transport via Bluetooth to embedded devices).

c4_create_rpc_ctx

api/colibri.h

Creates a unified RPC context that handles method type detection, proof generation, and verification.

This is a convenience API that wraps the separate prover and verifier APIs. It automatically determines whether a method is proofable, local, or unproofable, and drives the appropriate flow internally.

                `64` = `VERIFY_FLAG_OBLIVIOUS`, `128` = `VERIFY_FLAG_SKIP_WSP_CHECK`
                (SECURITY: disables the Weak Subjectivity Period anchor; only safe with an
                alternative trust anchor such as witness signatures or a hard-coded checkpoint),
                `1024` = `VERIFY_FLAG_PERSIST_HEADER_CACHE` (reload/save EL header cache from storage).

Example:

void* ctx = c4_create_rpc_ctx(
    "eth_getBalance",
    "[\"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\", \"latest\"]",
    1,    // Ethereum Mainnet
    0,    // No special prover flags
    0,    // No special verify flags
    2     // Use hybrid prover mode
);
void* c4_create_rpc_ctx(char* method, char* params, uint64_t chain_id, uint32_t prover_flags, uint32_t verify_flags, int prover_mode);

Parameters

  • method : The Ethereum RPC method (e.g., "eth_getBalance")
  • params : The method parameters as a JSON array string
  • chain_id : The blockchain chain ID
  • prover_flags : Flags for proof generation (see prover flag types)
  • verify_flags : Flags for verification bitmask. Common values: 2 = VERIFY_FLAG_PAP,
  • prover_mode : proof generation mode: 0 = local, 1 = remote, 2 = hybrid (header proof from server, execution data from RPC provider)

Returns

A new RPC context pointer, or NULL if creation failed

c4_set_checkpoint

api/colibri.h

Sets a trusted checkpoint for a chain (context-independent).

Parses a hex checkpoint string and stores it globally for the given chain. Call this once before any verification if the host has a known checkpoint. The checkpoint persists across all prover/verifier/RPC contexts for the chain.

A checkpoint is a beacon block root. For an L2 that settles on L1 (EEZ, Arbitrum One) it is stored for the L1 chain (c4_get_l1_chain_id_for_l2(chain_id)), whose sync committee the L2 proofs are verified against.

void c4_set_checkpoint(uint64_t chain_id, const char* trusted_checkpoint);

Parameters

  • chain_id : target chain ID
  • trusted_checkpoint : hex string with "0x" prefix (66 chars total), or NULL (no-op)

c4_reset_caches

api/colibri.h

Clears all in-process prover and verifier caches.

Use this between fixture-backed tests that share one process. Must not run concurrently with proof generation (rpc() / c4_prover_execute). Persistent storage (states_*, sync_*, header_tags_*) is left untouched.

void c4_reset_caches(void);

c4_rpc_set_witness_keys

api/colibri.h

Sets witness/signer keys on an RPC context (hex-encoded).

Used for sync committee weak subjectivity signing during proof generation (sent to remote prover as "signers") and verification.

void c4_rpc_set_witness_keys(void* ctx, const char* witness_keys);

Parameters

  • ctx : The RPC context created by c4_create_rpc_ctx()
  • witness_keys : hex string with "0x" prefix (e.g. "0xabcd..."), or NULL to clear

c4_rpc_set_proxy_urls

api/colibri.h

Sets comma-separated RPC and Beacon API URLs for proxy mode.

When the prover mode is C4_PROVER_MODE_PROXY (3), the client supplies its own RPC and Beacon API endpoints. Call this after c4_create_rpc_ctx() and before the first c4_rpc_execute_json_status().

void c4_rpc_set_proxy_urls(void* ctx, const char* rpc_urls, const char* beacon_urls);

Parameters

  • ctx : The RPC context created by c4_create_rpc_ctx()
  • rpc_urls : comma-separated HTTPS RPC endpoint URLs, or NULL
  • beacon_urls : comma-separated Beacon API base URLs, or NULL

c4_rpc_set_min_latest_block_ts

api/colibri.h

Sets the lower bound for block.timestamp on "latest" requests.

The verifier rejects proofs whose block timestamp is older than ts for eth_call, eth_estimateGas, and colibri_simulateTransaction when the request uses the "latest" block tag. Pass 0 to disable the check. The host typically computes ts = now - max_age_seconds from the platform wallclock; the C library never reads the wallclock itself so the check works the same way on native, WASM, and embedded targets.

void c4_rpc_set_min_latest_block_ts(void* ctx, uint64_t ts);

Parameters

  • ctx : The RPC context created by c4_create_rpc_ctx()
  • ts : Lower bound as Unix timestamp in seconds (0 disables the check)

c4_rpc_execute_json_status

api/colibri.h

Executes one step of the unified RPC state machine.

This function drives the full RPC lifecycle: method type detection, proof generation (or remote proof fetching), and verification. Call it repeatedly until it returns "success" or "error".

The returned JSON format is identical to c4_verify_execute_json_status():

  • "success" with a "result" field containing the verified RPC result
  • "error" with an "error" field
  • "pending" with a "requests" array of data requests to fulfill

For "pending" responses, the "requests" array may contain requests of type "prover" (when using a remote prover) or "eth_rpc" (for unproofable methods), in addition to the usual "beacon_api" and "eth_rpc" requests from the prover/verifier.

Memory Management: The returned JSON string must be freed by the caller using free().

Example:

void* ctx = c4_create_rpc_ctx("eth_getBalance", "[\"0xabc...\", \"latest\"]", 1, 0, 0, 0);

while (1) {
    char* status_json = c4_rpc_execute_json_status(ctx);
    json_t status = parse_json(status_json);
    free(status_json);

    if (strcmp(status.status, "success") == 0) {
        printf("Result: %s\n", json_stringify(status.result));
        break;
    } else if (strcmp(status.status, "error") == 0) {
        fprintf(stderr, "Error: %s\n", status.error);
        break;
    } else if (strcmp(status.status, "pending") == 0) {
        for (int i = 0; i < status.requests_count; i++)
            handle_request(&status.requests[i]);
    }
}

c4_free_rpc_ctx(ctx);
char* c4_rpc_execute_json_status(void* ctx);

Parameters

  • ctx : The RPC context created by c4_create_rpc_ctx()

Returns

A JSON string describing the current status

c4_free_rpc_ctx

api/colibri.h

Frees all resources associated with an RPC context.

void c4_free_rpc_ctx(void* ctx);

Parameters

  • ctx : The RPC context to free (may be NULL, in which case this is a no-op)

c4_configure_chain

api/colibri.h

Registers a chain configuration at runtime from a JSON blob.

The JSON must be an object with a "chain_type" field that selects which chain-type-specific handler receives the rest of the payload. chain_type accepts either a numeric C4_CHAIN_TYPE_* constant or one of the canonical string selectors "ethereum", "op", "eez", "arbitrum". The remaining fields are forwarded unchanged to the handler; see the per-chain schema in src/chains/<chain>/... or the Adding-a-chain documentation for the exact layout (e.g. for Ethereum: chain_id, genesis_validators_root, fork_epochs, fork_versions, plus optional blob-schedule fields).

The handler owns heap-allocated copies of every inner table for the lifetime of the process; the caller may free its input immediately. Chains baked into the core (mainnet / sepolia / gnosis / OP mainnet / Arbitrum One / …) always take precedence over runtime entries.

Example:

{
  "chain_type": "ethereum",
  "chain_id":   42,
  "genesis_validators_root": "0x4b363db9...",
  "fork_epochs":   [0, 0, 0, 0, 0, 0, 1536],
  "fork_versions": [
    "0x00000000", "0x01000000", "0x02000000", "0x03000000",
    "0x04000000", "0x05000000", "0x06000000", "0x07000000"
  ]
}
    the caller must free with `free()`.
char* c4_configure_chain(const char* conf);

Parameters

  • conf : JSON object as C string (see schema above and per-chain docs)

Returns

NULL on success; otherwise a dynamically allocated error message