Skip to main content

PRISM Consensus Engine

QoreChain embeds PRISM (Policy-driven Reinforcement-learning for Intelligent State Machines), a reinforcement-learning optimization layer, directly into the consensus layer via the x/rlconsensus module. PRISM observes chain metrics every N blocks and is designed to run inference through a fixed-point neural network and propose consensus parameter adjustments — all deterministically, with no floating-point arithmetic in consensus-critical paths.

Current status (mainnet checked 4 November 2026 on v3.2.6, which it ran until 12 November 2026 when it moved to v3.2.7; testnet checked 27 October 2026 on v3.2.6; it has run v3.2.8 since 12 November 2026)

Mainnet. The agent is in conservative mode, collects an observation and a reward every 10 blocks, and has no policy weights loaded: it has taken 0 steps and applies no parameter change. Block time is determined by the validators' node configuration, not by PRISM. Loading a policy, changing the mode, resuming the agent and updating the reward weights are governance actions that are currently disabled on mainnet by the circuit breaker (the four control messages are still on the disabled list), so the agent's state cannot have changed. Since v3.2.6 the PRISM query routes under /qorechain/rlconsensus/v1/ answer on mainnet as well (checked 4 November 2026: all seven returned 200; the agent reported conservative mode, epoch 0, 0 steps, no policy weights, an empty last action and the default applied values). The four control messages are still on the disabled list.

Testnet. Testnet governance set the agent to shadow mode and loaded a small demonstration policy (25 inputs, one hidden layer of 4 units, 5 outputs, 129 weights, epoch 1; it is a test of the plumbing, not the production network described below). In shadow mode the agent observes every 10 blocks, computes its reward and a proposed action, and records them (rl_action_proposed event) without changing any value: applied_params keeps its defaults (block time 5000 ms, gas price floor 100) and last_action reports "applied": false. Since v3.2.6 both networks serve the module over REST under /qorechain/rlconsensus/v1/: agent (mode, epoch, step count, circuit-breaker state), params, observation, reward, policy, applied_params and last_action; the agent circuit breaker was corrected and its history is bounded in the same release, and the rlConsensusParams EVM precompile (0x…0C01) now returns the module's values (the precompile is active on the testnet only; on mainnet it is not active and a call returns empty data, checked 4 November 2026).

Two release changes tighten what a future policy or parameter change can do. Since v3.2.2 a governance policy update is validated with checked arithmetic. Since v3.2.3 the governance messages are range-checked on the raw wire value (the agent mode) and each reward weight must lie between 0 and 1.

The PRISM optimization loop: observe chain state, run policy inference, clamp and apply parameter changes, then feed the result back.


Architecture Overview​

PRISM consists of four components:

  1. Observation Collector — Gathers 25-dimensional chain state vectors at configurable intervals.
  2. Policy Network (MLP) — A Go-native multi-layer perceptron that maps observations to actions.
  3. Reward Computer — Evaluates the quality of parameter changes using a weighted multi-objective function.
  4. Circuit Breaker — Monitors chain health and reverts all PRISM-tuned parameters if instability is detected.

All components operate within the ABCI lifecycle and produce deterministic, verifiable outputs across all validator nodes.


Policy Network​

The policy network is a feedforward multi-layer perceptron (MLP) implemented entirely in Go with int64 fixed-point arithmetic (scaled by 10^8).

Network Architecture​

The table and parameter count below describe the design size of the policy network (two hidden layers of 256 units). No policy of this size is loaded on either network: mainnet has no policy loaded, and the testnet runs a small demonstration policy (25 inputs, one hidden layer of 4 units, 5 outputs, 129 weights).

PropertyValue
Input dimensions25
Hidden layers2
Hidden layer sizes256, 256
Output dimensions5
Activation (hidden)ReLU
Activation (output)tanh
Total parameters73,733
Precisionint64 fixed-point (scaled by 10^8)

Parameter Count Breakdown​

Layer 1: 25 * 256 + 256 = 6,656 (input -> hidden_1)
Layer 2: 256 * 256 + 256 = 65,792 (hidden_1 -> hidden_2)
Layer 3: 256 * 5 + 5 = 1,285 (hidden_2 -> output)
Total: 73,733

