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

re-enable spend max feature #1698

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

re-enable spend max feature #1698

wants to merge 19 commits into from

Conversation

TalDerei
Copy link
Contributor

@TalDerei TalDerei commented Aug 15, 2024

references #1660 and depends on #1801.

to address the feature regression, we implement additional safety checks in both the frontend and services package.

  1. The frontend uses checkSendMaxInvariants to determine if certain invariants are satisfied and decide whether to construct the transaction as a Spend or Output transaction planner request. This determines the appropriate planner request that the wasm planner will consume to craft the fully-formed transaction.

  2. In the transaction planner service implementation, we've added additional constraint checks in assertSpendMax on the fully-formed transaction. However, these checks occur only after the planning step because, with the current code, there's no effective way to enforce these constraints directly in the wasm planner. This provides a greater degree of validation and safety.

In thinking about this more, while these approaches increase safety, they don't completely cover the entire domain space. There is still an external risk to third-party consumers of our wasm package since we don't enforce these checks directly in the wasm planner. To address this, the final step is to implement the same checks in assertSpendMax directly within the wasm planner. This requires public getters to access the private fields inside the ActionList struct. This is currently implemented in this PR but is blocked until a minor point release is cut on the protocol side.

update – added extra safety checks directly inside the wasm planner.

@TalDerei TalDerei self-assigned this Aug 15, 2024
Copy link

changeset-bot bot commented Aug 15, 2024

🦋 Changeset detected

Latest commit: 337b4b9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@penumbra-zone/services Major
minifront Minor
@penumbra-zone/wasm Minor
@penumbra-zone/perspective Major
@penumbra-zone/query Major
@penumbra-zone/storage Major
@penumbra-zone/ui Patch
node-status Patch
@repo/tailwind-config Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@TalDerei TalDerei marked this pull request as draft August 15, 2024 00:16
@TalDerei
Copy link
Contributor Author

TalDerei commented Aug 15, 2024

enumerating various test cases manually per #1660 (comment).

The way the logic is structured, if both invariantOne and invariantTwo are false, isSendingMax will be false, crafting an output TPR. However, if either of the invariants is satisfied, a spend TPR will be crafted.


0. User sends the non-maximum amount of an alternative fee asset (GM), and pays fees with the native asset (UM).

Screenshot 2024-09-14 at 4 15 33 PM Screenshot 2024-09-14 at 4 15 45 PM
invariantOne:  false
invariantTwo:  false
isSendingMax:  false
TPR: output

1. User sends the maximum amount of an alternative fee asset (GM), and pays fees with the native asset (UM).

Screenshot 2024-08-14 at 8 47 55 AM Screenshot 2024-08-14 at 10 03 41 PM
invariantOne:  false
invariantTwo:  false
isSendingMax:  false
TPR: output
Screenshot 2024-09-14 at 4 17 29 PM Screenshot 2024-09-14 at 4 17 41 PM
invariantOne:  false
invariantTwo:  false
isSendingMax:  false
TPR: output

2. User sends the non-maximum amount of an another asset (Pizza), and pays fees with an alternative fee asset (GN).

Screenshot 2024-09-14 at 4 26 36 PM Screenshot 2024-09-14 at 4 26 45 PM
invariantOne:  false
invariantTwo:  false
isSendingMax:  false
TPR: output

3. User sends the maximum amount of an another asset (Pizza), and pays fees with an alternative fee asset (GN).

Screenshot 2024-08-14 at 10 09 56 PM
invariantOne:  false
invariantTwo:  false
isSendingMax:  false
TPR: output
Screenshot 2024-09-14 at 4 28 42 PM Screenshot 2024-09-14 at 4 31 49 PM
invariantOne:  false
invariantTwo:  false
isSendingMax:  false
TPR: output

4. User sends the non-maximum amount of the native asset (UM).

Screenshot 2024-09-14 at 4 34 38 PM Screenshot 2024-09-14 at 4 35 26 PM
invariantOne:  false
invariantTwo:  false
isSendingMax:  false
TPR: output

5. User sends the maximum amount of the native asset (UM).

Screenshot 2024-08-14 at 10 11 26 PM
invariantOne:  true
invariantTwo:  false
isSendingMax:  true
TPR: spend
Screenshot 2024-09-14 at 4 37 08 PM Screenshot 2024-09-14 at 4 37 15 PM
invariantOne:  true
invariantTwo:  false
isSendingMax:  true
TPR: spend

6. User sends the non-maximum amount of alternative asset (GM), and pays fees with the same alternative asset (GM) since the native token (UM) is absent.

Screenshot 2024-09-14 at 4 44 28 PM Screenshot 2024-09-14 at 4 44 37 PM
invariantOne:  false
invariantTwo:  false
isSendingMax:  false
TPR: output

7. User sends the maximum amount of alternative asset (GM), and pays fees with the same alternative asset (GM) since the native token (UM) is absent.

Screenshot 2024-08-14 at 10 15 36 PM
invariantOne:  false
invariantTwo:  true
isSendingMax:  true
TPR: spend
Screenshot 2024-09-14 at 4 45 40 PM Screenshot 2024-09-14 at 4 45 29 PM
invariantOne:  false
invariantTwo:  true
isSendingMax:  true
TPR: spend

8. Not able to pay for fees."

Screenshot 2024-09-14 at 4 57 09 PM Screenshot 2024-09-14 at 4 57 13 PM

@TalDerei TalDerei marked this pull request as ready for review August 15, 2024 05:39
@TalDerei TalDerei marked this pull request as draft August 15, 2024 14:06
@TalDerei TalDerei marked this pull request as ready for review August 15, 2024 14:54
@TalDerei
Copy link
Contributor Author

@Valentine1898 optimistically requested review. I'll implement more comprehensive unit testing and incorporate the additional constraint checks.

@TalDerei TalDerei mentioned this pull request Sep 3, 2024
* refactor to use zustand and remove extraneous state

* more refactor and linting
@TalDerei
Copy link
Contributor Author

TalDerei commented Sep 11, 2024

update

this has taken a backseat in favor of more pressing sync refactoring, but reprioritizing this by adding unit tests that have been sitting in a local branch for some time.

@TalDerei TalDerei requested a review from a team September 19, 2024 04:05
@TalDerei
Copy link
Contributor Author

TalDerei commented Sep 19, 2024

waiting for runner to pick up CI job.

@penumbra-zone/web-team please test with sample transactions for extra assurance folks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: Can we split the wasm code off into its own PR? Also, definitely think we need tests for this. See test_planner_delegator_vote.rs as a reference for passing in a mock db.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, will open separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

3 participants