MinterUpgradeable : double-subtracting smNFT burns causes rebase underpayment
The MinterUpgradeable contract incorrectly calculates circulatingBlack by subtracting the smNFT balance twice, leading to an understated rebase amount and overstated gauge emissions. This diverts value from LPs/stakers to veBLACK voters.
lonelybones Follow with Akxai, codexNature and 2 others
Originally disclosed on Code4rena
Submitted by lonelybones, also found by Akxai, codexNature, hakunamatata, and holtzzx
https://github.com/code-423n4/2025-05-blackhole/blob/main/contracts/VotingEscrow.sol#L297
Finding description and impact
Root Cause: Incorrect circulatingBlack calculation in MinterUpgradeable.calculate_rebase()
The MinterUpgradeable.calculate_rebase() function (contracts/MinterUpgradeable.sol#L132) incorrectly calculates circulatingBlack when Supermassive NFTs (smNFTs) are present.
- smNFT Creation Burns
BLACK:BLACKtokens are burned when smNFTs are created/augmented inVotingEscrow.sol(e.g.,contracts/VotingEscrow.sol#L796,#L933). This correctly reducesBLACK.totalSupply()(contracts/Black.sol#L97). _blackTotalis Post-Burn Supply:MinterUpgradeable.calculate_rebase()reads this already-reducedtotalSupplyinto_blackTotal(contracts/MinterUpgradeable.sol#L127).- Double Subtraction Flaw: The calculation for
circulatingBlackeffectively becomes_blackTotal - _veTotal - _smNFTBalance. Since_blackTotalis already net of the burned_smNFTBalance,_smNFTBalanceis erroneously subtracted twice.
Impact
Misallocation of minted emissions (high severity): this double-subtraction results in an artificially low circulatingBlack value. The rebase formula (Rebase ~ _weeklyMint * (circulatingBlack / blackSupply)^2 / 2) is highly sensitive to this error.
- Understated Rebase: The
rebaseAmountpaid toRewardsDistributor(for LPs/stakers) is significantly lower than intended. - Overstated Gauge Emissions: Consequently, emissions allocated to gauges (
_gauge = _emission - _rebase - _teamEmissions) are significantly overstated. - Economic Imbalance: This systematically diverts value from LPs/stakers to
veBLACKvoters who direct gauge emissions, undermining the protocol’s economic model. The misallocation is persistent and scales with the total_smNFTBalance.
The Proof of Concept demonstrates this flaw, leading to a tangible misdirection of emissions each epoch. This directly affects a new core feature (smNFTs) and critical system logic.
Recommended mitigation steps
Correct the circulatingBlack calculation in MinterUpgradeable.calculate_rebase() (contracts/MinterUpgradeable.sol#L132).
Given _blackTotal = _black.totalSupply() (already reduced by smNFT burns) and _veTotal = _black.balanceOf(address(_ve)):
Corrected circulatingBlack calculation:
// In MinterUpgradeable.calculate_rebase()
uint circulatingBlack_corrected = _blackTotal - _veTotal;
This ensures _smNFTBalance (representing tokens already removed from _blackTotal) is not subtracted again. The blackSupply denominator (_blackTotal + _superMassiveBonus) can remain, as it reflects an effective total supply including smNFT bonus effects.
Proof of Concept
A Hardhat test (test/poc-rebase-miscalculation.js), utilizing necessary mock contracts, has been developed to demonstrate the vulnerability.
The PoC executes the following key steps:
-
Deploys core contracts (
Black,VotingEscrow,MinterUpgradeable) and required mocks. -
Creates both a standard veNFT lock and a Supermassive NFT (smNFT), triggering the
BLACKtoken burn for the smNFT. -
Advances time to enable a new minting period via
MinterUpgradeable.update_period(). -
Compares rebase calculations: It invokes
MinterUpgradeable.calculate_rebase()and compares this value to a manually corrected calculation that rectifies the double-subtraction of_smNFTBalance. -
Verifies emission misallocation: It calls
MinterUpgradeable.update_period()to perform the actual minting and distribution. It then asserts that:- The
BLACKtokens transferred to the (mocked)RewardsDistributormatch the contract’s flawed, lower rebase calculation. - The
BLACKtokens approved for the (mocked)GaugeManagerare consequently higher than they would be with a correct rebase, and this excess precisely matches the amount miscalculated from the rebase.
- The
Key findings demonstrated by the PoC:
- The contract’s
calculate_rebase()function yields a significantly lower rebase amount than the correctly calculated value when_smNFTBalance > 0. - This understated rebase amount is what is actually distributed.
- The difference (the “misallocated amount”) is verifiably diverted towards gauge emissions.
The full PoC script and mock contracts will be provided below. The test passes and includes detailed console logs to trace the state and calculations.
poc_rebase_miscalculation.js:
const { expect } = require("chai");
const { ethers, network } = require("hardhat");
describe("MinterUpgradeable - Rebase Miscalculation PoC", function () {
let deployer, user1, team; // Signers
let blackToken, votingEscrow, minter, gaugeManagerMock, rewardsDistributorMock, blackGovernorMock;
let votingBalanceLogic, votingDelegationLib; // Libraries
const WEEK = 1800;
const PRECISION = ethers.BigNumber.from("10000");
const TOKEN_DECIMALS = 18; // For formatting ethers
async function setupContracts() {
[deployer, user1, team] = await ethers.getSigners();
const BlackFactory = await ethers.getContractFactory("Black");
blackToken = await BlackFactory.deploy();
await blackToken.deployed();
if (!(await blackToken.initialMinted())) {
await blackToken.connect(deployer).initialMint(deployer.address);
}
const initialUserTokens = ethers.utils.parseEther("1000000");
await blackToken.connect(deployer).transfer(user1.address, initialUserTokens);
const VotingBalanceLogicFactory = await ethers.getContractFactory("VotingBalanceLogic");
votingBalanceLogic = await VotingBalanceLogicFactory.deploy();
await votingBalanceLogic.deployed();
const VotingDelegationLibFactory = await ethers.getContractFactory("VotingDelegationLib");
votingDelegationLib = await VotingDelegationLibFactory.deploy();
await votingDelegationLib.deployed();
const VotingEscrowFactory = await ethers.getContractFactory("VotingEscrow", {
libraries: { VotingBalanceLogic: votingBalanceLogic.address },
});
votingEscrow = await VotingEscrowFactory.deploy(blackToken.address, ethers.constants.AddressZero, ethers.constants.AddressZero);
await votingEscrow.deployed();
if ((await votingEscrow.team()) !== team.address) {
await votingEscrow.connect(deployer).setTeam(team.address);
}
const GaugeManagerMockFactory = await ethers.getContractFactory("GaugeManagerMock");
gaugeManagerMock = await GaugeManagerMockFactory.deploy();
await gaugeManagerMock.deployed();
const RewardsDistributorMockFactory = await ethers.getContractFactory("RewardsDistributorMock");
rewardsDistributorMock = await RewardsDistributorMockFactory.deploy();
await rewardsDistributorMock.deployed();
const BlackGovernorMockFactory = await ethers.getContractFactory("BlackGovernorMock");
blackGovernorMock = await BlackGovernorMockFactory.deploy();
await blackGovernorMock.deployed();
await gaugeManagerMock.setBlackGovernor(blackGovernorMock.address);
const MinterFactory = await ethers.getContractFactory("MinterUpgradeable");
minter = await MinterFactory.deploy();
await minter.deployed();
await minter.connect(deployer).initialize(gaugeManagerMock.address, votingEscrow.address, rewardsDistributorMock.address);
if ((await minter.team()) !== team.address) {
await minter.connect(deployer).setTeam(team.address);
await minter.connect(team).acceptTeam();
}
await minter.connect(deployer)._initialize([], [], 0);
await blackToken.connect(deployer).setMinter(minter.address);
await blackToken.connect(user1).approve(votingEscrow.address, ethers.constants.MaxUint256);
}
async function advanceToNextMintingPeriod(minterContract) {
let currentActivePeriod = await minterContract.active_period();
let currentTime = ethers.BigNumber.from((await ethers.provider.getBlock('latest')).timestamp);
let targetTimeForUpdate = currentActivePeriod.add(WEEK);
if (currentTime.lt(targetTimeForUpdate)) {
const timeToAdvance = targetTimeForUpdate.sub(currentTime).toNumber();
if (timeToAdvance > 0) {
await network.provider.send("evm_increaseTime", [timeToAdvance]);
}
}
await network.provider.send("evm_mine"); // Mine a block regardless to update timestamp
}
// Helper function to format BigNumbers consistently for logging
function formatBN(bn) {
return ethers.utils.formatUnits(bn, TOKEN_DECIMALS);
}
it("should have correct rebase when smNFTBalance is zero", async function () {
await setupContracts();
const lockAmount = ethers.utils.parseEther("10000");
const lockDuration = WEEK * 52;
await votingEscrow.connect(user1).create_lock(lockAmount, lockDuration, false /* isSMNFT */);
await advanceToNextMintingPeriod(minter);
const veTotal = await blackToken.balanceOf(votingEscrow.address);
const blackTotal = await blackToken.totalSupply();
const smNFTBalance = await votingEscrow.smNFTBalance();
const superMassiveBonus = await votingEscrow.calculate_sm_nft_bonus(smNFTBalance);
const weeklyEmission = await minter.weekly();
console.log("\n--- Test Case: smNFTBalance is ZERO ---");
console.log(" veTotal:", formatBN(veTotal));
console.log(" blackTotal:", formatBN(blackTotal));
console.log(" smNFTBalance:", formatBN(smNFTBalance)); // Should be 0
console.log(" superMassiveBonus:", formatBN(superMassiveBonus)); // Should be 0
console.log(" Weekly Mint:", formatBN(weeklyEmission));
const rebaseContract = await minter.calculate_rebase(weeklyEmission);
console.log(" Rebase (Contract):", formatBN(rebaseContract));
// Corrected calculation (should match contract when smNFTBalance is 0)
// Contract's circulatingBlack = blackTotal - veTotal - smNFTBalance
// Corrected circulatingBlack = blackTotal - veTotal
// Since smNFTBalance is 0, these are the same.
const correctedCirculating = blackTotal.sub(veTotal);
const correctedDenominator = blackTotal.add(superMassiveBonus); // bonus is 0
let correctedRebase = ethers.BigNumber.from(0);
if (!correctedDenominator.isZero() && correctedCirculating.gte(0)) {
const numSq = correctedCirculating.mul(correctedCirculating);
const denSqTimes2 = correctedDenominator.mul(correctedDenominator).mul(2);
if(!denSqTimes2.isZero()) {
correctedRebase = weeklyEmission.mul(numSq).div(denSqTimes2);
}
}
console.log(" Rebase (Corrected):", formatBN(correctedRebase));
expect(smNFTBalance).to.equal(0, "smNFTBalance should be zero for this test case");
const diff = rebaseContract.sub(correctedRebase).abs();
// Allow for extremely small dust if any fixed point math slightly differs, though should be equal
const tolerance = ethers.utils.parseUnits("1", "wei");
expect(diff).to.be.lte(tolerance, "Rebase calculations should be identical when smNFTBalance is zero");
});
it("should demonstrate rebase miscalculation when smNFTBalance is positive", async function () {
await setupContracts(); // Ensure fresh state for this test
const lockAmount = ethers.utils.parseEther("10000");
const smNFTLockAmount = ethers.utils.parseEther("50000");
const lockDuration = WEEK * 52 * 1;
await votingEscrow.connect(user1).create_lock(lockAmount, lockDuration, false /* isSMNFT */);
await votingEscrow.connect(user1).create_lock(smNFTLockAmount, lockDuration, true /* isSMNFT */);
await advanceToNextMintingPeriod(minter);
const veTotal_before = await blackToken.balanceOf(votingEscrow.address);
const blackTotal_before = await blackToken.totalSupply();
const smNFTBalance_before = await votingEscrow.smNFTBalance();
const superMassiveBonus_before = await votingEscrow.calculate_sm_nft_bonus(smNFTBalance_before);
const weeklyEmission_for_period = await minter.weekly();
console.log("\n--- Test Case: smNFTBalance is POSITIVE ---");
console.log("State BEFORE Minter.update_period / calculate_rebase (Revised Inputs):");
console.log(" veTotal (tokens in VE for normal/perm locks):", formatBN(veTotal_before));
console.log(" blackTotal (actual totalSupply after smNFT burn):", formatBN(blackTotal_before));
console.log(" smNFTBalance (sum of original principals burned for smNFTs):", formatBN(smNFTBalance_before));
console.log(" superMassiveBonus (conceptual bonus on smNFTBalance):", formatBN(superMassiveBonus_before));
console.log(" Weekly Mint for this period (emission to be distributed):", formatBN(weeklyEmission_for_period));
const rebaseAmount_from_contract_calc = await minter.calculate_rebase(weeklyEmission_for_period);
console.log("Rebase Amount calculated BY CONTRACT'S LOGIC:", formatBN(rebaseAmount_from_contract_calc));
// Corrected Logic: circulatingBlack should NOT double-subtract smNFTBalance
const corrected_circulatingBlack = blackTotal_before.sub(veTotal_before); // Numerator: BT - VT
// Corrected Denominator: actual total supply + conceptual bonus
const corrected_blackSupply_denominator = blackTotal_before.add(superMassiveBonus_before); // Denominator: BT + B
console.log("\nFor Manual/Corrected Calculation:");
console.log(" Corrected Circulating Black (ActualCirculating):", formatBN(corrected_circulatingBlack));
console.log(" Corrected Black Supply Denominator (ActualTotalSupply + Bonus):", formatBN(corrected_blackSupply_denominator));
let corrected_rebaseAmount = ethers.BigNumber.from(0);
if (!corrected_blackSupply_denominator.isZero() && corrected_circulatingBlack.gte(0)) {
const num_squared = corrected_circulatingBlack.mul(corrected_circulatingBlack);
const den_squared_times_2 = corrected_blackSupply_denominator.mul(corrected_blackSupply_denominator).mul(2);
if (!den_squared_times_2.isZero()) {
corrected_rebaseAmount = weeklyEmission_for_period.mul(num_squared).div(den_squared_times_2);
}
}
console.log("Rebase Amount calculated MANUALLY (Corrected Logic):", formatBN(corrected_rebaseAmount));
const expected_misallocated_rebase = corrected_rebaseAmount.sub(rebaseAmount_from_contract_calc);
console.log("Expected Misallocated Rebase (Corrected - Contract):", formatBN(expected_misallocated_rebase));
// --- Assertions for Vulnerable Outcome ---
expect(smNFTBalance_before).to.be.gt(0, "Test setup failed: smNFTBalance should be positive for this test case");
expect(rebaseAmount_from_contract_calc).to.be.lt(corrected_rebaseAmount, "Contract's rebase should be less than corrected rebase when smNFTs exist");
expect(expected_misallocated_rebase).to.be.gt(0, "Expected misallocated rebase amount should be greater than zero");
// --- Demonstrate Upstream Impact on State ---
const rewardsDistributor_bal_before_mint = await blackToken.balanceOf(rewardsDistributorMock.address);
const minterTeamAddress = await minter.team();
const team_bal_before_mint = await blackToken.balanceOf(minterTeamAddress);
const gaugeManager_allowance_before_mint = await blackToken.allowance(minter.address, gaugeManagerMock.address);
// Calculate expected team and gauge amounts based on BOTH contract's flawed rebase AND corrected rebase
const teamRate = await minter.teamRate();
const MAX_BPS = await minter.MAX_BPS();
const teamEmission_contract = weeklyEmission_for_period.mul(teamRate).div(MAX_BPS);
const gaugeEmission_contract = weeklyEmission_for_period.sub(rebaseAmount_from_contract_calc).sub(teamEmission_contract);
const teamEmission_corrected = weeklyEmission_for_period.mul(teamRate).div(MAX_BPS); // team emission is same
const gaugeEmission_corrected = weeklyEmission_for_period.sub(corrected_rebaseAmount).sub(teamEmission_corrected);
console.log("\n--- Predicted Distribution (based on contract's flawed rebase) ---");
console.log(" Predicted Rebase to Distributor:", formatBN(rebaseAmount_from_contract_calc));
console.log(" Predicted Emission to Team:", formatBN(teamEmission_contract));
console.log(" Predicted Emission to Gauges:", formatBN(gaugeEmission_contract));
console.log("\n--- Predicted Distribution (based on CORRECTED rebase) ---");
console.log(" Predicted Rebase to Distributor (Corrected):", formatBN(corrected_rebaseAmount));
console.log(" Predicted Emission to Team (Corrected):", formatBN(teamEmission_corrected));
console.log(" Predicted Emission to Gauges (Corrected):", formatBN(gaugeEmission_corrected));
// Execute the minting period update
await minter.connect(deployer).update_period();
const rewardsDistributor_bal_after_mint = await blackToken.balanceOf(rewardsDistributorMock.address);
const team_bal_after_mint = await blackToken.balanceOf(minterTeamAddress);
const gaugeManager_allowance_after_mint = await blackToken.allowance(minter.address, gaugeManagerMock.address);
const rebase_actually_paid = rewardsDistributor_bal_after_mint.sub(rewardsDistributor_bal_before_mint);
const team_actually_paid = team_bal_after_mint.sub(team_bal_before_mint);
const gauge_actually_approved = gaugeManager_allowance_after_mint.sub(gaugeManager_allowance_before_mint); // Assuming allowance starts at 0 or reset
console.log("\n--- Actual Distribution After Minter.update_period() ---");
console.log(" Actual Rebase Paid to RewardsDistributor:", formatBN(rebase_actually_paid));
console.log(" Actual Emission Paid to Team:", formatBN(team_actually_paid));
console.log(" Actual Emission Approved for GaugeManager:", formatBN(gauge_actually_approved));
// Assert that actual payments match the contract's flawed calculations
expect(rebase_actually_paid).to.equal(rebaseAmount_from_contract_calc, "Actual rebase paid should match contract's flawed calculation");
expect(team_actually_paid).to.equal(teamEmission_contract, "Actual team emission should match contract's calculation");
expect(gauge_actually_approved).to.equal(gaugeEmission_contract, "Actual gauge approval should match contract's calculation");
// Assert that gauge emission is higher than it should be
expect(gauge_actually_approved).to.be.gt(gaugeEmission_corrected, "Gauge emission is higher than it should be due to understated rebase");
const excessToGauges = gauge_actually_approved.sub(gaugeEmission_corrected);
expect(excessToGauges).to.equal(expected_misallocated_rebase, "Excess to gauges should equal the rebase misallocation");
});
});
contracts/mocks/GaugeManagerMock.sol:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
// Corrected path: go up one level from 'mocks' to 'contracts', then into 'interfaces'
import { IBlackGovernor } from "../interfaces/IBlackGovernor.sol";
contract GaugeManagerMock {
address public blackGovernor;
uint256 public lastRewardAmount; // Added to observe notified amount
function notifyRewardAmount(uint256 amount) external {
lastRewardAmount = amount;
}
function getBlackGovernor() external view returns (address) {
return blackGovernor;
}
function setBlackGovernor(address _gov) external { // Added for setup convenience
blackGovernor = _gov;
}
}
contracts/mocks/RewardsDistributorMock.sol:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract RewardsDistributorMock {
// event TokenCheckpointed(); // Optional: if you want to verify it's called
function checkpoint_token() external {
// emit TokenCheckpointed(); // Optional
}
}
contracts/mocks/BlackGovernorMock.sol:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
// Assuming IBlackGovernor.sol is in contracts/interfaces/
// Corrected path: go up one level from 'mocks' to 'contracts', then into 'interfaces'
import { IBlackGovernor } from "../interfaces/IBlackGovernor.sol";
contract BlackGovernorMock {
IBlackGovernor.ProposalState public mockProposalState = IBlackGovernor.ProposalState.Pending;
function status() external view returns (IBlackGovernor.ProposalState) {
return mockProposalState;
}
// Helper to change state for testing if needed
function setMockProposalState(IBlackGovernor.ProposalState _newState) external {
mockProposalState = _newState;
}
}
Status: Mitigation confirmed. Full details in reports from lonelybones, rayss and maxvzuvex.
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
What the attacker needed
SmNFTs exist (smNFTBalance > 0); A new minting period is triggered
The fix
The circulatingBlack calculation should be corrected to subtract only _veTotal from _blackTotal, removing the double subtraction of _smNFTBalance.
How it was found
- Deploy core contracts and mocks.
- Create a standard veNFT lock and a Supermassive NFT (smNFT), triggering the BLACK token burn for the smNFT.
- Advance time to enable a new minting period via MinterUpgradeable.update_period().
- Compare the contract's calculate_rebase() result with a manually corrected calculation.
- Call update_period() to perform minting and distribution, then verify that the rebase paid to RewardsDistributor matches the flawed lower value and that gauge emissions are higher than they should be.
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.
When you create a special NFT (smNFT), the protocol burns some BLACK tokens, reducing the total supply. The minter contract then calculates how many tokens to distribute as rewards (rebase) by subtracting the amount locked in voting escrow and the smNFT balance from the total supply. But because the total supply already excludes the burned smNFT tokens, subtracting the smNFT balance again makes the circulating supply look smaller than it is, so the rebase reward is too low and more tokens go to gauge emissions instead.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.