main.rs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2025 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 std::{
  19. env,
  20. fs::File,
  21. io::{Cursor, Read},
  22. };
  23. use darkfi::{
  24. Result,
  25. zk::{Proof, VerifyingKey, ZkCircuit, empty_witnesses},
  26. zkas::ZkBinary,
  27. };
  28. use darkfi_sdk::pasta::pallas::Base;
  29. use darkfi_serial::deserialize;
  30. fn main() -> Result<()> {
  31. let args: Vec<String> = env::args().collect();
  32. if args.len() != 2 {
  33. println!("Usage: ./verifier opcode_name");
  34. return Ok(())
  35. }
  36. let file_name = &args[1];
  37. let name = file_name.split(".").next().unwrap();
  38. //Load zkbin, proof, verifying key, public inputs from file
  39. let mut file = File::open(format!("../generator/proof/{name}.zk.bin"))?;
  40. let mut bincode = vec![];
  41. file.read_to_end(&mut bincode)?;
  42. let mut file = File::open(format!("../generator/proof/{name}.proof.bin"))?;
  43. let mut proof_bin = vec![];
  44. file.read_to_end(&mut proof_bin)?;
  45. let mut file = File::open(format!("../generator/proof/{name}.vks.bin"))?;
  46. let mut vkbin = vec![];
  47. file.read_to_end(&mut vkbin)?;
  48. let mut file = File::open(format!("../generator/proof/{name}.pi.bin"))?;
  49. let mut public_inputs_bin = vec![];
  50. file.read_to_end(&mut public_inputs_bin)?;
  51. // Deserialize and Verify
  52. let zkbin = ZkBinary::decode(&bincode)?;
  53. let verifier_witnesses = empty_witnesses(&zkbin)?;
  54. // Create the circuit
  55. let circuit = ZkCircuit::new(verifier_witnesses, &zkbin);
  56. let proof: Proof = deserialize(&proof_bin)?;
  57. let mut vk_buf = Cursor::new(vkbin);
  58. let vk = VerifyingKey::read::<Cursor<Vec<u8>>, ZkCircuit>(&mut vk_buf, circuit)?;
  59. //let vk = VerifyingKey::build(zkbin.k, &circuit);
  60. let public_inputs: Vec<Base> = deserialize(&public_inputs_bin)?;
  61. Ok(proof.verify(&vk, &public_inputs)?)
  62. }