Skip to content

Commit

Permalink
fix: update README; small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sifnoc committed Nov 1, 2023
1 parent 98a2039 commit 7313ce3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 35 deletions.
48 changes: 21 additions & 27 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,43 +46,23 @@ SIGNATURE_VERIFICATION_MESSAGE="Summa proof of solvency for CryptoExchange" carg

## Important Notices

### Generating Verifiers for Backend
### Generating and updating verifier contracts for Backend

If you need to update the verifier contracts for the backend, you can either follow the manual steps or use the provided bash script.
The verifier contracts in the backend were generated using a predefined set of parameters: `N_ASSETS = 2` and `N_BYTES=14`, as indicated [here](https://github.com/summa-dev/summa-solvency/blob/master/zk_prover/examples/gen_solvency_verifier.rs#L21-L22).
If you intend to work with different parameters, you'll need to adjust these hard-coded values and then generate new verifier contracts.

The process described below assists in both generating the verifiers and updating the Summa contract, which integrates the new verifiers as constructors.

#### Using the Bash Script

We have provided a bash script to automate the process of updating the verifier contracts. To use the script:
We have provided a bash script to automate the process of updating the verifier contracts and the Summa contract. To use the script:

Ensure you have the necessary permissions to execute the script.
```
backend $ chmod +x scripts/update_verifier_contracts.sh
```

Run the script.
```
backend $ scripts/update_verifier_contracts.sh
backend $ chmod +x scripts/update_verifier_contracts.sh
```

The script will handle building the verifier contracts, deploying them to the local environment, and generating the Rust interface files for the backend.

#### Manual Steps

If you prefer to update the verifier contracts manually, follow these steps:

1. **Build the Verifier Contracts**:
- Move to the `zk_prover` directory.
- Run the [`gen_solvency_verifier`](https://github.com/summa-dev/summa-solvency/blob/master/zk_prover/examples/gen_solvency_verifier.rs) and [`gen_inclusion_verifier`](https://github.com/summa-dev/summa-solvency/blob/master/zk_prover/examples/gen_inclusion_verifier.rs) located within the `zk_prover/examples`.
- For detailed instructions [building a solvency verifier contract](https://github.com/summa-dev/summa-solvency/tree/master/zk_prover#build-a-solvency-verifier-contract) and [building an inclusion verifier contract.](https://github.com/summa-dev/summa-solvency/tree/master/zk_prover#build-an-inclusion-verifier-contract)
2. **Deploy Contracts to Local Environment**:
- Navigate to the `contracts` directory
- Deploy the contracts to a Hardhat environment. This step will refresh the ABI files(`src/contracts/abi/*.json`) in the backend.
3. **Generate Rust Interface Files**:
- Move to the `backend` directory.
- Execute the build script in the backend. This will produce the Rust interface files: `inclusion_verifier.rs`, `solvency_verifier.rs`, and `summa_contract.rs`.

This section provides CEX with the option to use the bash script for convenience or to follow the manual steps if you prefer.

## Summa solvency flow example

This example illustrates how Summa interacts with the Summa contract and the user side.
Expand Down Expand Up @@ -168,3 +148,17 @@ The result will display as:
```
4. Verifying the proof on contract verifier for User #0: true
```

### 4. Verify Proof of Inclusion

This is the final step in the Summa process and the only part that occurs on the user side. Users receive the proof for a specific round and use methods available on the deployed Summa contract. Importantly, the Summa contract verifier function is a view function, meaning it doesn't consume gas or change the blockchain's state.

In this step, you'll see:
- Retrieve the `mst_root` from the Summa contract and match it with the `root_hash` in the proof.
- Ensure the `leaf_hash` aligns with the hash based on the `username` and `balances` provided by the CEX.
- Use the `verify_inclusion_proof` method on the Summa contract to validate the proof.
The result will display as:

**Note:** In a production environment, users can independently verify their proof using public interfaces, such as Etherscan, as shown below:
![Summa contract interface on Etherscan](summa_verifier_interface.png)
This offers an added layer of transparency and trust.
7 changes: 1 addition & 6 deletions backend/examples/summa_solvency_flow.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#![feature(generic_const_exprs)]
use std::{
error::Error,
fs::{remove_file, File},
io::BufReader,
io::Write,
};
use std::{error::Error, fs::Fle, io::BufReader, io::Write};

use ethers::types::U256;
use serde_json::{from_reader, to_string_pretty};
Expand Down
4 changes: 2 additions & 2 deletions backend/scripts/update_verifier_contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e
# Build the verifier contracts
echo "1. Building verifier contracts"
cd ../zk_prover
cargo run --example gen_inclusion_verifier
cargo run --example gen_solvency_verifier
cargo run --release --example gen_inclusion_verifier
cargo run --release --example gen_solvency_verifier

# Deploy contracts to local environment
echo "2. Deploying contracts to local environment"
Expand Down
Binary file added backend/summa_verifier_interface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7313ce3

Please sign in to comment.