#![allow(non_snake_case)]
use crate::prelude::*;
use bytemuck::{Pod, Zeroable};
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct AccountMetaZC {
pub pubkey: Pubkey,
pub is_signer: bool,
pub is_writable: bool,
}
#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
pub struct AccountMetaBorsh {
pub pubkey: Pubkey,
pub is_signer: bool,
pub is_writable: bool,
}
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct CallbackZC {
pub program_id: Pubkey,
pub accounts: [AccountMetaZC; 32],
pub accounts_len: u32,
pub ix_data: [u8; 1024],
pub ix_data_len: u32,
}
impl Default for CallbackZC {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
pub struct Callback {
pub program_id: Pubkey,
pub accounts: Vec<AccountMetaBorsh>,
pub ix_data: Vec<u8>,
}
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct VrfRound {
pub alpha: [u8; 256],
pub alpha_len: u32,
pub request_slot: u64,
pub request_timestamp: i64,
pub result: [u8; 32],
pub num_verified: u32,
pub _ebuf: [u8; 256],
}
impl Default for VrfRound {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum VrfStatus {
StatusNone,
StatusRequesting,
StatusVerifying,
StatusVerified,
StatusCallbackSuccess,
StatusVerifyFailure,
}
impl std::fmt::Display for VrfStatus {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
VrfStatus::StatusNone => write!(f, "StatusNone"),
VrfStatus::StatusRequesting => write!(f, "StatusRequesting"),
VrfStatus::StatusVerifying => write!(f, "StatusVerifying"),
VrfStatus::StatusVerified => write!(f, "StatusVerified"),
VrfStatus::StatusCallbackSuccess => write!(f, "StatusCallbackSuccess"),
VrfStatus::StatusVerifyFailure => write!(f, "StatusVerifyFailure"),
}
}
}
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct EcvrfProofZC {
pub Gamma: EdwardsPointZC, pub c: Scalar,
pub s: Scalar,
}
impl Default for EcvrfProofZC {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
#[allow(dead_code)]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct Scalar {
pub(crate) bytes: [u8; 32],
}
unsafe impl Pod for Scalar {}
unsafe impl Zeroable for Scalar {}
#[derive(Copy, Clone, Default)]
#[repr(C)]
pub struct FieldElement51(pub(crate) [u64; 5]);
unsafe impl Pod for FieldElement51 {}
unsafe impl Zeroable for FieldElement51 {}
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct FieldElementZC {
pub(crate) bytes: [u64; 5],
}
impl Default for FieldElementZC {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
unsafe impl Pod for FieldElementZC {}
unsafe impl Zeroable for FieldElementZC {}
impl From<FieldElement51> for FieldElementZC {
fn from(val: FieldElement51) -> Self {
FieldElementZC { bytes: val.0 }
}
}
impl From<FieldElementZC> for FieldElement51 {
fn from(val: FieldElementZC) -> Self {
FieldElement51(val.bytes)
}
}
#[allow(missing_docs)]
#[derive(Copy, Clone)]
#[repr(C)]
pub struct CompletedPoint {
pub X: FieldElement51,
pub Y: FieldElement51,
pub Z: FieldElement51,
pub T: FieldElement51,
}
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct CompletedPointZC {
pub X: FieldElementZC,
pub Y: FieldElementZC,
pub Z: FieldElementZC,
pub T: FieldElementZC,
}
impl Default for CompletedPointZC {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
unsafe impl Pod for CompletedPoint {}
unsafe impl Zeroable for CompletedPoint {}
impl From<CompletedPoint> for CompletedPointZC {
fn from(val: CompletedPoint) -> Self {
CompletedPointZC {
X: val.X.into(),
Y: val.Y.into(),
Z: val.Z.into(),
T: val.T.into(),
}
}
}
impl From<CompletedPointZC> for CompletedPoint {
fn from(val: CompletedPointZC) -> Self {
CompletedPoint {
X: val.X.into(),
Y: val.Y.into(),
Z: val.Z.into(),
T: val.T.into(),
}
}
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct EdwardsPoint {
pub(crate) X: FieldElement51,
pub(crate) Y: FieldElement51,
pub(crate) Z: FieldElement51,
pub(crate) T: FieldElement51,
}
#[allow(dead_code)]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct EdwardsPointZC {
pub(crate) X: FieldElementZC,
pub(crate) Y: FieldElementZC,
pub(crate) Z: FieldElementZC,
pub(crate) T: FieldElementZC,
}
impl Default for EdwardsPointZC {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
#[derive(Copy, Clone, Default)]
#[repr(C)]
pub struct ProjectivePoint {
pub X: FieldElement51,
pub Y: FieldElement51,
pub Z: FieldElement51,
}
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct ProjectivePointZC {
pub(crate) X: FieldElementZC,
pub(crate) Y: FieldElementZC,
pub(crate) Z: FieldElementZC,
}
impl Default for ProjectivePointZC {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
unsafe impl Pod for ProjectivePoint {}
unsafe impl Zeroable for ProjectivePoint {}
impl From<ProjectivePoint> for ProjectivePointZC {
fn from(val: ProjectivePoint) -> Self {
ProjectivePointZC {
X: val.X.into(),
Y: val.Y.into(),
Z: val.Z.into(),
}
}
}
impl From<ProjectivePointZC> for ProjectivePoint {
fn from(val: ProjectivePointZC) -> Self {
ProjectivePoint {
X: val.X.into(),
Y: val.Y.into(),
Z: val.Z.into(),
}
}
}
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct EcvrfIntermediate {
pub r: FieldElementZC,
pub N_s: FieldElementZC,
pub D: FieldElementZC,
pub t13: FieldElementZC,
pub t15: FieldElementZC,
}
unsafe impl Pod for EcvrfIntermediate {}
unsafe impl Zeroable for EcvrfIntermediate {}
#[allow(non_snake_case)]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct VrfBuilder {
pub producer: Pubkey,
pub status: VrfStatus,
pub repr_proof: [u8; 80],
pub proof: EcvrfProofZC,
pub Y_point: Pubkey,
pub stage: u32,
pub stage1_out: EcvrfIntermediate,
pub R_1: EdwardsPointZC, pub R_2: EdwardsPointZC, pub stage3_out: EcvrfIntermediate,
pub H_point: EdwardsPointZC, pub s_reduced: Scalar,
pub Y_point_builder: [FieldElementZC; 3],
pub Y_ristretto_point: EdwardsPointZC, pub mul_round: u8,
pub hash_points_round: u8,
pub mul_tmp1: CompletedPointZC,
pub U_point1: EdwardsPointZC, pub U_point2: EdwardsPointZC, pub V_point1: EdwardsPointZC, pub V_point2: EdwardsPointZC, pub U_point: EdwardsPointZC, pub V_point: EdwardsPointZC, pub u1: FieldElementZC,
pub u2: FieldElementZC,
pub invertee: FieldElementZC,
pub y: FieldElementZC,
pub z: FieldElementZC,
pub p1_bytes: [u8; 32],
pub p2_bytes: [u8; 32],
pub p3_bytes: [u8; 32],
pub p4_bytes: [u8; 32],
pub c_prime_hashbuf: [u8; 16],
pub m1: FieldElementZC,
pub m2: FieldElementZC,
pub tx_remaining: u32,
pub verified: bool,
pub result: [u8; 32],
}
impl Default for VrfBuilder {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}