From 03ddc60637e0e218265ed69c909af35312539ec3 Mon Sep 17 00:00:00 2001 From: Constance Beguier Date: Thu, 17 Oct 2024 09:57:30 +0200 Subject: [PATCH] Move ActionGroupAuthorized into swap_bundle.rs file --- src/builder.rs | 5 ++--- src/bundle.rs | 31 ------------------------------- src/swap_bundle.rs | 37 +++++++++++++++++++++++++++++++++++-- tests/builder.rs | 9 +++++---- tests/zsa.rs | 4 ++-- 5 files changed, 44 insertions(+), 42 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 2b301e339..449757ace 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -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::{ @@ -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}, }; diff --git a/src/bundle.rs b/src/bundle.rs index 48b92aaa9..de69c3613 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -526,37 +526,6 @@ impl Bundle { } } -/// 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; -} - -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 Bundle { - /// 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 DynamicUsage for Bundle { fn dynamic_usage(&self) -> usize { self.actions.dynamic_usage() diff --git a/src/swap_bundle.rs b/src/swap_bundle.rs index dd8b29c93..5261e02df 100644 --- a/src/swap_bundle.rs +++ b/src/swap_bundle.rs @@ -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}, @@ -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. @@ -155,6 +157,37 @@ impl + std::iter::Sum> SwapBundle { } } +/// 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; +} + +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 Bundle { + /// 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 SwapBundle { /// Returns the list of action groups that make up this swap bundle. pub fn action_groups(&self) -> &Vec> { diff --git a/tests/builder.rs b/tests/builder.rs index 63ee6f94a..741184415 100644 --- a/tests/builder.rs +++ b/tests/builder.rs @@ -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; diff --git a/tests/zsa.rs b/tests/zsa.rs index 520c1951b..1ea16e49b 100644 --- a/tests/zsa.rs +++ b/tests/zsa.rs @@ -4,7 +4,7 @@ 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}, @@ -12,7 +12,7 @@ use orchard::{ 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,