proofer.h
The proofer API is used to create proofs for a given method and parameters.
Example:
proofer_ctx_t* ctx = c4_proofer_create("eth_getBlockByNumber", "[\"latest\", false]", C4_PROOFER_FLAG_INCLUDE_CODE);
to use run the c4_proofer_execute in a loop:
```c
data_request_t* data_request = NULL;
bytes_t proof = {0};
char* error = NULL;
while (true) {
switch (c4_proofer_status(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:
error = strdup(ctx->state.error);
break;
}
}
c4_proofer_free(ctx);
proofer_flag_types_t
a bitmask holding flags used during the proofer context.
typedef enum {
C4_PROOFER_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_PROOFER_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_PROOFER_FLAG_UV_WORKER_REQUIRED flag.
C4_PROOFER_FLAG_UV_WORKER_REQUIRED = 1 << 2, // requests the proof execution to run in a worker thread instead of the main eventloop.
C4_PROOFER_FLAG_CHAIN_STORE = 1 << 3, // allows the proofer to use internal request with data from the chain stroe
} proofer_flag_types_t;
proofer_flags_t
a bitmask holding flags used during the proofer context.
typedef uint32_t proofer_flags_t;
proofer_ctx_t
a struct holding the proofer context.
typedef struct {
char* method; // rpc-method
json_t params; // rpc- params
bytes_t proof; // result or proof as bytes
chain_id_t chain_id; // target chain
c4_state_t state; // proofer ctx state, holind errors and requests.
proofer_flags_t flags; // proofer flags
bytes_t client_state; // optional client_state representing the synced periods and trusted blockhashes
bytes_t witness_key; // witness key for the proofer
#ifdef PROOFER_CACHE
cache_entry_t* cache; // cache for the proofer (only active in the server context)
#endif
#ifdef HTTP_SERVER
uint32_t client_type; // client type for the proofer (for beacon API only)
#endif
} proofer_ctx_t;
c4_proofer_create
create a new proofer context
proofer_ctx_t* c4_proofer_create(char* method, char* params, chain_id_t chain_id, proofer_flags_t flags);
Parameters
method
: the rpc-method to proofparams
: the rpc-params to proofchain_id
: the target chainflags
: the proofer flags
Returns
the proofer context, which needs to get freed with c4_proofer_free
c4_proofer_free
cleanup for the ctx
void c4_proofer_free(proofer_ctx_t* ctx);
Parameters
ctx
: the proofer context
c4_proofer_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.
c4_status_t c4_proofer_execute(proofer_ctx_t* ctx);
Parameters
ctx
: the proofer context
Returns
the status of the proofer
c4_proofer_status
returns the status of the proofer
c4_status_t c4_proofer_status(proofer_ctx_t* ctx);
Parameters
ctx
: the proofer context
Returns
the status of the proofer
Last updated