daod: correctly specify spend_hook and user_data when minting new supply of treasury tokens

This commit is contained in:
narodnik
2022-08-15 13:52:38 +02:00
parent e81809d39f
commit ee294eac35
3 changed files with 52 additions and 24 deletions

View File

@@ -25,7 +25,7 @@ use darkfi::{
nullifier::Nullifier,
proof::{ProvingKey, VerifyingKey},
token_id::generate_id,
types::DrkCircuitField,
types::{DrkCircuitField, DrkSpendHook, DrkUserData},
OwnCoin, OwnCoins, Proof,
},
node::state::{ProgramState, StateUpdate},
@@ -294,25 +294,50 @@ pub async fn demo() -> Result<()> {
tx.zk_verify(&zk_bins);
// Wallet stuff
// It might just be easier to hash it ourselves from keypair and blind...
let dao_bulla = {
assert_eq!(tx.func_calls.len(), 1);
let func_call = &tx.func_calls[0];
let call_data = func_call.call_data.as_any();
assert_eq!((&*call_data).type_id(), TypeId::of::<dao_contract::mint::validate::CallData>());
let call_data = call_data.downcast_ref::<dao_contract::mint::validate::CallData>().unwrap();
call_data.dao_bulla.clone()
};
///////////////////////////////////////////////////
//// Mint the initial supply of treasury token
//// and send it all to the DAO directly
///////////////////////////////////////////////////
let token_id = pallas::Base::random(&mut OsRng);
let keypair = Keypair::random(&mut OsRng);
// Address of deployed contract in our example is hook_dao_exec
// This field is public, you can see it's being sent to a DAO
// but nothing else is visible.
//
// In the python code we wrote:
//
// spend_hook = b"0xdao_ruleset"
//
let hook_dao_exec = DrkSpendHook::random(&mut OsRng);
let spend_hook = hook_dao_exec;
// The user_data can be a simple hash of the items passed into the ZK proof
// up to corresponding linked ZK proof to interpret however they need.
// In out case, it's the bulla for the DAO
let user_data = dao_bulla.0;
let builder = money_contract::transfer::builder::Builder {
clear_inputs: vec![money_contract::transfer::builder::BuilderClearInputInfo {
value: 110,
token_id,
value: xdrk_supply,
token_id: xdrk_token_id,
signature_secret: cashier_signature_secret,
}],
inputs: vec![],
outputs: vec![money_contract::transfer::builder::BuilderOutputInfo {
value: 110,
token_id,
public: keypair.public,
value: xdrk_supply,
token_id: xdrk_token_id,
public: dao_keypair.public,
spend_hook,
user_data,
}],
};
@@ -335,6 +360,9 @@ pub async fn demo() -> Result<()> {
tx.zk_verify(&zk_bins);
// Wallet stuff
// DAO reads the money received from the encrypted note
///////////////////////////////////////////////////
Ok(())

View File

@@ -30,6 +30,8 @@ pub struct Note {
pub serial: DrkSerial,
pub value: u64,
pub token_id: DrkTokenId,
pub spend_hook: DrkSpendHook,
pub user_data: DrkUserData,
pub coin_blind: DrkCoinBlind,
pub value_blind: DrkValueBlind,
pub token_blind: DrkValueBlind,
@@ -52,12 +54,15 @@ pub struct BuilderInputInfo {
pub merkle_path: Vec<MerkleNode>,
pub secret: SecretKey,
pub note: Note,
pub user_data_blind: DrkUserDataBlind,
}
pub struct BuilderOutputInfo {
pub value: u64,
pub token_id: DrkTokenId,
pub public: PublicKey,
pub spend_hook: DrkSpendHook,
pub user_data: DrkUserData,
}
impl Builder {
@@ -121,11 +126,6 @@ impl Builder {
};
let burn_pk = &zk_info.proving_key;
// TODO: this is disabled for now. We need to enable this.
let spend_hook = DrkSpendHook::from(0);
let user_data = DrkUserData::from(0);
let user_data_blind = DrkUserDataBlind::random(&mut OsRng);
// Note from the previous output
let note = input.note;
@@ -136,9 +136,9 @@ impl Builder {
value_blind,
token_blind,
note.serial,
spend_hook,
user_data,
user_data_blind,
note.spend_hook,
note.user_data,
input.user_data_blind,
note.coin_blind,
input.secret,
input.leaf_position,
@@ -178,10 +178,6 @@ impl Builder {
};
let mint_pk = &zk_info.proving_key;
// TODO: this is disabled for now. We need to enable this.
let spend_hook = DrkSpendHook::from(0);
let user_data = DrkUserData::from(0);
let (mint_proof, revealed) = create_mint_proof(
mint_pk,
output.value,
@@ -189,8 +185,8 @@ impl Builder {
value_blind,
token_blind,
serial,
spend_hook,
user_data,
output.spend_hook,
output.user_data,
coin_blind,
output.public,
)?;
@@ -201,6 +197,8 @@ impl Builder {
serial,
value: output.value,
token_id: output.token_id,
spend_hook: output.spend_hook,
user_data: output.user_data,
coin_blind,
value_blind,
token_blind,

View File

@@ -5,7 +5,6 @@ use darkfi::{
crypto::{
diffie_hellman::{kdf_sapling, sapling_ka_agree},
keypair::{PublicKey, SecretKey},
types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValueBlind},
},
util::serial::{Decodable, Encodable, SerialDecodable, SerialEncodable},
Error, Result,
@@ -59,7 +58,10 @@ impl EncryptedNote2 {
#[cfg(test)]
mod tests {
use super::*;
use darkfi::crypto::keypair::Keypair;
use darkfi::crypto::{
keypair::Keypair,
types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValueBlind},
};
use group::ff::Field;
#[test]