Guides

Production integration

Design a service around StateSync-GKR. Learn what the library provides and what your service adds, how requests and results stay matched, how to handle failures without weakening checks, what to record and what the measured deployments show.

StateSync-GKR is a library. A service that proves or verifies state operations adds request intake, state access, scheduling, transport, storage and monitoring around it. Since version 1.2.0 the repository also ships serving components for the intake, scheduling and transport parts, composed into a reference proof server; Serving components describes them. This guide describes the boundary between the library and your service, and the design decisions on your side of that boundary.

Before you begin#

What the library provides and what your service adds#

ConcernStateSync-GKR providesYour service adds
Circuitsprepare and PreparedSyncOne preparation per operation kind and configuration, built at startup
Provingprove_sync_op_prepared, make_job_prepared and prove_batch_parallel; in ssgkr-serving, completion::complete, complete_batch and ContinuousRunner, which build, prove, encode, hash and free each job on one workerThe worker count, jobs in flight and timeouts for your hosts
Verificationverify_sync_op_prepared and verify_encoded_sync_opThe list of configurations you accept and the handling of false
Transportencode_sync_result and the inner-proof-v1 format; in ssgkr-serving, wire frames bound to run and job identifiers, with size limits and a per-frame write deadlineClient authentication, transport security and retransmission
Statecompiler::smt_valid_native for a native check of one requestAuthenticated roots, witnesses, the order of updates and every change to stored state
Schedulingbatching::WitnessQueue, DeadlineScheduler and BatchProver as building blocks; in ssgkr-serving, the shared admission cap with explicit refusals, the return budget and the reference server's four The limits for your load and memory, and the choice of mode
ObservabilityThe library writes no logs and emits no metrics; ssgkr-serving records per-job stage times, and the reference server writes JSON-lines recordsMetrics export, traces and alerts

The facade also defines OssCoreInterface, a minimal contract between a host system and the prover: next_request returns the next pending request and deliver hands back a result. MockOssCore implements it in memory for tests. The contract has no request identifiers, queue bounds, backpressure, priorities or retries, so a service adds those on its own side, and it is not one of the interfaces that the release line keeps fixed.

Follow one request through the service#

  1. Admit. Assign an identifier, check the request against your bounds, then queue it or refuse it. Record the admission outcome.
  2. Build. Authenticate the root, read the leaf and the sibling path from your state store and build the SyncRequest.
  3. Prove. Select the preparation by the request's operation kind, build the job and prove it on your worker pool.
  4. Deliver. Encode the result and send it with the identifier.
  5. Verify. Check the received bytes against the original request with verify_encoded_sync_op.
  6. Record and apply. Record the outcome and its timings. Apply any state change that depends on the proof, such as adopting the new root of an update, only after verification returns true.

Admit and validate requests#

  • Fix the tree depth, leaf bound and layer strategy at deployment. Requests carry data for a configuration; they never select one. Configuration values do not limit resource use, so choose them before you accept requests from untrusted sources (Configuration).
  • Bound every queue. When a bound is reached, refuse the request and record the refusal as an outcome of its own. The admission cap in ssgkr-serving does this across connections.
  • Select the preparation by each request's operation kind. The prepared proving calls refuse a request of another kind with SyncError::KindMismatch in every build profile; treat that error as a request error.
  • Authenticate every root against your trusted source before you build a request. A root recomputed from caller-supplied siblings shows only that the siblings are consistent with that root.
  • Turn away malformed requests before proving with compiler::smt_valid_native, as shown in Proving state operations. It does not replace verification.
  • Apply your own transition rules to updates before proving. The engine proves any pair of old and new leaf states.
  • Bound the size of the proof messages you receive (Encoding and transport).

Prepared state in a long-running service#

  • Build one PreparedSync per operation kind and configuration at startup, share it across workers, and rebuild it when the configuration or the source revision changes. Prepared execution has the details.
  • Log the circuit commitment of each preparation, which circuit_commitment() returns. It identifies the exact circuit behind every proof made or checked with that preparation. For a stable 32-byte form in logs, pass it to wrap::prepared::circuit_commitment_bytes, which returns its canonical little-endian bytes.
  • A separate verifier service builds its own preparations from the same configuration. Proofs made under any other configuration fail its identity comparison.

