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

dex: relax inner guard for withdrawn LP updates #5051

Merged
merged 2 commits into from
Feb 5, 2025

Conversation

erwanor
Copy link
Member

@erwanor erwanor commented Feb 4, 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

  • 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.

  • 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

@erwanor erwanor added consensus-breaking breaking change to execution of on-chain data A-dex Area: Relates to the dex labels Feb 4, 2025
@erwanor erwanor mentioned this pull request Feb 4, 2025
28 tasks
@conorsch conorsch force-pushed the protocol/lqt_branch branch from 40a9320 to ba746f5 Compare February 4, 2025 22:48
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)
@cronokirby cronokirby force-pushed the erwan/dex_relax_guard branch from 89f101d to 71602f6 Compare February 4, 2025 22:53
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),
},
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

ACK – references #5035 (comment)

Copy link
Member

@hdevalence hdevalence left a 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.

@erwanor erwanor merged commit bb7dea6 into protocol/lqt_branch Feb 5, 2025
8 checks passed
@erwanor erwanor deleted the erwan/dex_relax_guard branch February 5, 2025 20:09
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
A-dex Area: Relates to the dex consensus-breaking breaking change to execution of on-chain data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants