> For the complete documentation index, see [llms.txt](https://docs.vest.exchange/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.vest.exchange/overview/vest-architecture/zkrisk-engine.md).

# zkRisk Engine

**Overview**

zkRisk is Vest's decentralized risk engine that powers the pricing and risk management across the entire platform. It uses zero-knowledge proofs (ZKPs) to ensure that every trade is priced fairly and that the system remains solvent, without revealing sensitive user data.

Traditional exchanges rely on manual intervention, static risk limits, and reactive liquidations to control systemic risk. In contrast, zkRisk continuously measures the health of the entire ecosystem in real time, using mathematical tools like Expected Shortfall (EVaR) and volatility forecasts. It automatically adjusts prices and funding rates based on how much risk each trade adds to the system, discouraging risky behavior before it becomes a problem.

By embedding these calculations directly on-chain through succinct proofs, zkRisk allows Vest to operate trustlessly: users don't need to rely on the exchange to act fairly — they can verify it for themselves. The result is a decentralized, preventative, and scalable model of risk management designed specifically for next-generation financial ecosystems.

**Coherent Risk Measure**

Consider $$n$$ markets, where the underlying assets follow a price process

$$
S\_t = \begin{pmatrix} S\_t^{(1)} \ \vdots \ S\_t^{(n)} \end{pmatrix} \in \mathbb{R}\_{++}^n,
$$

adapted on a filtered probability space

$$
(\Omega, \mathcal{F}, {\mathcal{F\_{t0}} \leq t \leq T}, \mathbb{P})
$$

We will define the exchange’s liability at time $$t$$ as a function of $$S\_t$$<sub>,</sub> parameterized by the state of the exchange $$\theta = (q, C, P, L)$$.

Note the following variables and their corresponding definitions:

$$q \in \mathbb{R}^n$$: the vector of long-short imbalances ($q\_i > 0$ implies that the $i$th market is long-heavy, hence the AMM is net short)

$$C = q^\top \bar{S} \in \mathbb{R}$$: the summation of entry notional sizes (signed) of all open positions

$$P \in \mathbb{R}+$$: capital owned by the AMM

$$L \in \mathbb{R}+$$: capital provided by LPs<br>

Then X<sub>t,</sub> the net payout to traders if all outstanding positions were to be closed at prices S<sub>t</sub>, is given by

$$X\_t(\theta) := f(S\_t; \theta) = q^\top S\_t - (C + P + L)$$

In other words, X<sub>t</sub> represents the net payout to traders if all outstanding positions were to be closed at prices S<sub>t</sub>.

We use a monetary risk measure — a mapping from a set of random variables to the real numbers — to calculate the amount of capital needed to cover the potential shortfall with high probability. In particular, we adopt an extension of a coherent risk measure called Entropic Value-at-Risk (EVaR).

EVaR is the tightest upper bound to Value-at-Risk (VaR) and Conditional Value-at-Risk (CVaR), derived from the Chernoff bound

$$P(X \geq a) \leq e^{-za} M\_X(z) = \alpha$$.  Solving for $$\alpha$$,

$$\text{EVaR}*{1-\alpha}(X) = \inf*{z > 0} \left{ z^{-1} \ln \left( \frac{M\_X(z)}{\alpha} \right) \right}$$

for a confidence level $$1 - \alpha$$.

Using EVaR, zkRisk charges premia and funding to guarantee solvency with respect to rolling windows by ensuring the following invariant holds with high probability at t:

$$X\_{t + \tau} < 0$$.

We define our risk measure as

$$\rho(X\_{t+\tau} \mid \mathcal{F}*t) := \text{EVaR}*{1-\alpha}(X\_{t+\tau}^{+} - P\_t \mid \mathcal{F}\_t)$$

with capital buffer

$$P\_t = \sum\_{s = t - \tau}^{t} \pi\_s^p + f\_s^p$$.

Here, $$\pi^p$$ and $$f^p$$ are premium and funding collected by the AMM respectively.<br>

We define $$(\cdot)^+ := \max(0, \cdot)$$ to ignore upside (i.e., negative shortfall only).

**Premia**

For a new trade $$\mathbf{q}\_t \in \mathbb{R}^n$$, zkRisk charges premium or provides rebate such that the risk before and after accepting the trade remains invariant. In particular, we define the premium as

$$\pi\_t^{\rho} := \left( \rho(X\_{t+\tau}(\theta') \mid \mathcal{F}*t) - \rho(X*{t+\tau}(\theta) \mid \mathcal{F}\_t) \right)^+$$

where $$\theta = (\mathbf{q}, C, P, L)$$ and $$\theta' = (\mathbf{q} + \mathbf{q}\_t, C + \mathbf{q}\_t^\top S\_t, P, L)$$ represent states before and after accepting the trade.

At $$t + \tau$$, AMM-owned capital $$P$$ is incremented by $$\pi\_t^{\rho}$$.

**Funding**

While premia charges for marginal change in risk from the change in liability, zkRisk needs to collect funding from open positions to cover the market risk.

Given our risk measure is 1-positive homogeneous, we use a risk attribution mechanism called Euler allocation to define per-market funding rate. Let $$X\_t^{(i)}$$ be the liability arising from the $$i$$th market. We calculate the amount of funding assigned to the $$i$$th market as

$$\rho\_{\text{Euler}}(X\_{t+\tau}^{(i)} \mid \mathcal{F}*t) := \left. \frac{\partial \rho\left(\sum*{i=1}^n u\_i X\_{t+\tau}^{(i)} \mid \mathcal{F}*t\right)}{\partial u\_i} \right|*{(1, \ldots, 1)}$$

This represents the marginal risk added by long-short imbalance in the $$i$$th market.

We now define instantaneous funding charged across all open positions as<br>

$$f\_t^{\rho}(X\_{t+\tau}^{(i)} \mid \mathcal{F}*t) := \left. \frac{\partial \rho*{\text{Euler}}(X\_{t+\tau}^{(i)} \mid \mathcal{F}*t)}{\partial \tau} \right|*{\tau}$$

which corresponds to the marginal change in risk with respect to time.

Now, for each trader $$j \in I\_i$$ with position size $$q\_{ij} \in \mathbb{R}$$ where $$\sum\_{j \in I\_i} q\_{ij} = q\_i$$, they are responsible for covering

$$f\_t^{\rho}(X\_{t+\tau}^{(i)} \mid \mathcal{F}*t) \cdot \frac{q*{ij}}{q\_i}.$$

$$f\_t^{\rho}(X\_{t+\tau}^{(i)} \mid \mathcal{F}t) \cdot \frac{q{ij}}{q\_i} > 0$$ means trader $$j$$ pays the funding, and they receive it otherwise.

Similar to premium, $$P$$ will be incremented at time $$t + \tau$$ with funding charged at time $$t$$.<br>

<figure><img src="https://124624211-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQlq6AkAAcetsIZV6GQyc%2Fuploads%2FVnUrwpOMcNdyHlFWjd5L%2FScreenshot%202025-04-22%20at%2010.12.46%20PM.png?alt=media&amp;token=eac3e23a-7697-4409-8969-4def68ebf398" alt=""><figcaption></figcaption></figure>
