mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
daod: merge zk_public_values() and zk_proof_addrs() into a single function, and so deprecate zip! macro
This commit is contained in:
@@ -50,12 +50,8 @@ pub struct CallData {
|
||||
}
|
||||
|
||||
impl CallDataBase for CallData {
|
||||
fn zk_public_values(&self) -> Vec<Vec<DrkCircuitField>> {
|
||||
vec![vec![self.dao_bulla.0]]
|
||||
}
|
||||
|
||||
fn zk_proof_addrs(&self) -> Vec<String> {
|
||||
vec!["dao-mint".to_string()]
|
||||
fn zk_public_values(&self) -> Vec<(String, Vec<DrkCircuitField>)> {
|
||||
vec![("dao-mint".to_string(), vec![self.dao_bulla.0])]
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
|
||||
@@ -52,7 +52,7 @@ pub struct CallData {
|
||||
}
|
||||
|
||||
impl CallDataBase for CallData {
|
||||
fn zk_public_values(&self) -> Vec<Vec<DrkCircuitField>> {
|
||||
fn zk_public_values(&self) -> Vec<(String, Vec<DrkCircuitField>)> {
|
||||
let mut zk_publics = Vec::new();
|
||||
let mut total_funds_commit = pallas::Point::identity();
|
||||
|
||||
@@ -67,21 +67,24 @@ impl CallDataBase for CallData {
|
||||
let sigpub_x = *sigpub_coords.x();
|
||||
let sigpub_y = *sigpub_coords.y();
|
||||
|
||||
zk_publics.push(vec![
|
||||
value_commit_x,
|
||||
value_commit_y,
|
||||
self.header.token_commit,
|
||||
input.merkle_root.0,
|
||||
sigpub_x,
|
||||
sigpub_y,
|
||||
]);
|
||||
zk_publics.push((
|
||||
"dao-propose-burn".to_string(),
|
||||
vec![
|
||||
value_commit_x,
|
||||
value_commit_y,
|
||||
self.header.token_commit,
|
||||
input.merkle_root.0,
|
||||
sigpub_x,
|
||||
sigpub_y,
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
let total_funds_coords = total_funds_commit.to_affine().coordinates().unwrap();
|
||||
let total_funds_x = *total_funds_coords.x();
|
||||
let total_funds_y = *total_funds_coords.y();
|
||||
zk_publics.push(
|
||||
// dao-propose-main proof
|
||||
zk_publics.push((
|
||||
"dao-propose-main".to_string(),
|
||||
vec![
|
||||
self.header.token_commit,
|
||||
self.header.dao_merkle_root.0,
|
||||
@@ -89,20 +92,11 @@ impl CallDataBase for CallData {
|
||||
total_funds_x,
|
||||
total_funds_y,
|
||||
],
|
||||
);
|
||||
));
|
||||
|
||||
zk_publics
|
||||
}
|
||||
|
||||
fn zk_proof_addrs(&self) -> Vec<String> {
|
||||
let mut zk_addrs = Vec::new();
|
||||
for input in &self.inputs {
|
||||
zk_addrs.push("dao-propose-burn".to_string());
|
||||
}
|
||||
zk_addrs.push("dao-propose-main".to_string());
|
||||
zk_addrs
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ pub struct CallData {
|
||||
}
|
||||
|
||||
impl CallDataBase for CallData {
|
||||
fn zk_public_values(&self) -> Vec<Vec<DrkCircuitField>> {
|
||||
fn zk_public_values(&self) -> Vec<(String, Vec<DrkCircuitField>)> {
|
||||
let mut zk_publics = Vec::new();
|
||||
let mut total_value_commit = pallas::Point::identity();
|
||||
|
||||
@@ -74,16 +74,18 @@ impl CallDataBase for CallData {
|
||||
let sigpub_x = *sigpub_coords.x();
|
||||
let sigpub_y = *sigpub_coords.y();
|
||||
|
||||
// dao-vote-burn proof
|
||||
zk_publics.push(vec![
|
||||
input.nullifier.0,
|
||||
value_commit_x,
|
||||
value_commit_y,
|
||||
self.header.token_commit,
|
||||
input.merkle_root.0,
|
||||
sigpub_x,
|
||||
sigpub_y,
|
||||
]);
|
||||
zk_publics.push((
|
||||
"dao-vote-burn".to_string(),
|
||||
vec![
|
||||
input.nullifier.0,
|
||||
value_commit_x,
|
||||
value_commit_y,
|
||||
self.header.token_commit,
|
||||
input.merkle_root.0,
|
||||
sigpub_x,
|
||||
sigpub_y,
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
let vote_commit_coords = self.header.vote_commit.to_affine().coordinates().unwrap();
|
||||
@@ -93,8 +95,9 @@ impl CallDataBase for CallData {
|
||||
let value_commit_coords = total_value_commit.to_affine().coordinates().unwrap();
|
||||
let value_commit_x = *value_commit_coords.x();
|
||||
let value_commit_y = *value_commit_coords.y();
|
||||
zk_publics.push(
|
||||
// dao-vote-main proof
|
||||
|
||||
zk_publics.push((
|
||||
"dao-vote-main".to_string(),
|
||||
vec![
|
||||
self.header.token_commit,
|
||||
self.header.proposal_bulla,
|
||||
@@ -103,20 +106,11 @@ impl CallDataBase for CallData {
|
||||
value_commit_x,
|
||||
value_commit_y,
|
||||
],
|
||||
);
|
||||
));
|
||||
|
||||
zk_publics
|
||||
}
|
||||
|
||||
fn zk_proof_addrs(&self) -> Vec<String> {
|
||||
let mut zk_addrs = Vec::new();
|
||||
for input in &self.inputs {
|
||||
zk_addrs.push("dao-vote-burn".to_string());
|
||||
}
|
||||
zk_addrs.push("dao-vote-main".to_string());
|
||||
zk_addrs
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
@@ -108,14 +108,6 @@ impl ZkContractTable {
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! zip {
|
||||
($x: expr) => ($x);
|
||||
($x: expr, $($y: expr), +) => (
|
||||
$x.iter().zip(
|
||||
zip!($($y), +))
|
||||
)
|
||||
}
|
||||
|
||||
pub struct Transaction {
|
||||
pub func_calls: Vec<FuncCall>,
|
||||
}
|
||||
@@ -127,24 +119,18 @@ impl Transaction {
|
||||
fn zk_verify(&self, zk_bins: &ZkContractTable) {
|
||||
for func_call in &self.func_calls {
|
||||
let proofs_public_vals = &func_call.call_data.zk_public_values();
|
||||
let proofs_addrs = &func_call.call_data.zk_proof_addrs();
|
||||
|
||||
assert_eq!(
|
||||
proofs_public_vals.len(),
|
||||
proofs_addrs.len(),
|
||||
"proof_public_vals.len()={} and proof_addrs.len()={} do not match",
|
||||
proofs_public_vals.len(),
|
||||
proofs_addrs.len(),
|
||||
);
|
||||
assert_eq!(
|
||||
proofs_addrs.len(),
|
||||
func_call.proofs.len(),
|
||||
"proof_addrs.len()={} and func_call.proofs.len()={} do not match",
|
||||
proofs_addrs.len(),
|
||||
"proof_public_vals.len()={} and func_call.proofs.len()={} do not match",
|
||||
proofs_public_vals.len(),
|
||||
func_call.proofs.len()
|
||||
);
|
||||
for (i, (key, (proof, public_vals))) in
|
||||
zip!(proofs_addrs, &func_call.proofs, proofs_public_vals).enumerate()
|
||||
for (i, (proof, (key, public_vals))) in
|
||||
func_call.proofs.iter().zip(proofs_public_vals.iter()).enumerate()
|
||||
{
|
||||
debug!(target: "demo", "Tranaction::zk_verify i: {}, key: {}", i, key);
|
||||
match zk_bins.lookup(key).unwrap() {
|
||||
ZkContractInfo::Binary(info) => {
|
||||
let verifying_key = &info.verifying_key;
|
||||
@@ -177,10 +163,7 @@ pub struct FuncCall {
|
||||
pub trait CallDataBase {
|
||||
// Public values for verifying the proofs
|
||||
// Needed so we can convert internal types so they can be used in Proof::verify()
|
||||
fn zk_public_values(&self) -> Vec<Vec<DrkCircuitField>>;
|
||||
|
||||
// The zk contract ID needed to lookup in the table
|
||||
fn zk_proof_addrs(&self) -> Vec<String>;
|
||||
fn zk_public_values(&self) -> Vec<(String, Vec<DrkCircuitField>)>;
|
||||
|
||||
// For upcasting to CallData itself so it can be read in state_transition()
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
|
||||
@@ -35,12 +35,10 @@ pub struct CallData {
|
||||
}
|
||||
|
||||
impl CallDataBase for CallData {
|
||||
fn zk_public_values(&self) -> Vec<Vec<DrkCircuitField>> {
|
||||
vec![vec![self.header.public_c]]
|
||||
}
|
||||
fn zk_proof_addrs(&self) -> Vec<String> {
|
||||
vec!["example-foo".to_string()]
|
||||
fn zk_public_values(&self) -> Vec<(String, Vec<DrkCircuitField>)> {
|
||||
vec![("example-foo".to_string(), vec![self.header.public_c])]
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
@@ -166,28 +166,17 @@ pub struct CallData {
|
||||
}
|
||||
|
||||
impl CallDataBase for CallData {
|
||||
fn zk_public_values(&self) -> Vec<Vec<DrkCircuitField>> {
|
||||
fn zk_public_values(&self) -> Vec<(String, Vec<DrkCircuitField>)> {
|
||||
let mut public_values = Vec::new();
|
||||
for input in &self.inputs {
|
||||
public_values.push(input.revealed.make_outputs());
|
||||
public_values.push(("money-transfer-burn".to_string(), input.revealed.make_outputs()));
|
||||
}
|
||||
for output in &self.outputs {
|
||||
public_values.push(output.revealed.make_outputs());
|
||||
public_values.push(("money-transfer-mint".to_string(), output.revealed.make_outputs()));
|
||||
}
|
||||
public_values
|
||||
}
|
||||
|
||||
fn zk_proof_addrs(&self) -> Vec<String> {
|
||||
let mut result = Vec::new();
|
||||
for _ in &self.inputs {
|
||||
result.push("money-transfer-burn".to_string());
|
||||
}
|
||||
for _ in &self.outputs {
|
||||
result.push("money-transfer-mint".to_string());
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user