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

Sherlock 163,140, 34 & 31: Remove support for non standard NFTs #585

Merged
merged 4 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions src/ERC721Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ import {
IERC721PoolLenderActions
} from './interfaces/pool/erc721/IERC721Pool.sol';
import { IERC721Taker } from './interfaces/pool/erc721/IERC721Taker.sol';
import {
ICryptoPunks,
ICryptoKitties,
NFTTypes
} from './interfaces/pool/erc721/IERC721NonStandard.sol';

import { FlashloanablePool } from './base/FlashloanablePool.sol';

Expand Down Expand Up @@ -64,7 +59,6 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool {

// immutable args offset
uint256 internal constant SUBSET = 93;
uint256 internal constant NFT_TYPE = 125;

/***********************/
/*** State Variables ***/
Expand Down Expand Up @@ -556,22 +550,13 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool {
uint256[] calldata tokenIds_
) internal {
bool subset = _getArgUint256(SUBSET) != 0;
uint8 nftType = _getArgUint8(NFT_TYPE);

for (uint256 i = 0; i < tokenIds_.length;) {
uint256 tokenId = tokenIds_[i];
if (subset && !tokenIdsAllowed[tokenId]) revert OnlySubset();
poolTokens_.push(tokenId);

if (nftType == uint8(NFTTypes.STANDARD_ERC721)){
_transferNFT(msg.sender, address(this), tokenId);
}
else if (nftType == uint8(NFTTypes.CRYPTOKITTIES)) {
ICryptoKitties(_getArgAddress(COLLATERAL_ADDRESS)).transferFrom(msg.sender ,address(this), tokenId);
}
else{
ICryptoPunks(_getArgAddress(COLLATERAL_ADDRESS)).buyPunk(tokenId);
}
_transferNFT(msg.sender, address(this), tokenId);

unchecked { ++i; }
}
Expand All @@ -594,21 +579,11 @@ contract ERC721Pool is FlashloanablePool, IERC721Pool {

uint256 noOfNFTsInPool = poolTokens_.length;

uint8 nftType = _getArgUint8(NFT_TYPE);

for (uint256 i = 0; i < amountToRemove_;) {
uint256 tokenId = poolTokens_[--noOfNFTsInPool]; // start with transferring the last token added in bucket
poolTokens_.pop();

if (nftType == uint8(NFTTypes.STANDARD_ERC721)){
_transferNFT(address(this), toAddress_, tokenId);
}
else if (nftType == uint8(NFTTypes.CRYPTOKITTIES)) {
ICryptoKitties(_getArgAddress(COLLATERAL_ADDRESS)).transfer(toAddress_, tokenId);
}
else {
ICryptoPunks(_getArgAddress(COLLATERAL_ADDRESS)).transferPunk(toAddress_, tokenId);
}
_transferNFT(address(this), toAddress_, tokenId);

tokensTransferred[i] = tokenId;

Expand Down
28 changes: 5 additions & 23 deletions src/ERC721PoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ClonesWithImmutableArgs } from '@clones/ClonesWithImmutableArgs.sol';
import { IERC165 } from '@openzeppelin/contracts/utils/introspection/IERC165.sol';

import { IERC721PoolFactory } from './interfaces/pool/erc721/IERC721PoolFactory.sol';
import { NFTTypes } from './interfaces/pool/erc721/IERC721NonStandard.sol';

import { IERC20Token, PoolType } from './interfaces/pool/IPool.sol';

Expand Down Expand Up @@ -56,26 +55,10 @@ contract ERC721PoolFactory is PoolDeployer, IERC721PoolFactory {
) external canDeploy(getNFTSubsetHash(tokenIds_), collateral_, quote_, interestRate_) returns (address pool_) {
uint256 quoteTokenScale = 10**(18 - IERC20Token(quote_).decimals());

NFTTypes nftType;
// CryptoPunks NFTs
if (collateral_ == 0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB ) {
nftType = NFTTypes.CRYPTOPUNKS;
}
// CryptoKitties and CryptoFighters NFTs
else if (collateral_ == 0x06012c8cf97BEaD5deAe237070F9587f8E7A266d || collateral_ == 0x87d598064c736dd0C712D329aFCFAA0Ccc1921A1) {
nftType = NFTTypes.CRYPTOKITTIES;
}
// All other NFTs that support the EIP721 standard
else {
// Here 0x80ac58cd is the ERC721 interface Id
// Neither a standard NFT nor a non-standard supported NFT(punk, kitty or fighter)
try IERC165(collateral_).supportsInterface(0x80ac58cd) returns (bool supportsERC721Interface) {
if (!supportsERC721Interface) revert NFTNotSupported();
} catch {
revert NFTNotSupported();
}

nftType = NFTTypes.STANDARD_ERC721;
try IERC165(collateral_).supportsInterface(0x80ac58cd) returns (bool supportsERC721Interface) {
if (!supportsERC721Interface) revert NFTNotSupported();
} catch {
revert NFTNotSupported();
}

bytes memory data = abi.encodePacked(
Expand All @@ -84,8 +67,7 @@ contract ERC721PoolFactory is PoolDeployer, IERC721PoolFactory {
collateral_,
quote_,
quoteTokenScale,
tokenIds_.length,
nftType
tokenIds_.length
);

ERC721Pool pool = ERC721Pool(address(implementation).clone(data));
Expand Down
20 changes: 0 additions & 20 deletions src/interfaces/pool/erc721/IERC721NonStandard.sol

This file was deleted.

121 changes: 0 additions & 121 deletions tests/forge/ERC721Pool/ERC721NonStandardTokenTransfer.sol

This file was deleted.