Streaming Consensus Protocol
Problem Statement
When operators independently fetch time-sensitive data from external sources (price feeds, sanctions lists, risk scores), they may receive different values due to timing differences, API response variability, or data source updates between requests. Since BLS signature aggregation requires all operators to sign the identical message, even minor numeric discrepancies in policy task data produce different consensus digests, causing aggregation to fail.Protocol Architecture
Newton solves this through a streaming two-phase consensus protocol built on NATS messaging. The protocol separates data collection (Prepare phase) from policy evaluation and BLS signing (Evaluate phase), using pipelined streaming to minimize end-to-end latency. Although the Evaluate phase performs two logical steps — policy evaluation and BLS signing — these execute atomically within a single NATS round-trip: each operator evaluates the policy, immediately signs the result, and streams the signed response back to the gateway. The protocol achieves low latency through three key properties:- Non-blocking fan-out. The gateway publishes a single NATS message that reaches all subscribed operators simultaneously, rather than making sequential per-operator requests.
- Streaming response collection. Operator responses are processed individually as they arrive over the NATS subscription, not collected in batch.
- Early quorum exit. Quorum is checked on every incoming Evaluate response. The moment the stake-weighted threshold is met, the protocol completes without waiting for remaining operators.
Prepare Phase: Distributed WASM Data Collection
The gateway publishes a Prepare request to the NATS task subject for the relevant chain. All operators subscribed to that chain’s task subject receive the request simultaneously. Each operator independently executes the WASM data provider — the “policy data WASM” — in its own sandboxed Wasmtime environment (WASM-Sandboxed Data Providers), fetches external data from the configured data sources, and publishes a Prepare response to the task-specific response subject containing:- The generated policy task data with ECDSA attestation
- A hash of the data for quick comparison
- A timestamp for freshness verification
Consensus Computation
The gateway applies median-based normalization to produce a single canonical dataset from the Prepare phase responses:- Early consensus check. If all operator responses contain identical policy task data, the gateway skips median computation entirely and uses the common data as-is. This avoids unnecessary processing for deterministic data sources.
- Numeric field extraction. The gateway parses each operator’s policy data JSON and extracts all numeric fields (integers and floating-point values) by path.
- Median computation. For each numeric field across all operator responses, the gateway computes the median value. The median is chosen over the mean because it is robust to outliers: a single operator returning an anomalous value does not skew the result.
- Tolerance verification. Each operator’s value is checked to ensure it falls within a configurable tolerance of the computed median. Values outside tolerance are rejected. This prevents operators with stale or manipulated data from influencing the consensus dataset.
- Normalization. All operator responses are normalized to use the median values, producing a canonical policy task dataset that all operators will use in the Evaluate phase.
| Parameter | Reference Default | Description |
|---|---|---|
| Tolerance threshold | 10% | Maximum deviation from median before rejection |
Evaluate Phase: Policy Evaluation and BLS Signing
The gateway publishes an Evaluate request to the NATS task subject with the consensus policy task data, the policy configuration fetched from on-chain, the original intent, and the task’s reference block. Each operator:- Receives the Evaluate request via its NATS subscription.
- Constructs the task response using the consensus policy task data (not their own data).
- Fetches the Rego policy from IPFS by CID.
- Evaluates the Rego policy against the canonical data.
- Computes the consensus digest (attestations zeroed).
- Signs the consensus digest with their BLS key.
- Publishes the BLS-signed response to the task-specific NATS response subject.
NATS Messaging Architecture
Newton uses NATS as its core messaging layer for all gateway-operator communication. NATS provides sub-millisecond message dispatch, automatic reconnection with configurable backoff, guaranteed per-subject ordering, and natural publish-subscribe fan-out. Subject hierarchy. All NATS subjects follow a structured namespace:shares.{task_id}) carry threshold decryption partial shares encrypted end-to-end to the recipient operator’s individual X25519 public key. DKG subjects are used during key generation ceremonies when the operator set changes.
Message authentication. All gateway-published messages include a gateway signature (EIP-712 typed structured data) that operators verify before processing. This prevents unauthorized parties from injecting tasks into the NATS subject namespace.
Deployment modes. NATS supports two deployment configurations:
| Mode | Description | Use Case |
|---|---|---|
| Embedded | NATS server runs in-process within the gateway | Local development and testing |
| Cluster | External multi-node NATS cluster with replication | Staging and production deployment |