-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvk.rs
36 lines (31 loc) · 977 Bytes
/
vk.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! Verification key for `plonky2` in a format, acceptable by `zkVerify`.
use crate::config::Plonky2Config;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
#[cfg(feature = "std")]
extern crate std;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
#[cfg(feature = "std")]
use std::vec::Vec;
/// `Vk` encapsulating configuration.
#[serde_as]
#[derive(Serialize, Deserialize)]
pub struct Vk {
/// Configuration for this `Vk`.
pub config: Plonky2Config,
/// Serialized `VerifierCircuitData` from `plonky2`.
#[serde_as(as = "serde_with::hex::Hex")]
pub bytes: Vec<u8>,
}
#[cfg(feature = "converter")]
impl Vk {
/// Serializes the entire `Vk` struct to a binary format.
pub fn as_bytes(&self) -> Vec<u8> {
bincode::serialize(self).expect("Serialization to bytes failed")
}
/// Serializes the entire `Vk` struct to a hex-encoded string.
pub fn as_hex(&self) -> String {
hex::encode(self.as_bytes())
}
}