# Proof Of Solvency

The design doc for proof of solvency can be found by the binance team [here](https://gusty-radon-13b.notion.site/Proof-of-solvency-61414c3f7c1e46c5baec32b9491b2b3d)

I here talk about the recursive implementation for mina from how I implement it

## The Gnark Implmentation

the following picture is the circuit implementated by the binance team. It is not pretty to look at &#x20;

<figure><img src="https://2666457903-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdhKgRDf5sPua7CTobSuG%2Fuploads%2FybKga7i3VuzFynZgwGLI%2Fimage.png?alt=media&#x26;token=9c26a73b-1e21-4047-b53e-34811a11b6d4" alt=""><figcaption></figcaption></figure>

### Recursive Snark Implementation

The above implementation through recursive snarks can be boiled down just a simple circuit

<figure><img src="https://2666457903-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdhKgRDf5sPua7CTobSuG%2Fuploads%2FDLVZSOs5AjdQpeemmR81%2Fcarbon(3).png?alt=media&#x26;token=f540be7d-7ac2-4288-bf1f-a1eaaa95d94f" alt=""><figcaption></figcaption></figure>

In this circuit [here](https://github.com/utkarshdagoat/StealthTradeDAO/blob/master/packages/chain/src/runtime/zkPrograms/solvency/pos.ts) are the outlines of the circuit\


**Base Asset List Verification (`verifyAssetList`)**

This is the initial step in the recursive approach. It verifies a single asset entry in the CEX's asset list using a Merkle Map.

* **Inputs**:
  * `witness`: The Merkle proof (or witness) to validate the entry in the Merkle Map.
  * `elementId`, `TotalEquity`, `TotalDebt`, `USDTPrice`: Information about the asset to be verified.
  * `assetListCommitment`: The root of the Merkle Map (the commitment to the entire asset list).
* **Operation**:
  * It hashes the asset information and computes the Merkle Map's root and key.
  * It asserts that the computed key and root match the provided `assetListCommitment`.

This is the base proof, and its output is used as an input for the next recursive proof.

**2. Recursive Asset List Verification (`verifyAssetListRecursive`)**

In this method, the proof recursively verifies the updated asset list after the base verification.

* **Inputs**: Similar to the base method but with an additional input:
  * `proof`: A self-proof (i.e., the previous proof that was generated).
* **Operation**:
  * It first verifies the previous proof (`proof.verify()`).
  * Then, it computes the new Merkle root and checks whether it matches the updated `assetListCommitment`.

This step recursively chains the proof verification, ensuring that each update to the asset list is valid.

**3. Recursive User Batch Operations (`UserBatch`)**

Similarly, for users, the program verifies user batch operations. Here, after verifying the assets, the users' equity and debt are aggregated across assets.

* **Recursive Structure**:
  * `UserBatchBase`: This is the base method where a batch of user data is verified.
  * `UserBatch`: This method recursively verifies each batch update based on the last operation's proof.

This recursive verification of user operations ensures that for each new batch of users, their balances and commitments are updated correctly based on the previous proof.

#### Recursive Pattern

The recursive approach in zkSNARK is achieved by making each verification method dependent on the proof of the previous step. The program maintains the integrity of all prior proofs by verifying them recursively, chaining each step like this:

1. Start with an initial asset or user batch (base method).
2. For each new operation, generate a proof that verifies the current state and checks that it matches the result of the previous proof (recursive method).
3. Keep chaining these proofs, each verifying the next, to maintain consistency and correctness of the entire process.

This recursive proof aggregation is critical for ensuring that all changes across asset lists and user balances are valid, without the need to recompute everything from scratch.

