lead.rs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. use halo2_proofs::{arithmetic::Field, dev::MockProver, circuit::Value};
  2. use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
  3. use pasta_curves::{
  4. arithmetic::CurveAffine,
  5. group::{ff::PrimeField, Curve},
  6. pallas,
  7. };
  8. use darkfi::{
  9. blockchain::{
  10. Blockchain,
  11. epoch::{Epoch,EpochItem},
  12. },
  13. stakeholder::stakeholder::{Stakeholder},
  14. util::time::{Timestamp},
  15. crypto::{
  16. constants::MERKLE_DEPTH_ORCHARD,
  17. leadcoin::LeadCoin,
  18. merkle_node::MerkleNode,
  19. util::{mod_r_p, pedersen_commitment_scalar},
  20. },
  21. zk::circuit::lead_contract::LeadContract,
  22. };
  23. fn main() {
  24. let k: u32 = 13;
  25. //let lead_pk = ProvingKey::build(k, &LeadContract::default());
  26. //let lead_vk = VerifyingKey::build(k, &LeadContract::default());
  27. //
  28. const LEN: usize = 10;
  29. let epoch_item = EpochItem {
  30. value: 0, //static stake value
  31. };
  32. //TODO to read eta you need an access to the blockchain proof transaction.
  33. //need an emulation of the stakeholder as a node
  34. //TODO who should have view of the blockchain if not the stakeholder?
  35. // or should the blockchain be a node in itself?
  36. // but that doesn't make sense, since each stakeholder might end up with different view of it.
  37. let genesis_data = blake3::hash(b"");
  38. let db = sled::open("/tmp/darkfi.db").unwrap();
  39. let oc = Blockchain::new(&db, Timestamp::current_time(), genesis_data).unwrap();
  40. let stakeholder = Stakeholder {
  41. blockchain: oc,
  42. };
  43. let eta : pallas::Base = stakeholder.get_eta();
  44. let epoch = Epoch {
  45. len: Some(LEN),
  46. item: Some(epoch_item),
  47. eta: eta,
  48. };
  49. let coins: Vec<LeadCoin> = epoch.create_coins();
  50. let coin_idx = 0;
  51. let coin = coins[coin_idx];
  52. let contract = LeadContract {
  53. path: Value::known(coin.path.unwrap()),
  54. coin_pk_x: Value::known(coin.pk_x.unwrap()),
  55. coin_pk_y: Value::known(coin.pk_y.unwrap()),
  56. root_sk: Value::known(coin.root_sk.unwrap()),
  57. sf_root_sk: Value::known(mod_r_p(coin.root_sk.unwrap())),
  58. path_sk: Value::known(coin.path_sk.unwrap()),
  59. coin_timestamp: Value::known(coin.tau.unwrap()), //
  60. coin_nonce: Value::known(coin.nonce.unwrap()),
  61. coin1_blind: Value::known(coin.c1_blind.unwrap()),
  62. value: Value::known(coin.value.unwrap()),
  63. coin2_blind: Value::known(coin.c2_blind.unwrap()),
  64. cm_pos: Value::known(coin.idx),
  65. //sn_c1: Value::known(coin.sn.unwrap()),
  66. slot: Value::known(coin.sl.unwrap()),
  67. mau_rho: Value::known(mod_r_p(coin.rho_mu.unwrap())),
  68. mau_y: Value::known(mod_r_p(coin.y_mu.unwrap())),
  69. root_cm: Value::known(coin.root_cm.unwrap()),
  70. };
  71. //let proof = create_lead_proof(lead_pk.clone(), coin.clone()).unwrap();
  72. //verify_lead_proof(&lead_vk, &proof, coin);
  73. // calculate public inputs
  74. let public_inputs = coin.public_inputs();
  75. let prover = MockProver::run(k, &contract, vec![public_inputs]).unwrap();
  76. //
  77. assert_eq!(prover.verify(), Ok(()));
  78. //
  79. }