Claiming rewards in GovernanceHYBR will always revert
The claimRewards function in GovernanceHYBR.sol calls a voter contract getter with only a token ID, but the underlying mapping requires both an ID and an index, so the call always reverts. As a result, the operator can never claim rewards, leaving the function completely broken.
Submitted by OpaBatyo, also found by 0xvd and harry
GovernanceHYBR.sol #L370
Details
When the operator claims rewards in GovernanceHYBR.sol, the function attempts to fetch the voted pools aray from the voter contract:
// Claim bribes from voted pools
address[] memory votedPools = IVoter(voter).poolVote(veTokenId);
This line will always revert and the function is broken. It attempts to fetch the addresses array from a mapping in VoterV3.sol:
mapping(uint256 => address[]) public poolVote;
This will not work - the way solidity auto-generates a getter for a mapping is using an id and index. Although this exists in the interface, it is not used correctly in the function to claim itself:
function poolVote(uint id, uint _index) external view returns(address _pair); // correct way to be fetched
But the way it’s fetched in claimRewards() will not work since solidity cannot return an addresses array using only the tokenId of the mapping.
Impact
Function is completely broken.
Mitigation
Add a getter function in VoterV3.sol that returns an array of addresses and use that instead when claiming rewards:
function getPoolVote(uint tokenId) external view returns (address[] memory) {
return poolVote[tokenId];
}
Proof of concept
-
Copy
MockERC20.solfromcl/contracts/mocks/tove33/contracts/test/ -
Change
MockERC20.solsolc version topragma solidity ^0.8.0;for tests to run and import it inC4PoCTestbed.t.sol -
Paste following in
C4PoCTestbed.t.solcontract level:contract C4PoCTestbed is Test, CLContractsImporter { ... address public USDC; address public USDT; address public DAI; address public gHybrOperator; -
Paste the following function to
C4PoCTestbed.t.solto initialize parameters.function lastPhase() internal { // Deploy USDC, USDT, DAI, and WETH USDC = address(new MockERC20("USDC", "USDC", 6)); USDT = address(new MockERC20("USDT", "USDT", 6)); DAI = address(new MockERC20("DAI", "DAI", 18)); // We need to initialize Bribe Factory properly for the tests to run bribeFactoryV3.initialize(address(voter), address(gaugeManager), address(permissionsRegistry), address(tokenHandler)); // We need to set roles so that we can whitelist the mock tokens permissionsRegistry.setRoleFor(address(team), "GOVERNANCE"); // Whitelisting the mock tokens vm.startPrank(address(team)); tokenHandler.whitelistToken(address(USDC)); tokenHandler.whitelistToken(address(USDT)); tokenHandler.whitelistToken(address(DAI)); tokenHandler.whitelistConnector(address(USDC)); tokenHandler.whitelistConnector(address(USDT)); tokenHandler.whitelistConnector(address(DAI)); vm.stopPrank(); // Creating the pools address pairA = thenaFiFactory.createPair(address(USDC), address(USDT), true); address pairB = thenaFiFactory.createPair(address(USDC), address(DAI), true); // Creating the gauges gaugeManager.createGauge(pairA, 0); gaugeManager.createGauge(pairB, 0); // Set Voter and operator on GrowthHYBR gHybr.setVoter(address(voter)); gHybr.setOperator(address(gHybrOperator)); } -
Paste the following in the
C4PoCTestbed.t.sol’ssetUp()functionfunction setUp() public virtual { ... gHybrOperator = makeAddr("operator"); ... lastPhase(); } -
Add this test to
C4PoC.t.solfunction testMappingRevert() external { // Deal Alice tokens and deposit address alice = makeAddr("alice"); deal(address(hybr), address(alice), 100e18); vm.startPrank(alice); hybr.approve(address(gHybr), type(uint256).max); gHybr.deposit(100e18, address(alice)); // Warp 1 week vm.warp(block.timestamp + 1 weeks + 301); // Voting for pools with gHYBR NFT address[] memory poolVotes = thenaFiFactory.pairs(); uint256[] memory weights = new uint256[](poolVotes.length); weights[0] = 50; weights[1] = 50; vm.startPrank(address(gHybrOperator)); gHybr.vote(poolVotes, weights); // Warp more time vm.warp(block.timestamp + 48 hours); // Attempt to claim rewards vm.startPrank(address(gHybrOperator)); vm.expectRevert(); gHybr.claimRewards(); }Run with
forge test --mt testMappingRevert -vvvv
fixed Claiming rewards in GovernanceHYBR
Status: Mitigation confirmed. Full details in the mitigation review reports from niffylord, rayss, and ZanyBonzy.
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
The code called a mapping getter with only the token ID, but Solidity auto-generated getters for mappings require both the key and an index, so the call reverted.
Impact
The claimRewards function is completely broken and cannot be used to claim rewards.
What the attacker needed
Operator role; voted pools exist
The fix
A getter function should be added to VoterV3.sol that returns the full array of voted pools, and claimRewards should use that instead.
How it was found
- Copy MockERC20.sol into the test directory and adjust its Solidity version.
- Import MockERC20 into the test bed and add state variables for tokens and an operator.
- Deploy mock tokens, whitelist them, create pools and gauges, and set the voter and operator.
- In setUp, create an operator address and call the initialization function.
- Write a test that deposits tokens, votes for pools, and then calls claimRewards expecting a revert.
- Run the test with forge test.
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.
A smart contract tried to read a list of pools from another contract, but it used the wrong way to ask for that list. The other contract only knows how to return one item at a time when given two numbers, so the request always failed. This meant a key function for collecting rewards could never work.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.