libzeropool_zkbob/circuit/
note.rs

1use crate::fawkes_crypto::circuit::{
2    bool::CBool,
3    num::CNum,
4    poseidon::c_poseidon
5};
6use crate::fawkes_crypto::core::signal::Signal;
7use crate::fawkes_crypto::circuit::cs::{RCS, CS};
8use crate::circuit::boundednum::CBoundedNum;
9use crate::native::{note::Note, params::PoolParams};
10use crate::constants;
11
12#[derive(Clone, Signal)]
13#[Value = "Note<C::Fr>"]
14pub struct CNote<C:CS> {
15    pub d: CBoundedNum<C, { constants::DIVERSIFIER_SIZE_BITS }>,
16    pub p_d: CNum<C>,
17    pub b: CBoundedNum<C, { constants::BALANCE_SIZE_BITS }>,
18    pub t: CBoundedNum<C, { constants::SALT_SIZE_BITS }>,
19}
20
21
22impl<C:CS> CNote<C> {
23    pub fn hash<P: PoolParams<Fr = C::Fr>>(
24        &self,
25        params: &P,
26    ) -> CNum<C> {
27        let inputs = [self.d.as_num().clone(), self.p_d.clone(), self.b.as_num().clone(), self.t.as_num().clone()];
28        c_poseidon(&inputs, params.note())
29    }
30
31    // returns zero if note is dummy or nonzero otherwise
32    pub fn is_dummy_raw(&self) -> CNum<C> {
33        self.b.as_num().clone()
34    }
35
36    pub fn is_zero(&self) -> CBool<C> {
37        (self.d.as_num() + self.b.as_num() + self.t.as_num()).is_zero() & self.p_d.is_zero()
38    }
39}