Anyone can steal CryptoPunk during the deposit flow to WPunkGateway
The WPunkGateway contract's supplyPunk function allowed anyone to deposit a CryptoPunk that had been offered for sale to the gateway at zero price, minting the resulting nTokens to the caller. An attacker could monitor for such offers and call supplyPunk with themselves as the beneficiary, stealing the deposited CryptoPunk.
Submitted by 0x52, also found by Dravee, c7e7eff, xiaoming90, KingNFT, Big0XDev, and cccz
https://github.com/code-423n4/2022-11-paraspace/blob/c6820a279c64a299a783955749fdc977de8f0449/paraspace-core/contracts/ui/WPunkGateway.sol#L77-L95 https://github.com/code-423n4/2022-11-paraspace/blob/c6820a279c64a299a783955749fdc977de8f0449/paraspace-core/contracts/ui/WPunkGateway.sol#L129-L155 https://github.com/code-423n4/2022-11-paraspace/blob/c6820a279c64a299a783955749fdc977de8f0449/paraspace-core/contracts/ui/WPunkGateway.sol#L167-L193
All CryptoPunk deposits can be stolen.
Proof of Concept
CryptoPunks were created before the ERC721 standard. A consequence of this is that they do not possess the transferFrom method. To approximate this a user can offerPunkForSaleToAddress for a price of 0 to effectively approve the contract to transferFrom.
function supplyPunk(
DataTypes.ERC721SupplyParams[] calldata punkIndexes,
address onBehalfOf,
uint16 referralCode
) external nonReentrant {
for (uint256 i = 0; i < punkIndexes.length; i++) {
Punk.buyPunk(punkIndexes[i].tokenId);
Punk.transferPunk(proxy, punkIndexes[i].tokenId);
// gatewayProxy is the sender of this function, not the original gateway
WPunk.mint(punkIndexes[i].tokenId);
}
Pool.supplyERC721(
address(WPunk),
punkIndexes,
onBehalfOf,
referralCode
);
}
The current implementation of WPunkGateway#supplyPunk allows anyone to execute and determine where the nTokens are minted to. To complete the flow supply flow a user would need to offerPunkForSaleToAddress for a price of 0 to WPunkGateway. After they have done this, anyone can call the function to deposit the punk and mint the nTokens to themselves, effectively stealing it.
Example:
User A owns tokenID of 1. They want to deposit it so they call offerPunkForSaleToAddress with an amount of 0, effectively approving the WPunkGateway to transfer their CryptoPunk. User B monitors the transactions and immediately calls supplyPunk with themselves as onBehalfOf. This completes the transfer of the CryptoPunk and deposits it into the pool but mints the nTokens to User B, allowing them to effectively steal the CryptoPunk.
The same fundamental issue exists with acceptBidWithCredit and batchAcceptBidWithCredit.
Recommended Mitigation Steps
Query the punkIndexToAddress to find the owner and only allow owner to deposit:
for (uint256 i = 0; i < punkIndexes.length; i++) {
+ address owner = Punk.punkIndexToAddress(punkIndexes[i].tokenId);
+ require(owner == msg.sender);
Punk.buyPunk(punkIndexes[i].tokenId);
Punk.transferPunk(proxy, punkIndexes[i].tokenId);
// gatewayProxy is the sender of this function, not the original gateway
WPunk.mint(punkIndexes[i].tokenId);
}
yubo-ruan (Paraspace) confirmed
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 deposit function did not verify that the caller was the owner of the Punk being deposited, so anyone could trigger the transfer and direct the minted nTokens to themselves.
Impact
Any CryptoPunk deposit could be stolen by an attacker who calls the deposit function first, and the same issue affects the bid-acceptance functions.
What the attacker needed
Victim offers Punk to gateway at zero price; attacker monitors the blockchain
The fix
The deposit function should check that the caller is the current owner of each Punk before transferring it.
How it was found
- The victim offers their CryptoPunk for sale to the WPunkGateway at a price of zero, effectively approving the gateway to transfer it.
- The attacker monitors transactions and sees the offer.
- The attacker calls supplyPunk with themselves as the onBehalfOf address.
- The gateway transfers the CryptoPunk into the pool and mints the nTokens to the attacker.
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.
CryptoPunks are an early NFT collection that lacks a standard approval function. To let a contract move a Punk, the owner must list it for sale to that contract at zero price. The gateway contract then lets anyone finalise the deposit and choose who receives the deposit receipt tokens, so a watcher can take the Punk for themselves.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.