Keep requests and results matched#

  • ProveJob, SyncResult and the encoded bytes carry no request identifier. Keep your own mapping from admission until a verdict exists.
  • Within one process, map job positions back to requests, as in Batching and parallelism. Between processes, carry the identifier in your envelope and verify each reply against the request it names, as in Encoding and transport.
  • Proving is deterministic, so a second proof for the same request and configuration has the same bytes as the first. Treat a repeated delivery for an identifier you have already settled as a duplicate.

Errors and async runtimes#

  • Every error type implements Debug and Clone, and most do not implement std::error::Error (Errors). Map them into your service's own error type by matching on the variant, instead of relying on ? conversion into a generic error type.
  • Proving and verification are synchronous and CPU-bound. In an async service, run them on a dedicated pool, such as your Rayon pool or a blocking task, so they do not stall the async executor.

Handle failures without weakening checks#

FailureWhat the library reportsAction
The configuration does not compileSyncError::Compile from prepare, prove_sync_op or make_jobFail startup and fix the configuration; a retry returns the same error
A malformed request: a path of the wrong length or an oversized leaf encodingSyncError::WitnessReject that request; other requests are unaffected
A request of another operation kind than the preparationSyncError::KindMismatch { prepared, requested } from prove_sync_op_prepared or make_job_preparedReject that request, or route it to the preparation of its own kind
A request that does not hold, a key out of range or a mismatched public inputProving still succeeds; verification returns falseReject the request. A successful proving call is never acceptance
Received bytes fail decoding or the identity comparisonfalse from verify_encoded_sync_opReject the bytes and check the sender's configuration and transport. Never change the expected identity to match
A proof is rejectedfalseFinal for those bytes. Do not weaken the verifier and do not retry the same input in a loop
Encoding failsEncodeErrorCountOverflow means a leaf bound above 65,535; the other variants mean the proof did not come unchanged from this prover
prove_batch returns fewer proofs than jobsA short vectorThe configuration does not compile; compare counts before pairing proofs with jobs
A tampered or mismatched proof is acceptedtrue where false was expectedStop and report it through the Security policy
A configuration value at or above the field order, or a leaf pre-image of the wrong width passed to hash_leaf_preA panic, in every build profileValidate the configuration at startup and call hash_leaf_pre only with pre-images from leaf_fold. Isolate proving so that a panic ends one worker, not the service

Record the source revision, the configuration and the error class with every failure; Errors lists every variant. A type that places each offered request in exactly one outcome class keeps these rules visible in code and gives your success fractions a complete denominator:

src/outcome.rsRust
use statesync_gkr::SyncError;

/// The final outcome of one offered request. Every offered request ends in
/// exactly one outcome, so success fractions can count all offers.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Outcome {
    /// The verifier returned `true` within the latency budget.
    Accepted,
    /// The verifier returned `true` after the latency budget.
    AcceptedLate,
    /// The verifier returned `false`. Final for these bytes.
    Rejected,
    /// The service could not produce a proof.
    NotProved(Cause),
    /// Refused before any work started, for example because a bounded queue was full.
    Refused,
}

/// Why a request could not be proved.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Cause {
    /// The configuration does not compile. Fix it; a retry fails the same way.
    Configuration,
    /// The request is malformed. Reject it; other requests are unaffected.
    Request,
}

/// Map a proving error to its cause.
pub fn cause_of(error: &SyncError) -> Cause {
    match error {
        SyncError::Compile(_) => Cause::Configuration,
        SyncError::Witness(_) => Cause::Request,
        // The request was routed to the preparation of another kind.
        SyncError::KindMismatch { .. } => Cause::Request,
    }
}

Record what happened#

RecordWhy it matters
Request identifier, operation kind and configuration: depth, leaf bound and strategyTies each outcome to one circuit
Source revision and the preparation's circuit commitmentIdentifies the code and the circuit that produced or checked a proof
Each root and the source that authenticated itRoot provenance is your responsibility
Scheduled or received time, admission, batch start and end, encoding, sending, receipt and verificationSeparates queueing from computation and transport
The outcome class of every offered requestSuccess fractions need every offered request in the denominator
Batch sizes and queue length per operation kind over timeA queue that keeps growing at a constant means the setting does not sustain that rate
Worker CPU use and process memoryCapacity planning. Spare average CPU is a reason to examine the serving path, not a proportional capacity reserve
Encoded proof sizeTransport and storage sizing

Measure each latency on one monotonic clock, from the request's scheduled or received time to the verifier's result, and do not subtract timestamps taken on different hosts to estimate network time. When you report throughput, compute rates over the completion window including the drain after input stops. Accepted requests divided by the scheduled duration can hide a growing queue.

