mirror of https://github.com/zcash/orchard.git
updated `derive` for NoteType
This commit is contained in:
parent
48779d582f
commit
430e0473aa
|
@ -19,6 +19,7 @@ pub mod value_commit_v;
|
||||||
pub const ORCHARD_PERSONALIZATION: &str = "z.cash:Orchard";
|
pub const ORCHARD_PERSONALIZATION: &str = "z.cash:Orchard";
|
||||||
|
|
||||||
/// SWU hash-to-curve personalization for the value commitment generator
|
/// SWU hash-to-curve personalization for the value commitment generator
|
||||||
|
/// TODO: should we change to "NOTE_TYPE_PERSONALIZATION"?
|
||||||
pub const VALUE_COMMITMENT_PERSONALIZATION: &str = "z.cash:Orchard-cv";
|
pub const VALUE_COMMITMENT_PERSONALIZATION: &str = "z.cash:Orchard-cv";
|
||||||
|
|
||||||
/// SWU hash-to-curve personalization for the note type generator
|
/// SWU hash-to-curve personalization for the note type generator
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
use group::ff::PrimeField;
|
use group::ff::PrimeField;
|
||||||
use halo2_proofs::arithmetic::CurveExt;
|
use halo2_proofs::arithmetic::CurveExt;
|
||||||
use pasta_curves::pallas;
|
use pasta_curves::{pallas};
|
||||||
use subtle::CtOption;
|
use subtle::CtOption;
|
||||||
|
|
||||||
use crate::constants::fixed_bases::{VALUE_COMMITMENT_PERSONALIZATION, VALUE_COMMITMENT_V_BYTES};
|
use crate::constants::fixed_bases::{VALUE_COMMITMENT_PERSONALIZATION, VALUE_COMMITMENT_V_BYTES};
|
||||||
|
use crate::keys::SpendValidatingKey;
|
||||||
use crate::spec::extract_p;
|
use crate::spec::extract_p;
|
||||||
// use crate::keys::SpendValidatingKey;
|
|
||||||
|
|
||||||
/// Note type identifier.
|
/// Note type identifier.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct NoteType(pub(crate) pallas::Base);
|
pub struct NoteType(pub(crate) pallas::Base);
|
||||||
|
|
||||||
impl NoteType {
|
// the hasher used to derive the assetID
|
||||||
/*
|
#[allow(non_snake_case)]
|
||||||
/// Generates a dummy note type for use as $\rho$ in dummy spent notes.
|
fn assetID_hasher(msg: Vec<u8>) -> pallas::Base {
|
||||||
pub(crate) fn dummy(rng: &mut impl RngCore) -> Self {
|
let hasher = pallas::Point::hash_to_curve(VALUE_COMMITMENT_PERSONALIZATION);
|
||||||
NoteType(extract_p(&pallas::Point::random(rng)))
|
extract_p(&hasher(msg.as_bytes())))
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
impl NoteType {
|
||||||
|
|
||||||
/// Deserialize the note_type from a byte array.
|
/// Deserialize the note_type from a byte array.
|
||||||
pub fn from_bytes(bytes: &[u8; 32]) -> CtOption<Self> {
|
pub fn from_bytes(bytes: &[u8; 32]) -> CtOption<Self> {
|
||||||
|
@ -35,18 +36,19 @@ impl NoteType {
|
||||||
///
|
///
|
||||||
/// [notetypes]: https://zips.z.cash/protocol/nu5.pdf#notetypes
|
/// [notetypes]: https://zips.z.cash/protocol/nu5.pdf#notetypes
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub(super) fn derive(asset_idx: u64) -> Self {
|
pub(super) fn derive(ak: &SpendValidatingKey, assetDesc: &[u8; 64]) -> Self {
|
||||||
let hasher = pallas::Point::hash_to_curve(VALUE_COMMITMENT_PERSONALIZATION);
|
let mut s = vec![];
|
||||||
let V = hasher(&VALUE_COMMITMENT_V_BYTES);
|
|
||||||
|
|
||||||
let value = pallas::Scalar::from(asset_idx);
|
s.extend_from_slice(&ak.to_bytes());
|
||||||
|
s.extend_from_slice(assetDesc);
|
||||||
|
|
||||||
NoteType(extract_p(&(V * value)))
|
NoteType(assetID_hasher(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// note type for the "native" token (zec)
|
/// Note type for the "native" currency (zec), maintains backward compatibility with Orchard untyped notes.
|
||||||
|
#[allow(non_snake_case)]
|
||||||
pub fn native() -> Self {
|
pub fn native() -> Self {
|
||||||
Self::derive(1)
|
NoteType(assetID_hasher(VALUE_COMMITMENT_V_BYTES.to_vec()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue