Corpus Core Docs

prover.h

The prover API is used to create proofs for a given method and parameters.

Example:

prover_ctx_t* ctx = c4_prover_create("eth_getBlockByNumber", "[\"latest\", false]", chain_id, C4_PROVER_FLAG_INCLUDE_CODE);

// Execute prover in a loop:
data_request_t* data_request = NULL;
bytes_t proof = {0};
while (true) {
  switch (c4_prover_execute(ctx)) {
    case C4_SUCCESS:
      proof = bytes_dup(ctx->proof);
      break;
    case C4_PENDING:
      while ((data_request = c4_state_get_pending_request(&ctx->state)))
         fetch_data(data_request);
      break;
    case C4_ERROR:
      printf("Error: %s\n", ctx->state.error);
      break;
  }
}
c4_prover_free(ctx);

prover_flag_types_t

prover/prover.h

Prover options and runtime flags stored in prover_ctx_t.flags.

Combine with bitwise OR when calling c4_prover_create. Some flags are set internally during execution (e.g. C4_PROVER_FLAG_UV_WORKER_REQUIRED, C4_PROVER_FLAG_INPUT_VALIDATED); those must not be treated as public request options.

Per-flag semantics are documented on each enumerator below.

typedef enum {
  C4_PROVER_FLAG_INCLUDE_CODE       = 1 << 0,  // includes the code of the contracts when creating the proof for eth_call, otherwise the verifier will need to fetch and cache the code as needed
  C4_PROVER_FLAG_UV_SERVER_CTX      = 1 << 1,  // the proofser is running in a UV-server and if the we expect cpu-intensice operations, we should return pending after setting the C4_PROVER_FLAG_UV_WORKER_REQUIRED flag.
  C4_PROVER_FLAG_UV_WORKER_REQUIRED = 1 << 2,  // requests the proof execution to run in a worker thread instead of the main eventloop.
  C4_PROVER_FLAG_CHAIN_STORE        = 1 << 3,  // allows the prover to use internal request with data from the chain stroe
  C4_PROVER_FLAG_UNSTABLE_LATEST    = 1 << 4,  // usually we use latest-1, but if this is set we return the real "latest"
  C4_PROVER_FLAG_INCLUDE_SYNC       = 1 << 5,  // if true, the sync data will be included in the proof (requires the client_state to be set)
  C4_PROVER_FLAG_USE_DEBUG_TRACE    = 1 << 6,  // if true, eth_call uses legacy debug_traceCall (prestateTracer) instead of the default eth_createAccessList
  C4_PROVER_FLAG_ZK_PROOF           = 1 << 7,  // if true, the the prover will try to store the zk_proof within the sync_section
  C4_PROVER_FLAG_CALL_BLOCK_CONTEXT = 1 << 8,  // unused: eth_call now reads EVM block context from the verified RLP EL header
  C4_PROVER_FLAG_HYBRID             = 1 << 9,  // hybrid mode: header proof from remote server, execution data from RPC provider
  C4_PROVER_FLAG_PROXY              = 1 << 10, // server: request used client-supplied RPC/Beacon URLs (proxy mode)
  C4_PROVER_FLAG_LIGHT_CLIENT       = 1 << 11, // light client mode: extended header cache TTL for "latest" (full block_time instead of half)
  C4_PROVER_FLAG_LOGS_COMPLETENESS  = 1 << 12, // if true, eth_getLogs generates a completeness proof over the requested block range (proves no matching log was omitted)
  C4_PROVER_FLAG_INPUT_VALIDATED    = 1 << 13, // internal/transient: set once the request input params have been validated (see CHECK_JSON_INPUT). Prevents re-validation on async re-entries and nested dispatch. Not a request option and never serialized.
  C4_PROVER_FLAG_NIMBUS             = 1 << 14, // Nimbus CL compatibility: find child headers via slot scan instead of `headers?parent_root=` (status-im/nimbus-eth2#7305) and use the Nimbus historical_summaries URL.
  C4_PROVER_FLAG_LODESTAR           = 1 << 15, // Lodestar CL compatibility: enables the unofficial `/eth/v0/beacon/proof/state/{state_id}` (CompactMultiProof) endpoint used as a self-build fallback for LightClientBootstrap and Gloas LightClientUpdate when the standard endpoints do not return data. Must be OFF for non-Lodestar beacon clients so the fallback is never attempted.
  C4_PROVER_FLAG_ARB_BATCH_POSTER   = 1 << 16, // server precheck: prove `batch_poster` on L1 and embed it in sync_data. Not a client request option.
} prover_flag_types_t;

prover_flags_t

prover/prover.h

Bitmask of prover_flag_types_t values stored in prover_ctx_t.flags.

typedef uint32_t prover_flags_t;

bytes32[32]

prover/prover.h

CHECK_JSON_INPUT(val, def, error_prefix) - Validate request input params once per context.

Validates val against the schema def, but only if the input parameters have not been validated yet for this prover context. On success it sets C4_PROVER_FLAG_INPUT_VALIDATED so async re-entries (repeated C4_PENDING executions) and nested dispatch skip re-validation.

Prefer this over CHECK_JSON_CACHED for request parameters: it avoids hashing the payload on every call and instead relies on a single per-context flag. CHECK_JSON_CACHED remains the right choice for large results (e.g. eth_getBlockReceipts) which are validated once but are not the request input. Assumes a prover_ctx_t* ctx is in scope.

