lead.rs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2022 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use futures::executor::block_on;
  19. use halo2_proofs::dev::MockProver;
  20. use pasta_curves::pallas;
  21. use url::Url;
  22. use darkfi::{
  23. consensus::ouroboros::{Epoch, EpochConsensus, Stakeholder},
  24. crypto::{
  25. lead_proof,
  26. leadcoin::{LeadCoin, LEAD_PUBLIC_INPUT_LEN},
  27. },
  28. net::Settings,
  29. };
  30. fn main() {
  31. env_logger::init();
  32. let k: u32 = 13;
  33. //
  34. let _value = 33223; //static stake value
  35. //
  36. let settings = Settings {
  37. inbound: vec![Url::parse("tls://127.0.0.1:12002").unwrap()],
  38. outbound_connections: 4,
  39. manual_attempt_limit: 0,
  40. seed_query_timeout_seconds: 8,
  41. connect_timeout_seconds: 10,
  42. channel_handshake_seconds: 4,
  43. channel_heartbeat_seconds: 10,
  44. external_addr: vec![Url::parse("tls://127.0.0.1:12002").unwrap()],
  45. peers: [Url::parse("tls://127.0.0.1:12003").unwrap()].to_vec(),
  46. seeds: [
  47. Url::parse("tls://irc0.dark.fi:11001").unwrap(),
  48. Url::parse("tls://irc1.dark.fi:11001").unwrap(),
  49. ]
  50. .to_vec(),
  51. ..Default::default()
  52. };
  53. let consensus = EpochConsensus::new(Some(22), Some(3), Some(22), Some(0));
  54. let stakeholder: Stakeholder =
  55. block_on(Stakeholder::new(consensus, settings, "db", 0, Some(k))).unwrap();
  56. let eta: pallas::Base = stakeholder.get_eta();
  57. let mut epoch = Epoch::new(consensus, eta);
  58. let sigma = pallas::Base::from(10);
  59. let coins: Vec<Vec<LeadCoin>> = epoch.create_coins(sigma.clone(), sigma, vec![]);
  60. let coin = coins[0][0];
  61. let contract = coin.create_contract();
  62. let public_inputs: [pallas::Base; LEAD_PUBLIC_INPUT_LEN] = coin.public_inputs_as_array();
  63. let lead_pk = stakeholder.get_leadprovkingkey();
  64. let lead_vk = stakeholder.get_leadverifyingkey();
  65. let proof = lead_proof::create_lead_proof(&lead_pk.clone(), coin.clone()).unwrap();
  66. lead_proof::verify_lead_proof(&lead_vk, &proof, &public_inputs);
  67. let prover = MockProver::run(k, &contract, vec![public_inputs.to_vec()]).unwrap();
  68. prover.assert_satisfied();
  69. assert_eq!(prover.verify(), Ok(()));
  70. }