lead.rs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. use halo2_proofs::{arithmetic::Field, dev::MockProver};
  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 = coin.create_contract();
  53. //let proof = create_lead_proof(lead_pk.clone(), coin.clone()).unwrap();
  54. //verify_lead_proof(&lead_vk, &proof, coin);
  55. // calculate public inputs
  56. let public_inputs = coin.public_inputs();
  57. let prover = MockProver::run(k, &contract, vec![public_inputs]).unwrap();
  58. //
  59. assert_eq!(prover.verify(), Ok(()));
  60. //
  61. }