CHECK_JSON_INPUT(json_at(ctx->params, 0), JSON_GET_LOGS_FILTER_FIELDS, "Invalid eth_getLogs filter: ");
#define CHECK_JSON_INPUT(val, def, error_prefix)          \
  do {                                                    \
    if (!(ctx->flags & C4_PROVER_FLAG_INPUT_VALIDATED)) { \
      CHECK_JSON(val, def, error_prefix);                 \
      ctx->flags |= C4_PROVER_FLAG_INPUT_VALIDATED;       \
    }                                                     \
  } while (0)

#ifdef PROVER_CACHE
typedef union {
  uint8_t  bytes32[32];

prover_trace_span_t

prover/prover.h

State for a single proof generation run.

Create with c4_prover_create, drive c4_prover_execute until not C4_PENDING, then read proof. On failure, inspect state.error.

#ifdef PROVER_TRACE
// Forward declaration for pointer fields
typedef struct prover_trace_span prover_trace_span_t;

c4_prover_create

prover/prover.h

Allocates and initializes a prover context for one RPC proof request.

Always returns a non-NULL context. On invalid input, ctx->state.error is set and subsequent c4_prover_execute calls return C4_ERROR. ctx->version starts as this build's client version. A server replaces it with the requesting client's version before execution.

// The context is zero-filled with safe_calloc(). Do not mark this M_RET:
// ownership_returns(malloc) tells scan-build the block is uninitialized, so
// reads of state.error are reported as garbage. That report is not a real bug.
prover_ctx_t* c4_prover_create(char* method, char* params, chain_id_t chain_id, prover_flags_t flags);

Parameters

  • method : RPC method to prove (must not be NULL)
  • params : JSON array string, or NULL for "[]"
  • chain_id : target chain id
  • flags : bitmask of prover_flag_types_t

Returns

newly allocated context; release with c4_prover_free

c4_prover_free

prover/prover.h

Releases all resources owned by ctx, including the context struct.

void c4_prover_free(prover_ctx_t* ctx);

Parameters

  • ctx : prover context to destroy (may be NULL)

c4_prover_execute

prover/prover.h

Runs one step of proof generation for the chain module selected by ctx->chain_id.

When the return value is C4_PENDING, satisfy requests in ctx->state and call again. Repeat until C4_SUCCESS (ctx->proof populated) or C4_ERROR (ctx->state.error).

c4_status_t c4_prover_execute(prover_ctx_t* ctx);

Parameters

  • ctx : prover context (must not be NULL)

Returns

C4_PENDING, C4_SUCCESS, or C4_ERROR

c4_prover_status

prover/prover.h

Derives the current prover state without advancing execution.

c4_status_t c4_prover_status(prover_ctx_t* ctx);

Parameters

  • ctx : prover context (must not be NULL)

Returns

C4_ERROR if state.error is set, C4_SUCCESS if proof is ready, otherwise C4_PENDING

c4_prover_cache_get

prover/prover.h

Retrieve a cached value by key from the local list, then the global cache.

If found globally, copies metadata into the local list for thread-safe reuse.

const void* c4_prover_cache_get(prover_ctx_t* ctx, bytes32_t key);

Parameters

  • ctx : prover context
  • key : 32-byte cache key

Returns

read-only pointer to cached value, or NULL if not found (do not mutate; valid until cache cleanup or c4_prover_free)

c4_prover_cache_get_local

prover/prover.h

Retrieve a cached value by key from the local per-context list only.

const void* c4_prover_cache_get_local(prover_ctx_t* ctx, bytes32_t key);

Parameters

  • ctx : prover context
  • key : 32-byte cache key

Returns

read-only pointer to cached value, or NULL if not found

c4_prover_cache_set

prover/prover.h

Store a value in the local cache.

Entries with duration_ms > 0 may be promoted to the global cache when c4_prover_free runs; duration_ms == 0 keeps the entry local-only.

void c4_prover_cache_set(prover_ctx_t* ctx, bytes32_t key, void* value, uint32_t size, uint64_t duration_ms, cache_free_cb free);

Parameters

  • ctx : prover context
  • key : 32-byte cache key
  • value : cached payload (free takes ownership)
  • size : size of value in bytes
  • duration_ms : TTL in milliseconds for global promotion (0 = local-only)
  • free : callback invoked when the entry is evicted

c4_prover_cache_cleanup

prover/prover.h

Evicts expired or oversized entries from the global cache.

void c4_prover_cache_cleanup(uint64_t now, uint64_t extra_size);

Parameters

  • now : current time in milliseconds (same clock as current_ms)
  • extra_size : reserve this many bytes before enforcing the size cap

c4_prover_cache_invalidate

prover/prover.h

Marks a global cache entry as invalid (immediate expiry).

void c4_prover_cache_invalidate(bytes32_t key);

Parameters

  • key : 32-byte cache key to invalidate

c4_prover_cache_stats

prover/prover.h

Returns statistics for the global prover cache.

void c4_prover_cache_stats(uint64_t* entries, uint64_t* size, uint64_t* max_size, uint64_t* capacity);

Parameters

  • entries : number of entries in the global cache
  • size : total bytes stored in cached payloads
  • max_size : configured maximum cache size in bytes
  • capacity : allocated slot capacity of the global array

c4_reset_prover_caches

prover/prover.h

Clears chain-specific in-process prover 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_prover_caches(void);

current_ms

prover/prover.h

Monotonic millisecond clock for cache TTL and server timing.

Uses libuv when C4_PROVER_USE_UV_TIME is defined, otherwise current_unix_ms.

uint64_t current_ms();

Returns

milliseconds since an implementation-defined epoch (consistent within the process)

REQUEST_WORKER_THREAD

prover/prover.h

Simplified version of REQUEST_WORKER_THREAD_CATCH without cleanup code.

#define REQUEST_WORKER_THREAD(ctx) REQUEST_WORKER_THREAD_CATCH(ctx, );

Parameters

  • ctx : the prover context