lead_proof.rs 893 B

12345678910111213141516171819202122232425262728293031323334
  1. use log::error;
  2. use rand::rngs::OsRng;
  3. use crate::{
  4. crypto::{
  5. leadcoin::LeadCoin,
  6. proof::{Proof, ProvingKey, VerifyingKey},
  7. types::*,
  8. },
  9. Result, VerifyFailed, VerifyResult,
  10. };
  11. #[allow(clippy::too_many_arguments)]
  12. pub fn create_lead_proof(pk: &ProvingKey, coin: LeadCoin) -> Result<Proof> {
  13. let contract = coin.create_contract();
  14. let public_inputs = coin.public_inputs();
  15. let proof = Proof::create(&pk, &[contract], &public_inputs, &mut OsRng)?;
  16. Ok(proof)
  17. }
  18. pub fn verify_lead_proof(
  19. vk: &VerifyingKey,
  20. proof: &Proof,
  21. public_inputs: &[DrkCircuitField],
  22. ) -> VerifyResult<()> {
  23. match proof.verify(vk, public_inputs) {
  24. Ok(()) => Ok(()),
  25. Err(e) => {
  26. error!("lead verification failed: {}", e);
  27. Err(VerifyFailed::InternalError("lead verification failure".to_string()))
  28. }
  29. }
  30. }