use evm_arithmetization::{
fixed_recursive_verifier::{extract_block_public_values, extract_two_to_one_block_hash},
proof::PublicValues,
BlockHeight,
};
use plonky2::plonk::config::Hasher as _;
use serde::{Deserialize, Serialize};
use crate::types::{Hash, Hasher, PlonkyProofIntern};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct GeneratedTxnProof {
pub p_vals: PublicValues,
pub intern: PlonkyProofIntern,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct GeneratedAggProof {
pub p_vals: PublicValues,
pub intern: PlonkyProofIntern,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct GeneratedBlockProof {
pub b_height: BlockHeight,
pub intern: PlonkyProofIntern,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct GeneratedAggBlockProof {
pub intern: PlonkyProofIntern,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum AggregatableProof {
Txn(GeneratedTxnProof),
Agg(GeneratedAggProof),
}
impl AggregatableProof {
pub(crate) fn public_values(&self) -> PublicValues {
match self {
AggregatableProof::Txn(info) => info.p_vals.clone(),
AggregatableProof::Agg(info) => info.p_vals.clone(),
}
}
pub(crate) const fn is_agg(&self) -> bool {
match self {
AggregatableProof::Txn(_) => false,
AggregatableProof::Agg(_) => true,
}
}
pub(crate) const fn intern(&self) -> &PlonkyProofIntern {
match self {
AggregatableProof::Txn(info) => &info.intern,
AggregatableProof::Agg(info) => &info.intern,
}
}
}
impl From<GeneratedTxnProof> for AggregatableProof {
fn from(v: GeneratedTxnProof) -> Self {
Self::Txn(v)
}
}
impl From<GeneratedAggProof> for AggregatableProof {
fn from(v: GeneratedAggProof) -> Self {
Self::Agg(v)
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum AggregatableBlockProof {
Block(GeneratedBlockProof),
Agg(GeneratedAggBlockProof),
}
impl AggregatableBlockProof {
pub fn pv_hash(&self) -> Hash {
match self {
AggregatableBlockProof::Block(info) => {
let pv = extract_block_public_values(&info.intern.public_inputs);
Hasher::hash_no_pad(pv)
}
AggregatableBlockProof::Agg(info) => {
let hash = extract_two_to_one_block_hash(&info.intern.public_inputs);
Hash::from_partial(hash)
}
}
}
pub(crate) const fn is_agg(&self) -> bool {
match self {
AggregatableBlockProof::Block(_) => false,
AggregatableBlockProof::Agg(_) => true,
}
}
pub(crate) const fn intern(&self) -> &PlonkyProofIntern {
match self {
AggregatableBlockProof::Block(info) => &info.intern,
AggregatableBlockProof::Agg(info) => &info.intern,
}
}
}
impl From<GeneratedBlockProof> for AggregatableBlockProof {
fn from(v: GeneratedBlockProof) -> Self {
Self::Block(v)
}
}
impl From<GeneratedAggBlockProof> for AggregatableBlockProof {
fn from(v: GeneratedAggBlockProof) -> Self {
Self::Agg(v)
}
}