Skip to content

Commit

Permalink
Move ActionGroupAuthorized into swap_bundle.rs file
Browse files Browse the repository at this point in the history
  • Loading branch information
ConstanceBeguier committed Oct 17, 2024
1 parent 8f87e24 commit 03ddc60
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
5 changes: 2 additions & 3 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ use rand::{prelude::SliceRandom, CryptoRng, RngCore};

use zcash_note_encryption_zsa::NoteEncryption;

use crate::builder::BuildError::{BurnNative, BurnZero};
use crate::bundle::ActionGroupAuthorized;
use crate::{
action::Action,
address::Address,
builder::BuildError::{BurnNative, BurnZero},
bundle::{derive_bvk, Authorization, Authorized, Bundle, Flags},
circuit::{Circuit, Instance, OrchardCircuit, Proof, ProvingKey},
keys::{
Expand All @@ -27,7 +26,7 @@ use crate::{
note_encryption::{OrchardDomain, OrchardDomainCommon},
orchard_flavor::{OrchardFlavor, OrchardZSA},
primitives::redpallas::{self, Binding, SpendAuth},
swap_bundle::ActionGroup,
swap_bundle::{ActionGroup, ActionGroupAuthorized},
tree::{Anchor, MerklePath},
value::{self, NoteValue, OverflowError, ValueCommitTrapdoor, ValueCommitment, ValueSum},
};
Expand Down
31 changes: 0 additions & 31 deletions src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,37 +526,6 @@ impl<V, D: OrchardDomainCommon> Bundle<Authorized, V, D> {
}
}

/// Authorizing data for an action group, ready to be sent to the matcher.
#[derive(Debug, Clone)]
pub struct ActionGroupAuthorized {
proof: Proof,
}

impl Authorization for ActionGroupAuthorized {
type SpendAuth = redpallas::Signature<SpendAuth>;
}

impl ActionGroupAuthorized {
/// Constructs the authorizing data for a bundle of actions from its constituent parts.
pub fn from_parts(proof: Proof) -> Self {
ActionGroupAuthorized { proof }
}

/// Return the proof component of the authorizing data.
pub fn proof(&self) -> &Proof {
&self.proof
}
}

impl<V, D: OrchardDomainCommon> Bundle<ActionGroupAuthorized, V, D> {
/// Verifies the proof for this bundle.
pub fn verify_proof(&self, vk: &VerifyingKey) -> Result<(), halo2_proofs::plonk::Error> {
self.authorization()
.proof()
.verify(vk, &self.to_instances())
}
}

impl<V: DynamicUsage, D: OrchardDomainCommon> DynamicUsage for Bundle<Authorized, V, D> {
fn dynamic_usage(&self) -> usize {
self.actions.dynamic_usage()
Expand Down
37 changes: 35 additions & 2 deletions src/swap_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
bundle::commitments::hash_action_groups_txid_data,
bundle::{derive_bvk, ActionGroupAuthorized, Bundle, BundleCommitment},
bundle::{derive_bvk, Bundle, BundleCommitment},
note::AssetBase,
orchard_flavor::OrchardZSA,
primitives::redpallas::{self, Binding},
Expand All @@ -12,8 +12,10 @@ use crate::{

use crate::builder::{BuildError, InProgress, InProgressSignatures, Unauthorized, Unproven};
use crate::bundle::Authorization;
use crate::circuit::ProvingKey;
use crate::circuit::{ProvingKey, VerifyingKey};
use crate::keys::SpendAuthorizingKey;
use crate::note_encryption::OrchardDomainCommon;
use crate::primitives::redpallas::SpendAuth;
use k256::elliptic_curve::rand_core::{CryptoRng, RngCore};

/// An action group.
Expand Down Expand Up @@ -155,6 +157,37 @@ impl<V: Copy + Into<i64> + std::iter::Sum> SwapBundle<V> {
}
}

/// Authorizing data for an action group, ready to be sent to the matcher.
#[derive(Debug, Clone)]
pub struct ActionGroupAuthorized {
proof: Proof,
}

impl Authorization for ActionGroupAuthorized {
type SpendAuth = redpallas::Signature<SpendAuth>;
}

impl ActionGroupAuthorized {
/// Constructs the authorizing data for a bundle of actions from its constituent parts.
pub fn from_parts(proof: Proof) -> Self {
ActionGroupAuthorized { proof }
}

/// Return the proof component of the authorizing data.
pub fn proof(&self) -> &Proof {
&self.proof
}
}

impl<V, D: OrchardDomainCommon> Bundle<ActionGroupAuthorized, V, D> {
/// Verifies the proof for this bundle.
pub fn verify_proof(&self, vk: &VerifyingKey) -> Result<(), halo2_proofs::plonk::Error> {
self.authorization()
.proof()
.verify(vk, &self.to_instances())
}
}

impl<V> SwapBundle<V> {
/// Returns the list of action groups that make up this swap bundle.
pub fn action_groups(&self) -> &Vec<ActionGroup<ActionGroupAuthorized, V>> {
Expand Down
9 changes: 5 additions & 4 deletions tests/builder.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use bridgetree::BridgeTree;
use incrementalmerkletree::Hashable;
use orchard::{
builder::{Builder, BundleType},
bundle::{ActionGroupAuthorized, Authorized, Flags},
bundle::{Authorized, Flags},
circuit::{ProvingKey, VerifyingKey},
keys::{FullViewingKey, PreparedIncomingViewingKey, Scope, SpendAuthorizingKey, SpendingKey},
note::{AssetBase, ExtractedNoteCommitment},
note_encryption::OrchardDomain,
orchard_flavor::{OrchardFlavor, OrchardVanilla, OrchardZSA},
swap_bundle::{ActionGroup, SwapBundle},
swap_bundle::{ActionGroup, ActionGroupAuthorized, SwapBundle},
tree::{MerkleHashOrchard, MerklePath},
value::NoteValue,
Anchor, Bundle, Note,
};

use bridgetree::BridgeTree;
use incrementalmerkletree::Hashable;
use rand::rngs::OsRng;
use zcash_note_encryption_zsa::try_note_decryption;

Expand Down
4 changes: 2 additions & 2 deletions tests/zsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use crate::builder::{verify_action_group, verify_bundle, verify_swap_bundle};

use orchard::{
builder::{Builder, BundleType},
bundle::{ActionGroupAuthorized, Authorized},
bundle::Authorized,
circuit::{ProvingKey, VerifyingKey},
issuance::{verify_issue_bundle, IssueBundle, IssueInfo, Signed, Unauthorized},
keys::{FullViewingKey, PreparedIncomingViewingKey, Scope, SpendAuthorizingKey, SpendingKey},
keys::{IssuanceAuthorizingKey, IssuanceValidatingKey},
note::{AssetBase, ExtractedNoteCommitment},
note_encryption::OrchardDomain,
orchard_flavor::OrchardZSA,
swap_bundle::{ActionGroup, SwapBundle},
swap_bundle::{ActionGroup, ActionGroupAuthorized, SwapBundle},
tree::{MerkleHashOrchard, MerklePath},
value::NoteValue,
Address, Anchor, Bundle, Note,
Expand Down

0 comments on commit 03ddc60

Please sign in to comment.