Root provenance and state changes#

StateSync-GKR does not authenticate roots, commit state, order updates or reach consensus, and the measured serving profiles end at the acceptance of the inner proof. Your service owns these steps:

  • Record which trusted source supplied each root, and when.
  • Order the updates to one tree yourself, and build each update against the root that the previous update produced.
  • Adopt a new root, or make any other state change that depends on a proof, only after the verifier accepts that proof.

Choose a deployment shape#

The v1.2.0 serving measurements come from the reference server in benches/serving, which delivered every proof over TCP to a separate verifying frontend, with v1.1.0 measured on the same day. All of them used a balanced mix of membership, non-membership and update requests at depth 24 and periodic arrivals:

Worker deploymentOffered loadServer settingsResultPeriod
One 192-core VM, 384 GiB3,300 requests/sv1.2.0 continuous, 190 jobs in flight, one connectionAll 5,940,000 timed requests accepted within one second; p99 35.3 msOne 30-minute run
One 192-core VM, 384 GiB1,000 requests/sv1.2.0 continuousEvery timed request within one second; p99 33.7–33.9 ms, against 433.8–475.1 ms for v1.1.0 the same dayThree 60-second runs
One 96-core VM, 192 GiB3,000 requests/sv1.2.0 continuous, 94 jobs in flightEvery timed request within one second; p99 37.6 msOne 15-second run
One 48-core VM, 96 GiB2,000 requests/sv1.2.0 continuous, 46 jobs in flightEvery timed request within one second; p99 147.0 msOne 15-second run
One 48-core VM, 96 GiB500 requests/sv1.2.0 continuousAll 450,000 timed requests within one second; p99 33.4 msOne 15-minute run

Serving capacity gives the full v1.2.0 results, and Benchmark results keeps the earlier v1.1.0 campaign. What these runs show about deployment:

  • Prefer a loop that never waits for a batch. At 1,000 requests/s on 192 cores, the same v1.2.0 prover had p99 159.2–162.0 ms in the earlier serving loop and 33.7–33.9 ms in continuous mode. Timed in the earlier loop at 1,150 requests/s, freeing one finished batch's intermediate data on one thread took 45.27 ms of the 45.50 ms pause after each full batch; in continuous mode each worker frees its own job in about 23 µs.
  • Plan the reply traffic. Every reply carries a complete proof of about 177 to 187 KB. On 96 and 192 cores the limit within one second was one connection's reply traffic, about 5 Gbit/s, while the server had CPU to spare; in 15-second screens, two connections to the same server carried 5,000 requests/s within one second.
  • Compare deployments at equal total resources. At 1,000 requests/s with v1.1.0, two 48-core workers kept every request within 500 ms, while one 96-core worker with batch cap 96 built up a queue. With v1.2.0 both held p99 below 35 ms. Performance tuning has the numbers and their limits.
  • Bound memory and count refusals. Above capacity, the server's peak memory sampled from /proc was 535.2 MiB under a 2,760 MiB limit (393.5 MiB by GNU time); finished replies wait under the return budget instead of growing a queue. Requests that are refused, never sent or never answered all count against your success fraction.
  • A short pass is not a confirmation. With v1.1.0 at 1,150 requests/s, three 15-second screens met one second for every request, and the 60-second run did not. Confirm a setting over a longer window before you rely on it.
  • A finite run is not sustained capacity. That v1.1.0 run completed 1,123.89 requests per second over its completion window, including the drain after input stopped, and its queue grew throughout, so it did not establish a rate that the deployment could sustain.
  • Your traffic is not the benchmark's. The benchmark cycled 192 fixed fixtures per operation kind with periodic arrivals. Random or bursty traffic and other operation mixes need their own measurements.

Checklist#

  • Roots are authenticated against a trusted source before requests are built.
  • Every queue is bounded, and refusals are recorded as their own outcome.
  • One preparation exists per operation kind and accepted configuration, and its circuit commitment is logged.
  • Every request keeps an identifier and its original form until a verdict exists.
  • Only a true verification result counts as acceptance, and state changes wait for it.
  • Configuration errors stop the service; request errors reject one request; false is final for the bytes.
  • Every offered request ends in exactly one recorded outcome, with timings on one clock.
  • Deployment settings are confirmed with a long run on your own traffic before you rely on them.

Next steps#