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

Pi/pool-manage-fix #81

Merged
merged 16 commits into from
May 9, 2024
Merged

Pi/pool-manage-fix #81

merged 16 commits into from
May 9, 2024

Conversation

Quantumplation
Copy link
Member

@Quantumplation Quantumplation commented May 6, 2024

This primarily fixes a few last minute bug/vulnerability we found during mainnet testing.

First, the pool manage code misunderstood what the output_index would refer to. It was treated as if it was the index within the inputs of the pool output, but it was in fact just the normal output_index from the producing transaction.

To fix this, we just scan over the inputs to find the index of the pool input.

Second, we can't withdraw all of the liquidity, because "pool_has_correct_output" checks for 3 or 4 tokens. To fix this, we just do a different check if we have 0 LP tokens left.

Finally, strategies were signing the details, rather than the whole execution. This could have led to reusing one signature for a different order, or using the signature outside of the intended validity window.

In addition, since we're making changes anyway, this does some other non-functional cleanup:

  • aiken fmt
  • adds some comments for some new code
  • cleans up the build script
  • finishes applying parameters for some of the scripts we haven't used yet
  • add a documentation validator, which makes plutus.json more complete

The output_index field doesn't refer to the index within the list of inputs, but the index within the outputs on the tx that produced it.
So this code would have only worked sometimes, coincidentally, and maybe even have introduced subtle exploits.

Instead, we scan over the inputs to find the pool input being spent, so we can make sure the redeemer correctly points to that one.
Aiken only includes types it can see from the transitive dependency of the top level; There were a few types that were unused at the surface, so didn't appear in the final blueprint. This just adds a `documentation` validator to make sure they show up
When withdrawing the last bit of liquidity, we were checking that there were 3 or 4 tokens on the output; but because we withdrew the last bit, that isn't sufficient
This is actually really subtly important; we were checking that the *details* were signed, which excludes the validity range and the txRef; that would have allowed someone to repurpose one signature for a different order. It's important that the signature covers the whole execution, not just the details.
build.sh Outdated Show resolved Hide resolved
@Quantumplation Quantumplation merged commit 1ea250d into main May 9, 2024
1 check passed
@Quantumplation Quantumplation deleted the pi/pool-manage-fix branch May 9, 2024 01:02
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