-
-
Save Austin-Williams/3e757dccd62d329401c26e287c0b9dae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
/** | |
* @title Bypasser | |
* @dev Bypasser is a malicious SimpleTimelock beneficiary that | |
* allows the owner to divest before the timelock has expired. | |
*/ | |
contract Bypasser { | |
// owner of the contract | |
address payable public owner; | |
// price required to purchase ownership from current owner | |
uint256 public price; | |
// only owner can call functions with this modifier | |
modifier onlyOwner() { | |
require(msg.sender == owner, "only owner can call this"); | |
_; | |
} | |
// accept ETH | |
function () external payable {} | |
constructor() public { | |
owner = msg.sender; | |
} | |
// allows current owner to collect any ETH in this contract | |
function collect() external onlyOwner { | |
owner.transfer(address(this).balance); | |
} | |
// allows the current owner to set the price of buying ownership | |
function setPrice(uint256 newPrice) external payable onlyOwner { | |
price = newPrice; | |
} | |
// allows anyone willing to pay the `price` to become the new owner | |
function buyOwnership() external payable { | |
require(price != 0, "cannot buy ownership when the price is 0"); | |
require(msg.value >= price, "did not send enough funds"); | |
uint256 pricePaid = price; | |
address payable oldOwner = owner; | |
// set price to zero | |
price = 0; | |
// set new owner | |
owner = msg.sender; | |
// pay the old owner | |
oldOwner.transfer(pricePaid); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think
uint256 pricePaid = price;
should becomeuint256 pricePaid = msg.value;