Skip to content

API Reference — CoSMeTIC Prover APIs

CoSMeTIC exposes three independent Flask APIs, each targeting a different statistical test. All three share the same job-based workflow and endpoint structure.


Services and ports

API File Default port Test
api_acc_test.py Logistic Accuracy 5012 Proves accuracy of a logistic classifier
api_ks_test.py Kolmogorov-Smirnov 5013 Proves the KS test statistic
api_lrt_test.py Likelihood Ratio Test 5014 Proves the LRT statistic (full vs. reduced model)
api_input_files.py Input Files (helper) 5015 Lists and downloads the input_<hash>.json files from all three tests (read-only; see section 10)

Replace <HOST> and <PORT> in all examples below with the actual server address and port.


Workflow overview

POST /<test>/setup          (async) → job_id
GET  /jobs/<job_id>         → poll until "done"

POST /check-hash/           → do proofs already exist for this user_hash? (optional)

POST /prove-hash/           (async) → job_id
GET  /jobs/<job_id>         → poll until "done"

POST /verify-job/<job_id>   → verification result
GET  /jobs/<job_id>/download → ZIP of .pf files

DELETE /jobs/<job_id>       → cleanup

Key concepts

user_hash

The raw hash string identifying the user record (leaf) you want to prove membership or non-membership for.

  • If the hash exists in the SMT → inclusion proof.
  • If the hash does not exist → exclusion proof using the default-leaf path.

nonce

A random vector used to ensure zero-knowledge soundness across repeated proofs.

  • Shape varies by test (see table below).
  • If omitted, the server generates a random nonce automatically.
  • If provided, must match the exact shape expected by the circuit.
API Nonce shape Example
ACC (1, 3) [[0.0, 0.0, 0.0]]
LRT (1, 11) [[0.0, 0.0, ..., 0.0]] (11 values)
KS (1, 17) [[0.0, 0.0, ..., 0.0]] (17 values)

smt_list

The list of SMTs to generate proofs for within a single request.

API Valid values Meaning
ACC ["length", "acc"] Two sub-trees for accuracy
LRT ["full", "reduced"] Full model vs. reduced model
KS (not required) s1 and s2 are implicit

1. Setup

Setup builds the SMTs and compiles EZKL circuits (proving keys, verification keys, settings). It must complete before any proof jobs can run.

Invocation modes

Mode 1 — explicit JSON (recommended)

curl -X POST "http://<HOST>:<PORT>/<TEST>/setup" \
  -H "Content-Type: application/json" \
  -d '{
    "ID": "1,1",
    "ZKP_MODE": 1,
    "GEN_FULL_PROOF": 1,
    "SETUP_MRP": 1,
    "SETUP_LTR": 1,
    "ZKP_SCALER": 10,
    "TREE_HEIGHT": 8,
    "TEST_INCLUSION": false,
    "TEST_EXCLUSION": false
  }'

Replace <TEST> with acc, ks, or lrt.

Mode 2 — defaults from environment variables

curl -X POST "http://<HOST>:<PORT>/<TEST>/setup"

Mode 3 — partial override

curl -X POST "http://<HOST>:<PORT>/<TEST>/setup" \
  -H "Content-Type: application/json" \
  -d '{"TREE_HEIGHT": 16}'

Setup payload fields

Field Type Description
ID string Comma-separated run IDs ("1,1")
ZKP_MODE int (0/1) Enable actual zk-SNARK generation
GEN_FULL_PROOF int (0/1) Generate proofs at every SMT level
SETUP_MRP int (0/1) Compile/key-gen for the MRP circuit
SETUP_LTR int (0/1) Compile/key-gen for the LTR circuit
ZKP_SCALER int Fixed-point scaling factor for circuits
TREE_HEIGHT int SMT height (e.g., 8, 16, 256)
TEST_INCLUSION bool Run an inclusion test after setup
TEST_EXCLUSION bool Run an exclusion test after setup

Setup response

{
  "job_id": "<uuid>",
  "status_url": "/jobs/<uuid>"
}

2. Check job status

All async operations (setup and prove) return a job_id. Poll until status == "done".

curl -s "http://<HOST>:<PORT>/jobs/<job-id>"

Status values

Status Meaning
queued Waiting to be picked up by the executor
running Actively generating proofs or running setup
done Complete — proofs/artifacts are ready
error Failed — check the error field in the response

3. Submit a proof generation job

ACC

curl -X POST "http://<HOST>:<PORT>/prove-hash/" \
  -H "Content-Type: application/json" \
  -d '{
    "smt_list": ["length", "acc"],
    "user_hash": "<RAW_HASH>",
    "nonce": [[0.0, 0.0, 0.0]]
  }'

LRT

curl -X POST "http://<HOST>:<PORT>/prove-hash/" \
  -H "Content-Type: application/json" \
  -d '{
    "smt_list": ["full", "reduced"],
    "user_hash": "<RAW_HASH>",
    "nonce": [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]
  }'

