Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
9dd7ff7
Circleci project setup (#1)
PaulLaux Mar 30, 2022
29c4f09
issuer keys implementation (#5)
daniben31 Jun 14, 2022
86abc31
Added NoteType to Notes (#2)
PaulLaux Jun 14, 2022
ff25221
ZSA note encryption in Orchard crate (#3)
naure Jul 20, 2022
5486099
Zsa builder (#4)
PaulLaux Sep 19, 2022
3ce74b2
Issuance (#12)
PaulLaux Sep 29, 2022
5312b03
E2E tests for issuance (#20)
alexeykoren Oct 20, 2022
c48d354
disabled split notes (#22)
PaulLaux Oct 20, 2022
1a1459a
Review fixes (#23)
PaulLaux Oct 26, 2022
7b6b6ac
Review fixes2 (#24)
PaulLaux Oct 27, 2022
ee069b4
verify_issue_bundle() cleanup (#25)
PaulLaux Oct 28, 2022
fc5df36
updating Cargo.toml to point to appropriate librustzcash patch
vivek-arte Oct 10, 2022
80b2689
orchard crate updated to build with updated librustzcash - tests stil…
vivek-arte Oct 30, 2022
32b90f8
edits to test sections
vivek-arte Nov 4, 2022
1f34308
changes based on reviewed changes in zcash_note_encryption
vivek-arte Nov 24, 2022
ea8bcb2
adding zcash_note_encryption to orchard crate for better parallel upd…
vivek-arte Nov 26, 2022
5666246
using ? operator in place of match
vivek-arte Nov 26, 2022
577e920
removing duplicate AEAD_TAG_SIZE definition
vivek-arte Nov 26, 2022
2398891
fixing clippy errors
vivek-arte Nov 26, 2022
569df61
refactoring names of NotePlaintext, EncNoteCiphertext, and versions t…
vivek-arte Nov 26, 2022
3eb1614
refactoring to rename ZSA-specific constants as '.._ZSA'
vivek-arte Nov 26, 2022
f6da6a5
fixing tests to work with V3 notes, plus rust-fmt
vivek-arte Dec 6, 2022
b2ba44b
updating to use &CompactNote instead of &[u8]
vivek-arte Dec 6, 2022
1cf2a2c
updating Rust to 1.61.0 to pass Clippy tests
vivek-arte Dec 6, 2022
f47c098
further Rustfmt fixes
vivek-arte Dec 6, 2022
64407d2
fixing Clippy error
vivek-arte Dec 6, 2022
914f4e9
updating the bundle commitments to include asset ID personalization
vivek-arte Dec 6, 2022
9f30147
fixing Rustfmt errors
vivek-arte Dec 6, 2022
1ce300a
updated names for constants
PaulLaux Dec 19, 2022
4721bdd
updated naming
PaulLaux Dec 20, 2022
28e3cde
added Bytes(v1)
PaulLaux Dec 21, 2022
ffa4921
minor update
PaulLaux Dec 21, 2022
0660370
removed From<(Self::NotePlaintextBytes, AEADBytes)>
PaulLaux Dec 21, 2022
80892a6
better slice handling
PaulLaux Dec 22, 2022
0644aa8
removed AEADTAG data struct
PaulLaux Dec 22, 2022
6e0b3c1
improved code
PaulLaux Dec 25, 2022
abdbf8d
removed split_tag
PaulLaux Dec 25, 2022
45c3e20
chaged from_byte to from_vec #1
PaulLaux Dec 25, 2022
2ebea7f
chaged from_byte to from_vec #2
PaulLaux Dec 25, 2022
769758d
chaged from_byte to from_vec #3
PaulLaux Dec 25, 2022
6f329f8
removed AsMut
PaulLaux Dec 25, 2022
8cced99
removed AsMut #2
PaulLaux Dec 25, 2022
111be37
changed style for From
PaulLaux Dec 26, 2022
4c52098
changed style for From #2
PaulLaux Dec 26, 2022
0f6e301
changed AsRef to AsMut
PaulLaux Dec 26, 2022
82cd194
changed AsRef to AsMut #2
PaulLaux Dec 26, 2022
24bf883
added extract_tag()
PaulLaux Dec 26, 2022
e0bd981
reverted to original v2 note encryption, modified to support the new …
PaulLaux Dec 28, 2022
cb72f10
minor cleanup
PaulLaux Dec 28, 2022
8f02a5f
Merge branch 'zsa1' into v3_encryption
PaulLaux Dec 28, 2022
0f5c714
cleanup
PaulLaux Dec 28, 2022
b1bf0a5
added encoding test to note_encryption v2
PaulLaux Jan 3, 2023
fc0c45a
cleanup
PaulLaux Jan 3, 2023
6a54fea
clippy fixes
PaulLaux Jan 3, 2023
0940e2b
clippy fixes 2
PaulLaux Jan 3, 2023
7e7a15c
replaced DynamicUsage
PaulLaux Jan 3, 2023
39e85e6
renamed OrchardDomain to OrchardDomainV2
PaulLaux Jan 3, 2023
ffb8d1a
added note_encryption_v2v3.rs
PaulLaux Jan 8, 2023
24a52f6
updated note_encryption_v3
PaulLaux Jan 10, 2023
c4ab99c
adjusted types
PaulLaux Jan 12, 2023
d644384
updated domain to V3
PaulLaux Jan 22, 2023
55ce92f
updated bundle commitmennt
PaulLaux Jan 22, 2023
baeb1cb
removed local zcash_note_encryption and cleanup
PaulLaux Jan 23, 2023
de6e87c
fixed comment
PaulLaux Jan 23, 2023
c6e048a
Merge branch 'zsa1' into v3_encryption
PaulLaux Jan 23, 2023
343120d
updated cargo.toml
PaulLaux Jan 23, 2023
49a7775
updated dep
PaulLaux Jan 24, 2023
bd8d553
review fixes1
PaulLaux Jan 31, 2023
365d4ef
review fixes2
PaulLaux Jan 31, 2023
35da288
minor fix
PaulLaux Jan 31, 2023
8df5638
updeted dep
PaulLaux Jan 31, 2023
79b0744
updeted dep
PaulLaux Jan 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ debug = true

[profile.bench]
debug = true

[patch.crates-io]
zcash_note_encryption = { git = "https://github.com/QED-it/librustzcash.git", rev = "07c377ddedf71ab7c7a266d284b054a2dafc2ed4" }
8 changes: 4 additions & 4 deletions benches/note_decryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use orchard::{
circuit::ProvingKey,
keys::{FullViewingKey, PreparedIncomingViewingKey, Scope, SpendingKey},
note::AssetId,
note_encryption::{CompactAction, OrchardDomain},
note_encryption_v3::{CompactAction, OrchardDomainV3},
value::NoteValue,
Anchor, Bundle,
};
Expand Down Expand Up @@ -79,7 +79,7 @@ fn bench_note_decryption(c: &mut Criterion) {
};
let action = bundle.actions().first();

let domain = OrchardDomain::for_action(action);
let domain = OrchardDomainV3::for_action(action);

let compact = {
let mut group = c.benchmark_group("note-decryption");
Expand Down Expand Up @@ -120,12 +120,12 @@ fn bench_note_decryption(c: &mut Criterion) {
let ivks = 2;
let valid_ivks = vec![valid_ivk; ivks];
let actions: Vec<_> = (0..100)
.map(|_| (OrchardDomain::for_action(action), action.clone()))
.map(|_| (OrchardDomainV3::for_action(action), action.clone()))
.collect();
let compact: Vec<_> = (0..100)
.map(|_| {
(
OrchardDomain::for_action(action),
OrchardDomainV3::for_action(action),
CompactAction::from(action),
)
})
Expand Down
4 changes: 2 additions & 2 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub(crate) mod testing {
// FIXME: make a real one from the note.
let encrypted_note = TransmittedNoteCiphertext {
epk_bytes: [0u8; 32],
enc_ciphertext: [0u8; 580],
enc_ciphertext: [0u8; 612],

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

out_ciphertext: [0u8; 80]
};
Action {
Expand Down Expand Up @@ -192,7 +192,7 @@ pub(crate) mod testing {
// FIXME: make a real one from the note.
let encrypted_note = TransmittedNoteCiphertext {
epk_bytes: [0u8; 32],
enc_ciphertext: [0u8; 580],
enc_ciphertext: [0u8; 612],
out_ciphertext: [0u8; 80]
};

Expand Down
20 changes: 11 additions & 9 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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(&note.recipient())?;
Some(SpendInfo {
dummy_sk: None,
fvk,
scope,
note,
merkle_path,
split_flag: false,
split_flag,
})
}

Expand All @@ -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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we prefer unwrap over expect with comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only when the expect() comment is trivial.

}
}

Expand Down Expand Up @@ -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),
};

Expand Down Expand Up @@ -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,
Expand Down
18 changes: 11 additions & 7 deletions src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
circuit::{Instance, Proof, VerifyingKey},
keys::{IncomingViewingKey, OutgoingViewingKey, PreparedIncomingViewingKey},
note::Note,
note_encryption::OrchardDomain,
note_encryption_v3::OrchardDomainV3,
primitives::redpallas::{self, Binding, SpendAuth},
tree::Anchor,
value::{ValueCommitTrapdoor, ValueCommitment, ValueSum},
Expand Down Expand Up @@ -305,7 +305,7 @@ impl<T: Authorization, V> Bundle<T, V> {
.iter()
.enumerate()
.filter_map(|(idx, action)| {
let domain = OrchardDomain::for_action(action);
let domain = OrchardDomainV3::for_action(action);
prepared_keys.iter().find_map(|(ivk, prepared_ivk)| {
try_note_decryption(&domain, prepared_ivk, action)
.map(|(n, a, m)| (idx, (*ivk).clone(), n, a, m))
Expand All @@ -324,7 +324,7 @@ impl<T: Authorization, V> Bundle<T, V> {
) -> Option<(Note, Address, [u8; 512])> {
let prepared_ivk = PreparedIncomingViewingKey::new(key);
self.actions.get(action_idx).and_then(move |action| {
let domain = OrchardDomain::for_action(action);
let domain = OrchardDomainV3::for_action(action);
try_note_decryption(&domain, &prepared_ivk, action)
})
}
Expand All @@ -341,7 +341,7 @@ impl<T: Authorization, V> Bundle<T, V> {
.iter()
.enumerate()
.filter_map(|(idx, action)| {
let domain = OrchardDomain::for_action(action);
let domain = OrchardDomainV3::for_action(action);
keys.iter().find_map(move |key| {
try_output_recovery_with_ovk(
&domain,
Expand All @@ -365,7 +365,7 @@ impl<T: Authorization, V> Bundle<T, V> {
key: &OutgoingViewingKey,
) -> Option<(Note, Address, [u8; 512])> {
self.actions.get(action_idx).and_then(move |action| {
let domain = OrchardDomain::for_action(action);
let domain = OrchardDomainV3::for_action(action);
try_output_recovery_with_ovk(
&domain,
key,
Expand Down Expand Up @@ -527,7 +527,7 @@ pub mod testing {
use super::{Action, Authorization, Authorized, Bundle, Flags};

pub use crate::action::testing::{arb_action, arb_unauthorized_action};
use crate::note::asset_id::testing::zsa_asset_id;
use crate::note::asset_id::testing::arb_zsa_asset_id;
use crate::note::AssetId;
use crate::value::testing::arb_value_sum;

Expand Down Expand Up @@ -591,7 +591,11 @@ pub mod testing {

prop_compose! {
/// Create an arbitrary vector of assets to burn.
pub fn arb_asset_to_burn()(asset_id in zsa_asset_id(), value in arb_value_sum()) -> (AssetId, ValueSum) {
pub fn arb_asset_to_burn()
(
asset_id in arb_zsa_asset_id(),
value in arb_value_sum()
) -> (AssetId, ValueSum) {
(asset_id, value)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/bundle/commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,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 Orchard [..52]

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);
}

Expand Down
38 changes: 18 additions & 20 deletions src/issuance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl IssueBundle<Signed> {
/// * Asset description size is collect.
/// * `AssetId` for the `IssueAction` has not been previously finalized.
/// * For each `Note` inside an `IssueAction`:
/// * All notes have the same, correct `NoteType`.
/// * All notes have the same, correct `AssetId`.
pub fn verify_issue_bundle(
bundle: &IssueBundle<Signed>,
sighash: [u8; 32],
Expand All @@ -356,7 +356,6 @@ pub fn verify_issue_bundle(

let s = &mut HashSet::<AssetId>::new();

// An IssueAction could have just one properly derived AssetId.
let newly_finalized = bundle
.actions()
.iter()
Expand All @@ -373,7 +372,7 @@ pub fn verify_issue_bundle(
return Err(IssueActionPreviouslyFinalizedNoteType(asset));
}

// Add to finalization set, if needed.
// Add to the finalization set, if needed.
if action.is_finalized() {
newly_finalized.insert(asset);
}
Expand Down Expand Up @@ -1025,30 +1024,31 @@ 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::asset_id::testing::zsa_asset_id;
use crate::note::testing::arb_zsa_note;
use proptest::collection::vec;
use proptest::prelude::*;
use proptest::prop_compose;
use proptest::string::string_regex;
use rand::{rngs::StdRng, SeedableRng};

prop_compose! {
/// Generate an issue action given note value
pub fn arb_issue_action()(
note in arb_zsa_note(),
asset_descr in string_regex(".{1,512}").unwrap()
) -> IssueAction {
IssueAction::new(asset_descr, &note)
/// Generate an issue action
pub fn arb_issue_action(asset_desc: String)
(
asset in zsa_asset_id(asset_desc.clone()),
)
(
note in arb_zsa_note(asset),
)-> IssueAction {
IssueAction::new(asset_desc.clone(), &note)
}
}

prop_compose! {
/// Generate an arbitrary issue bundle with fake authorization data. This bundle does not
/// necessarily respect consensus rules; for that use
/// [`crate::builder::testing::arb_issue_bundle`]
/// Generate an arbitrary issue bundle with fake authorization data.
pub fn arb_unathorized_issue_bundle(n_actions: usize)
(
actions in vec(arb_issue_action(), n_actions),
actions in vec(arb_issue_action("asset_desc".to_string()), n_actions),
ik in arb_issuance_validating_key()
) -> IssueBundle<Unauthorized> {
IssueBundle {
Expand All @@ -1061,11 +1061,10 @@ pub mod testing {

prop_compose! {
/// Generate an arbitrary issue bundle with fake authorization data. This bundle does not
/// necessarily respect consensus rules; for that use
/// [`crate::builder::testing::arb_issue_bundle`]
/// necessarily respect consensus rules
pub fn arb_prepared_issue_bundle(n_actions: usize)
(
actions in vec(arb_issue_action(), n_actions),
actions in vec(arb_issue_action("asset_desc".to_string()), n_actions),
ik in arb_issuance_validating_key(),
fake_sighash in prop::array::uniform32(prop::num::u8::ANY)
) -> IssueBundle<Prepared> {
Expand All @@ -1079,11 +1078,10 @@ pub mod testing {

prop_compose! {
/// Generate an arbitrary issue bundle with fake authorization data. This bundle does not
/// necessarily respect consensus rules; for that use
/// [`crate::builder::testing::arb_issue_bundle`]
/// necessarily respect consensus rules
pub fn arb_signed_issue_bundle(n_actions: usize)
(
actions in vec(arb_issue_action(), n_actions),
actions in vec(arb_issue_action("asset_desc".to_string()), n_actions),
ik in arb_issuance_validating_key(),
isk in arb_issuance_authorizing_key(),
rng_seed in prop::array::uniform32(prop::num::u8::ANY),
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ mod constants;
pub mod issuance;
pub mod keys;
pub mod note;
pub mod note_encryption;
// pub mod note_encryption; // disabled until backward compatability is implemented.
pub mod note_encryption_v3;
pub mod primitives;
mod spec;
pub mod tree;
Expand Down
27 changes: 22 additions & 5 deletions src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ pub struct TransmittedNoteCiphertext {
/// The serialization of the ephemeral public key
pub epk_bytes: [u8; 32],
/// The encrypted note ciphertext
pub enc_ciphertext: [u8; 580],
pub enc_ciphertext: [u8; 612],
/// An encrypted value that allows the holder of the outgoing cipher
/// key for the note to recover the note plaintext.
pub out_ciphertext: [u8; 80],
Expand All @@ -302,7 +302,7 @@ pub mod testing {
use proptest::prelude::*;

use crate::note::asset_id::testing::arb_asset_id;
use crate::note::asset_id::testing::zsa_asset_id;
use crate::note::AssetId;
use crate::value::testing::arb_note_value;
use crate::{
address::testing::arb_address, note::nullifier::testing::arb_nullifier, value::NoteValue,
Expand Down Expand Up @@ -336,13 +336,30 @@ pub mod testing {
}

prop_compose! {
/// Generate an arbitrary ZSA note
pub fn arb_zsa_note()(
/// Generate an arbitrary native note
pub fn arb_native_note()(
recipient in arb_address(),
value in arb_note_value(),
rho in arb_nullifier(),
rseed in arb_rseed(),
) -> Note {
Note {
recipient,
value,
asset: AssetId::native(),
rho,
rseed,
}
}
}

prop_compose! {
/// Generate an arbitrary zsa note
pub fn arb_zsa_note(asset: AssetId)(
recipient in arb_address(),
value in arb_note_value(),
rho in arb_nullifier(),
rseed in arb_rseed(),
asset in zsa_asset_id(),
) -> Note {
Note {
recipient,
Expand Down
15 changes: 13 additions & 2 deletions src/note/asset_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ pub mod testing {
}

prop_compose! {
/// Generate the ZSA note type
pub fn zsa_asset_id()(
/// Generate an asset ID
pub fn arb_zsa_asset_id()(
sk in arb_spending_key(),
str in "[A-Za-z]{255}"
) -> AssetId {
Expand All @@ -130,6 +130,17 @@ pub mod testing {
}
}

prop_compose! {
/// Generate an asset ID using a specific description
pub fn zsa_asset_id(asset_desc: String)(
sk in arb_spending_key(),
) -> AssetId {
assert!(super::is_asset_desc_of_valid_size(&asset_desc));
let isk = IssuanceAuthorizingKey::from(&sk);
AssetId::derive(&IssuanceValidatingKey::from(&isk), &asset_desc)
}
}

#[test]
fn test_vectors() {
let test_vectors = crate::test_vectors::asset_id::test_vectors();
Expand Down
Loading