-
Notifications
You must be signed in to change notification settings - Fork 0
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
OrchardZSA backward compatability #100
Changes from all commits
8bee528
5f78e72
5221c29
e07fab9
ee0a07d
8d2d130
b177325
4900519
0a3d231
f3ae948
fc64461
c6f8936
ce46de0
e5ab5d0
a8dadc9
a8a72c2
120b090
5d5bbf1
97f55f9
90512c8
416b496
a1e6cd6
8b28a0e
fc20a5a
1d68e0b
c820dae
088494a
46a222e
367c701
dc97b7a
cc99400
e2306e3
d721463
6ba0a38
19dbd0a
b6d577e
8795ca4
58e05b1
e67c792
a9af64c
69dfd4a
c374534
95d53e3
5ca986f
465a6aa
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 |
---|---|---|
|
@@ -4,3 +4,5 @@ Cargo.lock | |
.vscode | ||
.idea | ||
action-circuit-layout.png | ||
*.[0-9] | ||
*.[0-9][0-9] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ use orchard::{ | |
bundle::Flags, | ||
circuit::{ProvingKey, VerifyingKey}, | ||
keys::{FullViewingKey, Scope, SpendingKey}, | ||
orchard_flavors::OrchardZSA, | ||
value::NoteValue, | ||
Anchor, Bundle, | ||
}; | ||
|
@@ -23,8 +24,9 @@ fn criterion_benchmark(c: &mut Criterion) { | |
let sk = SpendingKey::from_bytes([7; 32]).unwrap(); | ||
let recipient = FullViewingKey::from(&sk).address_at(0u32, Scope::External); | ||
|
||
let vk = VerifyingKey::build(); | ||
let pk = ProvingKey::build(); | ||
// FIXME: consider adding test for OrchardVanilla as well | ||
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. From @PaulLaux: 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. Done (we have created a new task). |
||
let vk = VerifyingKey::build::<OrchardZSA>(); | ||
let pk = ProvingKey::build::<OrchardZSA>(); | ||
|
||
let create_bundle = |num_recipients| { | ||
let mut builder = Builder::new( | ||
|
@@ -42,7 +44,7 @@ fn criterion_benchmark(c: &mut Criterion) { | |
) | ||
.unwrap(); | ||
} | ||
let bundle: Bundle<_, i64> = builder.build(rng).unwrap(); | ||
let bundle: Bundle<_, i64, OrchardZSA> = builder.build(rng).unwrap(); | ||
|
||
let instances: Vec<_> = bundle | ||
.actions() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ use memuse::DynamicUsage; | |
|
||
use crate::{ | ||
note::{ExtractedNoteCommitment, Nullifier, TransmittedNoteCiphertext}, | ||
note_encryption::OrchardDomain, | ||
primitives::redpallas::{self, SpendAuth}, | ||
value::ValueCommitment, | ||
}; | ||
|
@@ -15,30 +16,30 @@ use crate::{ | |
/// Internally, this may both consume a note and create a note, or it may do only one of | ||
/// the two. TODO: Determine which is more efficient (circuit size vs bundle size). | ||
#[derive(Debug, Clone)] | ||
pub struct Action<A> { | ||
pub struct Action<A, D: OrchardDomain> { | ||
/// The nullifier of the note being spent. | ||
nf: Nullifier, | ||
/// The randomized verification key for the note being spent. | ||
rk: redpallas::VerificationKey<SpendAuth>, | ||
/// A commitment to the new note being created. | ||
cmx: ExtractedNoteCommitment, | ||
/// The transmitted note ciphertext. | ||
encrypted_note: TransmittedNoteCiphertext, | ||
encrypted_note: TransmittedNoteCiphertext<D>, | ||
/// A commitment to the net value created or consumed by this action. | ||
cv_net: ValueCommitment, | ||
/// The authorization for this action. | ||
authorization: A, | ||
} | ||
|
||
impl<T> Action<T> { | ||
impl<A, D: OrchardDomain> Action<A, D> { | ||
/// Constructs an `Action` from its constituent parts. | ||
pub fn from_parts( | ||
nf: Nullifier, | ||
rk: redpallas::VerificationKey<SpendAuth>, | ||
cmx: ExtractedNoteCommitment, | ||
encrypted_note: TransmittedNoteCiphertext, | ||
encrypted_note: TransmittedNoteCiphertext<D>, | ||
cv_net: ValueCommitment, | ||
authorization: T, | ||
authorization: A, | ||
) -> Self { | ||
Action { | ||
nf, | ||
|
@@ -66,7 +67,7 @@ impl<T> Action<T> { | |
} | ||
|
||
/// Returns the encrypted note ciphertext. | ||
pub fn encrypted_note(&self) -> &TransmittedNoteCiphertext { | ||
pub fn encrypted_note(&self) -> &TransmittedNoteCiphertext<D> { | ||
&self.encrypted_note | ||
} | ||
|
||
|
@@ -76,12 +77,12 @@ impl<T> Action<T> { | |
} | ||
|
||
/// Returns the authorization for this action. | ||
pub fn authorization(&self) -> &T { | ||
pub fn authorization(&self) -> &A { | ||
&self.authorization | ||
} | ||
|
||
/// Transitions this action from one authorization state to another. | ||
pub fn map<U>(self, step: impl FnOnce(T) -> U) -> Action<U> { | ||
pub fn map<U>(self, step: impl FnOnce(A) -> U) -> Action<U, D> { | ||
Action { | ||
nf: self.nf, | ||
rk: self.rk, | ||
|
@@ -93,7 +94,7 @@ impl<T> Action<T> { | |
} | ||
|
||
/// Transitions this action from one authorization state to another. | ||
pub fn try_map<U, E>(self, step: impl FnOnce(T) -> Result<U, E>) -> Result<Action<U>, E> { | ||
pub fn try_map<U, E>(self, step: impl FnOnce(A) -> Result<U, E>) -> Result<Action<U, D>, E> { | ||
Ok(Action { | ||
nf: self.nf, | ||
rk: self.rk, | ||
|
@@ -105,7 +106,7 @@ impl<T> Action<T> { | |
} | ||
} | ||
|
||
impl DynamicUsage for Action<redpallas::Signature<SpendAuth>> { | ||
impl<D: OrchardDomain> DynamicUsage for Action<redpallas::Signature<SpendAuth>, D> { | ||
#[inline(always)] | ||
fn dynamic_usage(&self) -> usize { | ||
0 | ||
|
@@ -132,6 +133,7 @@ pub(crate) mod testing { | |
commitment::ExtractedNoteCommitment, nullifier::testing::arb_nullifier, | ||
testing::arb_note, TransmittedNoteCiphertext, | ||
}, | ||
note_encryption::OrchardDomain, | ||
primitives::redpallas::{ | ||
self, | ||
testing::{arb_spendauth_signing_key, arb_spendauth_verification_key}, | ||
|
@@ -141,70 +143,82 @@ pub(crate) mod testing { | |
|
||
use super::Action; | ||
|
||
prop_compose! { | ||
/// Generate an action without authorization data. | ||
pub fn arb_unauthorized_action(spend_value: NoteValue, output_value: NoteValue)( | ||
nf in arb_nullifier(), | ||
rk in arb_spendauth_verification_key(), | ||
note in arb_note(output_value), | ||
asset in arb_asset_base() | ||
) -> Action<()> { | ||
let cmx = ExtractedNoteCommitment::from(note.commitment()); | ||
let cv_net = ValueCommitment::derive( | ||
spend_value - output_value, | ||
ValueCommitTrapdoor::zero(), | ||
asset | ||
); | ||
// FIXME: make a real one from the note. | ||
let encrypted_note = TransmittedNoteCiphertext { | ||
epk_bytes: [0u8; 32], | ||
enc_ciphertext: [0u8; 612], | ||
out_ciphertext: [0u8; 80] | ||
}; | ||
Action { | ||
nf, | ||
rk, | ||
cmx, | ||
encrypted_note, | ||
cv_net, | ||
authorization: () | ||
/// `ActionArb` serves as a utility structure in property-based testing, designed specifically to adapt | ||
/// `arb_...` functions for compatibility with both variations of the Orchard protocol: Vanilla and ZSA. | ||
/// This adaptation is necessary due to the proptest crate's limitation, which prevents the direct | ||
/// transformation of `arb_...` functions into generic forms suitable for testing different protocol | ||
/// flavors. | ||
#[derive(Debug)] | ||
pub struct ActionArb<D: OrchardDomain> { | ||
phantom: std::marker::PhantomData<D>, | ||
} | ||
|
||
impl<D: OrchardDomain> ActionArb<D> { | ||
prop_compose! { | ||
/// Generate an action without authorization data. | ||
pub fn arb_unauthorized_action(spend_value: NoteValue, output_value: NoteValue)( | ||
nf in arb_nullifier(), | ||
rk in arb_spendauth_verification_key(), | ||
note in arb_note(output_value), | ||
asset in arb_asset_base() | ||
) -> Action<(), D> { | ||
let cmx = ExtractedNoteCommitment::from(note.commitment()); | ||
let cv_net = ValueCommitment::derive( | ||
spend_value - output_value, | ||
ValueCommitTrapdoor::zero(), | ||
asset | ||
); | ||
// FIXME: make a real one from the note. | ||
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. From @PaulLaux: 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. Done. |
||
let encrypted_note = TransmittedNoteCiphertext::<D> { | ||
epk_bytes: [0u8; 32], | ||
enc_ciphertext: D::NoteCiphertextBytes::from(vec![0u8; D::ENC_CIPHERTEXT_SIZE].as_ref()), | ||
out_ciphertext: [0u8; 80] | ||
}; | ||
Action { | ||
nf, | ||
rk, | ||
cmx, | ||
encrypted_note, | ||
cv_net, | ||
authorization: () | ||
} | ||
} | ||
} | ||
} | ||
|
||
prop_compose! { | ||
/// Generate an action with invalid (random) authorization data. | ||
pub fn arb_action(spend_value: NoteValue, output_value: NoteValue)( | ||
nf in arb_nullifier(), | ||
sk in arb_spendauth_signing_key(), | ||
note in arb_note(output_value), | ||
rng_seed in prop::array::uniform32(prop::num::u8::ANY), | ||
fake_sighash in prop::array::uniform32(prop::num::u8::ANY), | ||
asset in arb_asset_base() | ||
) -> Action<redpallas::Signature<SpendAuth>> { | ||
let cmx = ExtractedNoteCommitment::from(note.commitment()); | ||
let cv_net = ValueCommitment::derive( | ||
spend_value - output_value, | ||
ValueCommitTrapdoor::zero(), | ||
asset | ||
); | ||
|
||
// FIXME: make a real one from the note. | ||
let encrypted_note = TransmittedNoteCiphertext { | ||
epk_bytes: [0u8; 32], | ||
enc_ciphertext: [0u8; 612], | ||
out_ciphertext: [0u8; 80] | ||
}; | ||
|
||
let rng = StdRng::from_seed(rng_seed); | ||
|
||
Action { | ||
nf, | ||
rk: redpallas::VerificationKey::from(&sk), | ||
cmx, | ||
encrypted_note, | ||
cv_net, | ||
authorization: sk.sign(rng, &fake_sighash), | ||
prop_compose! { | ||
/// Generate an action with invalid (random) authorization data. | ||
pub fn arb_action(spend_value: NoteValue, output_value: NoteValue)( | ||
nf in arb_nullifier(), | ||
sk in arb_spendauth_signing_key(), | ||
note in arb_note(output_value), | ||
rng_seed in prop::array::uniform32(prop::num::u8::ANY), | ||
fake_sighash in prop::array::uniform32(prop::num::u8::ANY), | ||
asset in arb_asset_base() | ||
) -> Action<redpallas::Signature<SpendAuth>, D> { | ||
let cmx = ExtractedNoteCommitment::from(note.commitment()); | ||
let cv_net = ValueCommitment::derive( | ||
spend_value - output_value, | ||
ValueCommitTrapdoor::zero(), | ||
asset | ||
); | ||
|
||
// FIXME: make a real one from the note. | ||
let encrypted_note = TransmittedNoteCiphertext::<D> { | ||
epk_bytes: [0u8; 32], | ||
enc_ciphertext: D::NoteCiphertextBytes::from(vec![0u8; D::ENC_CIPHERTEXT_SIZE].as_ref()), | ||
out_ciphertext: [0u8; 80] | ||
}; | ||
|
||
let rng = StdRng::from_seed(rng_seed); | ||
|
||
Action { | ||
nf, | ||
rk: redpallas::VerificationKey::from(&sk), | ||
cmx, | ||
encrypted_note, | ||
cv_net, | ||
authorization: sk.sign(rng, &fake_sighash), | ||
} | ||
} | ||
} | ||
} | ||
|
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.
From @PaulLaux (possibly outdated as the file was changed):
are you sure we need to override it twice?
here and lines 29,33
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.
Done. Fixed the
hex
andhalf
dependencies by removing them from "dev-dependencies". Regardinghash
- in the upstream (zcash/orchard 0.8.0), they replaced hash withahash
, which is only present in "dev-dependencies". As for other duplications (includinghalo2_gadgets
), they cannot be removed from "dev-dependencies" because they have different features enabled.