mod.rs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. use async_executor::Executor;
  2. use async_std::sync::Arc;
  3. use halo2_proofs::arithmetic::Field;
  4. use log::{debug, error, info};
  5. use std::fmt;
  6. use rand::rngs::OsRng;
  7. use std::{thread, time::Duration};
  8. use crate::zk::circuit::{BurnContract, LeadContract, MintContract};
  9. use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
  10. use crate::{
  11. blockchain::{Blockchain, Epoch, EpochConsensus},
  12. consensus::{
  13. clock::{Clock, Ticks},
  14. Block, BlockInfo, Header, OuroborosMetadata, StakeholderMetadata, StreamletMetadata,
  15. TransactionLeadProof,
  16. },
  17. crypto::{
  18. address::Address,
  19. coin::OwnCoin,
  20. constants::MERKLE_DEPTH,
  21. keypair::{PublicKey, SecretKey},
  22. leadcoin::LeadCoin,
  23. merkle_node::MerkleNode,
  24. note::{EncryptedNote, Note},
  25. nullifier::Nullifier,
  26. proof::{Proof, ProvingKey, VerifyingKey},
  27. schnorr::{SchnorrSecret},
  28. },
  29. net::{MessageSubscription, P2p, Settings, SettingsPtr},
  30. node::state::{state_transition, ProgramState, StateUpdate},
  31. tx::{
  32. builder::{
  33. TransactionBuilder, TransactionBuilderClearInputInfo, TransactionBuilderOutputInfo,
  34. },
  35. Transaction,
  36. },
  37. util::{path::expand_path, time::Timestamp},
  38. Result,
  39. };
  40. use url::Url;
  41. use pasta_curves::pallas;
  42. use group::ff::PrimeField;
  43. const LOG_T: &str = "stakeholder";
  44. const TREE_LEN: usize = 100;
  45. #[derive(Debug)]
  46. pub struct SlotWorkspace {
  47. pub st: blake3::Hash, // hash of the previous block
  48. pub e: u64, // epoch index
  49. pub sl: u64, // relative slot index
  50. pub txs: Vec<Transaction>, // unpublished block transactions
  51. pub root: MerkleNode,
  52. /// merkle root of txs
  53. pub m: StakeholderMetadata,
  54. pub om: OuroborosMetadata,
  55. pub is_leader: bool,
  56. pub proof: Proof,
  57. pub block: BlockInfo,
  58. }
  59. impl Default for SlotWorkspace {
  60. fn default() -> Self {
  61. Self {
  62. st: blake3::hash(b""),
  63. e: 0,
  64. sl: 0,
  65. txs: vec![],
  66. root: MerkleNode(pallas::Base::zero()),
  67. is_leader: false,
  68. m: StakeholderMetadata::default(),
  69. om: OuroborosMetadata::default(),
  70. proof: Proof::default(),
  71. block: BlockInfo::default(),
  72. }
  73. }
  74. }
  75. impl SlotWorkspace {
  76. pub fn new_block(&self) -> (BlockInfo, blake3::Hash) {
  77. let sm = StreamletMetadata::new(vec![]);
  78. let header = Header::new(self.st, self.e, self.sl, Timestamp::current_time(), self.root);
  79. let block = BlockInfo::new(header, self.txs.clone(), self.m.clone(), self.om.clone(), sm);
  80. let hash = block.blockhash();
  81. (block, hash)
  82. }
  83. pub fn add_tx(&mut self, tx: Transaction) {
  84. self.txs.push(tx);
  85. }
  86. pub fn set_root(&mut self, root: MerkleNode) {
  87. self.root = root;
  88. }
  89. pub fn set_stakeholdermetadata(&mut self, meta: StakeholderMetadata) {
  90. self.m = meta;
  91. }
  92. pub fn set_ouroborosmetadata(&mut self, meta: OuroborosMetadata) {
  93. self.om = meta;
  94. }
  95. pub fn set_sl(&mut self, sl: u64) {
  96. self.sl = sl;
  97. }
  98. pub fn set_st(&mut self, st: blake3::Hash) {
  99. self.st = st;
  100. }
  101. pub fn set_e(&mut self, e: u64) {
  102. self.e = e;
  103. }
  104. pub fn set_proof(&mut self, proof: Proof) {
  105. self.proof = proof;
  106. }
  107. pub fn set_leader(&mut self, alead: bool) {
  108. self.is_leader = alead;
  109. }
  110. }
  111. struct StakeholderState {
  112. /// The entire Merkle tree state
  113. tree: BridgeTree<MerkleNode, MERKLE_DEPTH>,
  114. /// List of all previous and the current Merkle roots.
  115. /// This is the hashed value of all the children.
  116. merkle_roots: Vec<MerkleNode>,
  117. /// Nullifiers prevent double spending
  118. nullifiers: Vec<Nullifier>,
  119. /// All received coins
  120. // NOTE: We need maybe a flag to keep track of which ones are
  121. // spent. Maybe the spend field links to a tx hash:input index.
  122. // We should also keep track of the tx hash:output index where
  123. // this coin was received.
  124. own_coins: Vec<OwnCoin>,
  125. /// Verifying key for the mint zk circuit.
  126. mint_vk: VerifyingKey,
  127. /// Verifying key for the burn zk circuit.
  128. burn_vk: VerifyingKey,
  129. /// Public key of the cashier
  130. cashier_signature_public: PublicKey,
  131. /// Public key of the faucet
  132. faucet_signature_public: PublicKey,
  133. /// List of all our secret keys
  134. secrets: Vec<SecretKey>,
  135. }
  136. impl ProgramState for StakeholderState {
  137. fn is_valid_cashier_public_key(&self, public: &PublicKey) -> bool {
  138. public == &self.cashier_signature_public
  139. }
  140. fn is_valid_faucet_public_key(&self, public: &PublicKey) -> bool {
  141. public == &self.faucet_signature_public
  142. }
  143. fn is_valid_merkle(&self, merkle_root: &MerkleNode) -> bool {
  144. self.merkle_roots.iter().any(|m| m == merkle_root)
  145. }
  146. fn nullifier_exists(&self, nullifier: &Nullifier) -> bool {
  147. self.nullifiers.iter().any(|n| n == nullifier)
  148. }
  149. fn mint_vk(&self) -> &VerifyingKey {
  150. &self.mint_vk
  151. }
  152. fn burn_vk(&self) -> &VerifyingKey {
  153. &self.burn_vk
  154. }
  155. }
  156. impl StakeholderState {
  157. fn apply(&mut self, mut update: StateUpdate) {
  158. // Extend our list of nullifiers with the ones from the update
  159. self.nullifiers.append(&mut update.nullifiers);
  160. // Update merkle tree and witnesses
  161. for (coin, enc_note) in update.coins.into_iter().zip(update.enc_notes.into_iter()) {
  162. // Add the new coins to the Merkle tree
  163. let node = MerkleNode(coin.0);
  164. self.tree.append(&node);
  165. // Keep track of all Merkle roots that have existed
  166. self.merkle_roots.push(self.tree.root(0).unwrap());
  167. // If it's our own coin, witness it and append to the vector.
  168. if let Some((note, secret)) = self.try_decrypt_note(enc_note) {
  169. let leaf_position = self.tree.witness().unwrap();
  170. let nullifier = Nullifier::new(secret, note.serial);
  171. let own_coin = OwnCoin { coin, note, secret, nullifier, leaf_position };
  172. self.own_coins.push(own_coin);
  173. }
  174. }
  175. }
  176. fn try_decrypt_note(&self, ciphertext: EncryptedNote) -> Option<(Note, SecretKey)> {
  177. // Loop through all our secret keys...
  178. for secret in &self.secrets {
  179. // .. attempt to decrypt the note ...
  180. if let Ok(note) = ciphertext.decrypt(secret) {
  181. // ... and return the decrypted note for this coin.
  182. return Some((note, *secret))
  183. }
  184. }
  185. // We weren't able to decrypt the note with any of our keys.
  186. None
  187. }
  188. }
  189. pub struct Stakeholder {
  190. pub blockchain: Blockchain, // stakeholder view of the blockchain
  191. pub net: Arc<P2p>,
  192. pub clock: Clock,
  193. pub ownedcoins: Vec<OwnCoin>, // owned stakes
  194. pub epoch: Epoch, // current epoch
  195. pub epoch_consensus: EpochConsensus, // configuration for the epoch
  196. pub lead_pk: ProvingKey,
  197. pub mint_pk: ProvingKey,
  198. pub burn_pk: ProvingKey,
  199. pub lead_vk: VerifyingKey,
  200. pub mint_vk: VerifyingKey,
  201. pub burn_vk: VerifyingKey,
  202. pub playing: bool,
  203. pub workspace: SlotWorkspace,
  204. pub id: i64,
  205. pub cashier_signature_public: PublicKey,
  206. pub faucet_signature_public: PublicKey,
  207. pub cashier_signature_secret: SecretKey,
  208. pub faucet_signature_secret: SecretKey,
  209. //pub subscription: Subscription<Result<ChannelPtr>>,
  210. //pub chanptr : ChannelPtr,
  211. //pub msgsub : MessageSubscription::<BlockInfo>,
  212. }
  213. impl Stakeholder {
  214. pub async fn new(
  215. consensus: EpochConsensus,
  216. settings: Settings,
  217. rel_path: &str,
  218. id: i64,
  219. k: Option<u32>,
  220. ) -> Result<Self> {
  221. let path = expand_path(rel_path).unwrap();
  222. let db = sled::open(&path)?;
  223. let ts = Timestamp::current_time();
  224. let genesis_hash = blake3::hash(b"");
  225. let bc = Blockchain::new(&db, ts, genesis_hash).unwrap();
  226. let eta = pallas::Base::one();
  227. let epoch = Epoch::new(consensus, eta);
  228. let lead_pk = ProvingKey::build(k.unwrap(), &LeadContract::default());
  229. let mint_pk = ProvingKey::build(k.unwrap(), &MintContract::default());
  230. let burn_pk = ProvingKey::build(k.unwrap(), &BurnContract::default());
  231. let lead_vk = VerifyingKey::build(k.unwrap(), &LeadContract::default());
  232. let mint_vk = VerifyingKey::build(k.unwrap(), &MintContract::default());
  233. let burn_vk = VerifyingKey::build(k.unwrap(), &BurnContract::default());
  234. let p2p = P2p::new(settings.clone()).await;
  235. let workspace = SlotWorkspace::default();
  236. let clock = Clock::new(
  237. Some(consensus.get_epoch_len()),
  238. Some(consensus.get_slot_len()),
  239. Some(consensus.get_tick_len()),
  240. settings.peers,
  241. );
  242. let cashier_signature_secret = SecretKey::random(&mut OsRng);
  243. let cashier_signature_public = PublicKey::from_secret(cashier_signature_secret);
  244. let faucet_signature_secret = SecretKey::random(&mut OsRng);
  245. let faucet_signature_public = PublicKey::from_secret(faucet_signature_secret);
  246. debug!(target: LOG_T, "stakeholder constructed");
  247. Ok(Self {
  248. blockchain: bc,
  249. net: p2p,
  250. clock,
  251. ownedcoins: vec![], //TODO should be read from wallet db.
  252. epoch,
  253. epoch_consensus: consensus,
  254. lead_pk,
  255. mint_pk,
  256. burn_pk,
  257. lead_vk,
  258. mint_vk,
  259. burn_vk,
  260. playing: true,
  261. workspace,
  262. id,
  263. cashier_signature_public,
  264. faucet_signature_public,
  265. cashier_signature_secret,
  266. faucet_signature_secret,
  267. })
  268. }
  269. /*
  270. /// wrapper on schnorr public verify
  271. pub fn verify(&self, message: &[u8], signature: &Signature) -> bool {
  272. info!(target: LOG_T, "verify()");
  273. self.keypair.public.verify(message, signature)
  274. }
  275. */
  276. pub fn get_leadprovkingkey(&self) -> ProvingKey {
  277. info!(target: LOG_T, "get_leadprovkingkey()");
  278. self.lead_pk.clone()
  279. }
  280. pub fn get_mintprovkingkey(&self) -> ProvingKey {
  281. info!(target: LOG_T, "get_mintprovkingkey()");
  282. self.mint_pk.clone()
  283. }
  284. pub fn get_burnprovkingkey(&self) -> ProvingKey {
  285. info!(target: LOG_T, "get_burnprovkingkey()");
  286. self.burn_pk.clone()
  287. }
  288. pub fn get_leadverifyingkey(&self) -> VerifyingKey {
  289. info!(target: LOG_T, "get_leadverifyingkey()");
  290. self.lead_vk.clone()
  291. }
  292. pub fn get_mintverifyingkey(&self) -> VerifyingKey {
  293. info!(target: LOG_T, "get_mintverifyingkey()");
  294. self.mint_vk.clone()
  295. }
  296. pub fn get_burnverifyingkey(&self) -> VerifyingKey {
  297. info!(target: LOG_T, "get_burnverifyingkey()");
  298. self.burn_vk.clone()
  299. }
  300. /// get list stakeholder peers on the p2p network for synchronization
  301. pub fn get_peers(&self) -> Vec<Url> {
  302. info!(target: LOG_T, "get_peers()");
  303. let settings: SettingsPtr = self.net.settings();
  304. settings.peers.clone()
  305. }
  306. /*
  307. fn new_block(&self) {
  308. //TODO initialize blocks in the epoch, and add coin commitment in genesis
  309. let block_info = BlockInfo::new(st, e, sl, txs, metadata, sm);
  310. self.block = block_info;
  311. }
  312. */
  313. async fn init_network(&self) -> Result<()> {
  314. info!(target: LOG_T, "init_network()");
  315. let exec = Arc::new(Executor::new());
  316. self.net.clone().start(exec.clone()).await?;
  317. exec.spawn(self.net.clone().run(exec.clone())).detach();
  318. info!(target: LOG_T, "net initialized");
  319. Ok(())
  320. }
  321. pub fn get_net(&self) -> Arc<P2p> {
  322. info!(target: LOG_T, "get_net()");
  323. //TODO use P2p ptr not to overwrite wrappers
  324. self.net.clone()
  325. }
  326. /// add new blockinfo to the blockchain
  327. pub fn add_block(&self, block: BlockInfo) {
  328. info!(target: LOG_T, "add_block()");
  329. let blocks = [block];
  330. let _len = self.blockchain.add(&blocks);
  331. }
  332. pub fn add_tx(&mut self, tx: Transaction) {
  333. info!(target: LOG_T, "add_tx()");
  334. self.workspace.add_tx(tx);
  335. }
  336. /// extract leader selection lottery randomness \eta
  337. /// it's the hash of the previous lead proof
  338. /// converted to pallas base
  339. pub fn get_eta(&self) -> pallas::Base {
  340. info!(target: LOG_T, "get_eta()");
  341. let proof_tx_hash = self.blockchain.get_last_proof_hash().unwrap();
  342. let mut bytes: [u8; 32] = *proof_tx_hash.as_bytes();
  343. // read first 254 bits
  344. bytes[30] = 0;
  345. bytes[31] = 0;
  346. pallas::Base::from_repr(bytes).unwrap()
  347. }
  348. pub fn valid_block(&self, _blk: BlockInfo) -> bool {
  349. info!(target: LOG_T, "valid_block()");
  350. //TODO implement
  351. true
  352. }
  353. /// listen to the network,
  354. /// for new transactions.
  355. pub fn sync_tx(&self) {
  356. //TODO
  357. }
  358. /// listen to the network channels,
  359. /// receive new messages, or blocks,
  360. /// validate the block proof, and the transactions,
  361. /// if so add the proof to metadata if stakeholder isn't the lead.
  362. pub async fn sync_block(&self) {
  363. info!(target: LOG_T, "syncing blocks");
  364. for chanptr in self.net.channels().lock().await.values() {
  365. let message_subsytem = chanptr.get_message_subsystem();
  366. message_subsytem.add_dispatch::<BlockInfo>().await;
  367. //TODO start channel if isn't started yet
  368. //let info = chanptr.get_info();
  369. let msg_sub: MessageSubscription<BlockInfo> =
  370. chanptr.subscribe_msg::<BlockInfo>().await.expect("missing blockinfo");
  371. let res = msg_sub.receive().await.unwrap();
  372. let blk: BlockInfo = (*res).to_owned();
  373. //TODO validate the block proof, and transactions.
  374. if self.valid_block(blk.clone()) {
  375. //TODO if valid only.
  376. let _len = self.blockchain.add(&[blk]);
  377. } else {
  378. error!(target: LOG_T, "received block is invalid!");
  379. }
  380. }
  381. }
  382. pub async fn background(&mut self, hardlimit: Option<u8>) {
  383. info!(target: LOG_T, "background");
  384. let _ = self.init_network().await;
  385. let _ = self.clock.sync().await;
  386. let mut c: u8 = 0;
  387. let lim: u8 = hardlimit.unwrap_or(0);
  388. while self.playing {
  389. if c > lim && lim > 0 {
  390. break
  391. }
  392. // clock ticks slot begins
  393. // initialize the epoch if it's the time
  394. // check for leadership
  395. match self.clock.ticks().await {
  396. Ticks::GENESIS { e, sl } => {
  397. //TODO (res) any initialization happening here?
  398. self.new_epoch();
  399. self.new_slot(e, sl);
  400. }
  401. Ticks::NEWEPOCH { e, sl } => {
  402. self.new_epoch();
  403. self.new_slot(e, sl);
  404. }
  405. Ticks::NEWSLOT { e, sl } => self.new_slot(e, sl),
  406. Ticks::TOCKS => {
  407. info!(target: LOG_T, "tocks");
  408. // slot is about to end.
  409. // sync, and validate.
  410. // no more transactions to be received/send to the end of slot.
  411. if self.workspace.is_leader {
  412. info!(target: LOG_T, "[leadership won]");
  413. //craete block
  414. let (block_info, _block_hash) = self.workspace.new_block();
  415. //add the block to the blockchain
  416. self.add_block(block_info.clone());
  417. let block: Block = Block::from(block_info.clone());
  418. // publish the block
  419. //TODO (fix) before publishing the workspace tx root need to be set.
  420. let _ret = self.net.broadcast(block).await;
  421. } else {
  422. //
  423. self.sync_block().await;
  424. }
  425. }
  426. Ticks::IDLE => continue,
  427. Ticks::OUTOFSYNC => {
  428. error!(target: LOG_T, "clock/blockchain are out of sync");
  429. // clock, and blockchain are out of sync
  430. let _ = self.clock.sync().await;
  431. self.sync_block().await;
  432. }
  433. }
  434. thread::sleep(Duration::from_millis(1000));
  435. c += 1;
  436. }
  437. }
  438. /// on the onset of the epoch, layout the new the competing coins
  439. /// assuming static stake during the epoch, enforced by the commitment to competing coins
  440. /// in the epoch's gen2esis data.
  441. fn new_epoch(&mut self) {
  442. info!(target: LOG_T, "[new epoch] {}", self);
  443. let eta = self.get_eta();
  444. let mut epoch = Epoch::new(self.epoch_consensus, eta);
  445. // total stake
  446. let num_slots = self.workspace.sl;
  447. let epochs = self.workspace.e;
  448. let epoch_len = self.epoch_consensus.get_epoch_len();
  449. // TODO sigma scalar for tunning target function
  450. // it's value is dependent on the tekonomics,
  451. // set to one untill then.
  452. let reward = pallas::Base::one();
  453. let num_slots = num_slots + epochs * epoch_len;
  454. let sigma: pallas::Base = pallas::Base::from(num_slots) * reward;
  455. epoch.create_coins(sigma, self.ownedcoins.clone()); // set epoch interal fields working space with competing coins
  456. self.epoch = epoch.clone();
  457. }
  458. /// at the begining of the slot
  459. /// stakeholder need to play the lottery for the slot.
  460. /// FIXME if the stakeholder is not winning, staker can try different coins before,
  461. /// commiting it's coins, to maximize success, thus,
  462. /// the lottery proof need to be conditioned on the slot itself, and previous proof.
  463. /// this will encourage each potential leader to play with honesty.
  464. /// TODO this is fixed by commiting to the stakers at epoch genesis slot
  465. /// * `e` - epoch index
  466. /// * `sl` - slot relative index
  467. fn new_slot(&mut self, e: u64, sl: u64) {
  468. info!(target: LOG_T, "[new slot] {}, e:{}, rel sl:{}", self, e, sl);
  469. let st: blake3::Hash = if e > 0 || (e == 0 && sl > 0) {
  470. self.workspace.block.blockhash()
  471. } else {
  472. blake3::hash(b"")
  473. };
  474. // set workspace
  475. self.workspace.set_sl(sl);
  476. self.workspace.set_e(e);
  477. self.workspace.set_st(st);
  478. let mut winning_coin_idx: usize = 0;
  479. let won = self.epoch.is_leader(sl, &mut winning_coin_idx);
  480. let proof = if won {
  481. self.epoch.get_proof(sl, winning_coin_idx, &self.get_leadprovkingkey())
  482. } else {
  483. Proof::new(vec![])
  484. };
  485. self.workspace.set_leader(won);
  486. self.workspace.set_proof(proof.clone());
  487. let coin = self.epoch.get_coin(sl as usize, winning_coin_idx as usize);
  488. let keypair = coin.keypair.unwrap();
  489. let addr = Address::from(keypair.public);
  490. let sign = keypair.secret.sign(proof.as_ref());
  491. let stakeholder_meta = StakeholderMetadata::new(sign, addr);
  492. let ouroboros_meta =
  493. OuroborosMetadata::new(self.get_eta().to_repr(), TransactionLeadProof::from(proof));
  494. self.workspace.set_stakeholdermetadata(stakeholder_meta);
  495. self.workspace.set_ouroborosmetadata(ouroboros_meta);
  496. //
  497. if won {
  498. //TODO (res) verify the coin is finalized
  499. // could be finalized in later slot accord to the finalization policy that is WIP.
  500. let owned_coin =
  501. self.finalize_coin(&self.epoch.get_coin(sl as usize, winning_coin_idx as usize));
  502. self.ownedcoins.push(owned_coin);
  503. }
  504. }
  505. //TODO (res) validate the owncoin is the same winning leadcoin
  506. pub fn finalize_coin(&self, coin: &LeadCoin) -> OwnCoin {
  507. info!(target: LOG_T, "finalize coin");
  508. let keypair = coin.keypair.unwrap();
  509. let mut state = StakeholderState {
  510. tree: BridgeTree::<MerkleNode, MERKLE_DEPTH>::new(TREE_LEN),
  511. merkle_roots: vec![],
  512. nullifiers: vec![],
  513. own_coins: vec![],
  514. mint_vk: self.mint_vk.clone(),
  515. burn_vk: self.burn_vk.clone(),
  516. cashier_signature_public: self.cashier_signature_public,
  517. faucet_signature_public: self.faucet_signature_public,
  518. secrets: vec![keypair.secret],
  519. };
  520. let token_id = pallas::Base::random(&mut OsRng);
  521. let builder = TransactionBuilder {
  522. clear_inputs: vec![TransactionBuilderClearInputInfo {
  523. value: coin.value.unwrap(),
  524. token_id,
  525. signature_secret: self.cashier_signature_secret,
  526. }],
  527. inputs: vec![],
  528. outputs: vec![TransactionBuilderOutputInfo {
  529. value: coin.value.unwrap(),
  530. token_id,
  531. public: keypair.public,
  532. }],
  533. };
  534. let tx = builder.build(&self.mint_pk, &self.burn_pk).unwrap();
  535. tx.verify(&state.mint_vk, &state.burn_vk).unwrap();
  536. let _note = tx.outputs[0].enc_note.decrypt(&keypair.secret).unwrap();
  537. let update = state_transition(&state, tx).unwrap();
  538. state.apply(update);
  539. state.own_coins[0].clone()
  540. }
  541. }
  542. impl fmt::Display for Stakeholder {
  543. fn fmt(&self, formater: &mut fmt::Formatter) -> fmt::Result {
  544. formater.write_fmt(format_args!("stakeholder with id: {}", self.id))
  545. }
  546. }