summa-solvency
Last updated
Last updated
This section describes how to use summa-solvency
backend to perform a full Protocol Flow.
First of all, it is essential to determine two key parameters:
The number of currencies that will be handled simultaneously in a single Proof of Solvency - N_CURRENCIES
The number of users included in a proof of solvency - N_USERS
Take, for example, a scenario where a Custodian opts to include ten currencies and 64 users in one proof. This setup enables the commitment to cover 64 users. Furthermore, it allows users to simultaneously verify their inclusion proof for all ten currencies in one go, rather than having to verify ten separate proofs.
Therefore, before starting, Custodians need to thoughtfully determine the N_CURRENCIES
and N_USERS
values.
Zero-knowledge-proof systems require a Trusted Setup. Summa uses the Halo2 proving system with the KZG polynomial commitment scheme. The UnivariateGrandSum
circuit requires a one-time, universal trusted setup, commonly known as a powers-of-tau ceremony.
To generate proving artifacts, custodians must first download the .ptau
file that corresponds with their circuit's size, denoted as K
.
Identifying the correct K
value is essential for Summa's halo2 circuit, as it is for any halo2 circuit. The minimum circuit size can be accurately determined based on the number of users by applying the following formula:
This formula ensures that the chosen K
value satisfies both the prerequisite condition N_USERS < 2^K - 6
and the minimum rows required for the range check circuit.
Pre-existing trusted setup files can be found at halo2-kzg-srs
. To download a specific .ptau
file, utilize the following command:
This action downloads a .ptau
file for a circuit size of k=17
.
In this example, we'll work under the assumption that N_CURRENCIES
is set to 2, and N_USERS
is 16. Additionally, it's presumed that the .ptau file is located at backend/ptau/hermez-raw-17
. Custodians have the flexibility to adjust these parameters and the .ptau file path within the kzg_prover/bin/gen_verifier.rs
file:
The gen_verifier.rs
script assists in generating a Solidity verifier contract. It initializes the circuit and generates the verifier contract using the halo2-solidity-verifier
.
To begin, clone the Summa Solvency repository:
Then, execute the script with the following commands:
This process yields new contracts: SnarkVerifier.sol
and VerifyingKey.sol
in contracts/src
. If you haven't calculated the K
correctly in step 2, you may encounter the following error:
This error indicates that the circuit size is too small. To ensure K
is correctly determined to match the requirements, please revisit the section2. Powers Of Tau . To solve that, a .ptau
file with a correct K
must be downloaded, and the function must be adjusted accordingly:
Following the generation of the SNARK verifier contract, "SnarkVerifier.sol", it is now necessary to deploy the main Summa Smart Contract, "Summa.sol". The deployment process requires the addresses of three verifier contracts and verifying key contract —"SnarkVerifier.sol", "GrandSumVerifier.sol", "InclusionVerifier.sol" and "VerifyingKey.sol"—to be provided to the "Summa.sol" constructor.
Modify Key Parameter
Custodians must update specific parameters within the deployment script located at "contracts/scripts/deploy.ts". These parameters should match the N_CURRENCIES
value specified earlier.
Updating Hardhat Configuration
The Summa-solvency project includes a Hardhat configuration file "hardhat.config.ts", primarily intended for testing. Custodians are required to modify the configuration to deploy the contract using their own account and node settings. For detailed instructions on configuring the Hardhat file, visit Hardhat Configuration Documentation.
Running Deploy Script
Execute the command below with the network name set in the previous step from the contracts
folder
To deploy the contract, execute the following command from the contracts directory, ensuring the network name matches the one set in the Hardhat configuration:
Successful execution of this script will deploy the Summa contract to the specified network, and generate a "deployments.json" file. This file contains the address of the deployed Summa Contract and is saved in "backend/src/contracts/deployments.json".
Once the setup is completed, the Custodian can utilize summa-solvency backend to perform a full Proof of Solvency flow.
The Summa Solvency Flow Example illustrates the process for performing the necessary steps, as outlined below.
Custodians are able to provide proofs of ownership for their addresses to the Summa contract using the AddressOwnership
feature. To accomplish this, they must first compile a CSV file (signature_csv
) containing the account addresses, chain names, signatures of the messages, and the messages themselves. Following this preparation, custodians can submit ownership proofs by executing the following transaction:
The signer
in the above code is an instance of SummaSigner
, which includes LocalWallet from ethers-rs, and is essential for signing Ethereum transactions for the Summa contract. It is used to sign transactions that send ownership proofs to the Summa contract. However, one of its internal components, LocalWallet
, is considered an insecure wallet type for production use in ethers-rs.
For enhanced security, custodians are encouraged to explore more secure signer structures available in ethers-rs. A variety of options, including AwsSigner and hardware wallets, offer increased security measures. Details on these and other signers can be found in the ethers-rs documentation: https://docs.rs/ethers/latest/ethers/signers/index.html. To switch from using LocalWallet to a hardware wallet, the SummaSigner configuration would need to be modified accordingly.
The signer
is only used to submit proofs and commitments to Summa contract so it does not have to hold any of the Custodian funds. Note that since Summa contract is an Ownable
contract, the signer
has to be the same used to deploy the Summa contract. Otherwise, transactions will be reverted.
To generate the liabilities commitment and user inclusion proofs a custodian has to prepare a CSV file, referred to as "entry.csv" , which contains all usernames and their N_CURRENCIES
balances. The csv file format looks like this:
The first column header must be the username, and the rest of the columns should follow the pattern balance_[Currency]_[Chain]. Assuming the CSV file is named as entry.csv
, initialize Univariate Grand Sum circuit as follows:
Initializing a round requires multiple parameters: zk_snark_proof
, advice_polys
, params
, vk
, and timestamp
:
params
: An instance of ParamsKZG
from halo2, initialized as in the Generate SNARK Verifier Contract section.
zk_snark_proof
: The proof generated from the UnivariateGrandSum
circuit.
advice_polys
: The advice polynomials that were used as witness data to create the zk_snark_proof.
vk
: The verifying key for the zk_snark_proof
.
timestamp
: A UNIX timestamp marking the moment the liabilities snapshot (reflected in the "entry.csv" file) was taken.
Now, the custodian can send the commitment transaction using the dispatch_commitment
method:
Internally, dispatch_commitment
submits a transaction to the Summa Contract using the submitCommitment
function, which includes the zk_snark_proof
, grand_sum_proof
, and the total balance of the KZG polynomials.
Now, the custodian can generate inclusion proofs for their users using the round
, Initialized from the previous step.
The get_proof_of_inclusion
method requires a user_index
, which corresponds to the index of the user's data within the Entry CSV file ("entry.csv"), as established in the prior section.
The custodian can then provide these inclusion proofs to their users.
Generating proofs for all the users at once can present some scaling issues. Alternatively, the custodian can generate such proof only if the user queries it. Please refer to the benchmarks.
Users who have received a proof for a specific round can utilize the verify_inclusion_proof
API provided by the backend. The term downloaded_inclusion_proof
denotes the proof users have obtained from custodians.
For guidance on processing downloaded_inclusion_proof
at the code level, please check the Summa Solvency Flow Example.
To perform the verification, users must also provide the snapshot_time
corresponding to the timestamp when the Liabilities Commitment was registered with the smart contract.
Note that the verify_inclusion_proof
function in the Summa contract is a view function that does not consume gas nor alters the state of the blockchain, and therefore, is free to call. This allows users to independently verify their proofs using public frontends like Etherscan, ensuring added transparency and trust without incurring any cost.
Alternatively, custodians may offer an application similar to the demonstrated above for users to verify their inclusion proofs locally.