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

a bitmask holding flags used during the prover context.

prover_flags_t

prover/prover.h

a bitmask holding flags used during the prover context.

prover_trace_span_t

prover/prover.h

a struct holding the prover context.

c4_prover_create

prover/prover.h

create a new prover context Always returns a valid context - check ctx->state.error for validation errors.

Parameters

  • method : the rpc-method to proof (required, cannot be NULL)

  • params : the rpc-params to proof (optional, defaults to "[]" if NULL)

  • chain_id : the target chain

  • flags : the prover flags

Returns

the prover context, which needs to get freed with c4_prover_free.

c4_prover_free

prover/prover.h

cleanup for the ctx

Parameters

  • ctx : the prover context

c4_prover_execute

prover/prover.h

tries to create the proof, but if there are pending requests, they need to fetched before calling it again. This function should be called until it returns C4_SUCCESS or C4_ERROR.

Parameters

  • ctx : the prover context

Returns

the status of the prover

c4_prover_status

prover/prover.h

returns the status of the prover

Parameters

  • ctx : the prover context

Returns

the status of the prover

c4_prover_cache_get

prover/prover.h

Retrieve a cached value by key. First checks local cache, then global cache. If found in global cache, copies entry to local cache for thread-safety. Caller MUST NOT modify the returned data. Pointer is valid until cache cleanup or context destruction.

Parameters

  • ctx : the prover context

  • key : 32-byte cache key

Returns

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

c4_prover_cache_get_local

prover/prover.h

Retrieve a cached value by key, but only from the local cahe. Caller MUST NOT modify the returned data. Pointer is valid until cache cleanup or context destruction.

Parameters

  • ctx : the 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. Will be moved to global cache on context destruction if duration_ms > 0.

Parameters

  • ctx : the prover context

  • key : 32-byte cache key

  • value : pointer to the value to cache (ownership transferred)

  • size : size of the cached value in bytes

  • duration_ms : cache TTL in milliseconds (0 = local-only, never moved to global)

  • free : function to free the value when cache entry is removed

c4_prover_cache_cleanup

prover/prover.h

Clean up expired entries from global cache and enforce size limits. Removes entries that are expired OR would exceed size limit (unless in use).

Parameters

  • now : current timestamp in milliseconds

  • extra_size : additional size to reserve (for new entries)

c4_prover_cache_invalidate

prover/prover.h

Invalidate a cache entry by key (marks as expired).

Parameters

  • key : 32-byte cache key to invalidate

c4_prover_cache_stats

prover/prover.h

Get statistics about the global cache.

Parameters

  • entries : number of entries in global cache

  • size : current total size of cached data in bytes

  • max_size : maximum allowed cache size in bytes

  • capacity : current allocated capacity of the cache array

REQUEST_WORKER_THREAD

prover/prover.h

Simplified version of REQUEST_WORKER_THREAD_CATCH without cleanup code.

Parameters

  • ctx : the prover context

Last updated