|
|
@@ -21,10 +21,7 @@ use darkfi::{
|
|
|
zkas::ZkBinary,
|
|
|
Result,
|
|
|
};
|
|
|
-use darkfi_sdk::{
|
|
|
- crypto::{note::AeadEncryptedNote, pasta_prelude::*, pedersen_commitment_u64, Blind, Keypair},
|
|
|
- pasta::pallas,
|
|
|
-};
|
|
|
+use darkfi_sdk::crypto::{note::AeadEncryptedNote, Blind, Keypair};
|
|
|
use log::debug;
|
|
|
use rand::rngs::OsRng;
|
|
|
|
|
|
@@ -40,12 +37,12 @@ pub struct AuthTokenMintCallDebris {
|
|
|
|
|
|
/// Struct holding necessary information to build a `Money::AuthTokenMintV1` contract call.
|
|
|
pub struct AuthTokenMintCallBuilder {
|
|
|
+ /// Coin attributes
|
|
|
pub coin_attrs: CoinAttributes,
|
|
|
+ /// Token attributes
|
|
|
pub token_attrs: TokenAttributes,
|
|
|
-
|
|
|
/// Mint authority keypair
|
|
|
pub mint_keypair: Keypair,
|
|
|
-
|
|
|
/// `AuthTokenMint_V1` zkas circuit ZkBinary
|
|
|
pub auth_mint_zkbin: ZkBinary,
|
|
|
/// Proving key for the `AuthTokenMint_V1` zk circuit,
|
|
|
@@ -56,55 +53,32 @@ impl AuthTokenMintCallBuilder {
|
|
|
pub fn build(&self) -> Result<AuthTokenMintCallDebris> {
|
|
|
debug!("Building Money::AuthTokenMintV1 contract call");
|
|
|
|
|
|
- let value_blind = Blind::random(&mut OsRng);
|
|
|
- let value_commit = pedersen_commitment_u64(self.coin_attrs.value, value_blind);
|
|
|
-
|
|
|
// Create the proof
|
|
|
-
|
|
|
- let (public_x, public_y) = self.coin_attrs.public_key.xy();
|
|
|
-
|
|
|
let prover_witnesses = vec![
|
|
|
- // Coin attributes
|
|
|
- Witness::Base(Value::known(public_x)),
|
|
|
- Witness::Base(Value::known(public_y)),
|
|
|
- Witness::Base(Value::known(pallas::Base::from(self.coin_attrs.value))),
|
|
|
- Witness::Base(Value::known(self.coin_attrs.spend_hook.inner())),
|
|
|
- Witness::Base(Value::known(self.coin_attrs.user_data)),
|
|
|
- Witness::Base(Value::known(self.coin_attrs.blind.inner())),
|
|
|
// Token attributes
|
|
|
Witness::Base(Value::known(self.token_attrs.auth_parent.inner())),
|
|
|
Witness::Base(Value::known(self.token_attrs.blind.inner())),
|
|
|
- // Secret key used by mint
|
|
|
+ // Secret key used by the mint authority
|
|
|
Witness::Base(Value::known(self.mint_keypair.secret.inner())),
|
|
|
- // Random blinding factor for the value commitment
|
|
|
- Witness::Scalar(Value::known(value_blind.inner())),
|
|
|
];
|
|
|
|
|
|
let mint_pubkey = self.mint_keypair.public;
|
|
|
- let value_coords = value_commit.to_affine().coordinates().unwrap();
|
|
|
|
|
|
- let public_inputs = vec![
|
|
|
- mint_pubkey.x(),
|
|
|
- mint_pubkey.y(),
|
|
|
- self.token_attrs.to_token_id().inner(),
|
|
|
- self.coin_attrs.to_coin().inner(),
|
|
|
- *value_coords.x(),
|
|
|
- *value_coords.y(),
|
|
|
- ];
|
|
|
+ let public_inputs =
|
|
|
+ vec![mint_pubkey.x(), mint_pubkey.y(), self.token_attrs.to_token_id().inner()];
|
|
|
|
|
|
//darkfi::zk::export_witness_json("proof/witness/auth_token_mint_v1.json", &prover_witnesses, &public_inputs);
|
|
|
let circuit = ZkCircuit::new(prover_witnesses, &self.auth_mint_zkbin);
|
|
|
let proof = Proof::create(&self.auth_mint_pk, &[circuit], &public_inputs, &mut OsRng)?;
|
|
|
|
|
|
// Create the note
|
|
|
-
|
|
|
let note = MoneyNote {
|
|
|
value: self.coin_attrs.value,
|
|
|
token_id: self.coin_attrs.token_id,
|
|
|
spend_hook: self.coin_attrs.spend_hook,
|
|
|
user_data: self.coin_attrs.user_data,
|
|
|
coin_blind: self.coin_attrs.blind,
|
|
|
- value_blind,
|
|
|
+ value_blind: Blind::random(&mut OsRng),
|
|
|
token_blind: Blind::ZERO,
|
|
|
memo: vec![],
|
|
|
};
|
|
|
@@ -113,7 +87,6 @@ impl AuthTokenMintCallBuilder {
|
|
|
|
|
|
let params = MoneyAuthTokenMintParamsV1 {
|
|
|
token_id: self.token_attrs.to_token_id(),
|
|
|
- value_commit,
|
|
|
enc_note,
|
|
|
mint_pubkey,
|
|
|
};
|