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

feat: support selfPermitForERC721 #62

Merged
merged 3 commits into from
Jul 18, 2024

Conversation

chefburger
Copy link
Collaborator

It provides SelfPermitERC721 extension support for migrator because v3 LP Token supports PermitERC721 extension. This is extremely helpful if user want to approve through offchain signature

uint8 v,
bytes32 r,
bytes32 s
) external payable override {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need payable since this doesn't use msg.value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i remember if we remove payable here, multicall will fail if msg.value is non-zero ( consider the case when user call migrateFromV2 with some extra ETH ).

Copy link
Collaborator

@ChefMist ChefMist Jul 16, 2024

Choose a reason for hiding this comment

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

agree with Burger, though if possible maybe can add a simple test, so it fail if someone remove the payable 🙏

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

test added, thx for reminding

payable
override
{
IERC721Permit(token).permit(address(this), tokenId, deadline, v, r, s);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this has the same issue as https://www.trust-security.xyz/post/permission-denied

_getAndIncrementNonce will increment the nonce, so here's how a griefing to cause the user tx to revert is done.

  1. User signs a valid signature and calls selfPermitERC721
  2. Attacker frontruns with the signature and calls IERC721Permit(token).permit(address(this), tokenId, deadline, v, r, s);
  3. Attacker uses the signature successfully and causes the user's nonce to increase
  4. User's tx revert as the nonce has already been increase and does not match the nonce used for the signature.

Copy link
Collaborator Author

@chefburger chefburger Jul 12, 2024

Choose a reason for hiding this comment

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

Oh, i got what u mean, so would u recommend i call selfPermitERC721IfNecessary here ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I took a second look and I think selfPermitERC721IfNecessary would still revert if the user if frontrun once, but after that, if selfPermitERC721IfNecessary is used again (although not necessary since the approve is done by the frontrun), it will work.

Copy link
Collaborator Author

@chefburger chefburger Jul 12, 2024

Choose a reason for hiding this comment

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

Sorry, i don't understand why is not working at the first time. I am thinking the workflow as such:

  1. User offchain sign and send the tx
  2. Attacker monitors the tx in mem-pool and frontruns it
  3. Now the nonce has increased and our migrator contract has been approved to do operation on the NFT
  4. User's tx arrives but since migrator has already been approved, if body will be skipped.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah yes, it will skip at step 4. It will be ok if selfPermitERC721IfNecessary if always used then

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can write a comment in the code to always use selfPermitERC721IfNecessary then

@chefburger chefburger force-pushed the feat/supportSelfPermitForERC721 branch from 4b9b8d4 to 7a702f3 Compare July 15, 2024 04:31
@chefburger chefburger force-pushed the feat/supportSelfPermitForERC721 branch from 7a702f3 to 5b2a93a Compare July 16, 2024 05:46
@chefburger chefburger merged commit c331872 into feat/binPool-migrator Jul 18, 2024
2 checks passed
@chefburger chefburger deleted the feat/supportSelfPermitForERC721 branch July 18, 2024 07:16
chefburger added a commit that referenced this pull request Jul 18, 2024
* feat: impl binPool migrator

* refactor: restructure & renaming accordingly

* test: add tests cases for binPool migrator

* chore: renaming as well to align with clMigrator

* fix: add check to prevent token mismatch between source and target pool

* feat: added refundETH function and necessary comments

* optimization: avoid duplicate external call when query v2/v3 pool info

* feat: support selfPermitForERC721 (#62)

* feat: support selfPermitForERC721

* docs: added comments suggesting users to use selfPermitERC721IfNecessary

* test: added tests to prevent ppl from removing payable keyword from external functions
chefburger added a commit that referenced this pull request Jul 18, 2024
* feat: implement v4Migrator for cl-pool

* feat: added same price slippage check for migrateFromV2

* feat: using actual receive amount when adding liquidity to v4

* test: added test for clMigrator

* fix: take into consideration of extra funds when calc refund

* optimization: avoid unnecessary approve in old token cases

* optimization: avoid unnecessary refund call after adding liquidity

* optimization: avoid unnecessary WETH unwrap

* fix: extra check so that non-owner can not steal funds from lpV3 token

* typo

* refactor: restructure baseMigrator a bit so that more can be reused across pool type

* chore: typo and renaming

* V4 BinMigrator (#59)

* feat: impl binPool migrator

* refactor: restructure & renaming accordingly

* test: add tests cases for binPool migrator

* chore: renaming as well to align with clMigrator

* fix: add check to prevent token mismatch between source and target pool

* feat: added refundETH function and necessary comments

* optimization: avoid duplicate external call when query v2/v3 pool info

* feat: support selfPermitForERC721 (#62)

* feat: support selfPermitForERC721

* docs: added comments suggesting users to use selfPermitERC721IfNecessary

* test: added tests to prevent ppl from removing payable keyword from external functions

* docs: add explanation about the case where extra token0 is ETH
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.

4 participants