Fixed-Point Arithmetic​

All MLP computations use int64 values scaled by FixedPointScale = 10^8. This eliminates non-determinism from IEEE 754 floating-point rounding differences across hardware platforms.

  • Multiplication: fixMul(a, b) = (a / SCALE) * b + (a % SCALE) * b / SCALE (split to prevent overflow)
  • ReLU: relu(x) = max(0, x)
  • tanh: Pade approximant tanh(x) ~ x * (3*S - x^2) / (3*S + x^2) for |x| <= 2.5*SCALE, clamped to +/- SCALE otherwise

Policy weights are designed to be stored on-chain as a flattened []int64 vector and updated via governance proposal. No policy is loaded on mainnet today; the testnet runs a small demonstration policy in shadow mode (see the status note above).


Observation Vector​

PRISM collects a 25-dimensional observation vector at each observation interval (default: every 10 blocks).

IndexDimensionDescription
0block_utilizationBlock gas used / block gas limit
1tx_countNumber of transactions in the block
2avg_tx_sizeMean transaction size in bytes
3block_timeTime since previous block (ms)
4block_time_deltaBlock time minus target block time (ms)
5gas_price_50thMedian gas price
6gas_price_95th95th-percentile gas price
7mempool_sizeNumber of pending transactions
8mempool_bytesTotal bytes of pending transactions
9validator_countActive validator count
10validator_giniGini coefficient of validator power distribution
11missed_block_ratioFraction of validators that missed signing
12avg_commit_latencyAverage commit round latency (ms)
13max_commit_latencyMaximum commit round latency (ms)
14precommit_ratioFraction of precommits received
15failed_tx_ratioFraction of failed transactions
16avg_gas_per_txMean gas consumed per transaction
17reward_per_validatorMean reward per validator (uqor)
18slash_countNumber of slashing events in observation window
19jail_countNumber of jail events in observation window
20inflation_rateCurrent emission rate
21bonded_ratioBonded tokens / total supply
22reputation_meanMean reputation score across active validators
23reputation_stddevStandard deviation of reputation scores
24mev_estimateEstimated MEV extracted (heuristic)

All values are stored as LegacyDec string representations and converted to int64 fixed-point before inference.


Action Space​

The MLP output is a 5-dimensional action vector, where each dimension represents a proposed change to a consensus parameter. The tanh activation constrains raw outputs to [-1, 1], which are then scaled by mode-specific bounds.

IndexAction DimensionDescription
0block_time_deltaProposed change to target block time (ms)
1gas_price_deltaProposed change to base gas price
2validator_set_size_deltaProposed change to target validator set size (logged only, not applied)
3pool_weight_rpos_deltaProposed change to RPoS pool priority weight
4pool_weight_dpos_deltaProposed change to DPoS pool priority weight

Actions are clamped to the maximum change bounds defined by the current PRISM mode before application.


Reward Function​

The reward signal evaluates how well recent parameter changes improved chain performance. It is computed as a weighted sum of five objectives:

R = 0.30 * delta_throughput
+ 0.25 * delta_finality
+ 0.20 * delta_decentralization
- 0.15 * mev_estimate
- 0.10 * failed_tx_ratio
ComponentWeightDirectionSource Metric
Throughput+0.30MaximizeChange in block utilization
Finality+0.25MaximizeChange in precommit ratio
Decentralization+0.20MaximizeNegative change in validator Gini coefficient
MEV-0.15MinimizeCurrent MEV estimate
Failed Transactions-0.10MinimizeCurrent failed transaction ratio

The reward weights are governance-configurable and must sum to exactly 1.0.


PRISM Modes​

PRISM operates in one of four modes, controllable via governance (the mode-change message is currently switched off on mainnet):

ModeIDMax ChangeBehavior
Shadow00%Observe and log recommendations only. No parameters are changed. Default in code. Since testnet governance proposal 29 the testnet agent runs in Shadow mode; the mainnet agent is in Conservative mode (genesis setting) with no policy loaded, so it applies no change.
Conservative1+/- 10%Apply parameter changes within tight bounds. Suitable for initial live deployment (mainnet's current mode, with no policy loaded).
Autonomous2+/- 25%Apply parameter changes within wider bounds. For mature networks with validated policies.
Paused30%PRISM is completely idle. No observations are collected and no inference runs.

Mode transitions require a governance proposal. The recommended deployment path is: Shadow → Conservative → Autonomous.


Circuit Breaker​

The circuit breaker is a safety mechanism that monitors chain health and automatically reverts all PRISM-tuned parameters if instability is detected.

Detection Logic​

The circuit breaker evaluates the last 50 blocks (configurable via circuit_breaker_window):

  1. Compute block time deltas — For each consecutive pair of block timestamps, compute the block time delta.
  2. Classify healthy blocks — A block is considered healthy if its delta is positive and within 2x the target block time.
  3. Compute healthy fraction — Compute the healthy fraction = healthy blocks / total deltas.

Trigger Condition​

If the healthy fraction falls below the threshold (default: 50%), the circuit breaker triggers.

Response​

When triggered, the circuit breaker:

  1. Reverts all PRISM-applied parameters (block time, gas price, pool weights) to their default values.
  2. Pauses PRISM (sets CircuitBreakerActive = true).
  3. Clears the in-memory policy to force a fresh reload.
  4. Emits a circuit_breaker_triggered event.

The circuit breaker automatically clears when the healthy fraction recovers above the threshold on subsequent evaluations.


Rollup Advisory Functions​

PRISM provides advisory functions for rollup parameter optimization:

  • SuggestRollupProfile — Analyzes current chain conditions and suggests optimal rollup configuration parameters (block time, gas limit, settlement frequency).
  • OptimizeRollupGas — Recommends gas pricing adjustments for rollup settlement transactions based on main chain congestion patterns.

These functions are informational only and do not modify chain state.


Deterministic Math Library​

All PRISM calculations use the mathutil package, which provides deterministic alternatives to standard floating-point math:

FunctionDescriptionMethod
IntegerSqrt(x)Square rootNewton's method on LegacyDec, 100-iteration convergence
TaylorLn1PlusX(x)Natural logarithm ln(1+x)Argument reduction + 15-term Taylor series
ExpApprox(x)Exponential e^x12-term Taylor series
SigmoidApprox(x)Sigmoid 1/(1+e^-x)ExpApprox with symmetry for negative inputs
ReputationMultiplier(r)Maps [0,1] to [0.5,2.0]Sigmoid with scale and offset

All functions operate on cosmossdk.io/math.LegacyDec values, ensuring identical results across all hardware platforms and Go compiler versions.


Parameters​

ParameterTypeDefaultDescription
enabledbooltrueEnable PRISM
observation_intervaluint6410Blocks between observation collections
agent_modePrismModeMainnet: 1 (Conservative). Testnet: 0 (Shadow, since proposal 29; the REST route reports it as shadow)Current operating mode
max_change_conservativeLegacyDec0.10Maximum parameter change in Conservative mode
max_change_autonomousLegacyDec0.25Maximum parameter change in Autonomous mode
circuit_breaker_windowuint6450Number of recent blocks monitored by circuit breaker
circuit_breaker_thresholdLegacyDec0.50Minimum healthy block fraction before trigger
default_block_time_msint645000Default target block time (ms) used as the observation baseline; the live block time is about 3.1 s on mainnet and about 1.3 s on testnet
default_base_gas_priceLegacyDec100Default base gas price
default_validator_set_sizeuint64100Default target validator set size
reward_weight_throughputLegacyDec0.30Reward weight for throughput improvement
reward_weight_finalityLegacyDec0.25Reward weight for finality improvement
reward_weight_decentralizationLegacyDec0.20Reward weight for decentralization improvement
reward_weight_mevLegacyDec0.15Penalty weight for MEV extraction
reward_weight_failed_txsLegacyDec0.10Penalty weight for failed transactions
  • Consensus Mechanism — the consensus layer PRISM optimizes.
  • AI Engine — the broader on-chain AI services and endpoints.
  • Tokenomics — how RL signals feed reward and parameter adjustments.