Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: minted early tracking #11066

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fix: minted early tracking #11066

wants to merge 1 commit into from

Conversation

0xpatrickdev
Copy link
Member

@0xpatrickdev 0xpatrickdev commented Feb 28, 2025

Description

Ensures the mintedEarly store can track multiple settlements for the same amount from the same address.

Security Considerations

Ensures state diagram invariants are upheld.

Scaling Considerations

Same considerations as #10729 - the mapStore could grow large if an attacker spams the settlementAccount with uusdc. In these changes we ensure to delete map store entries when the count goes to 0.

Documentation Considerations

Changes should be clear to maintainers.

Testing Considerations

Adds a new test for the scenario not originally considered.

Upgrade Considerations

The mintedEarly kind is a Remotable, so changing from a SetStore to a MapStore does not seem to affect upgradability.

These change should be included in the FUSDC GTM CE.

- ensure multiples of the same NFA+amount are tracked
@0xpatrickdev 0xpatrickdev requested a review from a team as a code owner February 28, 2025 02:18
@0xpatrickdev 0xpatrickdev self-assigned this Feb 28, 2025
Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

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

Good test.

We should have a multiset abstraction. Either with durable multiset or a light wrapper to make MapStore act like one.

@@ -174,8 +175,8 @@ export const prepareSettler = (
intermediateRecipient: config.intermediateRecipient,
/** @type {HostInterface<TargetRegistration>|undefined} */
registration: undefined,
/** @type {SetStore<ReturnType<typeof makeMintedEarlyKey>>} */
mintedEarly: zone.detached().setStore('mintedEarly'),
/** @type {MapStore<ReturnType<typeof makeMintedEarlyKey>, bigint>} */
Copy link
Member

Choose a reason for hiding this comment

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

What we really want is a MultiSet. Endo Patterns has CopyBag for that. I'm looking into whether we have a durable option.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool didn't know that was option. Will look out for your reply on what to use here.

@@ -221,7 +222,7 @@ export const prepareSettler = (

case PendingTxStatus.Advancing:
log('⚠️ tap: minted while advancing', nfa, amount);
this.state.mintedEarly.add(makeMintedEarlyKey(nfa, amount));
self.queueMintedEarly(nfa, amount);
Copy link
Member

Choose a reason for hiding this comment

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

it's not really a queuing operation because there's no distinguishing the items. I think it should still be add. But ideally we don't need this separate method because the data store is a multiset that manages repeated items itself.

@@ -256,7 +257,12 @@ export const prepareSettler = (
const { value: fullValue } = fullAmount;
const key = makeMintedEarlyKey(forwardingAddress, fullValue);
if (mintedEarly.has(key)) {
mintedEarly.delete(key);
const count = mintedEarly.get(key);
Copy link
Member

Choose a reason for hiding this comment

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

we should be using get and delete abstraction on the map to treat it as a multiset.

if we don't have a multiset durable store, we can have a utility that performs the multi-set on them.

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