-
Notifications
You must be signed in to change notification settings - Fork 0
Fix frontrunning vulnerability with Permit2 signature-based approvals (OZ-01) #48
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
Open
adnanhq
wants to merge
5
commits into
oz-audit-fixes
Choose a base branch
from
oz-fix-issue-1
base: oz-audit-fixes
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
733fb34
Add off-chain approval and args integrity validation for payment flow…
adnanhq aefbc16
Fix empty permit fallback in KWR, add Uniswap deps and update tests
adnanhq e77328d
Add permit2 submodule gitlink to fix CI builds
adnanhq 2a4f2a7
Use Mock Permit2 in tests to avoid solc mismatch
adnanhq 85ac5dc
refactor: extract shared refund logic to helper function
adnanhq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.22; | ||
|
|
||
| // ============================================================================ | ||
| // Inlined Permit2 interfaces (originally from Uniswap permit2 package) | ||
| // ============================================================================ | ||
|
|
||
| /// @title IEIP712 | ||
| interface IEIP712 { | ||
| function DOMAIN_SEPARATOR() external view returns (bytes32); | ||
| } | ||
|
|
||
| /// @title ISignatureTransfer | ||
| /// @notice Handles ERC20 token transfers through signature based actions | ||
| /// @dev Requires user's token approval on the Permit2 contract | ||
| interface ISignatureTransfer is IEIP712 { | ||
| /// @notice Thrown when the requested amount for a transfer is larger than the permissioned amount | ||
| /// @param maxAmount The maximum amount a spender can request to transfer | ||
| error InvalidAmount(uint256 maxAmount); | ||
|
|
||
| /// @notice Thrown when the number of tokens permissioned to a spender does not match the number of tokens being transferred | ||
| error LengthMismatch(); | ||
|
|
||
| /// @notice Emits an event when the owner successfully invalidates an unordered nonce. | ||
| event UnorderedNonceInvalidation(address indexed owner, uint256 word, uint256 mask); | ||
|
|
||
| /// @notice The token and amount details for a transfer signed in the permit transfer signature | ||
| struct TokenPermissions { | ||
| address token; | ||
| uint256 amount; | ||
| } | ||
|
|
||
| /// @notice The signed permit message for a single token transfer | ||
| struct PermitTransferFrom { | ||
| TokenPermissions permitted; | ||
| uint256 nonce; | ||
| uint256 deadline; | ||
| } | ||
|
|
||
| /// @notice Specifies the recipient address and amount for batched transfers. | ||
| struct SignatureTransferDetails { | ||
| address to; | ||
| uint256 requestedAmount; | ||
| } | ||
|
|
||
| /// @notice Used to reconstruct the signed permit message for multiple token transfers | ||
| struct PermitBatchTransferFrom { | ||
| TokenPermissions[] permitted; | ||
| uint256 nonce; | ||
| uint256 deadline; | ||
| } | ||
|
|
||
| /// @notice A map from token owner address and a caller specified word index to a bitmap. | ||
| function nonceBitmap(address, uint256) external view returns (uint256); | ||
|
|
||
| /// @notice Transfers a token using a signed permit message | ||
| function permitTransferFrom( | ||
| PermitTransferFrom memory permit, | ||
| SignatureTransferDetails calldata transferDetails, | ||
| address owner, | ||
| bytes calldata signature | ||
| ) external; | ||
|
|
||
| /// @notice Transfers a token using a signed permit message with extra witness data | ||
| function permitWitnessTransferFrom( | ||
| PermitTransferFrom memory permit, | ||
| SignatureTransferDetails calldata transferDetails, | ||
| address owner, | ||
| bytes32 witness, | ||
| string calldata witnessTypeString, | ||
| bytes calldata signature | ||
| ) external; | ||
|
|
||
| /// @notice Transfers multiple tokens using a signed permit message | ||
| function permitTransferFrom( | ||
| PermitBatchTransferFrom memory permit, | ||
| SignatureTransferDetails[] calldata transferDetails, | ||
| address owner, | ||
| bytes calldata signature | ||
| ) external; | ||
|
|
||
| /// @notice Transfers multiple tokens using a signed permit message with extra witness data | ||
| function permitWitnessTransferFrom( | ||
| PermitBatchTransferFrom memory permit, | ||
| SignatureTransferDetails[] calldata transferDetails, | ||
| address owner, | ||
| bytes32 witness, | ||
| string calldata witnessTypeString, | ||
| bytes calldata signature | ||
| ) external; | ||
|
|
||
| /// @notice Invalidates the bits specified in mask for the bitmap at the word position | ||
| function invalidateUnorderedNonces(uint256 wordPos, uint256 mask) external; | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // Application-level types | ||
| // ============================================================================ | ||
|
|
||
| /** | ||
| * @title IPermit2 | ||
| * @notice Re-exports ISignatureTransfer so that existing import paths work unchanged. | ||
| * @dev The canonical Permit2 deployment address is | ||
| * 0x000000000022D473030F116dDEE9F6B43aC78BA3 across all supported EVM chains. | ||
| */ | ||
| interface IPermit2 is ISignatureTransfer {} | ||
|
|
||
| /** | ||
| * @notice Application-specific struct bundling the Permit2 fields a caller must | ||
| * supply alongside each signature-based token transfer. | ||
| * @param nonce Unique nonce preventing signature replay (managed by Permit2). | ||
| * @param deadline Unix timestamp after which the permit is no longer valid. | ||
| * @param signature EIP-712 signature produced by the token owner. | ||
| */ | ||
| struct PermitData { | ||
| uint256 nonce; | ||
| uint256 deadline; | ||
| bytes signature; | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
_pledgeunconditionally callspermitWitnessTransferFromonINFO.getPermit2Address()without verifying that address has deployed code. On local/dev/unsupported chains where the canonical Permit2 address is empty, this external call can return success as a no-op, so execution continues and the contract mints a pledge NFT and updates raised totals without actually transferring tokens. Please gate this path with acode.length(or equivalent deployment) check before relying on Permit2 transfers.Useful? React with 👍 / 👎.