verify.h
The verifier API executes a proof verification. when calling c4_verify_from_bytes, c4_verify needs to be called until the status is either C4_ERROR or C4_SUCCESS.
Example:
verify_ctx_t ctx = {0};
for (
c4_status_t status = c4_verify_from_bytes(&ctx, request_bytes, method, json_parse(args), chain_id);
status == C4_PENDING;
status = c4_verify(&ctx))
curl_fetch_all(&ctx.state);
if (ctx.success) {
ssz_dump_to_file_no_quotes(stdout, ctx.data);
return EXIT_SUCCESS;
}
else if (ctx.state.error) {
fprintf(stderr, "proof is invalid: %s\n", ctx.state.error);
return EXIT_FAILURE;
}
verify_flags_t
Bitmask of verify_flag_t values stored in verify_ctx_t.flags.
typedef uint32_t verify_flags_t;
verify_flag_t
Verification behavior and security options for verify_ctx_t.flags.
Combine values with bitwise OR. Hosts typically set flags before c4_verify_init.
Some flags are set by the verifier during execution (e.g. VERIFY_FLAG_REVERTED);
VERIFY_FLAG_SYNC_REINIT_TRIED and VERIFY_FLAG_INNER_BLOCK are internal and must not be set by hosts.
Per-flag semantics are documented on each enumerator below.
typedef enum {
VERIFY_FLAG_FREE_DATA = 1 << 0, // if set, the data section will be freed after verification. This flag is set when the verifier generates the actual result data from the proof and needs cleanup afterwards.
VERIFY_FLAG_PAP = 1 << 1, // if set, Pragmatic Adaptive Privacy mode is active. The verifier may use cached storage values for optimistic execution and verify them afterwards.
VERIFY_FLAG_REMOTE_PROVER = 1 << 2, // if set, a remote prover server is available. The verifier may emit C4_DATA_TYPE_PROVER requests (e.g. fetch tx_cache, request block proofs).
VERIFY_FLAG_PROOF_ONLY = 1 << 3, // if set, the verifier will only return the proof and not the data.
VERIFY_FLAG_HYBRID = 1 << 4, // SECURITY: only safe when proof was generated by local hybrid prover that already verified the header
VERIFY_FLAG_REVERTED = 1 << 5, // set by the verifier when an `eth_call` / `eth_estimateGas` was successfully verified but the underlying EVM execution reverted. The revert data is exposed via `verify_ctx_t.data` (raw `bytes` SSZ type). Bindings/hosts should surface this as a structured error (e.g. JSON-RPC code 3) so callers like ethers can decode `OffchainLookup` (EIP-3668 / CCIP-Read) reverts.
VERIFY_FLAG_OBLIVIOUS = 1 << 6, // if set, the verifier will use the oblivious_node
VERIFY_FLAG_SKIP_WSP_CHECK = 1 << 7, // if set, skip the Weak Subjectivity Period check for prover-provided or fetched sync committee data. SECURITY: Only use when an alternative trust anchor (witness signatures, hard-coded checkpoint, signed package) is available. Disabling increases the risk of long-range attacks when syncing across periods older than the WSP.
VERIFY_FLAG_SYNC_REINIT_TRIED = 1 << 8, // internal transient flag: set by the verifier once it has attempted a full sync-state reinitialization (clear + re-bootstrap from a trusted checkpoint) during this verification. Prevents an infinite reinit loop when the requested period is genuinely older than any obtainable committee. Not intended to be set by hosts.
VERIFY_FLAG_LOGS_COMPLETENESS = 1 << 9, // if set, eth_getLogs requires a completeness proof: a plain logs proof is rejected because completeness was requested by the caller.
VERIFY_FLAG_PERSIST_HEADER_CACHE = 1 << 10, // if set, `c4_rpc_execute` reloads the in-process EL header cache and header tags from storage at the start of the request and writes them back on context free (same pair the CLI uses). Intended for tests so prover `last_block_hash` and hybrid cache hits are reproducible from a storage snapshot. Not needed in production.
VERIFY_FLAG_INNER_BLOCK = 1 << 11, // internal transient flag: set by `c4_verify_block` while a block proof is on the stack. A nested call (eip2935, an L1 block inside an L2 proof) then leaves the `"finalized"` requirement on the outer block. Cleared before `c4_verify_block` returns, including on `C4_PENDING`. Not intended to be set by hosts; `c4_verify_init` strips it.
} verify_flag_t;
verify_ctx_t
State for a single proof verification run.
Populate via c4_verify_init or c4_verify_from_bytes, then drive c4_verify
until the status is not C4_PENDING. On success, read data (and optionally
proof); on failure, read state.error.
typedef struct {
char* method; ///< RPC method name (not owned by the context)
json_t args; ///< RPC arguments as a parsed JSON array (references caller string)
ssz_ob_t proof; ///< Proof SSZ object (view into request bytes or empty)
ssz_ob_t data; ///< Verified result SSZ object, or empty until verification completes
ssz_ob_t sync_data; ///< Sync committee / checkpoint SSZ slice from the request, or empty
bool success; ///< Set by chain verifiers when cryptographic checks pass
c4_state_t state; ///< Pending `data_request_t` list and accumulated error message
chain_id_t chain_id; ///< Chain id for module dispatch and chain-specific rules
bytes_t witness_keys; ///< Concatenated 20-byte witness signer addresses (heap-owned when set)
verify_flags_t flags; ///< Bitmask of `verify_flag_t` values for this verification
uint64_t min_latest_block_ts; ///< Minimum allowed `block.timestamp` for `"latest"` freshness checks; `0` disables
void* user_data; ///< Optional method-specific state preserved across `C4_PENDING` rounds
void (*user_data_free)(void*); ///< Called from `c4_verify_free_data` to release `user_data`; may be NULL
} verify_ctx_t;
method_type_t
How an RPC method is handled for the given chain, params, and verify flags.
Returned by c4_get_method_type before a verify_ctx_t exists. Used by bindings
and the CLI to choose proof, direct RPC, or local execution paths.
typedef enum {
METHOD_UNDEFINED = 0, ///< Unknown method name for this chain
METHOD_PROOFABLE = 1, ///< Requires a cryptographic proof (local or remote prover)
METHOD_UNPROOFABLE = 2, ///< Served via direct JSON-RPC without proof verification
METHOD_NOT_SUPPORTED = 3, ///< Recognized name but not implemented for this chain
METHOD_LOCAL = 4 ///< Executed inside Colibri without fetching a remote proof (e.g. PAP cache hit)
} method_type_t;
c4_get_request_type
Returns the SSZ container definition for proof requests on a chain type.
Each registered chain module supplies one request container used to decode
request_bytes in c4_verify_init.
const ssz_def_t* c4_get_request_type(chain_type_t chain_type);
Parameters
chain_type: chain family (e.g.C4_CHAIN_TYPE_ETHEREUM)
Returns
SSZ definition for the chain's request type, or NULL if unsupported
c4_get_chain_type_from_req
get the chain-type from a given request.
The chain-type is based on the first byte of the request, which corresponds to the chain_type_t enum value.
chain_type_t c4_get_chain_type_from_req(bytes_t request_bytes);
Parameters
request_bytes: the request bytes to analyze
Returns
the chain type, defaults to C4_CHAIN_TYPE_ETHEREUM for invalid requests
c4_get_req_type_from_req
get the request type from a given request.
The request-type is based on the chain type extracted from the request.
const ssz_def_t* c4_get_req_type_from_req(bytes_t request_bytes);
Parameters
request_bytes: the request bytes to analyze
Returns
the SSZ definition for the request type
c4_verify
Runs one step of proof verification for the chain module selected by ctx->chain_id.
When the return value is C4_PENDING, satisfy requests in ctx->state (via
c4_req_set_response / c4_req_set_error) and call again. When the return
value is C4_ERROR, inspect ctx->state.error. When C4_SUCCESS, check
ctx->success and read ctx->data.
c4_status_t c4_verify(verify_ctx_t* ctx);
Parameters
ctx: initialized verification context (must not be NULL)
Returns
C4_PENDING if external data is required, C4_ERROR on failure, C4_SUCCESS when the step finished without pending work
c4_verify_from_bytes
Initializes ctx from encoded request bytes and runs c4_verify once.
Equivalent to c4_verify_init(..., flags=0) followed by c4_verify. Prefer
c4_verify_init when non-zero verify_flags_t values are required.
c4_status_t c4_verify_from_bytes(verify_ctx_t* ctx, bytes_t request_bytes, char* method, json_t args, chain_id_t chain_id);
Parameters
ctx: verification context to initialize (must not be NULL)request_bytes: SSZ-encoded request (data,proof,sync_data); empty bytes require a separate proof pathmethod: RPC method name (must not be NULL)args: RPC parameters as a parsed JSON arraychain_id: chain id for dispatch
Returns
same as c4_verify after initialization (C4_SUCCESS, C4_ERROR, or C4_PENDING)
c4_verify_free_data
Releases heap resources held by ctx but not ctx itself.
Frees SSZ data when VERIFY_FLAG_FREE_DATA is set, clears ctx->state,
witness key bytes, and optional user_data via user_data_free.
void c4_verify_free_data(verify_ctx_t* ctx);
Parameters
ctx: verification context to clean up (must not be NULL)
c4_verify_init
Initializes a verification context from request bytes and RPC metadata.
Parses request_bytes when non-empty; when empty, validates that method
and args are sufficient for the resolved method_type_t (or returns an error
such as "missing proof!" for proofable methods).
c4_status_t c4_verify_init(verify_ctx_t* ctx, bytes_t request_bytes, char* method, json_t args, chain_id_t chain_id, verify_flags_t flags);
Parameters
ctx: verification context to initialize (must not be NULL)request_bytes: encoded proof request, or empty for proof-less checksmethod: RPC method name (must not be NULL)args: RPC parameters as a parsed JSON arraychain_id: chain id for dispatchflags: verification flags stored inctx->flags.VERIFY_FLAG_FREE_DATAandVERIFY_FLAG_INNER_BLOCKare dropped; the verifier sets those itself.
Returns
C4_SUCCESS on successful initialization, C4_ERROR if validation fails (see ctx->state.error)
c4_get_method_type
get the method type for a given chain-id, method, params and verify flags.
The params are used in PAP mode to check whether cached data is available, which may change the returned method type (e.g. PROOFABLE to LOCAL). The flags (e.g. VERIFY_FLAG_PAP) must be passed because this function is called before the verify context exists.
method_type_t c4_get_method_type(chain_id_t chain_id, char* method, json_t params, verify_flags_t flags);
Parameters
chain_id: the chain-idmethod: the rpc-method nameparams: the rpc-params as parsed json array (may be empty)flags: verify flags (e.g. VERIFY_FLAG_PAP for PAP mode)
Returns
METHOD_PROOFABLE, METHOD_UNPROOFABLE, METHOD_LOCAL, METHOD_NOT_SUPPORTED, or METHOD_UNDEFINED
params_out)
Transforms method and params for a remote prover request.
Each chain module may rewrite the RPC method and parameters before they
are sent to the remote prover. For example, PAP mode may replace
eth_call with eth_getProof and adjust the params accordingly.
If no module transforms the payload, the output buffers remain empty
and the caller should use the original method/params.
Inspect method_out / params_out length to detect transformation.
void c4_get_prover_payload(chain_id_t chain_id, const char* method, const char* params,
verify_flags_t flags, buffer_t* method_out, buffer_t* params_out);
Parameters
chain_id: the chain-idmethod: the original rpc-method nameparams: the original rpc-params as JSON stringflags: verify flags (e.g. VERIFY_FLAG_PAP)method_out: output buffer for the transformed method (empty if unchanged)params_out: output buffer for the transformed params (empty if unchanged)
ttl_out)
Rewrites a delegated remote-prover request into a cache-friendly GET (URL + TTL).
Each chain module may opt-in for selected RPC methods that produce deterministic proofs
per (method, block, version, zk_proof, client_state, witness_key). If the module supports
caching for the given call, it writes the URL path to url_out (heap-allocated string body)
and the Cache-Control: max-age=<n> bound in seconds to ttl_out, and returns true.
Callers use the returned URL together with C4_DATA_METHOD_GET and drop the JSON POST body.
On false, the caller must fall back to the classic POST + JSON payload path.
bool c4_get_prover_cache_request(chain_id_t chain_id, const char* method, json_t params,
uint32_t version, bool zk_proof, bool light_client,
bytes_t client_state, bytes_t witness_key,
char** url_out, uint32_t* ttl_out);
Parameters
chain_id: the chain idmethod: the RPC method nameparams: the parsed JSON params array (typically[<block>, ...])version: the client version number to embed in the URLzk_proof: whether the ZK proof variant is requestedlight_client: whether the caller runs in light-client mode (affectslatestTTL)client_state: the client_state snapshot (may be empty)witness_key: the witness/signer keys (may be empty)url_out: output pointer receiving the heap-allocated URL path (ownership transferred to caller)ttl_out: output pointer receiving themax-agebound in seconds (0 for immutable resources)
Returns
true if a chain module produced a GET URL, false otherwise
c4_init_ctx_t
Helper context for chain-specific RPC initialization (c4_init_rpc_ctx).
The caller (e.g. the bindings layer) populates chain_id and client_state
before invoking c4_init_rpc_ctx. Each registered chain hook may then
prepend data_request_t entries (typically C4_DATA_TYPE_CACHE) to the
snapshots list. Ownership of allocated entries transfers to the caller,
which is responsible for freeing them (or transferring ownership further).
typedef struct {
chain_id_t chain_id; ///< target chain
bytes_t client_state; ///< snapshot of `client_state` at request start (read-only)
data_request_t* snapshots; ///< output: linked list of cache snapshots (owned by caller after the call returns)
} c4_init_ctx_t;
c4_init_rpc_ctx
Dispatches to chain-specific RPC-context initialization hooks.
Each chain module may register an INIT_RPC_CTX hook via CMake. Hooks
are invoked in registration order; they typically inspect client_state
to decide which cached data to snapshot and prepend matching entries to
ctx->snapshots. Hooks not relevant for the given chain_id simply
return without modifying ctx.
Hooks may append to ctx->snapshots.
void c4_init_rpc_ctx(c4_init_ctx_t* ctx);
Parameters
ctx: initialization context (must not be NULL)
c4_reset_verifier_caches
Clears chain-specific in-process verifier caches.
Each chain module may register a RESET_CACHES hook via CMake. Hooks
are invoked in registration order. Persistent storage is left untouched.
void c4_reset_verifier_caches(void);