Skip to content

[draft] ZSA assets swap#116

Open
ConstanceBeguier wants to merge 50 commits intozsa1from
zsa_swap
Open

[draft] ZSA assets swap#116
ConstanceBeguier wants to merge 50 commits intozsa1from
zsa_swap

Conversation

@ConstanceBeguier
Copy link
Collaborator

@ConstanceBeguier ConstanceBeguier commented Oct 10, 2024

This PR introduces the ability to create ActionGroup and SwapBundle for performing asset swaps.

This PR modifies the Builder:

  • A new reference_notes element has been added, which contains reference split notes. These notes can be used when creating actions.
  • A new build_action_group function allows the creation of an ActionGroup from a Builder. Like when creating a Bundle, the ActionGroup will initially be without proof and signatures. You will need to call create_proof and apply_signatures to add them.

This PR creates a new SwapBundle structure. A SwapBundle is created from a list of ActionGroups. During this creation, the following operations are performed

  • The evaluation of the value balance of the SwapBundle (by summing the value balances of each ActionGroup).
  • The evaluation of the binding signature key bsk of the SwapBundle (by summing the bsk of each ActionGroup).
  • The binding signature of the SwapBundle which is equal to the signature of the SwapBundle SIGHASH with the binding signature key bsk.

TODO

  • Should remove timelimit inside ActionGroup struct (this value is already present in Bundle)
  • In this PR, burning is not allowed in an ActionGroup, but we would like to allow it and store burning into inside ActionGroup.
    • The SpecificBuilderParams struct, the BurnNotEmptyInActionGroup error, and the bundle method need to be updated accordingly.
  • A Bundle can now contain an ActionGroup. This modification must be implemented.
/// An action group.
#[derive(Debug)]
pub struct ActionGroup<A: Authorization, V> {
    /// The action group main content.
    action_group: Bundle<A, V, OrchardZSA>,
    /// The action group timelimit.
    timelimit: u32,
    /// The binding signature key for the action group.
    ///
    /// During the building of the action group, this key is not set.
    /// Once the action group is finalized (it contains a spend authorizing signature for each
    /// action and a proof), the key is set.
    bsk: Option<redpallas::SigningKey<Binding>>,
}
  • There are currently two functions for computing orchard_action_groups_digest. These should be merged into a single function for better maintainability.
  • The function binding_validating_key into swap_bundle.rs must take into account the burns.

ZIP

  • The value balance of a swap order is missing in the current ZIP. The matcher (the entity who creates the swap bundle from the swap orders) must know the value balance of each swap order in order to compute the value balance of the swap bundle. The value balance of the swap bundle is equal to the sum of the value balance of each swap order.

@QED-it QED-it deleted a comment from what-the-diff bot Oct 10, 2024
@ConstanceBeguier ConstanceBeguier force-pushed the zsa_swap branch 2 times, most recently from b9e9112 to f4fdf5c Compare October 15, 2024 10:58
@ConstanceBeguier ConstanceBeguier changed the title [WIP] ZSA assets swap ZSA assets swap Oct 18, 2024
.iter()
.fold(
self.action_group
.prepare_for_action_group(&mut rng, action_group_digest),

Choose a reason for hiding this comment

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

Why do we get action_group_digest as parameter? Unlike sighash it is available via self, isn't it? This should be more fool-proof

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is exactly similar to the prepare function for Bundle.
It is inside the prepare_for_action_group function that you save the digest into self.

Choose a reason for hiding this comment

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

Yeah, yeah, I see where this design is coming from. It's just that in case of tx sighash it makes more sense because you don't have it inside the bundle

Anyway, given our conversations regarding signing sighash for action groups too unders some circumstances (e.g. when ther is only single action group inside tx) - it starts to be relevant for action group too

@ConstanceBeguier ConstanceBeguier changed the title ZSA assets swap [draft] ZSA assets swap Nov 25, 2024
@ConstanceBeguier ConstanceBeguier marked this pull request as draft November 25, 2024 09:14
@PaulLaux PaulLaux mentioned this pull request Mar 9, 2025
ConstanceBeguier and others added 22 commits October 13, 2025 14:09
All set of keys (user1, user2, matcher, reference) must be different.
This PR contains a set of additions/changes that allow ZSA Swaps to be
implemented in librustzcash:
- Adds Swap BundleType and Flag
- Adds AuthorizedWithProof trait that defines proof() method for both
Authorized and ActionGroupAuthorized
- Adds utility methods e.g. from_parts() for SwapBundle, is_empty() in
Builder
- Changes visibility of some methods e.g. dummy() for testing in
librustzcash
- Removes ActionGroup structure
# Conflicts:
#	src/builder.rs
#	src/pczt/tx_extractor.rs
@alexeykoren alexeykoren marked this pull request as ready for review January 20, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants