mirror of https://github.com/zcash/orchard.git
append some logic with todo macro
This commit is contained in:
parent
7b80d7c92e
commit
e2016c47ab
|
@ -9,6 +9,7 @@ use nonempty::NonEmpty;
|
|||
use pasta_curves::pallas;
|
||||
use rand::{prelude::SliceRandom, CryptoRng, RngCore};
|
||||
|
||||
use crate::asset_type::AssetType;
|
||||
use crate::{
|
||||
action::Action,
|
||||
address::Address,
|
||||
|
@ -189,14 +190,21 @@ struct ActionInfo {
|
|||
spend: SpendInfo,
|
||||
output: RecipientInfo,
|
||||
rcv: ValueCommitTrapdoor,
|
||||
asset_type: AssetType,
|
||||
}
|
||||
|
||||
impl ActionInfo {
|
||||
fn new(spend: SpendInfo, output: RecipientInfo, rng: impl RngCore) -> Self {
|
||||
fn new(
|
||||
spend: SpendInfo,
|
||||
output: RecipientInfo,
|
||||
rng: impl RngCore,
|
||||
asset_type: AssetType,
|
||||
) -> Self {
|
||||
ActionInfo {
|
||||
spend,
|
||||
output,
|
||||
rcv: ValueCommitTrapdoor::random(rng),
|
||||
asset_type,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,7 +227,13 @@ impl ActionInfo {
|
|||
let alpha = pallas::Scalar::random(&mut rng);
|
||||
let rk = ak.randomize(&alpha);
|
||||
|
||||
let note = Note::new(self.output.recipient, self.output.value, nf_old, &mut rng);
|
||||
let note = Note::new(
|
||||
self.output.recipient,
|
||||
self.output.value,
|
||||
nf_old,
|
||||
&mut rng,
|
||||
self.asset_type,
|
||||
);
|
||||
let cm_new = note.commitment();
|
||||
let cmx = cm_new.into();
|
||||
|
||||
|
@ -416,7 +430,7 @@ impl Builder {
|
|||
self.spends
|
||||
.into_iter()
|
||||
.zip(self.recipients.into_iter())
|
||||
.map(|(spend, recipient)| ActionInfo::new(spend, recipient, &mut rng))
|
||||
.map(|(spend, recipient)| ActionInfo::new(spend, recipient, &mut rng, todo!()))
|
||||
.collect()
|
||||
};
|
||||
|
||||
|
@ -729,6 +743,8 @@ pub trait InputView<NoteRef> {
|
|||
fn note_id(&self) -> &NoteRef;
|
||||
/// The value of the input being spent.
|
||||
fn value<V: From<u64>>(&self) -> V;
|
||||
/// The asset type of the input being spent.
|
||||
fn asset_type(&self) -> AssetType;
|
||||
}
|
||||
|
||||
impl InputView<()> for SpendInfo {
|
||||
|
@ -737,6 +753,10 @@ impl InputView<()> for SpendInfo {
|
|||
&()
|
||||
}
|
||||
|
||||
fn asset_type(&self) -> AssetType {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn value<V: From<u64>>(&self) -> V {
|
||||
V::from(self.note.value().inner())
|
||||
}
|
||||
|
@ -747,12 +767,17 @@ impl InputView<()> for SpendInfo {
|
|||
pub trait OutputView {
|
||||
/// The value of the output being produced.
|
||||
fn value<V: From<u64>>(&self) -> V;
|
||||
/// The asset type of the output being produced.
|
||||
fn asset_type(&self) -> AssetType;
|
||||
}
|
||||
|
||||
impl OutputView for RecipientInfo {
|
||||
fn value<V: From<u64>>(&self) -> V {
|
||||
V::from(self.value.inner())
|
||||
}
|
||||
fn asset_type(&self) -> AssetType {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Generators for property testing.
|
||||
|
|
|
@ -29,6 +29,22 @@ pub(crate) const L_VALUE: usize = 64;
|
|||
/// SWU hash-to-curve personalization for the group hash for key diversification
|
||||
pub const KEY_DIVERSIFICATION_PERSONALIZATION: &str = "z.cash:Orchard-gd";
|
||||
|
||||
/// First 64 bytes of the BLAKE2s input during group hash.
|
||||
/// This is chosen to be some random string that we couldn't have anticipated when we designed
|
||||
/// the algorithm, for rigidity purposes.
|
||||
/// We deliberately use an ASCII hex string of 32 bytes here.
|
||||
pub const GH_FIRST_BLOCK: &[u8; 64] =
|
||||
b"096b36a5804bfacef1691e173c366a47ff5ba84a44f26ddd7e8d9f79d5b42df0";
|
||||
|
||||
/// Length in bytes of the asset identifier
|
||||
pub const ASSET_IDENTIFIER_LENGTH: usize = 32;
|
||||
|
||||
/// BLAKE2s Personalization for deriving asset identifier from asset name
|
||||
pub const ASSET_IDENTIFIER_PERSONALIZATION: &[u8; 8] = b"MASP__t_";
|
||||
|
||||
/// BLAKE2s Personalization for the value commitment generator for the value
|
||||
pub const VALUE_COMMITMENT_GENERATOR_PERSONALIZATION: &[u8; 8] = b"MASP__v_";
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ff::PrimeField;
|
||||
|
|
|
@ -1088,6 +1088,7 @@ mod tests {
|
|||
NoteValue::from_raw(tv.note_v),
|
||||
rho,
|
||||
RandomSeed::from_bytes(tv.note_rseed, &rho).unwrap(),
|
||||
todo!(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
|
22
src/note.rs
22
src/note.rs
|
@ -7,6 +7,7 @@ use rand::RngCore;
|
|||
use subtle::CtOption;
|
||||
|
||||
use crate::{
|
||||
asset_type::{self, AssetType},
|
||||
keys::{EphemeralSecretKey, FullViewingKey, Scope, SpendingKey},
|
||||
spec::{to_base, to_scalar, NonZeroPallasScalar, PrfExpand},
|
||||
value::NoteValue,
|
||||
|
@ -99,6 +100,8 @@ pub struct Note {
|
|||
rho: Nullifier,
|
||||
/// The seed randomness for various note components.
|
||||
rseed: RandomSeed,
|
||||
/// The asset type that the note represents
|
||||
asset_type: AssetType,
|
||||
}
|
||||
|
||||
impl PartialEq for Note {
|
||||
|
@ -131,12 +134,14 @@ impl Note {
|
|||
value: NoteValue,
|
||||
rho: Nullifier,
|
||||
rseed: RandomSeed,
|
||||
asset_type: AssetType,
|
||||
) -> CtOption<Self> {
|
||||
let note = Note {
|
||||
recipient,
|
||||
value,
|
||||
rho,
|
||||
rseed,
|
||||
asset_type,
|
||||
};
|
||||
CtOption::new(note, note.commitment_inner().is_some())
|
||||
}
|
||||
|
@ -151,9 +156,16 @@ impl Note {
|
|||
value: NoteValue,
|
||||
rho: Nullifier,
|
||||
mut rng: impl RngCore,
|
||||
asset_type: AssetType,
|
||||
) -> Self {
|
||||
loop {
|
||||
let note = Note::from_parts(recipient, value, rho, RandomSeed::random(&mut rng, &rho));
|
||||
let note = Note::from_parts(
|
||||
recipient,
|
||||
value,
|
||||
rho,
|
||||
RandomSeed::random(&mut rng, &rho),
|
||||
asset_type,
|
||||
);
|
||||
if note.is_some().into() {
|
||||
break note.unwrap();
|
||||
}
|
||||
|
@ -178,6 +190,7 @@ impl Note {
|
|||
NoteValue::zero(),
|
||||
rho.unwrap_or_else(|| Nullifier::dummy(rng)),
|
||||
rng,
|
||||
AssetType::new(b"dummy").unwrap(),
|
||||
);
|
||||
|
||||
(sk, fvk, note)
|
||||
|
@ -299,12 +312,7 @@ pub mod testing {
|
|||
rho in arb_nullifier(),
|
||||
rseed in arb_rseed(),
|
||||
) -> Note {
|
||||
Note {
|
||||
recipient,
|
||||
value,
|
||||
rho,
|
||||
rseed,
|
||||
}
|
||||
Note {recipient,value,rho,rseed, asset_type: todo!() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ use zcash_note_encryption::{
|
|||
|
||||
use crate::{
|
||||
action::Action,
|
||||
asset_type::AssetType,
|
||||
keys::{
|
||||
DiversifiedTransmissionKey, Diversifier, EphemeralPublicKey, EphemeralSecretKey,
|
||||
OutgoingViewingKey, PreparedEphemeralPublicKey, PreparedIncomingViewingKey, SharedSecret,
|
||||
|
@ -48,6 +49,8 @@ pub(crate) fn prf_ock_orchard(
|
|||
)
|
||||
}
|
||||
|
||||
//sapling_parse_note_plaintext_without_memoと比較
|
||||
// TODO:plaintext通りに並び替える。そもそもbit列の並びを知る
|
||||
fn orchard_parse_note_plaintext_without_memo<F>(
|
||||
domain: &OrchardDomain,
|
||||
plaintext: &[u8],
|
||||
|
@ -72,9 +75,13 @@ where
|
|||
))?;
|
||||
|
||||
let pk_d = get_pk_d(&diversifier);
|
||||
|
||||
//plaintext?
|
||||
let asset_type = AssetType::from_identifier(plaintext[20..52].try_into().unwrap())?;
|
||||
let recipient = Address::from_parts(diversifier, pk_d);
|
||||
let note = Option::from(Note::from_parts(recipient, value, domain.rho, rseed))?;
|
||||
//to.create_noteを参考にrecipient.create_noteを作りたい
|
||||
let note = Option::from(Note::from_parts(
|
||||
recipient, value, domain.rho, rseed, asset_type,
|
||||
))?;
|
||||
Some((note, recipient))
|
||||
}
|
||||
|
||||
|
@ -395,7 +402,8 @@ mod tests {
|
|||
assert_eq!(ock.as_ref(), tv.ock);
|
||||
|
||||
let recipient = Address::from_parts(d, pk_d);
|
||||
let note = Note::from_parts(recipient, value, rho, rseed).unwrap();
|
||||
|
||||
let note = Note::from_parts(recipient, value, rho, rseed, todo!()).unwrap();
|
||||
assert_eq!(ExtractedNoteCommitment::from(note.commitment()), cmx);
|
||||
|
||||
let action = Action::from_parts(
|
||||
|
|
|
@ -267,7 +267,7 @@ impl ValueCommitTrapdoor {
|
|||
|
||||
/// A commitment to a [`ValueSum`].
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ValueCommitment(pallas::Point);
|
||||
pub struct ValueCommitment(pub pallas::Point);
|
||||
|
||||
impl Add<&ValueCommitment> for ValueCommitment {
|
||||
type Output = ValueCommitment;
|
||||
|
|
Loading…
Reference in New Issue