-
Notifications
You must be signed in to change notification settings - Fork 0
V3 encryption #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V3 encryption #38
Changes from 67 commits
9dd7ff7
29c4f09
86abc31
ff25221
5486099
3ce74b2
5312b03
c48d354
1a1459a
7b6b6ac
ee069b4
fc5df36
80b2689
32b90f8
1f34308
ea8bcb2
5666246
577e920
2398891
569df61
3eb1614
f6da6a5
b2ba44b
1cf2a2c
f47c098
64407d2
914f4e9
9f30147
1ce300a
4721bdd
28e3cde
ffa4921
0660370
80892a6
0644aa8
6e0b3c1
abdbf8d
45c3e20
2ebea7f
769758d
6f329f8
8cced99
111be37
4c52098
0f6e301
82cd194
24bf883
e0bd981
cb72f10
8f02a5f
0f5c714
b1bf0a5
fc0c45a
6a54fea
0940e2b
7e7a15c
39e85e6
ffb8d1a
24a52f6
c4ab99c
d644384
55ce92f
baeb1cb
de6e87c
c6e048a
343120d
49a7775
bd8d553
365d4ef
35da288
8df5638
79b0744
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ use crate::{ | |
| SpendingKey, | ||
| }, | ||
| note::{Note, TransmittedNoteCiphertext}, | ||
| note_encryption::OrchardNoteEncryption, | ||
| note_encryption_v3::OrchardNoteEncryption, | ||
| primitives::redpallas::{self, Binding, SpendAuth}, | ||
| tree::{Anchor, MerklePath}, | ||
| value::{self, NoteValue, OverflowError, ValueCommitTrapdoor, ValueCommitment, ValueSum}, | ||
|
|
@@ -79,15 +79,20 @@ impl SpendInfo { | |
| /// Returns `None` if the `fvk` does not own the `note`. | ||
| /// | ||
| /// [`Builder::add_spend`]: Builder::add_spend | ||
| pub fn new(fvk: FullViewingKey, note: Note, merkle_path: MerklePath) -> Option<Self> { | ||
| pub fn new( | ||
| fvk: FullViewingKey, | ||
| note: Note, | ||
| merkle_path: MerklePath, | ||
| split_flag: bool, | ||
| ) -> Option<Self> { | ||
| let scope = fvk.scope_for_address(¬e.recipient())?; | ||
| Some(SpendInfo { | ||
| dummy_sk: None, | ||
| fvk, | ||
| scope, | ||
| note, | ||
| merkle_path, | ||
| split_flag: false, | ||
| split_flag, | ||
| }) | ||
| } | ||
|
|
||
|
|
@@ -112,10 +117,7 @@ impl SpendInfo { | |
|
|
||
| /// Return a copy of this note with the split flag set to `true`. | ||
| fn create_split_spend(&self) -> Self { | ||
| let mut split_spend = SpendInfo::new(self.fvk.clone(), self.note, self.merkle_path.clone()) | ||
| .expect("The spend info is valid"); | ||
| split_spend.split_flag = true; | ||
| split_spend | ||
| SpendInfo::new(self.fvk.clone(), self.note, self.merkle_path.clone(), true).unwrap() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we prefer unwrap over expect with comment?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only when the |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -224,7 +226,7 @@ impl ActionInfo { | |
|
|
||
| let encrypted_note = TransmittedNoteCiphertext { | ||
| epk_bytes: encryptor.epk().to_bytes().0, | ||
| enc_ciphertext: encryptor.encrypt_note_plaintext(), | ||
| enc_ciphertext: encryptor.encrypt_note_plaintext().0, | ||
| out_ciphertext: encryptor.encrypt_outgoing_plaintext(&cv_net, &cmx, &mut rng), | ||
| }; | ||
|
|
||
|
|
@@ -278,7 +280,7 @@ impl Builder { | |
| /// Returns an error if the given Merkle path does not have the required anchor for | ||
| /// the given note. | ||
| /// | ||
| /// [`OrchardDomain`]: crate::note_encryption::OrchardDomain | ||
| /// [`OrchardDomain`]: crate::note_encryption_v3::OrchardDomainV3 | ||
| /// [`MerkleHashOrchard`]: crate::tree::MerkleHashOrchard | ||
| pub fn add_spend( | ||
| &mut self, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ use crate::issuance::{IssueAuth, IssueBundle, Signed}; | |
|
|
||
| const ZCASH_ORCHARD_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrchardHash"; | ||
| const ZCASH_ORCHARD_ACTIONS_COMPACT_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrcActCHash"; | ||
| const ZCASH_ORCHARD_ACTIONS_ASSETID_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrcActAHash"; | ||
|
PaulLaux marked this conversation as resolved.
Outdated
|
||
| const ZCASH_ORCHARD_ACTIONS_MEMOS_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrcActMHash"; | ||
| const ZCASH_ORCHARD_ACTIONS_NONCOMPACT_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxIdOrcActNHash"; | ||
| const ZCASH_ORCHARD_SIGS_HASH_PERSONALIZATION: &[u8; 16] = b"ZTxAuthOrchaHash"; | ||
|
|
@@ -42,13 +43,13 @@ pub(crate) fn hash_bundle_txid_data<A: Authorization, V: Copy + Into<i64>>( | |
| ch.update(&action.nullifier().to_bytes()); | ||
| ch.update(&action.cmx().to_bytes()); | ||
| ch.update(&action.encrypted_note().epk_bytes); | ||
| ch.update(&action.encrypted_note().enc_ciphertext[..52]); | ||
| ch.update(&action.encrypted_note().enc_ciphertext[..84]); // TODO: make sure it is backward compatible with [..52] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it is if I understand correctly. Shall we maybe select proper hasher here based on value of EncCipherText enum? This way we can hash both V2 and V3
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, for sure. Our final aim should be to replace all hardcoded numbers with the relevant constants. But right now, I'm focusing on creating a simple delta to highlight the changes. |
||
|
|
||
| mh.update(&action.encrypted_note().enc_ciphertext[52..564]); | ||
| mh.update(&action.encrypted_note().enc_ciphertext[84..596]); | ||
|
|
||
| nh.update(&action.cv_net().to_bytes()); | ||
| nh.update(&<[u8; 32]>::from(action.rk())); | ||
| nh.update(&action.encrypted_note().enc_ciphertext[564..]); | ||
| nh.update(&action.encrypted_note().enc_ciphertext[596..]); | ||
| nh.update(&action.encrypted_note().out_ciphertext); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1025,7 +1025,8 @@ mod tests { | |
| pub mod testing { | ||
| use crate::issuance::{IssueAction, IssueBundle, Prepared, Signed, Unauthorized}; | ||
| use crate::keys::testing::{arb_issuance_authorizing_key, arb_issuance_validating_key}; | ||
| use crate::note::testing::arb_zsa_note; | ||
| use crate::note::testing::arb_note; | ||
| use crate::value::NoteValue; | ||
| use proptest::collection::vec; | ||
| use proptest::prelude::*; | ||
| use proptest::prop_compose; | ||
|
|
@@ -1035,7 +1036,7 @@ pub mod testing { | |
| prop_compose! { | ||
| /// Generate an issue action given note value | ||
| pub fn arb_issue_action()( | ||
| note in arb_zsa_note(), | ||
| note in arb_note(NoteValue::from_raw(10)), | ||
| asset_descr in string_regex(".{1,512}").unwrap() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is from a previous merge, but is it not that
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, fixed it. |
||
| ) -> IssueAction { | ||
| IssueAction::new(asset_descr, ¬e) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded constants make me sad, but that's consistent with current style so probably this is more of a general comment rather than a suggestion