lead.rs 2.8 KB

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