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::Keypair;
25use log::debug;
26use rand::rngs::OsRng;
2728use crate::model::{MoneyAuthTokenFreezeParamsV1, TokenAttributes};
2930pub struct AuthTokenFreezeCallDebris {
31pub params: MoneyAuthTokenFreezeParamsV1,
32pub proofs: Vec<Proof>,
33}
3435/// Struct holding necessary information to build a `Money::AuthTokenFreezeV1` contract call.
36pub struct AuthTokenFreezeCallBuilder {
37/// Mint authority keypair
38pub mint_keypair: Keypair,
39pub token_attrs: TokenAttributes,
40/// `AuthTokenMint_V1` zkas circuit ZkBinary
41pub auth_mint_zkbin: ZkBinary,
42/// Proving key for the `AuthTokenMint_V1` zk circuit,
43pub auth_mint_pk: ProvingKey,
44}
4546impl AuthTokenFreezeCallBuilder {
47pub fn build(&self) -> Result<AuthTokenFreezeCallDebris> {
48debug!(target: "contract::money::client::auth_token_freeze", "Building Money::AuthTokenFreezeV1 contract call");
4950// For the AuthTokenFreeze call, we just need to produce a valid signature,
51 // and enforce the correct derivation inside ZK.
52let prover_witnesses = vec![
53// Token attributes
54Witness::Base(Value::known(self.token_attrs.auth_parent.inner())),
55 Witness::Base(Value::known(self.token_attrs.blind.inner())),
56// Secret key used by mint
57Witness::Base(Value::known(self.mint_keypair.secret.inner())),
58 ];
5960let mint_pubkey = self.mint_keypair.public;
61let token_id = self.token_attrs.to_token_id();
6263let public_inputs = vec![mint_pubkey.x(), mint_pubkey.y(), token_id.inner()];
64//darkfi::zk::export_witness_json("proof/witness/auth_token_mint_v1.json", &prover_witnesses, &public_inputs);
65let circuit = ZkCircuit::new(prover_witnesses, &self.auth_mint_zkbin);
66let proof = Proof::create(&self.auth_mint_pk, &[circuit], &public_inputs, &mut OsRng)?;
6768let params =
69 MoneyAuthTokenFreezeParamsV1 { mint_public: self.mint_keypair.public, token_id };
70let debris = AuthTokenFreezeCallDebris { params, proofs: vec![proof] };
71Ok(debris)
72 }
73}