forked from zcash/orchard
-
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
Generalized orchardZSA #96
Closed
dmidem
wants to merge
34
commits into
switch_issueauthsig_to_schnorr
from
orchardzsa-backward-compatability
Closed
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
f9563f4
draft2
PaulLaux ba18c57
draft3
PaulLaux 3d30876
draft4
PaulLaux 52c28f1
draft5
PaulLaux f144fdb
draft6
PaulLaux b626ed9
Generalize orchard_zsa for backward bompatibility with non-ZSA functi…
dmidem 65ae5f4
Minor changes in the doc comments
dmidem b628056
Add tests for note_encryption_v2
dmidem 19bdfe1
Rename V2 name suffixes to Vanilla, and V3 - to ZSA
dmidem 98ed01d
Make the Circuit struct generic to support different Orchard variants…
dmidem aeca03d
Continue Circuit generalization
dmidem 7642927
Split circuit implementation into circuit_vanilla and circuit_zsa
dmidem b9f2878
Fix to support modified halo2
dmidem 6958052
Add missed fields to fn print_action_circuit
dmidem 886796e
Pin half crate to 1.8.2 (to resolve MSRV conflict)
dmidem 6945948
Pin half crate to 1.8.2 for dev deps too (to resolve MSRV conflict)
dmidem 4ac06bf
Pin half crate to 2.2.1
dmidem 6ee3839
Fix cargo clippy errors
dmidem 656ecd9
Convert arb_... testing functions to methods of dummy generict struct…
dmidem eb10eb7
Make hash_bundle_txid_data function backwards compatible
dmidem d4f3b2b
Refactor note_encryption.rs:
dmidem 0a57dcc
Fix cargo clippy errors
dmidem f58a91c
Minor fix (make action module pub)
dmidem 5887dc8
Make add_chip.rs a shared module between circuit_vanilla and circuit_…
dmidem d08fcd8
Introduce OrcharcCircuit trait to eliminate repetitive 'where crate::…
dmidem 214a3e2
Introdice NoteByteReader and NoteByteWriter traiots to use with NoteB…
dmidem 0e4f0e9
note_encryption: extract Domain impl, OrchardDoimain and NoteBytes de…
dmidem e987f39
Use vec with a proper length for the concrete OrchardDomain to genera…
dmidem add7e3f
Use try_fold instead of fold when cargo clippy suggests it
dmidem fb868fd
Rename domain_impl.rs in note_encryption to domain.rs
dmidem f39fa28
Intriduce orchard_flavor module with OrchardVanilla and OrchardZSA st…
dmidem a680158
Fix naming (OrchardDomainContex to OrchardDomainBase, Curcuit to Orch…
dmidem 0f635d2
Fix 'half' dep duplication in Cargo.toml
dmidem 617d37a
Remove rng from AssetBase::random call
dmidem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. Let's do this 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. call |
||
let encrypted_note = TransmittedNoteCiphertext::<D> { | ||
epk_bytes: [0u8; 32], | ||
enc_ciphertext: D::NoteCiphertextBytes::from(&vec![0u8; D::ENC_CIPHERTEXT_SIZE]), | ||
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]), | ||
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), | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
yes, we need both
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.
lets have this as a separate task