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 */
1819use darkfi::{
20 zk::{halo2::Value, Proof, ProvingKey, Witness, ZkCircuit},
21 zkas::ZkBinary,
22Result,
23};
24use darkfi_sdk::{crypto::SecretKey, pasta::pallas};
25use log::debug;
26use rand::rngs::OsRng;
2728use crate::model::{Dao, DaoMintParams};
2930#[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>)> {
42debug!(target: "contract::dao::client::mint", "Building DAO contract mint transaction call");
4344let proposer_limit = pallas::Base::from(dao.proposer_limit);
45let quorum = pallas::Base::from(dao.quorum);
46let early_exec_quorum = pallas::Base::from(dao.early_exec_quorum);
47let approval_ratio_quot = pallas::Base::from(dao.approval_ratio_quot);
48let approval_ratio_base = pallas::Base::from(dao.approval_ratio_base);
4950// NOTE: It's important to keep these in the same order as the zkas code.
51let 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 ];
6667let (pub_x, pub_y) = dao.notes_public_key.xy();
68let dao_bulla = dao.to_bulla();
69let public = vec![pub_x, pub_y, dao_bulla.inner()];
7071//darkfi::zk::export_witness_json("proof/witness/mint.json", &prover_witnesses, &public);
72let circuit = ZkCircuit::new(prover_witnesses, dao_mint_zkbin);
73let proof = Proof::create(dao_mint_pk, &[circuit], &public, &mut OsRng)?;
7475let dao_mint_params = DaoMintParams { dao_bulla, dao_pubkey: dao.notes_public_key };
7677Ok((dao_mint_params, vec![proof]))
78}