Skip to content
Smart contracts Audit finding Intermediate

PositionManager & PermitERC721 Failure to comply with the EIP-4494

The PositionManager and PermitERC721 contracts do not comply with the EIP-4494 standard for permit-based ERC-721 approvals. This means third-party tools and contracts cannot detect or correctly use the permit functionality, and nonces cannot be tracked, leading to invalid or future signatures.

Haipls Follow

Originally disclosed on Code4rena

Submitted by Haipls

https://github.com/code-423n4/2023-05-ajna/blob/276942bc2f97488d07b887c8edceaaab7a5c3964/ajna-core/src/PositionManager.sol#L42 https://github.com/code-423n4/2023-05-ajna/blob/276942bc2f97488d07b887c8edceaaab7a5c3964/ajna-core/src/base/PermitERC721.sol#L77 https://github.com/code-423n4/2023-05-ajna/blob/276942bc2f97488d07b887c8edceaaab7a5c3964/ajna-core/src/base/PermitERC721.sol#L13 https://github.com/code-423n4/2023-05-ajna/blob/276942bc2f97488d07b887c8edceaaab7a5c3964/ajna-core/src/PositionManager.sol#L57

The contract PositionManager.sol inherits from PermitERC721.sol, but both contracts incorrectly implement the EIP-4494 standard, which is an important part of the contract. This leads to the following issues:

  • PositionManager & PermitERC721 are not EIP-4494 compliant
  • Automatic tools will not be able to determine that this contract has a permit for ERC721
  • Third-party contracts will not be able to determine that this is EIP-4494
  • Inability to correctly track which nonces are currently relevant, leading to the creation of invalid signatures/signatures for the future
  • No support for compact signatures

Proof of Concept

According to the specifications of the standard EIP-4494, the following violations were found:

  1. EIP-4494 requires the implementation of IERC165 and the indication of support for the interface 0x5604e225, which is not implemented
  2. EIP-4494 requires the presence of the function function nonces(uint256 tokenId) external view returns(uint256); which is missing
  3. EIP-4494 requires the function function permit(address spender, uint256 tokenId, uint256 deadline, bytes memory sig) external;, which is incorrectly declared as
File: 2023-05-ajna\ajna-core\src\base\PermitERC721.sol

77:     function permit(
78:         address spender_, uint256 tokenId_, uint256 deadline_, uint8 v_, bytes32 r_, bytes32 s_
79:     ) external {

Tools Used

Recommended Mitigation Steps

  • Correct the identified non-compliance issues so that the contracts meet the standard
  • Or remove references to the standard and provide a reference to the Uniswap V3 implementation

MikeHathaway (Ajna) confirmed

Picodes (judge) decreased severity to Low and commented:

Downgrading to Low as part of this is out of scope here, and the rest can be considered an instance of “function incorrect as to spec”

Haipls (warden) commented:

Hi @Picodes - The ajna-core/src/base/PermitERC721.sol is indeed out of scope, which subsequently makes points 1 and 3 out of scope as well. However, I’d like you to take another look at point 2.

EIP-4494 necessitates the inclusion of the function: function nonces(uint256 tokenId) external view returns(uint256); which is currently absent.

We can see that PermitERC721 is an abstract contract which only partially implements EIP-4494, and it does so incorrectly, thereby making this part out of scope. However, it also imposes a requirement (abstract contract with abstract _getAndIncrementNonce() method) on PositionManager to implement nonces method on its end, which is within scope. This conclusion can be drawn from the following method:

File: ajna-core/src/base/PermitERC721.sol

29:    /** @dev Gets the current nonce for a token ID and then increments it, returning the original value */
30:    function _getAndIncrementNonce(uint256 tokenId_) internal virtual returns (uint256);

This suggests that the nonces method must be implemented in PositionManager, PermitERC721 transfers this responsibility to descendants. And according to point 2, PositionManager is the final contract that violates the EIP-4494 standard, which is indeed within scope. According to EIP-4494 documentation, the nonces declaration is stated under Three new functions MUST be added to ERC-721:, which, in my opinion, can’t be simply dismissed as function incorrect as to spec. According to the practice I’ve observed, any violation of the standard with MUST label is usually rated as Medium.

Examples:

Thank you.

Picodes (judge) increased severity to Medium and commented:

@Haipls - your point is valid: PositionManager should implement nonces. I was reluctant to give this Medium severity as there are issues in PermitERC721 so the contract couldn’t implement the EIP anyway, but, after reflection and discussing it with another judge, the problem is significant enough to justify Medium severity.


The original report as published on Code4rena, by Haipls. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the contracts did not fully implement the required functions and interface declarations of EIP-4494, such as the nonces function and ERC-165 support.

Impact

Third-party contracts and tools cannot detect or correctly use the permit functionality, and nonces cannot be tracked, which could lead to invalid or future signatures being created.

What the attacker needed

None

The fix

The contracts should be corrected to fully comply with EIP-4494, or references to the standard should be removed and a reference to the Uniswap V3 implementation provided.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

EIP-4494 is a standard for allowing someone to approve another person to use a specific NFT without paying gas, using a signature. This report says the contracts that implement this standard do not follow its rules, so other programs cannot tell that the feature exists or use it properly.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Haipls

View all

7 more disclosed reports, best first.

More from Ajna Protocol

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.