KS

curl -X POST "http://<HOST>:<PORT>/prove-hash/" \
  -H "Content-Type: application/json" \
  -d '{
    "user_hash": "<RAW_HASH>",
    "nonce": [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]
  }'

4. Verify proofs

curl -s -X POST "http://<HOST>:<PORT>/verify-job/<job-id>"

Response structure

{
  "ok": true,
  "user_hash": "<RAW_HASH>",
  "results": [
    {"proof_file": "s1/ltr/test_<hash>.pf", "verified": true},
    ...
  ]
}

5. Download proofs (ZIP)

curl -OJ "http://<HOST>:<PORT>/jobs/<job-id>/download"

The downloaded archive contains .pf proof files organized by SMT and proof type:

<smt_name>/
  ltr/
    test_<raw_hash>.pf
  mrp/
    test_<raw_hash>_<level>.pf

6. Download precomputed abs-gap proof (KS and LRT only)

curl -OJ "http://<HOST>:<PORT>/abs-gap-proof"

Returns a single proof_1.pf file representing the abs-gap statistic generated during setup.


7. Download compiled artifacts

These static artifacts are produced during setup and can be reused for many proof jobs.

Compiled circuits

curl -X POST "http://<HOST>:<PORT>/fetch-cc" \
  -H "Content-Type: application/json" \
  -d '{"smt_list": ["s1", "s2"], "which": ["ltr", "mrp"]}' -OJ

Verification keys

curl -X POST "http://<HOST>:<PORT>/fetch-vk" \
  -H "Content-Type: application/json" \
  -d '{"smt_list": ["s1", "s2"], "which": ["ltr", "mrp"]}' -OJ

Settings

curl -X POST "http://<HOST>:<PORT>/fetch-settings" \
  -H "Content-Type: application/json" \
  -d '{"smt_list": ["s1", "s2"], "which": ["ltr", "mrp"]}' -OJ

For ACC and LRT, replace ["s1", "s2"] with the relevant smt_list (e.g., ["full", "reduced"] for LRT).


8. Delete a job

curl -X DELETE "http://<HOST>:<PORT>/jobs/<job-id>"

Marks the job as cancelled and removes its proof files from disk if the job was in done state.


9. Check if a hash has proofs

Available on all three APIs (ACC, KS, LRT). Checks whether input_<hash>.json files already exist for a given user_hash in that API's proof-results-*/ltr/ folders. It only reads the filesystem and never generates anything.

curl -X POST "http://<HOST>:<PORT>/check-hash/" \
  -H "Content-Type: application/json" \
  -d '{"user_hash": "<RAW_HASH>"}'

Response structure

Each API reports one flag per SMT, plus found_in_both and exists (found in at least one):

API Port Per-SMT keys
ACC 5012 found_in_log_acc, found_in_log_acc_length
KS 5013 found_in_s1, found_in_s2
LRT 5014 found_in_ll_full, found_in_ll_reduced
{
  "test_name": "logistic accuracy",
  "hash": "0d",
  "found_in_log_acc": true,
  "found_in_log_acc_length": true,
  "found_in_both": true,
  "exists": true
}

If user_hash is missing, the API returns 400 with {"error": true, "message": "user_hash is required"}.

Default ID only

The check looks only in the prover ID folder 1 (proofs/<test>/<smt>/1/proof-results-*/ltr/), which is what the default "ID": "1,1" produces. Proofs generated with a different setup ID are reported as exists: false.


10. Input Files API (port 5015)

A standalone, read-only helper service (api_input_files.py) that collects the input_<hash>.json files produced by all three tests. It runs as its own container in the Docker stack and reads from the shared proofs/ directory.

It scans these SMT folders under proofs/:

App SMT folders
ACC logistic_accuracy/log_acc, logistic_accuracy/log_acc_length
LRT logistic_lrt/ll_full, logistic_lrt/ll_reduced
KS ks/simple_sum_bincount_s1, ks/simple_sum_bincount_s2

As with /check-hash/, only the default prover ID folder 1 is scanned.

List input files

curl -s "http://<HOST>:5015/input-files/"

GET /input-files/list is an alias. Response:

{
  "count": 1,
  "files": [
    {
      "app": "acc",
      "branch": "log_acc",
      "proof_results": "proof-results-20260625063000",
      "hash": "0d",
      "path": "logistic_accuracy/log_acc/1/proof-results-20260625063000/ltr/input_0d.json"
    }
  ]
}

Download all input files (ZIP)

curl -OJ "http://<HOST>:5015/input-files/zip"

Returns all_input_files.zip, with entries named {app}/{branch}/{proof_results}/ltr/input_{hash}.json. Returns 404 if no input files exist yet.

Health check

curl -s "http://<HOST>:5015/health"

Returns {"status": "ok", "service": "input-files"}.

The port can be changed with the API_input_files_port environment variable (default 5015).