darkfi_sdk/crypto/constants/
fixed_bases.rsuse super::{L_ORCHARD_SCALAR, L_VALUE};
use halo2_gadgets::ecc::{
chip::{BaseFieldElem, FixedPoint, FullScalar, ShortScalar},
FixedPoints,
};
use pasta_curves::pallas;
pub mod commit_ivk_r;
pub mod note_commit_r;
pub mod nullifier_k;
pub mod spend_auth_g;
pub mod value_commit_r;
pub mod value_commit_v;
pub const ORCHARD_PERSONALIZATION: &str = "z.cash:Orchard";
pub const VALUE_COMMITMENT_PERSONALIZATION: &str = "z.cash:Orchard-cv";
pub const VALUE_COMMITMENT_V_BYTES: [u8; 1] = *b"v";
pub const VALUE_COMMITMENT_R_BYTES: [u8; 1] = *b"r";
pub const NOTE_COMMITMENT_PERSONALIZATION: &str = "z.cash:Orchard-NoteCommit";
pub const COMMIT_IVK_PERSONALIZATION: &str = "z.cash:Orchard-CommitIvk";
pub const FIXED_BASE_WINDOW_SIZE: usize = 3;
pub const H: usize = 1 << FIXED_BASE_WINDOW_SIZE;
pub const NUM_WINDOWS: usize = L_ORCHARD_SCALAR.div_ceil(FIXED_BASE_WINDOW_SIZE);
pub const NUM_WINDOWS_SHORT: usize = L_VALUE.div_ceil(FIXED_BASE_WINDOW_SIZE);
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum OrchardFixedBases {
Full(OrchardFixedBasesFull),
NullifierK,
ValueCommitV,
}
impl From<OrchardFixedBasesFull> for OrchardFixedBases {
fn from(full_width_base: OrchardFixedBasesFull) -> Self {
Self::Full(full_width_base)
}
}
impl From<ValueCommitV> for OrchardFixedBases {
fn from(_value_commit_v: ValueCommitV) -> Self {
Self::ValueCommitV
}
}
impl From<NullifierK> for OrchardFixedBases {
fn from(_nullifier_k: NullifierK) -> Self {
Self::NullifierK
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum OrchardFixedBasesFull {
CommitIvkR,
NoteCommitR,
ValueCommitR,
SpendAuthG,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct NullifierK;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct ValueCommitV;
#[derive(Clone, Debug, Eq, PartialEq)]
#[allow(non_snake_case)] pub struct ConstBaseFieldElement {
G: pallas::Affine,
u: Vec<[[u8; 32]; H]>,
z: Vec<u64>,
}
impl ConstBaseFieldElement {
pub fn value_commit_r() -> Self {
Self {
G: value_commit_r::generator(),
u: value_commit_r::U.to_vec(),
z: value_commit_r::Z.to_vec(),
}
}
pub fn nullifier_k() -> Self {
Self { G: nullifier_k::generator(), u: nullifier_k::U.to_vec(), z: nullifier_k::Z.to_vec() }
}
}
impl FixedPoints<pallas::Affine> for OrchardFixedBases {
type FullScalar = OrchardFixedBasesFull;
type ShortScalar = ValueCommitV;
type Base = ConstBaseFieldElement;
}
impl FixedPoint<pallas::Affine> for OrchardFixedBasesFull {
type FixedScalarKind = FullScalar;
fn generator(&self) -> pallas::Affine {
match self {
Self::CommitIvkR => commit_ivk_r::generator(),
Self::NoteCommitR => note_commit_r::generator(),
Self::ValueCommitR => value_commit_r::generator(),
Self::SpendAuthG => spend_auth_g::generator(),
}
}
fn u(&self) -> Vec<[[u8; 32]; H]> {
match self {
Self::CommitIvkR => commit_ivk_r::U.to_vec(),
Self::NoteCommitR => note_commit_r::U.to_vec(),
Self::ValueCommitR => value_commit_r::U.to_vec(),
Self::SpendAuthG => spend_auth_g::U.to_vec(),
}
}
fn z(&self) -> Vec<u64> {
match self {
Self::CommitIvkR => commit_ivk_r::Z.to_vec(),
Self::NoteCommitR => note_commit_r::Z.to_vec(),
Self::ValueCommitR => value_commit_r::Z.to_vec(),
Self::SpendAuthG => spend_auth_g::Z.to_vec(),
}
}
}
impl FixedPoint<pallas::Affine> for ConstBaseFieldElement {
type FixedScalarKind = BaseFieldElem;
fn generator(&self) -> pallas::Affine {
self.G
}
fn u(&self) -> Vec<[[u8; 32]; H]> {
self.u.clone()
}
fn z(&self) -> Vec<u64> {
self.z.clone()
}
}
impl FixedPoint<pallas::Affine> for NullifierK {
type FixedScalarKind = BaseFieldElem;
fn generator(&self) -> pallas::Affine {
nullifier_k::generator()
}
fn u(&self) -> Vec<[[u8; 32]; H]> {
nullifier_k::U.to_vec()
}
fn z(&self) -> Vec<u64> {
nullifier_k::Z.to_vec()
}
}
impl FixedPoint<pallas::Affine> for ValueCommitV {
type FixedScalarKind = ShortScalar;
fn generator(&self) -> pallas::Affine {
value_commit_v::generator()
}
fn u(&self) -> Vec<[[u8; 32]; H]> {
value_commit_v::U_SHORT.to_vec()
}
fn z(&self) -> Vec<u64> {
value_commit_v::Z_SHORT.to_vec()
}
}