Skip to content

Enable Merklized Distributions in Assets Pallet#5400

Open
shawntabrizi wants to merge 83 commits intoparitytech:masterfrom
shawntabrizi:shawntabrizi-assets-distribution
Open

Enable Merklized Distributions in Assets Pallet#5400
shawntabrizi wants to merge 83 commits intoparitytech:masterfrom
shawntabrizi:shawntabrizi-assets-distribution

Conversation

@shawntabrizi
Copy link
Member

@shawntabrizi shawntabrizi commented Aug 19, 2024

Depends on: #3881

This PR introduces a way for an asset issuer to distribute their token to many users using a single merkle root.

Users then present a merkle proof which is verified, and triggers the do_mint function.

A tracking storage ensures that each user only claims their distribution a single time.

The design allows for multiple distributions per asset id.

@shawntabrizi
Copy link
Member Author

This PR is blocked because the data structures in binary-merkle-tree crate are not usable in the runtime because usize does not work with Encode, Decode, or TypeInfo.

Ok(())
}

/// Mint a distribution of assets of a particular class.
Copy link
Contributor

Choose a reason for hiding this comment

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

Something about this can go into the main top docs and then in https://docs.rs/pallet-assets/latest/pallet_assets/?

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

Some small nits remaining, but the overall logic is good

Copy link
Contributor

@Ank4n Ank4n left a comment

Choose a reason for hiding this comment

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

First pass. Haven't looked yet at the proving trie code.

if all_refunded {
Self::deposit_event(Event::<T, I>::DistributionCleaned { distribution_id });
// Refund weight only the amount we actually used.
Ok(Some(T::WeightInfo::destroy_distribution(refund_count)).into())
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the incentive to clean up state? Shouldn't we refund all fees?

Copy link
Member Author

Choose a reason for hiding this comment

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

anyone can clean up state... but yeah we could add a deposit here for doing a distribution

) -> DispatchResult {
let origin = ensure_signed(origin)?;
let id: T::AssetId = id.into();
Self::do_mint_distribution(id, merkle_root, Some(origin))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking out loud: Should we not take some kind of deposit here (charging for the storage), that is only refunded when state (MerklizedDistributionTracker) is cleaned up? What stops some one to create large number of distributions?

@paritytech-review-bot paritytech-review-bot bot requested a review from a team September 23, 2024 21:47
@kianenigma kianenigma requested review from Ank4n and muharem October 25, 2024 10:38
ensure!(check_issuer == details.issuer, Error::<T, I>::NoPermission);
}

let info = DistributionInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps you have already considered this, but I'm still a little concerned that an account can create a bunch of distributions without paying any storage cost.

We could limit this by either

  • Requiring a deposit when creating a distribution.
  • Or, limit it to one active distribution per asset ID.

wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't expect multiple active distribution for an asset, probably that is the most straightforward. We can use AssetId as the key for MerklizedDistribution.

Copy link
Member Author

Choose a reason for hiding this comment

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

i am okay with you adding storage deposit to this PR. i would like to hand it off to someone else to own and take to finish line


#[pallet::storage]
/// Merklized distribution of an asset.
pub(super) type MerklizedDistribution<T: Config<I>, I: 'static = ()> = StorageMap<
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could be a CountedStorageMap to count active distributions.

Copy link
Member Author

Choose a reason for hiding this comment

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

no, because the count would go down when we clean up a distribution. and we want the count to remain unique

///
/// - `distribution_id`: The identifier of the distribution.
/// - `merkle_proof`: The merkle proof of the account and balance in a compact base-16
/// merkle trie used to authorize minting.
Copy link
Contributor

Choose a reason for hiding this comment

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

missing info about hashes?

Copy link
Contributor

@Ank4n Ank4n left a comment

Choose a reason for hiding this comment

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

Just one concern about preventing distribution spam, otherwise happy to approve.

@shawntabrizi
Copy link
Member Author

Why did this PR never get merged?

Was it audited?

@acatangiu
Copy link
Contributor

Why did this PR never get merged?

Was it audited?

Are you not the owner here? You should drive it to completion (audited, merged, released, integrated to fellowship runtimes), or find another owner to take responsibility for doing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T2-pallets This PR/Issue is related to a particular pallet.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

6 participants