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
a bitmask holding flags used during the prover context.
prover_flags_t
a bitmask holding flags used during the prover context.
prover_trace_span_t
a struct holding the prover context.
c4_prover_create
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 chainflags: the prover flags
Returns
the prover context, which needs to get freed with c4_prover_free.
c4_prover_free
cleanup for the ctx
Parameters
ctx: the prover context
c4_prover_execute
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
returns the status of the prover
Parameters
ctx: the prover context
Returns
the status of the prover
c4_prover_cache_get
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 contextkey: 32-byte cache key
Returns
read-only pointer to cached value, or NULL if not found.
c4_prover_cache_get_local
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 contextkey: 32-byte cache key
Returns
read-only pointer to cached value, or NULL if not found.
c4_prover_cache_set
Store a value in the local cache. Will be moved to global cache on context destruction if duration_ms > 0.
Parameters
ctx: the prover contextkey: 32-byte cache keyvalue: pointer to the value to cache (ownership transferred)size: size of the cached value in bytesduration_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
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 millisecondsextra_size: additional size to reserve (for new entries)
c4_prover_cache_invalidate
Invalidate a cache entry by key (marks as expired).
Parameters
key: 32-byte cache key to invalidate
c4_prover_cache_stats
Get statistics about the global cache.
Parameters
entries: number of entries in global cachesize: current total size of cached data in bytesmax_size: maximum allowed cache size in bytescapacity: current allocated capacity of the cache array
REQUEST_WORKER_THREAD
Simplified version of REQUEST_WORKER_THREAD_CATCH without cleanup code.
Parameters
ctx: the prover context
Last updated