Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Tree trait #179

Merged
merged 20 commits into from
Nov 10, 2023
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
15a6d0a
chore: add audit comments (#168)
sifnoc Nov 3, 2023
400fc49
Refactor backend by following internal audit comments (#173)
sifnoc Nov 3, 2023
d538b28
feat: added mutex lock to signer; used it as ref
sifnoc Nov 1, 2023
c750083
fix: mutex deadlock in signer
sifnoc Nov 3, 2023
be0f52d
chore: minor updates
sifnoc Nov 4, 2023
022dde6
feat: `Tree` trait
enricobottazzi Nov 6, 2023
b3990eb
fix: move `verify_proof` logic to `Tree` trait
enricobottazzi Nov 6, 2023
35478ec
feat: added method implementation to `Tree` trait and moved outside o…
enricobottazzi Nov 6, 2023
e17e493
refactor: signer spawn provider internally; updated comments
sifnoc Nov 7, 2023
d3c5562
Merge branch 'shared-signer' into enrico-tree-trait
sifnoc Nov 7, 2023
391f37c
fix: round now use Tree trait
sifnoc Nov 7, 2023
2f14b36
refactor: Round needs MST and Assets instead of csv files path
sifnoc Nov 7, 2023
3e8c855
fix: rollback applying csv_parser for AddressOwnership and Assets in …
sifnoc Nov 8, 2023
c80e964
fix: Solvency::init fn accept type that has Tree trait
sifnoc Nov 8, 2023
d42af95
Merge branch 'v1-improvements-and-consolidation' into enrico-tree-trait
sifnoc Nov 8, 2023
0c5153b
fix: updates for summa solvency contract v1.1
sifnoc Nov 8, 2023
4e180b2
chore: rename `compute_leaves` api
enricobottazzi Nov 9, 2023
5a9120f
fix: Rounds accept 'Tree' trait object
sifnoc Nov 9, 2023
c575a29
chore: removed and updated comments
sifnoc Nov 9, 2023
3afa5d7
chore: removed env variables 'SIGNATURE_VERIFICATION_MESSAGE'
sifnoc Nov 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'v1-improvements-and-consolidation' into enrico-tree-trait
  • Loading branch information
sifnoc committed Nov 8, 2023
commit d42af95c68566d93d08e6e13be4be06bed960eff
5 changes: 1 addition & 4 deletions backend/src/apis/round.rs
Original file line number Diff line number Diff line change
@@ -8,10 +8,7 @@ use serde::{Deserialize, Serialize};
use std::error::Error;

use super::csv_parser::parse_asset_csv;
use crate::contracts::{
generated::summa_contract::summa::Asset,
signer::{AddressInput, SummaSigner},
};
use crate::contracts::{generated::summa_contract::summa::Asset, signer::SummaSigner};
use summa_solvency::{
circuits::{
merkle_sum_tree::MstInclusionCircuit,
67 changes: 36 additions & 31 deletions contracts/src/Summa.sol
Original file line number Diff line number Diff line change
@@ -33,18 +33,37 @@ contract Summa is Ownable {
string chain;
}

// Verifier contracts
IVerifier private immutable solvencyVerifier;
/**
* @dev Struct representing a commitment submitted by the CEX.
* @param mstRoot Merkle sum tree root of the CEX's liabilities
* @param rootSums The total sums of the assets included in the tree
* @param assetChains The chains where the CEX holds the assets included into the tree
* @param assetNames The names of the assets included into the tree
*/
struct Commitment {
uint256 mstRoot;
uint256[] rootSums;
string[] assetNames;
string[] assetChains;
}

// User inclusion proof verifier
IVerifier private immutable inclusionVerifier;

// All address ownership proofs submitted by the CEX
// List of all address ownership proofs submitted by the CEX
AddressOwnershipProof[] public addressOwnershipProofs;

// Convenience mapping to check if an address has already been verified
/*
Boolean type is better than uint256 for this mapping, at least more than 2,100 gas is saved per call
*/
mapping(bytes32 => uint256) public ownershipProofByAddress;
function getAddressOwnershipProof(
bytes32 addressHash
) public view returns (AddressOwnershipProof memory) {
require(
_ownershipProofByAddress[addressHash] > 0,
"Address not verified"
);
// -1 comes from the fact that 0 is reserved to distinguish the case when the proof has not yet been submitted
return
addressOwnershipProofs[_ownershipProofByAddress[addressHash] - 1];
}

// Convenience mapping to check if an address has already been verified
mapping(bytes32 => uint256) private _ownershipProofByAddress;
@@ -86,12 +105,9 @@ contract Summa is Ownable {
bytes32 addressHash = keccak256(
abi.encodePacked(_addressOwnershipProofs[i].cexAddress)
);
uint256 index = ownershipProofByAddress[addressHash];
require(index == 0, "Address already verified");
/*
Is there any reason to assign value `i + 1` to `ownershipProofByAddress[addressHash]`?
*/
ownershipProofByAddress[addressHash] = i + 1;
uint256 proofIndex = _ownershipProofByAddress[addressHash];
require(proofIndex == 0, "Address already verified");

addressOwnershipProofs.push(_addressOwnershipProofs[i]);
_ownershipProofByAddress[addressHash] = addressOwnershipProofs
.length;
@@ -148,23 +164,12 @@ contract Summa is Ownable {
assetChains
);

emit SolvencyProofSubmitted(timestamp, inputs[0], assets);
}

/*
It would be helpful to provide a description of the public inputs for the `verifySolvencyProof` and `verifyInclusionProof` methods.
*/

/**
* Verify the proof of CEX solvency
* @param proof ZK proof
* @param publicInputs proof inputs
*/
function verifySolvencyProof(
bytes memory proof,
uint256[] memory publicInputs
) public view returns (bool) {
return solvencyVerifier.verify(publicInputs, proof);
emit LiabilitiesCommitmentSubmitted(
timestamp,
mstRoot,
rootSums,
assets
);
}

/**
2 changes: 1 addition & 1 deletion zk_prover/src/circuits/solvency.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ use crate::chips::merkle_sum_tree::{MerkleSumTreeChip, MerkleSumTreeConfig};
use crate::chips::poseidon::hash::{PoseidonChip, PoseidonConfig};
use crate::chips::poseidon::poseidon_spec::PoseidonSpec;
use crate::circuits::traits::CircuitBase;
use crate::merkle_sum_tree::{MerkleSumTree, Tree};
use crate::merkle_sum_tree::Tree;
use halo2_proofs::circuit::{AssignedCell, Layouter, SimpleFloorPlanner, Value};
use halo2_proofs::halo2curves::bn256::Fr as Fp;
use halo2_proofs::plonk::{
You are viewing a condensed version of this merge commit. You can view the full changes here.