-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from topos-protocol/verifier-data
Add a `VerifierState`
- Loading branch information
Showing
5 changed files
with
147 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//! Hardcoded circuit constants to be used when generating the prover circuits. | ||
use core::ops::Range; | ||
|
||
/// Default range to be used for the `ArithmeticStark` table. | ||
pub(crate) const DEFAULT_ARITHMETIC_RANGE: Range<usize> = 16..20; | ||
/// Default range to be used for the `BytePackingStark` table. | ||
pub(crate) const DEFAULT_BYTE_PACKING_RANGE: Range<usize> = 10..20; | ||
/// Default range to be used for the `CpuStark` table. | ||
pub(crate) const DEFAULT_CPU_RANGE: Range<usize> = 12..22; | ||
/// Default range to be used for the `KeccakStark` table. | ||
pub(crate) const DEFAULT_KECCAK_RANGE: Range<usize> = 14..17; | ||
/// Default range to be used for the `KeccakSpongeStark` table. | ||
pub(crate) const DEFAULT_KECCAK_SPONGE_RANGE: Range<usize> = 9..14; | ||
/// Default range to be used for the `LogicStark` table. | ||
pub(crate) const DEFAULT_LOGIC_RANGE: Range<usize> = 12..16; | ||
/// Default range to be used for the `MemoryStark` table. | ||
pub(crate) const DEFAULT_MEMORY_RANGE: Range<usize> = 17..25; |
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
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,72 @@ | ||
//! This module defines the `VerifierState`, that contains the necessary data to | ||
//! handle succinct block proofs verification. | ||
use core::borrow::Borrow; | ||
|
||
use log::info; | ||
use plonky2::recursion::cyclic_recursion::check_cyclic_proof_verifier_data; | ||
|
||
use crate::proof_gen::ProofGenResult; | ||
use crate::prover_state::ProverStateBuilder; | ||
use crate::types::PlonkyProofIntern; | ||
use crate::{prover_state::ProverState, types::VerifierData}; | ||
|
||
/// Plonky2 verifier state. | ||
/// | ||
/// The default generation requires generating all the prover data before | ||
/// extracting the verifier-related data, which can take a long time and require | ||
/// a large amount of memory. | ||
pub struct VerifierState { | ||
/// The verification circuit data associated to the block proof layer of the | ||
/// plonky2 prover state. | ||
pub state: VerifierData, | ||
} | ||
|
||
/// Builder for the verifier state. | ||
/// This is essentially the same as the [`ProverStateBuilder`], in that we need | ||
/// to first generate the entire prover state before extracting the verifier | ||
/// data. | ||
pub type VerifierStateBuilder = ProverStateBuilder; | ||
|
||
impl VerifierStateBuilder { | ||
/// Instantiate the verifier state from the builder. Note that this is a | ||
/// very expensive call! | ||
pub fn build_verifier(self) -> VerifierState { | ||
info!("Initializing Plonky2 aggregation verifier state (This may take a while)..."); | ||
let ProverState { state } = self.build(); | ||
info!("Finished initializing Plonky2 aggregation verifier state!"); | ||
|
||
VerifierState { | ||
state: state.final_verifier_data(), | ||
} | ||
} | ||
} | ||
|
||
/// Extracts the verifier state from the entire prover state. | ||
impl<T: Borrow<ProverState>> From<T> for VerifierState { | ||
fn from(prover_state: T) -> Self { | ||
VerifierState { | ||
state: prover_state.borrow().state.final_verifier_data(), | ||
} | ||
} | ||
} | ||
|
||
impl VerifierState { | ||
/// Verifies a `block_proof`. | ||
pub fn verify(&self, block_proof: &PlonkyProofIntern) -> ProofGenResult<()> { | ||
// Proof verification | ||
self.state | ||
.verify(block_proof.clone()) | ||
.map_err(|err| err.to_string())?; | ||
|
||
// Verifier data verification | ||
check_cyclic_proof_verifier_data( | ||
block_proof, | ||
&self.state.verifier_only, | ||
&self.state.common, | ||
) | ||
.map_err(|err| err.to_string())?; | ||
|
||
Ok(()) | ||
} | ||
} |