Global padding for bundle (#67)

Each bundle must contain at least two actions for privacy concerns.
Previously, we pad bundle to have at least two actions per asset.
Now, we pad bundle globally, and add dummy/split actions to have at least two actions per bundle.
This commit is contained in:
Constance Beguier 2023-06-06 12:40:06 +02:00 committed by GitHub
parent 32eee6e083
commit 02fa582c80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 9 deletions

View File

@ -464,6 +464,18 @@ impl Builder {
i64::try_from(value_balance).and_then(|i| V::try_from(i).map_err(|_| value::OverflowError))
}
/// Returns the number of actions to add to this bundle in order to contain at least MIN_ACTION actions.
fn num_missing_actions(&self) -> usize {
let num_actions = [self.spends.len(), self.recipients.len()]
.iter()
.max()
.cloned()
.unwrap();
(num_actions < MIN_ACTIONS)
.then(|| MIN_ACTIONS - num_actions)
.unwrap_or(0)
}
/// Builds a bundle containing the given spent notes and recipients.
///
/// The returned bundle will have no proof or signatures; these can be applied with
@ -480,11 +492,11 @@ impl Builder {
{
let num_spends = spends.len();
let num_recipients = recipients.len();
let num_actions = [num_spends, num_recipients, MIN_ACTIONS]
.iter()
.max()
.cloned()
.unwrap();
let mut num_actions = [num_spends, num_recipients].iter().max().cloned().unwrap();
// We might have to add dummy/split actions only for the first asset to reach MIN_ACTIONS.
pre_actions
.is_empty()
.then(|| num_actions += self.num_missing_actions());
let first_spend = spends.first().cloned();

View File

@ -408,7 +408,7 @@ fn zsa_issue_and_transfer() {
],
vec![],
anchor,
4,
2,
&keys,
)
.unwrap();
@ -436,7 +436,7 @@ fn zsa_issue_and_transfer() {
],
vec![],
native_anchor,
5,
4,
&keys,
)
.unwrap();
@ -468,7 +468,7 @@ fn zsa_issue_and_transfer() {
],
vec![],
anchor_t7,
4,
2,
&keys,
)
.unwrap();
@ -489,7 +489,7 @@ fn zsa_issue_and_transfer() {
],
vec![],
anchor_t7,
4,
2,
&keys,
)
.unwrap();