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

Middleware protect #152

Open
wants to merge 54 commits into
base: middleware-remove
Choose a base branch
from
Open

Middleware protect #152

wants to merge 54 commits into from

Conversation

Jun1on
Copy link
Contributor

@Jun1on Jun1on commented Jul 15, 2024

Related Issue

A malicious hook could perform the following actions that are deemed unsafe for the user:
beforeSwap: frontrun the user / remove liquidity
beforeAddLiquidity: cause the ratio of the two tokens owed to the pool to be different than expected by swapping to different price
deltas: steal funds from the user on swap, add liquidity, remove liquidity
dynamic fee: steal funds from the user on swap
unsafe remove functions have already been discussed in middleware-remove

Description of changes

This PR implements the MiddlewareProtect middleware, which protects the typical user from all malicious hook actions. This contract inherits MiddlewareRemove, so it already implements removeLiquidity protections.
beforeSwap: quotes the delta of a swap
afterSwap: checks the actual deltas. if different, revert.
beforeAddLiquidity: revert if the price is changed.
block deltas entirely.
block dynamic fee entirely.

@Jun1on Jun1on mentioned this pull request Jul 16, 2024
Jun1on and others added 24 commits July 16, 2024 14:58
* map recipient

* tests for use cases

* gas tests
* allow batching sig based approvals through p2 forwarder

* forwarder tests

* fix imports

* add multicall tests

* pr comments

* use contracts selector
* Take portion with test

* fuzz bips lib

* another test

* nits
* map exactIn amount to open delta

* Tests

* generalised settle

* remove console log

* other map functions

* settle vs swap map amounts

* Constants file and compiler warnings

* linting

* PR comment
* clean

* format

* with currencydeltas library

* remove currencydeltas library
* compiling

* compiling, gas snaps added

* add unit tests for PositionConfigLibrary

* subscriber tests

* pr comments

* use gas limit calcualtor

* test return data

* use solidity

* comments

* natspec & more tests

* payable

* pr comments

* pr comments

* inheritdoc
Co-authored-by: Sara Reynolds <snreynolds2506@gmail.com>
* clear or take

* misc code comment

* update naming; use delta resolver helper for clearOrTake

* nits

* reorder

* nits
* TAKE_PAIR

* getfullcredit

* take pair recipient

* add recipient test
* allow for nonsigners to call permit

* forge fmt

* test permit with multicall

* make DOMAIN_SEPARATOR immutable

* avoid chain fork replays

* misc test cleanup

* custom errors

* move magic hex to a constant

* unpayable permit

* use OZ EIP712

* separate out UnorderedNonce into a reusable contract

* move token URI to posm

* add back in payable permit

* fix cherry picked commits

* remove public digest getter

* replace range with config naming

* deprecate old test: requiring permission to increase liq

* pr feedback

* borrow pertmi2 nonce tests for UnorderedNonce

* dedicated permit and approve testing for ERC721Permit

* pr feedback: operator should be broadcaster of permit calls

* reorganize permit hashing and verification

* refactor ERC721Permit signature verification with generic signature calldata handler

* remove deprecated library

* fix imports

* formatting

* pr feedback

* optimize nonce bit flipping

* discard public PERMIT_TYPEHASH

* renaming

* library-ify bit flipping

* yall crazy for sending through the ringer

* nits
* add take

* merge conf

* noooo console

* pr comments
* wip bubble up revert

* fix formatting

* simple bubble

* test different error types on multicall

* additional testing for external contract reverts

* example core revert bubbling

* testing for different lengths

* cleanup

* cleanup unused imports

* delete stale gas

* minor nits
* permit hash in assembly

* fuzz test
* WOOF WOOF WOOF BARK BARK WOOF BARK

* remove address(this) check

* forge fmt

* discard version from EIP712

* Update src/base/EIP712.sol

Co-authored-by: Sara Reynolds <30504811+snreynolds@users.noreply.github.com>

* natspec for delegatecall error

* assembly optimization, pr nits

* test to validate assembly

---------

Co-authored-by: Sara Reynolds <30504811+snreynolds@users.noreply.github.com>
* take in router, plus remove safecast

* nested if optimisation in posm

* test of take command

* lint

* bring back contract balance and atspec
* rename files to avoid hardhat collisions

* rename colliding files with _v4 suffix

* remove unused import
* Align constants with UR

* rename

* another rename
* slippage params routing

* tests

* PR comment

* exact out tests
* add liquidity view

* comment
snreynolds and others added 25 commits August 4, 2024 19:14
* add bytes, clean up compiliation

* comments
* actions with no unlock

* Test lockless posm via hooks (#266)

* test hook which modifiesLiquidities in beforeSwap

* test hook modifying liquidity

* minor cleanups

* test that hooks cannot re-enter modifyLiquidities

* hook mints liquidity with modifyLiquidities

* PR cmments

* rename

* rename

* Update src/interfaces/IPositionManager.sol

Co-authored-by: Sara Reynolds <30504811+snreynolds@users.noreply.github.com>

* misc code comments

---------

Co-authored-by: saucepoint <saucepoint@protonmail.com>
Co-authored-by: saucepoint <98790946+saucepoint@users.noreply.github.com>
Co-authored-by: Sara Reynolds <30504811+snreynolds@users.noreply.github.com>
* initial impl

* hashing tests

* setApprovalForAll override tests

* reorganize ERC721Permit file

* separate out tests for permit and permitForAll

* tests for permitForAll

* regenerate gas

* add to interface

* pr feedback

* rename variable
* Wrap reverts thrown by subscribers

* add tests

* comment

---------

Co-authored-by: Sara Reynolds <snreynolds2506@gmail.com>
* move tokenURI

* reorder operations, fix mock

* inheritdoc, fix compiler warnings
* use v4-core latest

* use custom revert
* add mint position event

* merge main
* provide delta info to subscibers

* notifyModifyLiquidity parameters provided correctly

* do not provide liquidity delta to subscribers
* restore permissioning on increase

* fix comment

* fix code comments
* update amount checks

* take test after increase

* make natspec better, comments

---------

Co-authored-by: Alice Henshaw <henshawalice@gmail.com>
* Remove contract balance swap input

* combine take and swap helpers

* remove swap helper function
* move sub unsub

* use struct

* pass in bytes to setConfigId

* ...
@Jun1on Jun1on force-pushed the middleware-protect branch from 7e8c50c to 5eec68a Compare August 15, 2024 17:04
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.

7 participants