level 2 Fallout
이번엔 그냥 remix를 사용해보는 느낌
// 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];
}
}
사실 문제라기 보단 경각심 유도에 가깝지 않나 싶다. constructor는 컨트랙트와 동일한 이름으로도 선언이 가능한데 이때 오타가 나서 취약점이 생기는 예제이다. 이 문제를 풀게 된 개발자들 여러분은 코드 작성을 신중히 하길 바란다. ㅎㅇㅌ