-
Notifications
You must be signed in to change notification settings - Fork 312
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
dex: relax inner guard for withdrawn LP updates #5051
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40a9320
to
ba746f5
Compare
The DEX engine has an inner guard against invalid state transitions that acts as a last line of defense in case all other validation failed. This inner guard reifies the LP update state-machine, rejecting obviously wrong transitions (e.g, Closed -> Open). Previously, this inner guard defended against updating a withdrawn LP without increasing its sequence number. This is true in the ordinary case when users are driving the state change e.g, by burning/minting a new withdrawn LP. But too limiting in the case when the protocol itself performs an update. This PR: 1. Relax the inner guard 2. Simplifies the reward deposit logic 3. Provides a justification why the inner guard check is triply redundant. The guard is relaxed and removes a third layer of defense, the other two are: 1. The `withdraw_position` entrypoint called by the action handler 2. Check that the transaction value balances (burn, mint inc. seq)
89f101d
to
71602f6
Compare
TalDerei
approved these changes
Feb 4, 2025
Comment on lines
-521
to
-529
// Ok, you'd think we'd be done here, alas, the [`guard_invalid_transitions`] function | ||
// will complain if the position has already been withdrawn, but the sequence has not yet been incremented! | ||
new_state.state = match prev_state.state { | ||
position::State::Opened => position::State::Opened, | ||
position::State::Closed => position::State::Closed, | ||
position::State::Withdrawn { sequence } => position::State::Withdrawn { | ||
sequence: sequence.saturating_add(1), | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK – references #5035 (comment)
hdevalence
reviewed
Feb 5, 2025
hdevalence
approved these changes
Feb 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks correct to me.
conorsch
pushed a commit
that referenced
this pull request
Feb 5, 2025
**Overview** In this PR, we: - Relax the inner guard to allow withdrawn LP updates without `seq+1` - Simplify the reward deposit logic so that it sticks to depositing rewards **Context** Before updating position states, the DEX engine runs an inner guard to defend against ostensibly invalid state transitions (e.g, Closed -> Open). In particular, since there was no mechanism to update an LP without also updating its sequence number, that particular transition was disallowed. This is no longer the case with the implementation of epoch-scoped LQTs. **Other validation** The guard is relaxed and removes a third layer of defense, the other two are: 1. The `withdraw_position` entrypoint called by the action handler 2. Ordinary check that the transaction value balances (burn, mint inc. seq) ## Checklist before requesting a review - [x] I have added guiding text to explain how a reviewer should test these changes. This is tested once we test the end-to-end multi-withdraw mechanism. - [x] If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason: > LQT target
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
In this PR, we:
seq+1
Context
Before updating position states, the DEX engine runs an inner guard to defend against
ostensibly invalid state transitions (e.g, Closed -> Open).
In particular, since there was no mechanism to update an LP without also updating its
sequence number, that particular transition was disallowed. This is no longer the case
with the implementation of epoch-scoped LQTs.
Other validation
The guard is relaxed and removes a third layer of defense, the other two are: 1. The
withdraw_position
entrypoint called by the action handler 2. Ordinary check that thetransaction value balances (burn, mint inc. seq)
Checklist before requesting a review
This is tested once we test the end-to-end multi-withdraw mechanism.
If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there are not
consensus-breaking changes, for the following reason: