-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d6da01
commit 1dc6915
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//! Validation crate centered for plonky2-verifier. | ||
use crate::deserializer::deserialize_vk; | ||
use crate::DeserializeError; | ||
use plonky2::plonk::config::{GenericConfig, KeccakGoldilocksConfig, PoseidonGoldilocksConfig}; | ||
use plonky2::util::serialization::DefaultGateSerializer; | ||
use snafu::Snafu; | ||
|
||
/// Validation error. | ||
#[derive(Debug, Snafu)] | ||
pub enum ValidateError { | ||
/// Invalid data. | ||
#[snafu(display("Invalid data: [{}]", cause))] | ||
InvalidVK { | ||
/// Internal error. | ||
#[snafu(source)] | ||
cause: DeserializeError, | ||
}, | ||
} | ||
|
||
impl From<DeserializeError> for ValidateError { | ||
fn from(value: DeserializeError) -> Self { | ||
ValidateError::InvalidVK { cause: value } | ||
} | ||
} | ||
|
||
/// Validate vk with preset Poseidon over Goldilocks config available in `plonky2`. | ||
/// Uses `DefaultGateSerializer`. | ||
pub fn validate_vk_default_poseidon(vk: &[u8]) -> Result<(), ValidateError> { | ||
const D: usize = 2; | ||
type C = PoseidonGoldilocksConfig; | ||
type F = <C as GenericConfig<D>>::F; | ||
|
||
deserialize_vk::<F, C, D>(vk, &DefaultGateSerializer) | ||
.map(|_| ()) // Discard `Ok` value, map it to `()` | ||
.map_err(ValidateError::from) // Convert `DeserializeError` to `ValidateError` | ||
} | ||
|
||
/// Validate vk with preset Keccak over Goldilocks config available in `plonky2`. | ||
/// Uses `DefaultGateSerializer`. | ||
pub fn validate_vk_default_keccak(vk: &[u8]) -> Result<(), ValidateError> { | ||
const D: usize = 2; | ||
type C = KeccakGoldilocksConfig; | ||
type F = <C as GenericConfig<D>>::F; | ||
|
||
deserialize_vk::<F, C, D>(vk, &DefaultGateSerializer) | ||
.map(|_| ()) // Discard `Ok` value, map it to `()` | ||
.map_err(ValidateError::from) // Convert `DeserializeError` to `ValidateError` | ||
} |