-
Notifications
You must be signed in to change notification settings - Fork 35
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
feat: Tree
trait
#179
Conversation
* feat: create bash script for updating verifier interface files in backend * fix: error propagation with try operator; remove unnecessaries * refactor: changed data type in 'MstInclusionProof' * fix: generate solvency verifier contract * chore: remove left over * chore: update README * fix: remove left over; assert term * fix: update README; small fixes * feat: Signer accepts address or file path for init
zk_prover/src/merkle_sum_tree/mst.rs
Outdated
[usize; N_ASSETS + 1]: Sized, | ||
[usize; 2 * (1 + N_ASSETS)]: Sized, | ||
{ | ||
verify_proof(proof) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for miscommunication, but I meant that the method implementation should live in the trait directly. There's no benefit of putting it into a separate file. It would be convenient for any developer to click on a method name and see the implementation right away, no need to click through one more level. I suggested to move all the "util" methods to the tree trait as they are common for both trees and also represent the fire functionality of the Merkle tree (not auxiliary utility code).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied the changes in b3990eb
. I believe that this can only apply to verify_proof
while I cannot define the logic of generate_proof
within the Tree
trait as this will be different between MerkleSumTree
and AggregationMerkleSumTree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Would you give me some hint to understand about this? |
@sifnoc sorry about that. I think that my comment was cut off. What I meant was to update |
8b44b2f
to
3e8c855
Compare
23c8d8e
to
d42af95
Compare
contracts/src/Summa.sol
Outdated
@@ -85,6 +85,15 @@ contract Summa is Ownable { | |||
inclusionVerifier = _inclusionVerifier; | |||
} | |||
|
|||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's leftover from my audit comment, I will remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed c575a29
let signature_csv_path = "src/apis/csv/signatures.csv"; | ||
|
||
// The signer instance would be shared with `address_ownership` and `round` instances | ||
// | ||
// Using AddressInput::Address to directly provide the summa_contract's address. | ||
// For deployed contracts, if the address is stored in a config file, | ||
// you can alternatively use AddressInput::Path to specify the file's path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have an example of such config file? Can you add it to the comments if possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there is "backend/src/contracts/deployments.json".
I will add comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated c575a29
backend/src/tests.rs
Outdated
amount: U256::from(556863), | ||
}, | ||
]; | ||
assert_eq!(liability_commitment_logs.len(), 0); | ||
|
||
// Send sovlecy proof to contract |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed at 5a9120f
1, | ||
) | ||
.unwrap(); | ||
let entries = get_sample_entries(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add entry.csv
file back here? I think there was a misunderstanding in one of my previous comments. I didn't mean to remove the usage of entry.csv
. I just meants that this should no longer be an input for the Round
builder. But it's still ok to me to build the mst
using let merkle_tree =MerkleSumTree::new("src/merkle_sum_tree/csv/entry_16.csv")
and then pass it to Round
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated at 5a9120f
backend/src/sample_entries.rs
Outdated
use num_bigint::ToBigUint; | ||
use summa_solvency::merkle_sum_tree::Entry; | ||
|
||
pub fn get_sample_entries() -> Vec<Entry<2>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed at 5a9120f
rpc_url: &str, | ||
summa_address_input: AddressInput, | ||
entry_csv_path: &str, | ||
pub fn new<'a>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main point of the PR for me was that Round
should accept as input an object binded to the Tree
trait. Similarly to what you applied to Solvency::init
. But I don't know why you applied it to Solvency
which is now dismissed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's what you were looking for. Honestly, I was trying to figure out how to define the Tree
trait as a concrete type in the SolvencyCircuit
struct, but I realized it's impossible without using Box
, which is kind of smart pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that?
Can't you define it like this? https://github.com/summa-dev/summa-solvency/blob/enrico-tree-trait/zk_prover/src/circuits/solvency.rs#L76
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It because the merkle_sum_tree
in the solvency::init
evaluates some values, like root_hash
, not assign into SolvencyCircuit
. Anyway I fixed like this:
pub struct Snapshot<const LEVELS: usize, const N_ASSETS: usize, const N_BYTES: usize> {
mst: Box<dyn Tree<N_ASSETS, N_BYTES>>, // Instead of MerkleSumTree<N_ASSETS, N_BYTES>,
assets_state: [Asset; N_ASSETS],
trusted_setup: SetupArtifacts,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated at 5a9120f
}) | ||
} | ||
|
||
pub fn generate_proof_of_inclusion( | ||
&self, | ||
user_index: usize, | ||
) -> Result<MstInclusionProof, &'static str> { | ||
let merkle_proof = self.mst.generate_proof(user_index).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As soon as you modify Snapshot
to take an object with a Binded Trait Tree
this object will no longer have the get_entry
method as this method doesn't live on the Tree
trait. I don't know what's the best way to handle this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, as you already know I added get_entry
method in Tree
trait. and it works well.
but for removing get_entry
from Tree
trait, we have to add username
and balances
fields on the MerkleProof
.
the entry
is used to get username
and balances
In the MstInclusionCircuit
.
summa-solvency/zk_prover/src/circuits/merkle_sum_tree.rs
Lines 228 to 247 in 4e180b2
// Assign the entry username | |
let username = self.assign_value_to_witness( | |
layouter.namespace(|| "assign entry username"), | |
big_uint_to_fp(self.entry.username_as_big_uint()), | |
"entry username", | |
config.advices[0], | |
)?; | |
// Assign the entry balances | |
let mut current_balances = vec![]; | |
for i in 0..N_ASSETS { | |
let balance = self.assign_value_to_witness( | |
layouter.namespace(|| format!("assign entry balance {}", i)), | |
big_uint_to_fp(&self.entry.balances()[i]), | |
"entry balance", | |
config.advices[1], | |
)?; | |
current_balances.push(balance); | |
} |
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok let's keep it as it is for now!
If something comes up during the AggregationMerkleSumTree
implementation, we can just come back to summa-solvency
and fix that
proof.public_inputs[0], | ||
.submit_commitment( | ||
mst_root, | ||
root_sums, | ||
self.snapshot.assets_state.to_vec(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something to think about for the future: assets come from the same source as the user balances. E.g., when the CEX is building the tree, it knows that it's now querying the ETH balances or BTC balances. That's why I don't think that the assets would live in a separate CSV file. Imagine that when the CEX is querying the balances, it specifies the assets in the query. If we're sticking to CSV, I would imagine a CSV that looks like userId,balance_ETH_ETH,balance_USDT_ETH,...
. Won't request changes now but Interesting to know what you think @enricobottazzi @sifnoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really an asset "state" per se, it's kind of a mapping of what assets are submitted in the MST to leave the record inside the transaction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. It used to be a state when it also contained the asset_balances. Now it doesn't make sense for asset.csv
to live in a separate file. Opening an issue.
978a645
into
v1-improvements-and-consolidation
Replacement of #177
Tree
traitMerkleSumTree
now implementsTree
traitbuild_merkle_tree_from_entries
utils function tobuild_merkle_tree_from_leaves
to make it more generic.MerkleProof
struct to take leaf instead of entry. This makes it more generic.MstInclusion
Circuit constructor function to take MerkleProof rather than whole MerkleSumTreeto do @sifnoc :
Round
should no longer take acsv_path
as input. Instead, take an object that implements theTree
trait.generate_proof_of_inclusion
API on round should be modified to support the newtest
andexample
accordinglysumma_solvency::MerkleSumTree
module inside backend module (First, you include the external library in your Cargo.toml file and then use use statement to bring the module into scope in your library code). Then, expose the imported module to other users ofsumma_backend
library by using pub use statement. In this way, theaggregation-tree
repo would only need to usesumma_backend
as dependency while still being able to access the API needed to build theMerkleSumTree
, which is needed for the workers.