darkfi_dao_contract/client/
mint.rs

1/* This file is part of DarkFi (https://dark.fi)
2 *
3 * Copyright (C) 2020-2025 Dyne.org foundation
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18
19use darkfi::{
20    zk::{halo2::Value, Proof, ProvingKey, Witness, ZkCircuit},
21    zkas::ZkBinary,
22    Result,
23};
24use darkfi_sdk::{crypto::SecretKey, pasta::pallas};
25use log::debug;
26use rand::rngs::OsRng;
27
28use crate::model::{Dao, DaoMintParams};
29
30#[allow(clippy::too_many_arguments)]
31pub fn make_mint_call(
32    dao: &Dao,
33    dao_notes_secret_key: &SecretKey,
34    dao_proposer_secret_key: &SecretKey,
35    dao_proposals_secret_key: &SecretKey,
36    dao_votes_secret_key: &SecretKey,
37    dao_exec_secret_key: &SecretKey,
38    dao_early_exec_secret_key: &SecretKey,
39    dao_mint_zkbin: &ZkBinary,
40    dao_mint_pk: &ProvingKey,
41) -> Result<(DaoMintParams, Vec<Proof>)> {
42    debug!(target: "contract::dao::client::mint", "Building DAO contract mint transaction call");
43
44    let proposer_limit = pallas::Base::from(dao.proposer_limit);
45    let quorum = pallas::Base::from(dao.quorum);
46    let early_exec_quorum = pallas::Base::from(dao.early_exec_quorum);
47    let approval_ratio_quot = pallas::Base::from(dao.approval_ratio_quot);
48    let approval_ratio_base = pallas::Base::from(dao.approval_ratio_base);
49
50    // NOTE: It's important to keep these in the same order as the zkas code.
51    let prover_witnesses = vec![
52        Witness::Base(Value::known(proposer_limit)),
53        Witness::Base(Value::known(quorum)),
54        Witness::Base(Value::known(early_exec_quorum)),
55        Witness::Base(Value::known(approval_ratio_quot)),
56        Witness::Base(Value::known(approval_ratio_base)),
57        Witness::Base(Value::known(dao.gov_token_id.inner())),
58        Witness::Base(Value::known(dao_notes_secret_key.inner())),
59        Witness::Base(Value::known(dao_proposer_secret_key.inner())),
60        Witness::Base(Value::known(dao_proposals_secret_key.inner())),
61        Witness::Base(Value::known(dao_votes_secret_key.inner())),
62        Witness::Base(Value::known(dao_exec_secret_key.inner())),
63        Witness::Base(Value::known(dao_early_exec_secret_key.inner())),
64        Witness::Base(Value::known(dao.bulla_blind.inner())),
65    ];
66
67    let (pub_x, pub_y) = dao.notes_public_key.xy();
68    let dao_bulla = dao.to_bulla();
69    let public = vec![pub_x, pub_y, dao_bulla.inner()];
70
71    //darkfi::zk::export_witness_json("proof/witness/mint.json", &prover_witnesses, &public);
72    let circuit = ZkCircuit::new(prover_witnesses, dao_mint_zkbin);
73    let proof = Proof::create(dao_mint_pk, &[circuit], &public, &mut OsRng)?;
74
75    let dao_mint_params = DaoMintParams { dao_bulla, dao_pubkey: dao.notes_public_key };
76
77    Ok((dao_mint_params, vec![proof]))
78}