input
stringlengths 32
47.6k
| output
stringclasses 657
values |
---|---|
pragma solidity 0.4.26;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender)
external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value)
external returns (bool);
function transferFrom(address from, address to, uint256 value)
external returns (bool);
event Transfer(
address indexed from,
address indexed to,
uint256 value
);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
contract Ownable {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
/**
* @return the address of the owner.
*/
function owner() public view returns(address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner());
_;
}
/**
* @return true if `msg.sender` is the owner of the contract.
*/
function isOwner() public view returns(bool) {
return msg.sender == _owner;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* @notice Renouncing to ownership will leave the contract without an owner.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
* Don't use this function.
*/
/*
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
*/
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0));
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
}
contract Stoppable is Ownable{
bool public stopped = false;
modifier enabled {
require (!stopped);
_;
}
function stop() external onlyOwner {
stopped = true;
}
function start() external onlyOwner {
stopped = false;
}
}
contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(
address owner,
address spender
)
public
view
returns (uint256)
{
return _allowed[owner][spender];
}
/**
* @dev Transfer token for a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
require(spender != address(0));
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(
address from,
address to,
uint256 value
)
public
returns (bool)
{
require(value <= _allowed[from][msg.sender]);
_allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
_transfer(from, to, value);
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed_[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(
address spender,
uint256 addedValue
)
public
returns (bool)
{
require(spender != address(0));
_allowed[msg.sender][spender] = (
_allowed[msg.sender][spender].add(addedValue));
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed_[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(
address spender,
uint256 subtractedValue
)
public
returns (bool)
{
require(spender != address(0));
_allowed[msg.sender][spender] = (
_allowed[msg.sender][spender].sub(subtractedValue));
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(value <= _balances[from]);
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != 0);
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != 0);
require(value <= _balances[account]);
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
require(value <= _allowed[account][msg.sender]);
// Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted,
// this function needs to emit an event with the updated approval.
_allowed[account][msg.sender] = _allowed[account][msg.sender].sub(
value);
_burn(account, value);
}
}
contract ERC20Burnable is ERC20 {
/**
* @dev Burns a specific amount of tokens.
* @param value The amount of token to be burned.
*/
function burn(uint256 value) public {
_burn(msg.sender, value);
}
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param from address The address which you want to send tokens from
* @param value uint256 The amount of token to be burned
*/
/*
--Do not use
function burnFrom(address from, uint256 value) public {
_burnFrom(from, value);
//Only the owner's address can be burned. @ejkang
}
*/
}
contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
constructor(string name, string symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
/**
* @return the name of the token.
*/
function name() public view returns(string) {
return _name;
}
/**
* @return the symbol of the token.
*/
function symbol() public view returns(string) {
return _symbol;
}
/**
* @return the number of decimals of the token.
*/
function decimals() public view returns(uint8) {
return _decimals;
}
}
contract BMPToken is ERC20Detailed, ERC20Burnable, Stoppable {
constructor (
string memory name,
string memory symbol,
uint256 totalSupply,
uint8 decimals
) ERC20Detailed(name, symbol, decimals)
public {
_mint(owner(), totalSupply * 10**uint(decimals));
}
// Don't accept ETH
function () payable external {
revert();
}
//------------------------
// Lock account transfer
mapping (address => uint256) private _lockTimes;
mapping (address => uint256) private _lockAmounts;
event LockChanged(address indexed account, uint256 releaseTime, uint256 amount);
/// Lock user amount. (run only owner)
/// @param account account to lock
/// @param releaseTime Time to release from lock state.
/// @param amount amount to lock.
/// @return Boolean
function setLock(address account, uint256 releaseTime, uint256 amount) onlyOwner public {
//require(now < releaseTime, "ERC20 : Current time is greater than release time");
require(block.timestamp < releaseTime, "ERC20 : Current time is greater than release time");
require(amount != 0, "ERC20: Amount error");
_lockTimes[account] = releaseTime;
_lockAmounts[account] = amount;
emit LockChanged( account, releaseTime, amount );
}
/// Get Lock information (run anyone)
/// @param account user acount
/// @return lokced time and locked amount.
function getLock(address account) public view returns (uint256 lockTime, uint256 lockAmount) {
return (_lockTimes[account], _lockAmounts[account]);
}
/// Check lock state (run anyone)
/// @param account user acount
/// @param amount amount to check.
/// @return Boolean : Don't use balance (true)
function _isLocked(address account, uint256 amount) internal view returns (bool) {
return _lockAmounts[account] != 0 &&
_lockTimes[account] > block.timestamp &&
(
balanceOf(account) <= _lockAmounts[account] ||
balanceOf(account).sub(_lockAmounts[account]) < amount
);
}
/// Transfer token (run anyone)
/// @param recipient Token trasfer destination acount.
/// @param amount Token transfer amount.
/// @return Boolean
function transfer(address recipient, uint256 amount) enabled public returns (bool) {
require( !_isLocked( msg.sender, amount ) , "ERC20: Locked balance");
return super.transfer(recipient, amount);
}
/// Transfer token (run anyone)
/// @param sender Token trasfer source acount.
/// @param recipient Token transfer destination acount.
/// @param amount Token transfer amount.
/// @return Boolean
function transferFrom(address sender, address recipient, uint256 amount) enabled public returns (bool) {
require( !_isLocked( sender, amount ) , "ERC20: Locked balance");
return super.transferFrom(sender, recipient, amount);
}
/// Decrease token balance (run only owner)
/// @param value Amount to decrease.
function burn(uint256 value) onlyOwner public {
require( !_isLocked( msg.sender, value ) , "ERC20: Locked balance");
super.burn(value);
}
}
| These are the vulnerabilities found
1) locked-ether with Medium impact |
pragma solidity 0.6.5;
pragma experimental ABIEncoderV2;
interface ERC20 {
function approve(address, uint256) external returns (bool);
function transfer(address, uint256) external returns (bool);
function transferFrom(address, address, uint256) external returns (bool);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address) external view returns (uint256);
}
interface ProtocolAdapter {
/**
* @dev MUST return "Asset" or "Debt".
* SHOULD be implemented by the public constant state variable.
*/
function adapterType() external pure returns (string memory);
/**
* @dev MUST return token type (default is "ERC20").
* SHOULD be implemented by the public constant state variable.
*/
function tokenType() external pure returns (string memory);
/**
* @dev MUST return amount of the given token locked on the protocol by the given account.
*/
function getBalance(address token, address account) external view returns (uint256);
}
contract CurveStakingAdapter is ProtocolAdapter {
string public constant override adapterType = "Asset";
string public constant override tokenType = "ERC20";
address internal constant C_CRV = 0x845838DF265Dcd2c412A1Dc9e959c7d08537f8a2;
address internal constant Y_CRV = 0xdF5e0e81Dff6FAF3A7e52BA697820c5e32D806A8;
address internal constant B_CRV = 0x3B3Ac5386837Dc563660FB6a0937DFAa5924333B;
address internal constant S_CRV = 0xC25a3A3b969415c80451098fa907EC722572917F;
address internal constant P_CRV = 0xD905e2eaeBe188fc92179b6350807D8bd91Db0D8;
address internal constant THREE_CRV = 0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490;
address internal constant RENBTC_CRV = 0x49849C98ae39Fff122806C06791Fa73784FB3675;
address internal constant SBTC_CRV = 0x075b1bb99792c9E1041bA13afEf80C91a1e70fB3;
address internal constant HBTC_CRV = 0xb19059ebb43466C323583928285a49f558E572Fd;
address internal constant HUSD_CRV = 0x5B5CFE992AdAC0C9D48E05854B2d91C73a003858;
address internal constant USDK_CRV = 0x97E2768e8E73511cA874545DC5Ff8067eB19B787;
address internal constant USDN_CRV = 0x4f3E8F405CF5aFC05D68142F3783bDfE13811522;
address internal constant C_GAUGE = 0x7ca5b0a2910B33e9759DC7dDB0413949071D7575;
address internal constant Y_GAUGE = 0xFA712EE4788C042e2B7BB55E6cb8ec569C4530c1;
address internal constant B_GAUGE = 0x69Fb7c45726cfE2baDeE8317005d3F94bE838840;
address internal constant S_GAUGE = 0xA90996896660DEcC6E997655E065b23788857849;
address internal constant P_GAUGE = 0x64E3C23bfc40722d3B649844055F1D51c1ac041d;
address internal constant THREE_GAUGE = 0xbFcF63294aD7105dEa65aA58F8AE5BE2D9d0952A;
address internal constant RENBTC_GAUGE = 0xB1F2cdeC61db658F091671F5f199635aEF202CAC;
address internal constant SBTC_GAUGE = 0x705350c4BcD35c9441419DdD5d2f097d7a55410F;
address internal constant HBTC_GAUGE = 0x4c18E409Dc8619bFb6a1cB56D114C3f592E0aE79;
address internal constant HUSD_GAUGE = 0x2db0E83599a91b508Ac268a6197b8B14F5e72840;
address internal constant USDK_GAUGE = 0xC2b1DF84112619D190193E48148000e3990Bf627;
address internal constant USDN_GAUGE = 0xF98450B5602fa59CC66e1379DFfB6FDDc724CfC4;
/**
* @return Amount of staked LP tokens for a given account.
* @dev Implementation of ProtocolAdapter interface function.
*/
function getBalance(address token, address account) external view override returns (uint256) {
if (token == C_CRV) {
return ERC20(C_GAUGE).balanceOf(account);
} else if (token == Y_CRV) {
return ERC20(Y_GAUGE).balanceOf(account);
} else if (token == B_CRV) {
return ERC20(B_GAUGE).balanceOf(account);
} else if (token == S_CRV) {
return ERC20(S_GAUGE).balanceOf(account);
} else if (token == P_CRV) {
return ERC20(P_GAUGE).balanceOf(account);
} else if (token == THREE_CRV) {
return ERC20(THREE_GAUGE).balanceOf(account);
} else if (token == RENBTC_CRV) {
return ERC20(RENBTC_GAUGE).balanceOf(account);
} else if (token == SBTC_CRV) {
return ERC20(SBTC_GAUGE).balanceOf(account);
} else if (token == HBTC_CRV) {
return ERC20(HBTC_GAUGE).balanceOf(account);
} else if (token == HUSD_CRV) {
return ERC20(HUSD_GAUGE).balanceOf(account);
} else if (token == USDK_CRV) {
return ERC20(USDK_GAUGE).balanceOf(account);
} else if (token == USDN_CRV) {
return ERC20(USDN_GAUGE).balanceOf(account);
} else {
return 0;
}
}
}
| No vulnerabilities found |
pragma solidity 0.6.5;
pragma experimental ABIEncoderV2;
struct ProtocolBalance {
ProtocolMetadata metadata;
AdapterBalance[] adapterBalances;
}
struct ProtocolMetadata {
string name;
string description;
string websiteURL;
string iconURL;
uint256 version;
}
struct AdapterBalance {
AdapterMetadata metadata;
FullTokenBalance[] balances;
}
struct AdapterMetadata {
address adapterAddress;
string adapterType; // "Asset", "Debt"
}
struct FullTokenBalance {
TokenBalance base;
TokenBalance[] underlying;
}
struct TokenBalance {
TokenMetadata metadata;
uint256 amount;
}
struct TokenMetadata {
address token;
string name;
string symbol;
uint8 decimals;
}
struct Component {
address token;
string tokenType; // "ERC20" by default
uint256 rate; // price per full share (1e18)
}
interface ERC20 {
function approve(address, uint256) external returns (bool);
function transfer(address, uint256) external returns (bool);
function transferFrom(address, address, uint256) external returns (bool);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address) external view returns (uint256);
}
interface TokenAdapter {
/**
* @dev MUST return TokenMetadata struct with ERC20-style token info.
* struct TokenMetadata {
* address token;
* string name;
* string symbol;
* uint8 decimals;
* }
*/
function getMetadata(address token) external view returns (TokenMetadata memory);
/**
* @dev MUST return array of Component structs with underlying tokens rates for the given token.
* struct Component {
* address token; // Address of token contract
* string tokenType; // Token type ("ERC20" by default)
* uint256 rate; // Price per share (1e18)
* }
*/
function getComponents(address token) external view returns (Component[] memory);
}
interface SetTokenV2 {
function getTotalComponentRealUnits(address) external view returns (int256);
function getComponents() external view returns(address[] memory);
}
contract TokenSetsV2TokenAdapter is TokenAdapter {
/**
* @return TokenMetadata struct with ERC20-style token info.
* @dev Implementation of TokenAdapter interface function.
*/
function getMetadata(address token) external view override returns (TokenMetadata memory) {
return TokenMetadata({
token: token,
name: ERC20(token).name(),
symbol: ERC20(token).symbol(),
decimals: ERC20(token).decimals()
});
}
/**
* @return Array of Component structs with underlying tokens rates for the given token.
* @dev Implementation of TokenAdapter interface function.
*/
function getComponents(address token) external view override returns (Component[] memory) {
address[] memory components = SetTokenV2(token).getComponents();
Component[] memory underlyingTokens = new Component[](components.length);
for (uint256 i = 0; i < underlyingTokens.length; i++) {
underlyingTokens[i] = Component({
token: components[i],
tokenType: "ERC20",
rate: uint256(SetTokenV2(token).getTotalComponentRealUnits(components[i]))
});
}
return underlyingTokens;
}
}
| No vulnerabilities found |
pragma solidity 0.5.16;
interface IEnergiTokenProxy {
function proxyOwner() external view returns (address);
function delegate() external view returns (address);
function setProxyOwner(address _owner) external;
function upgradeDelegate(address _delegate) external;
}
contract EnergiTokenProxy is IEnergiTokenProxy {
address public delegate;
address public proxyOwner;
modifier onlyProxyOwner {
require(msg.sender == proxyOwner, 'EnergiTokenProxy: FORBIDDEN');
_;
}
constructor(address _owner, address _delegate) public {
proxyOwner = _owner;
delegate = _delegate;
}
function setProxyOwner(address _owner) external onlyProxyOwner {
proxyOwner = _owner;
}
function upgradeDelegate(address _delegate) external onlyProxyOwner {
delegate = _delegate;
}
function () external payable {
address _delegate = delegate;
require(_delegate != address(0));
assembly {
let ptr := mload(0x40)
calldatacopy(ptr, 0, calldatasize)
let result := delegatecall(gas, _delegate, ptr, calldatasize, 0, 0)
let size := returndatasize
returndatacopy(ptr, 0, size)
switch result
case 0 { revert(ptr, size) }
default { return(ptr, size) }
}
}
}
| These are the vulnerabilities found
1) locked-ether with Medium impact |
pragma solidity 0.6.5;
pragma experimental ABIEncoderV2;
struct ProtocolBalance {
ProtocolMetadata metadata;
AdapterBalance[] adapterBalances;
}
struct ProtocolMetadata {
string name;
string description;
string websiteURL;
string iconURL;
uint256 version;
}
struct AdapterBalance {
AdapterMetadata metadata;
FullTokenBalance[] balances;
}
struct AdapterMetadata {
address adapterAddress;
string adapterType; // "Asset", "Debt"
}
struct FullTokenBalance {
TokenBalance base;
TokenBalance[] underlying;
}
struct TokenBalance {
TokenMetadata metadata;
uint256 amount;
}
struct TokenMetadata {
address token;
string name;
string symbol;
uint8 decimals;
}
struct Component {
address token;
string tokenType; // "ERC20" by default
uint256 rate; // price per full share (1e18)
}
interface ERC20 {
function approve(address, uint256) external returns (bool);
function transfer(address, uint256) external returns (bool);
function transferFrom(address, address, uint256) external returns (bool);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address) external view returns (uint256);
}
interface TokenAdapter {
/**
* @dev MUST return TokenMetadata struct with ERC20-style token info.
* struct TokenMetadata {
* address token;
* string name;
* string symbol;
* uint8 decimals;
* }
*/
function getMetadata(address token) external view returns (TokenMetadata memory);
/**
* @dev MUST return array of Component structs with underlying tokens rates for the given token.
* struct Component {
* address token; // Address of token contract
* string tokenType; // Token type ("ERC20" by default)
* uint256 rate; // Price per share (1e18)
* }
*/
function getComponents(address token) external view returns (Component[] memory);
}
interface CurveRegistry {
function getSwapAndTotalCoins(address) external view returns (address, uint256);
function getName(address) external view returns (string memory);
}
interface stableswap {
function coins(int128) external view returns (address);
function coins(uint256) external view returns (address);
function balances(int128) external view returns (uint256);
function balances(uint256) external view returns (uint256);
}
contract CurveTokenAdapter is TokenAdapter {
address internal constant REGISTRY = 0x86A1755BA805ecc8B0608d56c22716bd1d4B68A8;
address internal constant CDAI = 0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643;
address internal constant CUSDC = 0x39AA39c021dfbaE8faC545936693aC917d5E7563;
address internal constant YDAIV2 = 0x16de59092dAE5CcF4A1E6439D611fd0653f0Bd01;
address internal constant YUSDCV2 = 0xd6aD7a6750A7593E092a9B218d66C0A814a3436e;
address internal constant YUSDTV2 = 0x83f798e925BcD4017Eb265844FDDAbb448f1707D;
address internal constant YTUSDV2 = 0x73a052500105205d34Daf004eAb301916DA8190f;
address internal constant YDAIV3 = 0xC2cB1040220768554cf699b0d863A3cd4324ce32;
address internal constant YUSDCV3 = 0x26EA744E5B887E5205727f55dFBE8685e3b21951;
address internal constant YUSDTV3 = 0xE6354ed5bC4b393a5Aad09f21c46E101e692d447;
address internal constant YBUSDV3 = 0x04bC0Ab673d88aE9dbC9DA2380cB6B79C4BCa9aE;
address internal constant YCDAI = 0x99d1Fa417f94dcD62BfE781a1213c092a47041Bc;
address internal constant YCUSDC = 0x9777d7E2b60bB01759D0E2f8be2095df444cb07E;
address internal constant YCUSDT = 0x1bE5d71F2dA660BFdee8012dDc58D024448A0A59;
address internal constant THREE_CRV = 0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490;
address internal constant HBTC_CRV = 0xb19059ebb43466C323583928285a49f558E572Fd;
/**
* @return TokenMetadata struct with ERC20-style token info.
* @dev Implementation of TokenAdapter interface function.
*/
function getMetadata(address token) external view override returns (TokenMetadata memory) {
return TokenMetadata({
token: token,
name: getPoolName(token),
symbol: ERC20(token).symbol(),
decimals: ERC20(token).decimals()
});
}
/**
* @return Array of Component structs with underlying tokens rates for the given token.
* @dev Implementation of TokenAdapter interface function.
*/
function getComponents(address token) external view override returns (Component[] memory) {
(address swap, uint256 totalCoins) = CurveRegistry(REGISTRY).getSwapAndTotalCoins(token);
Component[] memory underlyingComponents = new Component[](totalCoins);
address underlyingToken;
if (token == THREE_CRV || token == HBTC_CRV) {
for (uint256 i = 0; i < totalCoins; i++) {
underlyingToken = stableswap(swap).coins(i);
underlyingComponents[i] = Component({
token: underlyingToken,
tokenType: getTokenType(underlyingToken),
rate: stableswap(swap).balances(i) * 1e18 / ERC20(token).totalSupply()
});
}
} else {
for (uint256 i = 0; i < totalCoins; i++) {
underlyingToken = stableswap(swap).coins(int128(i));
underlyingComponents[i] = Component({
token: underlyingToken,
tokenType: getTokenType(underlyingToken),
rate: stableswap(swap).balances(int128(i)) * 1e18 / ERC20(token).totalSupply()
});
}
}
return underlyingComponents;
}
/**
* @return Pool name.
*/
function getPoolName(address token) internal view returns (string memory) {
return CurveRegistry(REGISTRY).getName(token);
}
function getTokenType(address token) internal pure returns (string memory) {
if (token == CDAI || token == CUSDC) {
return "CToken";
} else if (
token == YDAIV2 ||
token == YUSDCV2 ||
token == YUSDTV2 ||
token == YTUSDV2 ||
token == YDAIV3 ||
token == YUSDCV3 ||
token == YUSDTV3 ||
token == YBUSDV3 ||
token == YCDAI ||
token == YCUSDC ||
token == YCUSDT
) {
return "YToken";
} else {
return "ERC20";
}
}
}
| No vulnerabilities found |
pragma solidity 0.4.26;
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address who) external view returns (uint256);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through `transferFrom`. This is
* zero by default.
*
* This value changes when `approve` or `transferFrom` are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a `Transfer` event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* > Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an `Approval` event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a `Transfer` event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to `approve`. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public {
_owner = msg.sender;
}
/**
* @return the address of the owner.
*/
function owner() public view returns(address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_isOwner());
_;
}
/**
* @return true if `msg.sender` is the owner of the contract.
*/
function _isOwner() internal view returns(bool) {
return msg.sender == _owner;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0));
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
}
contract Stoppable is Ownable{
bool public stopped = false;
modifier enabled {
require (!stopped);
_;
}
function stop() external onlyOwner {
stopped = true;
}
function start() external onlyOwner {
stopped = false;
}
}
contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token for a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
require(value <= _balances[msg.sender], "ERC20: Overdrawn balance");
require(to != address(0));
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
require(spender != address(0));
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
require(value <= _balances[from], "ERC20: Overdrawn balance");
require(value <= _allowed[from][msg.sender]);
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
emit Transfer(from, to, value);
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed_[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
require(spender != address(0));
_allowed[msg.sender][spender] = (_allowed[msg.sender][spender].add(addedValue));
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed_[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
require(spender != address(0));
_allowed[msg.sender][spender] = (_allowed[msg.sender][spender].sub(subtractedValue));
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
return true;
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param amount The amount that will be created.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param amount The amount that will be burnt.
*/
function _burn(address account, uint256 amount) internal {
require(account != address(0));
require(amount <= _balances[account], "ERC20: Overdrawn balance");
_totalSupply = _totalSupply.sub(amount);
_balances[account] = _balances[account].sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* @param account The account whose tokens will be burnt.
* @param amount The amount that will be burnt.
*/
function _burnFrom(address account, uint256 amount) internal {
require(amount <= _allowed[account][msg.sender], "ERC20: Overdrawn balance");
// Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted,
// this function needs to emit an event with the updated approval.
_allowed[account][msg.sender] = _allowed[account][msg.sender].sub(amount);
_burn(account, amount);
}
}
contract ERC20Burnable is ERC20 {
/**
* @dev Burns a specific amount of tokens.
* @param value The amount of token to be burned.
*/
function burn(uint256 value) public {
_burn(msg.sender, value);
}
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param from address The address which you want to send tokens from
* @param value uint256 The amount of token to be burned
*/
function burnFrom(address from, uint256 value) public {
_burnFrom(from, value);
}
/**
* @dev Overrides ERC20._burn in order for burn and burnFrom to emit
* an additional Burn event.
*/
function _burn(address who, uint256 value) internal {
super._burn(who, value);
}
}
contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
constructor(string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
/**
* @return the name of the token.
*/
function name() public view returns(string memory) {
return _name;
}
/**
* @return the symbol of the token.
*/
function symbol() public view returns(string memory) {
return _symbol;
}
/**
* @return the number of decimals of the token.
*/
function decimals() public view returns(uint8) {
return _decimals;
}
}
contract AXTToken is ERC20Detailed, /*ERC20,*/ ERC20Burnable, Stoppable {
constructor (
string memory name,
string memory symbol,
uint256 totalSupply,
uint8 decimals
) ERC20Detailed(name, symbol, decimals)
public {
_mint(owner(), totalSupply * 10**uint(decimals));
}
// Don't accept ETH
function () payable external {
revert();
}
function mint(address account, uint256 amount) public onlyOwner returns (bool) {
_mint(account, amount);
return true;
}
//------------------------
// Lock account transfer
mapping (address => uint256) private _lockTimes;
mapping (address => uint256) private _lockAmounts;
event LockChanged(address indexed account, uint256 releaseTime, uint256 amount);
function setLock(address account, uint256 releaseTime, uint256 amount) onlyOwner public {
_lockTimes[account] = releaseTime;
_lockAmounts[account] = amount;
emit LockChanged( account, releaseTime, amount );
}
function getLock(address account) public view returns (uint256 lockTime, uint256 lockAmount) {
return (_lockTimes[account], _lockAmounts[account]);
}
function _isLocked(address account, uint256 amount) internal view returns (bool) {
return _lockTimes[account] != 0 &&
_lockAmounts[account] != 0 &&
_lockTimes[account] > block.timestamp &&
(
balanceOf(account) <= _lockAmounts[account] ||
balanceOf(account).sub(_lockAmounts[account]) < amount
);
}
function transfer(address recipient, uint256 amount) enabled public returns (bool) {
require( !_isLocked( msg.sender, amount ) , "ERC20: Locked balance");
return super.transfer(recipient, amount);
}
function transferFrom(address sender, address recipient, uint256 amount) enabled public returns (bool) {
require( !_isLocked( sender, amount ) , "ERC20: Locked balance");
return super.transferFrom(sender, recipient, amount);
}
}
| These are the vulnerabilities found
1) locked-ether with Medium impact |
pragma solidity 0.5.17;
library Address {
/**
* Returns whether the target address is a contract
* @dev This function will return false if invoked during the constructor of a contract,
* as the code is not actually created until after the constructor finishes.
* @param account address to check
* @return whether the target address is a contract
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
}
contract ERC20Interface {
function balanceOf(address tokenOwner) public view returns (uint256 balance);
function allowance(address tokenOwner, address spender) public view returns (uint256 remaining);
function transfer(address to, uint256 tokens) public returns (bool success);
function approve(address spender, uint256 tokens) public returns (bool success);
function transferFrom(address from, address to, uint256 tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint256 tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint256 tokens);
}
library SafeMath {
/**
The MIT License (MIT)
Copyright (c) 2016-2020 zOS Global Limited
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a && c >= b);
return c;
}
}
interface TokenRecipient {
function receiveApproval(address _from, uint256 _value, address _token, bytes calldata _extraData) external;
function tokenFallback(address _from, uint256 _value, bytes calldata _data) external;
}
contract Ownership {
address public owner;
event OwnershipUpdated(address oldOwner, address newOwner);
constructor() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
/**
* @dev Transfer the ownership to some other address.
* new owner can not be a zero address.
* Only owner can call this function
* @param _newOwner Address to which ownership is being transferred
*/
function updateOwner(address _newOwner)
public
onlyOwner
{
require(_newOwner != address(0x0), "Invalid address");
owner = _newOwner;
emit OwnershipUpdated(msg.sender, owner);
}
/**
* @dev Renounce the ownership.
* This will leave the contract without any owner.
* Only owner can call this function
* @param _validationCode A code to prevent aaccidental calling of this function
*/
function renounceOwnership(uint _validationCode)
public
onlyOwner
{
require(_validationCode == 123456789, "Invalid code");
owner = address(0);
emit OwnershipUpdated(msg.sender, owner);
}
}
library SafeERC20 {
/**
The MIT License (MIT)
Copyright (c) 2016-2020 zOS Global Limited
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
using Address for address;
function safeTransfer(ERC20Interface token, address to, uint256 value) internal {
require(address(token).isContract(), "SafeERC20: call to non-contract");
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function _callOptionalReturn(ERC20Interface token, bytes memory data) private {
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
contract OToken is ERC20Interface, Ownership {
using SafeMath for uint256;
using Address for address;
using SafeERC20 for ERC20Interface;
// State variables
string public constant name = 'O Token'; // Name of token
string public constant symbol = 'OT'; // Symbol of token
uint256 public constant decimals = 8; // Decimals in token
address public deputyOwner; // to perform tasks on behalf of owner in automated applications
uint256 public totalSupply = 0; // initially totalSupply 0
// external wallet addresses
address public suspenseWallet; // the contract resposible for burning tokens
address public centralRevenueWallet; // platform wallet to collect commission
address public minter; // adddress of minter
// to hold commissions on each token transfer
uint256 public commission_numerator; // commission percentage numerator
uint256 public commission_denominator;// commission percentage denominator
// mappings
mapping (address => uint256) balances; // balances mapping to hold OT balance of address
mapping (address => mapping (address => uint256) ) allowed; // mapping to hold allowances
mapping (address => bool) public isTaxFreeSender; // tokens transferred from these users won't be taxed
mapping (address => bool) public isTaxFreeRecipeint; // if token transferred to these addresses won't be taxed
mapping (string => mapping(string => bool)) public sawtoothHashMapping;
mapping (address => bool) public trustedContracts; // contracts on which tokenFallback will be called
// events
event MintOrBurn(address _from, address to, uint256 _token, string sawtoothHash, string orderId );
event CommssionUpdate(uint256 _numerator, uint256 _denominator);
event TaxFreeUserUpdate(address _user, bool _isWhitelisted, string _type);
event TrustedContractUpdate(address _contractAddress, bool _isActive);
event MinterUpdated(address _newMinter, address _oldMinter);
event SuspenseWalletUpdated(address _newSuspenseWallet, address _oldSuspenseWallet);
event DeputyOwnerUpdated(address _oldOwner, address _newOwner);
event CRWUpdated(address _newCRW, address _oldCRW);
constructor (address _minter, address _crw, address _newDeputyOwner)
public
onlyNonZeroAddress(_minter)
onlyNonZeroAddress(_crw)
onlyNonZeroAddress(_newDeputyOwner)
{
owner = msg.sender; // set owner address to be msg.sender
minter = _minter; // set minter address
centralRevenueWallet = _crw; // set central revenue wallet address
deputyOwner = _newDeputyOwner; // set deputy owner
commission_numerator = 1; // set commission
commission_denominator = 100;
// emit proper events
emit MinterUpdated(_minter, address(0));
emit CRWUpdated(_crw, address(0));
emit DeputyOwnerUpdated(_newDeputyOwner, address(0));
emit CommssionUpdate(1, 100);
}
// Modifiers
modifier canBurn() {
require(msg.sender == suspenseWallet, "only suspense wallet is allowed");
_;
}
modifier onlyMinter() {
require(msg.sender == minter,"only minter is allowed");
_;
}
modifier onlyDeputyOrOwner() {
require(msg.sender == owner || msg.sender == deputyOwner, "Only owner or deputy owner is allowed");
_;
}
modifier onlyNonZeroAddress(address _user) {
require(_user != address(0), "Zero address not allowed");
_;
}
modifier onlyValidSawtoothEntry(string memory _sawtoothHash, string memory _orderId) {
require(!sawtoothHashMapping[_sawtoothHash][_orderId], "Sawtooth hash amd orderId combination already used");
_;
}
////////////////////////////////////////////////////////////////
// Public Functions
////////////////////////////////////////////////////////////////
/**
* @notice Standard transfer function to Transfer token
* @dev The commission will be charged on top of _value
* @param _to recipient address
* @param _value amount of tokens to be transferred to recipient
* @return Bool value
*/
function transfer(address _to, uint256 _value) public returns (bool) {
return privateTransfer(msg.sender, _to, _value, false, false); // internal method
}
/**
* @notice Alternate method to standard transfer with fee deducted from transfer amount
* @dev The commission will be deducted from _value
* @param _to recipient address
* @param _value amount of tokens to be transferred to recipient
* @return Bool value
*/
function transferIncludingFee(address _to, uint256 _value)
public
onlyNonZeroAddress(_to)
returns(bool)
{
return privateTransfer(msg.sender, _to, _value, false, true);
}
/**
* @notice Bulk transfer
* @dev The commission will be charged on top of _value
* @param _addressArr array of recipient address
* @param _amountArr array of amounts corresponding to index on _addressArr
* @param _includingFees Denotes if fee should be deducted from amount or added to amount
* @return Bool value
*/
function bulkTransfer (address[] memory _addressArr, uint256[] memory _amountArr, bool _includingFees) public returns (bool) {
require(_addressArr.length == _amountArr.length, "Invalid params");
for(uint256 i = 0 ; i < _addressArr.length; i++){
uint256 _value = _amountArr[i];
address _to = _addressArr[i];
privateTransfer(msg.sender, _to, _value, false, _includingFees); // internal method
}
return true;
}
/**
* @notice Standard Approve function
* @dev This suffers from race condition. Use increaseApproval/decreaseApproval instead
* @param _spender The user which is allowed to spend on behalf of msg.sender
* @param _value amount of token allowed
* @return Bool value
*/
function approve(address _spender, uint256 _value) public returns (bool) {
return _approve(msg.sender, _spender, _value);
}
/**
* @notice Increase allowance
* @param _spender The user which is allowed to spend on behalf of msg.sender
* @param _addedValue amount by which allowance needs to be increased
* @return Bool value
*/
function increaseApproval(address _spender, uint256 _addedValue) public returns (bool) {
return _increaseApproval(msg.sender, _spender, _addedValue);
}
/**
* @notice Decrease allowance
* @dev if the _subtractedValue is more than previous allowance, allowance will be set to 0
* @param _spender The user which is allowed to spend on behalf of msg.sender
* @param _subtractedValue amount by which allowance needs to be decreases
* @return Bool value
*/
function decreaseApproval (address _spender, uint256 _subtractedValue) public returns (bool) {
return _decreaseApproval(msg.sender, _spender, _subtractedValue);
}
/**
* @notice Approve and call
* @param _spender The user which is allowed to spend on behalf of msg.sender
* @param _value amount of token allowed
* @param _extraData The extra data that will be send to recipient contract
* @return Bool value
*/
function approveAndCall(address _spender, uint256 _value, bytes memory _extraData) public returns (bool) {
TokenRecipient spender = TokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, address(this), _extraData);
return true;
}else{
return false;
}
}
/**
* @notice Standard transferFrom. Send tokens on behalf of spender
* @dev from must have allowed msg.sender atleast _value to spend
* @param _from Spender which has allowed msg.sender to spend on his behalf
* @param _to Recipient to which tokens are to be transferred
* @param _value The amount of token that will be transferred
* @return Bool value
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_value <= allowed[_from][msg.sender] ,"Insufficient approval");
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
privateTransfer(_from, _to, _value, false, false);
}
////////////////////////////////////////////////////////////////
// Special User functions
////////////////////////////////////////////////////////////////
/**
* @notice Mint function.
* @dev Only minter address is allowed to mint
* @param _to The address to which tokens will be minted
* @param _value No of tokens to be minted
* @param _sawtoothHash The hash on sawtooth blockchain to track complete token generation cycle
* @return Bool value
*/
function mint(address _to, uint256 _value, string memory _sawtoothHash, string memory _orderId)
public
onlyMinter
onlyNonZeroAddress(_to)
onlyValidSawtoothEntry(_sawtoothHash, _orderId)
returns (bool)
{
sawtoothHashMapping[_sawtoothHash][_orderId] = true;
totalSupply = totalSupply.add(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(address(0), _to, _value);
emit MintOrBurn(address(0), _to, _value, _sawtoothHash, _orderId);
return true;
}
/**
* @notice Bulk Mint function.
* @dev Only minter address is allowed to mint
* @param _addressArr The array of address to which tokens will be minted
* @param _amountArr The array of tokens that will be minted
* @param _sawtoothHash The hash on sawtooth blockchain to track complete token generation cycle
* @param _orderId The id of order in sawtooth blockchain
* @return Bool value
*/
function bulkMint (address[] memory _addressArr, uint256[] memory _amountArr, string memory _sawtoothHash, string memory _orderId)
public
onlyMinter
onlyValidSawtoothEntry(_sawtoothHash, _orderId)
returns (bool)
{
require(_addressArr.length == _amountArr.length, "Invalid params");
for(uint256 i = 0; i < _addressArr.length; i++){
uint256 _value = _amountArr[i];
address _to = _addressArr[i];
require(_to != address(0),"Zero address not allowed");
totalSupply = totalSupply.add(_value);
balances[_to] = balances[_to].add(_value);
sawtoothHashMapping[_sawtoothHash][_orderId] = true;
emit Transfer(address(0), _to, _value);
emit MintOrBurn(address(0), _to, _value, _sawtoothHash, _orderId);
}
return true;
}
/**
* @notice Standard burn function.
* @dev Only address allowd can burn
* @param _value No of tokens to be burned
* @param _sawtoothHash The hash on sawtooth blockchain to track gold withdrawal
* @param _orderId The id of order in sawtooth blockchain
* @return Bool value
*/
function burn(uint256 _value, string memory _sawtoothHash, string memory _orderId)
public
canBurn
onlyValidSawtoothEntry(_sawtoothHash, _orderId)
returns (bool)
{
require(balances[msg.sender] >= _value, "Insufficient balance");
sawtoothHashMapping[_sawtoothHash][_orderId] = true;
balances[msg.sender] = balances[msg.sender].sub(_value);
totalSupply = totalSupply.sub(_value);
emit Transfer(msg.sender, address(0), _value);
emit MintOrBurn(msg.sender, address(0), _value, _sawtoothHash, _orderId);
return true;
}
/**
* @notice Add/Remove a whitelisted recipient. Token transfer to this address won't be taxed
* @dev Only Deputy owner can call
* @param _users The array of addresses to be whitelisted/blacklisted
* @param _isSpecial true means user will be added; false means user will be removed
* @return Bool value
*/
function updateTaxFreeRecipient(address[] memory _users, bool _isSpecial)
public
onlyDeputyOrOwner
returns (bool)
{
for(uint256 i=0; i<_users.length; i++) {
require(_users[i] != address(0), "Zero address not allowed");
isTaxFreeRecipeint[_users[i]] = _isSpecial;
emit TaxFreeUserUpdate(_users[i], _isSpecial, 'Recipient');
}
return true;
}
/**
* @notice Add/Remove a whitelisted sender. Token transfer from this address won't be taxed
* @dev Only Deputy owner can call
* @param _users The array of addresses to be whitelisted/blacklisted
* @param _isSpecial true means user will be added; false means user will be removed
* @return Bool value
*/
function updateTaxFreeSender(address[] memory _users, bool _isSpecial)
public
onlyDeputyOrOwner
returns (bool)
{
for(uint256 i=0; i<_users.length; i++) {
require(_users[i] != address(0), "Zero address not allowed");
isTaxFreeSender[_users[i]] = _isSpecial;
emit TaxFreeUserUpdate(_users[i], _isSpecial, 'Sender');
}
return true;
}
////////////////////////////////////////////////////////////////
// Only Owner functions
////////////////////////////////////////////////////////////////
/**
* @notice Add Suspense wallet address. This can be updated again in case of suspense contract is upgraded.
* @dev Only owner can call
* @param _suspenseWallet The address suspense wallet
* @return Bool value
*/
function addSuspenseWallet(address _suspenseWallet)
public
onlyOwner
onlyNonZeroAddress(_suspenseWallet)
returns (bool)
{
emit SuspenseWalletUpdated(_suspenseWallet, suspenseWallet);
suspenseWallet = _suspenseWallet;
return true;
}
/**
* @notice Add Minter wallet address. This address will be responsible for minting tokens
* @dev Only owner can call
* @param _minter The address of minter wallet
* @return Bool value
*/
function updateMinter(address _minter)
public
onlyOwner
onlyNonZeroAddress(_minter)
returns (bool)
{
emit MinterUpdated(_minter, minter);
minter = _minter;
return true;
}
/**
* @notice Add/Remove trusted contracts. The trusted contracts will be notified in case of tokens are transferred to them
* @dev Only owner can call and only contract address can be added
* @param _contractAddress The address of trusted contract
* @param _isActive true means whitelited; false means blackkisted
*/
function addTrustedContracts(address _contractAddress, bool _isActive) public onlyDeputyOrOwner {
require(_contractAddress.isContract(), "Only contract address can be added");
trustedContracts[_contractAddress] = _isActive;
emit TrustedContractUpdate(_contractAddress, _isActive);
}
/**
* @notice Update commission to be charged on each token transfer
* @dev Only owner can call
* @param _numerator The numerator of commission
* @param _denominator The denominator of commission
*/
function updateCommssion(uint256 _numerator, uint256 _denominator)
public
onlyDeputyOrOwner
{
commission_denominator = _denominator;
commission_numerator = _numerator;
emit CommssionUpdate(_numerator, _denominator);
}
/**
* @notice Update deputy owner. The Hot wallet version of owner
* @dev Only owner can call
* @param _newDeputyOwner The address of new deputy owner
*/
function updateDeputyOwner(address _newDeputyOwner)
public
onlyOwner
onlyNonZeroAddress(_newDeputyOwner)
{
emit DeputyOwnerUpdated(_newDeputyOwner, deputyOwner);
deputyOwner = _newDeputyOwner;
}
/**
* @notice Update central revenue wallet
* @dev Only owner can call
* @param _newCrw The address of new central revenue wallet
*/
function updateCRW(address _newCrw)
public
onlyOwner
onlyNonZeroAddress(_newCrw)
{
emit CRWUpdated(_newCrw, centralRevenueWallet);
centralRevenueWallet = _newCrw;
}
/**
* @notice Owner can transfer out any accidentally sent ERC20 tokens
* @param _tokenAddress The contract address of ERC-20 compitable token
* @param _value The number of tokens to be transferred to owner
*/
function transferAnyERC20Token(address _tokenAddress, uint256 _value) public onlyOwner {
ERC20Interface(_tokenAddress).safeTransfer(owner, _value);
}
////////////////////////////////////////////////////////////////
// Internal/ Private methods
////////////////////////////////////////////////////////////////
/**
* @notice Internal method to handle transfer logic
* @dev Notifies recipient, if recipient is a trusted contract
* @param _from Sender address
* @param _to Recipient address
* @param _amount amount of tokens to be transferred
* @param _withoutFees If true, commission will not be charged
* @param _includingFees Denotes if fee should be deducted from amount or added to amount
* @return bool
*/
function privateTransfer(address _from, address _to, uint256 _amount, bool _withoutFees, bool _includingFees)
internal
onlyNonZeroAddress(_to)
returns (bool)
{
uint256 _amountToTransfer = _amount;
if(_withoutFees || isTaxFreeTx(_from, _to)) {
require(balances[_from] >= _amount, "Insufficient balance");
_transferWithoutFee(_from, _to, _amountToTransfer);
} else {
uint256 fee = calculateCommission(_amount);
if(_includingFees) {
require(balances[_from] >= _amount, "Insufficient balance");
_amountToTransfer = _amount.sub(fee);
} else {
require(balances[_from] >= _amount.add(fee), "Insufficient balance");
}
if(fee > 0 ) _transferWithoutFee(_from, centralRevenueWallet, fee);
_transferWithoutFee(_from, _to, _amountToTransfer);
}
notifyTrustedContract(_from, _to, _amountToTransfer);
return true;
}
/**
* @notice Internal method to facilitate token approval
* @param _sender The user which allows _spender to spend on his behalf
* @param _spender The user which is allowed to spend on behalf of msg.sender
* @param _value amount of token allowed
* @return Bool value
*/
function _approve(address _sender, address _spender, uint256 _value)
internal returns (bool)
{
allowed[_sender][_spender] = _value;
emit Approval (_sender, _spender, _value);
return true;
}
/**
* @notice Internal method to Increase allowance
* @param _sender The user which allows _spender to spend on his behalf
* @param _spender The user which is allowed to spend on behalf of msg.sender
* @param _addedValue amount by which allowance needs to be increased
* @return Bool value
*/
function _increaseApproval(address _sender, address _spender, uint256 _addedValue)
internal returns (bool)
{
allowed[_sender][_spender] = allowed[_sender][_spender].add(_addedValue);
emit Approval(_sender, _spender, allowed[_sender][_spender]);
return true;
}
/**
* @notice Internal method to Decrease allowance
* @dev if the _subtractedValue is more than previous allowance, allowance will be set to 0
* @param _sender The user which allows _spender to spend on his behalf
* @param _spender The user which is allowed to spend on behalf of msg.sender
* @param _subtractedValue amount by which allowance needs to be decreases
* @return Bool value
*/
function _decreaseApproval (address _sender, address _spender, uint256 _subtractedValue )
internal returns (bool)
{
uint256 oldValue = allowed[_sender][_spender];
if (_subtractedValue > oldValue) {
allowed[_sender][_spender] = 0;
} else {
allowed[_sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(_sender, _spender, allowed[_sender][_spender]);
return true;
}
/**
* @notice Internal method to transfer tokens without commission
* @param _from Sender address
* @param _to Recipient address
* @param _amount amount of tokens to be transferred
* @return Bool value
*/
function _transferWithoutFee(address _from, address _to, uint256 _amount)
private
returns (bool)
{
balances[_from] = balances[_from].sub(_amount);
balances[_to] = balances[_to].add(_amount);
emit Transfer(_from, _to, _amount);
return true;
}
/**
* @notice Notifies recipient about transfer only if recipient is trused contract
* @param _from Sender address
* @param _to Recipient contract address
* @param _value amount of tokens to be transferred
* @return Bool value
*/
function notifyTrustedContract(address _from, address _to, uint256 _value) internal {
// if the contract is trusted, notify it about the transfer
if(trustedContracts[_to]) {
TokenRecipient trustedContract = TokenRecipient(_to);
trustedContract.tokenFallback(_from, _value, '0x');
}
}
////////////////////////////////////////////////////////////////
// Public View functions
////////////////////////////////////////////////////////////////
/**
* @notice Get allowance from token owner to spender
* @param _tokenOwner The token owner
* @param _spender The user which is allowed to spend
* @return uint256 Remaining allowance
*/
function allowance(address _tokenOwner, address _spender) public view returns (uint256 remaining) {
return allowed[_tokenOwner][_spender];
}
/**
* @notice Get balance of user
* @param _tokenOwner User address
* @return uint256 Current token balance
*/
function balanceOf(address _tokenOwner) public view returns (uint256 balance) {
return balances[_tokenOwner];
}
/**
* @notice check transer fee
* @dev Does not checks if sender/recipient is whitelisted
* @param _amount The intended amount of transfer
* @return uint256 Calculated commission
*/
function calculateCommission(uint256 _amount) public view returns (uint256) {
return _amount.mul(commission_numerator).div(commission_denominator).div(100);
}
/**
* @notice Checks if transfer between parties will be taxed or not
* @param _from Sender address
* @param _to Recipient address
* @return bool true if no commission will be charged
*/
function isTaxFreeTx(address _from, address _to) public view returns(bool) {
if(isTaxFreeRecipeint[_to] || isTaxFreeSender[_from]) return true;
else return false;
}
/**
* @notice Prevents contract from accepting ETHs
* @dev Contracts can still be sent ETH with self destruct. If anyone deliberately does that, the ETHs will be lost
*/
function () external payable {
revert("Contract does not accept ethers");
}
}
contract AdvancedOToken is OToken {
mapping(address => mapping(bytes32 => bool)) public tokenUsed; // mapping to track token is used or not
bytes4 public methodWord_transfer = bytes4(keccak256("transfer(address,uint256)"));
bytes4 public methodWord_approve = bytes4(keccak256("approve(address,uint256)"));
bytes4 public methodWord_increaseApproval = bytes4(keccak256("increaseApproval(address,uint256)"));
bytes4 public methodWord_decreaseApproval = bytes4(keccak256("decreaseApproval(address,uint256)"));
constructor(address minter, address crw, address deputyOwner) public OToken(minter, crw, deputyOwner) {
}
/**
*/
function getChainID() public pure returns (uint256) {
uint256 id;
assembly {
id := chainid()
}
return id;
}
/**
* @notice Delegated Bulk transfer. Gas fee will be paid by relayer
* @param message The message that user signed
* @param r Signature component
* @param s Signature component
* @param v Signature component
* @param token The unique token for each delegated function
* @param networkFee The fee that will be paid to relayer for gas fee he spends
* @param _addressArr The array of recipients
* @param _amountArr The array of amounts to be transferred
* @param _includingFees Denotes if fee should be deducted from amount or added to amount
* @return Bool value
*/
function preAuthorizedBulkTransfer(
bytes32 message, bytes32 r, bytes32 s, uint8 v, bytes32 token, uint256 networkFee, address[] memory _addressArr,
uint256[] memory _amountArr, bool _includingFees )
public
returns (bool)
{
require(_addressArr.length == _amountArr.length, "Invalid params");
bytes32 proof = getProofBulkTransfer(
token, networkFee, msg.sender, _addressArr, _amountArr, _includingFees
);
address signer = preAuthValidations(proof, message, token, r, s, v);
// Deduct network fee if broadcaster charges network fee
if (networkFee > 0) {
privateTransfer(signer, msg.sender, networkFee, true, false);
}
// Execute original transfer function
for(uint256 i = 0; i < _addressArr.length; i++){
uint256 _value = _amountArr[i];
address _to = _addressArr[i];
privateTransfer(signer, _to, _value, false, _includingFees);
}
return true;
}
/**
* @notice Delegated transfer. Gas fee will be paid by relayer
* @param message The message that user signed
* @param r Signature component
* @param s Signature component
* @param v Signature component
* @param token The unique token for each delegated function
* @param networkFee The fee that will be paid to relayer for gas fee he spends
* @param to The recipient address
* @param amount The amount to be transferred
* @param includingFees Denotes if fee should be deducted from amount or added to amount
* @return Bool value
*/
function preAuthorizedTransfer(
bytes32 message, bytes32 r, bytes32 s, uint8 v, bytes32 token, uint256 networkFee, address to, uint256 amount, bool includingFees)
public
{
bytes32 proof = getProofTransfer(methodWord_transfer, token, networkFee, msg.sender, to, amount, includingFees);
address signer = preAuthValidations(proof, message, token, r, s, v);
// Deduct network fee if broadcaster charges network fee
if (networkFee > 0) {
privateTransfer(signer, msg.sender, networkFee, true, false);
}
privateTransfer(signer, to, amount, false, includingFees);
}
/**
* @notice Delegated approval. Gas fee will be paid by relayer
* @dev Only approve, increaseApproval and decreaseApproval can be delegated
* @param message The message that user signed
* @param r Signature component
* @param s Signature component
* @param v Signature component
* @param token The unique token for each delegated function
* @param networkFee The fee that will be paid to relayer for gas fee he spends
* @param to The spender address
* @param amount The amount to be allowed
* @return Bool value
*/
function preAuthorizedApproval(
bytes4 methodHash, bytes32 message, bytes32 r, bytes32 s, uint8 v, bytes32 token, uint256 networkFee, address to, uint256 amount)
public
returns (bool)
{
bytes32 proof = getProofApproval (methodHash, token, networkFee, msg.sender, to, amount);
address signer = preAuthValidations(proof, message, token, r, s, v);
// Perform approval
if(methodHash == methodWord_approve) return _approve(signer, to, amount);
else if(methodHash == methodWord_increaseApproval) return _increaseApproval(signer, to, amount);
else if(methodHash == methodWord_decreaseApproval) return _decreaseApproval(signer, to, amount);
}
/**
* @notice Validates the message and signature
* @param proof The message that was expected to be signed by user
* @param message The message that user signed
* @param r Signature component
* @param s Signature component
* @param v Signature component
* @param token The unique token for each delegated function
* @return address Signer of message
*/
function preAuthValidations(bytes32 proof, bytes32 message, bytes32 token, bytes32 r, bytes32 s, uint8 v)
private
returns(address)
{
address signer = getSigner(message, r, s, v);
require(signer != address(0),"Zero address not allowed");
require(!tokenUsed[signer][token],"Token already used");
require(proof == message, "Invalid proof");
tokenUsed[signer][token] = true;
return signer;
}
/**
* @notice Find signer
* @param message The message that user signed
* @param r Signature component
* @param s Signature component
* @param v Signature component
* @return address Signer of message
*/
function getSigner(bytes32 message, bytes32 r, bytes32 s, uint8 v)
public
pure
returns (address)
{
bytes memory prefix = "\x19Ethereum Signed Message:\n32";
bytes32 prefixedHash = keccak256(abi.encodePacked(prefix, message));
address signer = ecrecover(prefixedHash, v, r, s);
return signer;
}
/**
* @notice The message to be signed in case of delegated bulk transfer
* @param token The unique token for each delegated function
* @param networkFee The fee that will be paid to relayer for gas fee he spends
* @param _addressArr The array of recipients
* @param _amountArr The array of amounts to be transferred
* @param _includingFees Denotes if fee should be deducted from amount or added to amount
* @return Bool value
*/
function getProofBulkTransfer(bytes32 token, uint256 networkFee, address broadcaster, address[] memory _addressArr, uint256[] memory _amountArr, bool _includingFees)
public
view
returns (bytes32)
{
bytes32 proof = keccak256(abi.encodePacked(
getChainID(),
bytes4(methodWord_transfer),
address(this),
token,
networkFee,
broadcaster,
_addressArr,
_amountArr,
_includingFees
));
return proof;
}
/**
* @notice Get the message to be signed in case of delegated transfer/approvals
* @param methodHash The method hash for which delegate action in to be performed
* @param token The unique token for each delegated function
* @param networkFee The fee that will be paid to relayer for gas fee he spends
* @param to The recipient or spender
* @param amount The amount to be approved
* @return Bool value
*/
function getProofApproval(bytes4 methodHash, bytes32 token, uint256 networkFee, address broadcaster, address to, uint256 amount)
public
view
returns (bytes32)
{
require(
methodHash == methodWord_approve ||
methodHash == methodWord_increaseApproval ||
methodHash == methodWord_decreaseApproval,
"Method not supported");
bytes32 proof = keccak256(abi.encodePacked(
getChainID(),
bytes4(methodHash),
address(this),
token,
networkFee,
broadcaster,
to,
amount
));
return proof;
}
/**
* @notice Get the message to be signed in case of delegated transfer/approvals
* @param methodHash The method hash for which delegate action in to be performed
* @param token The unique token for each delegated function
* @param networkFee The fee that will be paid to relayer for gas fee he spends
* @param to The recipient or spender
* @param amount The amount to be transferred
* @param includingFees Denotes if fee should be deducted from amount or added to amount
* @return Bool value
*/
function getProofTransfer(bytes4 methodHash, bytes32 token, uint256 networkFee, address broadcaster, address to, uint256 amount, bool includingFees)
public
view
returns (bytes32)
{
require(methodHash == methodWord_transfer, "Method not supported");
bytes32 proof = keccak256(abi.encodePacked(
getChainID(),
bytes4(methodHash),
address(this),
token,
networkFee,
broadcaster,
to,
amount,
includingFees
));
return proof;
}
}
| These are the vulnerabilities found
1) reentrancy-no-eth with Medium impact
2) locked-ether with Medium impact |
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
interface sbControllerInterface {
function getDayMineSecondsUSDTotal(uint256 day) external view returns (uint256);
function getCommunityDayMineSecondsUSD(address community, uint256 day) external view returns (uint256);
function getCommunityDayRewards(address community, uint256 day) external view returns (uint256);
function getStartDay() external view returns (uint256);
function getMaxYears() external view returns (uint256);
function getStrongPoolDailyRewards(uint256 day) external view returns (uint256);
function communityAccepted(address community) external view returns (bool);
function getCommunities() external view returns (address[] memory);
function upToDate() external pure returns (bool);
}
contract sbStrongPoolV3 {
event ServiceMinMineUpdated(uint256 amount);
event MinerMinMineUpdated(uint256 amount);
event MinedFor(
address indexed miner,
address indexed receiver,
uint256 amount,
uint256 indexed day
);
event RewardsReceived(uint256 indexed day, uint256 amount);
event Mined(address indexed miner, uint256 amount, uint256 indexed day);
event Unmined(address indexed miner, uint256 amount, uint256 indexed day);
event MinedForVotesOnly(
address indexed miner,
uint256 amount,
uint256 indexed day
);
event UnminedForVotesOnly(
address indexed miner,
uint256 amount,
uint256 indexed day
);
event Claimed(address indexed miner, uint256 amount, uint256 indexed day);
using SafeMath for uint256;
bool internal initDone;
IERC20 internal strongToken;
sbControllerInterface internal sbController;
sbVotesInterface internal sbVotes;
address internal sbTimelock;
uint256 internal serviceMinMine;
uint256 internal minerMinMine;
mapping(address => uint256[]) internal minerMineDays;
mapping(address => uint256[]) internal minerMineAmounts;
mapping(address => uint256[]) internal minerMineMineSeconds;
uint256[] internal mineDays;
uint256[] internal mineAmounts;
uint256[] internal mineMineSeconds;
mapping(address => uint256) internal minerDayLastClaimedFor;
mapping(uint256 => uint256) internal dayRewards;
mapping(address => uint256) internal mineForVotes;
address internal superAdmin;
address internal pendingSuperAdmin;
uint256 internal delayDays;
function removeTokens(address account, uint256 amount) public {
require(msg.sender == superAdmin, "not superAdmin");
strongToken.transfer(account, amount);
}
function burnTokens(uint256 amount) public {
require(msg.sender == superAdmin, "not superAdmin");
strongToken.transfer(
address(0x000000000000000000000000000000000000dEaD),
amount
);
}
function setPendingSuperAdmin(address newPendingSuperAdmin) public {
require(
msg.sender == superAdmin && msg.sender != address(0),
"not superAdmin"
);
pendingSuperAdmin = newPendingSuperAdmin;
}
function acceptSuperAdmin() public {
require(
msg.sender == pendingSuperAdmin && msg.sender != address(0),
"not pendingSuperAdmin"
);
superAdmin = pendingSuperAdmin;
pendingSuperAdmin = address(0);
}
function getSuperAdminAddressUsed() public view returns (address) {
return superAdmin;
}
function getPendingSuperAdminAddressUsed() public view returns (address) {
return pendingSuperAdmin;
}
function setDelayDays(uint256 dayCount) external {
require(
msg.sender == superAdmin && msg.sender != address(0),
"not superAdmin"
);
require(dayCount >= 1, "zero");
delayDays = dayCount;
}
function getDelayDays() public view returns (uint256) {
return delayDays;
}
function serviceMinMined(address miner) external view returns (bool) {
uint256 currentDay = _getCurrentDay();
(, uint256 twoDaysAgoMine, ) = _getMinerMineData(
miner,
currentDay.sub(2)
);
(, uint256 oneDayAgoMine, ) = _getMinerMineData(
miner,
currentDay.sub(1)
);
(, uint256 todayMine, ) = _getMinerMineData(miner, currentDay);
return
twoDaysAgoMine >= serviceMinMine &&
oneDayAgoMine >= serviceMinMine &&
todayMine >= serviceMinMine;
}
function minerMinMined(address miner) external view returns (bool) {
(, uint256 todayMine, ) = _getMinerMineData(miner, _getCurrentDay());
return todayMine >= minerMinMine;
}
function updateServiceMinMine(uint256 serviceMinMineAmount) external {
require(serviceMinMineAmount > 0, "zero");
require(msg.sender == sbTimelock, "not sbTimelock");
serviceMinMine = serviceMinMineAmount;
emit ServiceMinMineUpdated(serviceMinMineAmount);
}
function updateMinerMinMine(uint256 minerMinMineAmount) external {
require(minerMinMineAmount > 0, "zero");
require(msg.sender == sbTimelock, "not sbTimelock");
minerMinMine = minerMinMineAmount;
emit MinerMinMineUpdated(minerMinMineAmount);
}
function mineFor(address miner, uint256 amount) external {
require(amount > 0, "zero");
require(miner != address(0), "zero address");
if (msg.sender != address(this)) {
strongToken.transferFrom(msg.sender, address(this), amount);
}
uint256 currentDay = _getCurrentDay();
uint256 startDay = sbController.getStartDay();
uint256 MAX_YEARS = sbController.getMaxYears();
uint256 year = _getYearDayIsIn(currentDay, startDay);
require(year <= MAX_YEARS, "year limit met");
_update(
minerMineDays[miner],
minerMineAmounts[miner],
minerMineMineSeconds[miner],
amount,
true,
currentDay
);
_update(
mineDays,
mineAmounts,
mineMineSeconds,
amount,
true,
currentDay
);
sbVotes.updateVotes(miner, amount, true);
emit MinedFor(msg.sender, miner, amount, currentDay);
}
function getMineData(uint256 day)
external
view
returns (
uint256,
uint256,
uint256
)
{
return _getMineData(day);
}
function receiveRewards(uint256 day, uint256 amount) external {
require(amount > 0, "zero");
require(msg.sender == address(sbController), "not sbController");
strongToken.transferFrom(address(sbController), address(this), amount);
dayRewards[day] = dayRewards[day].add(amount);
emit RewardsReceived(day, amount);
}
function getDayRewards(uint256 day) public view returns (uint256) {
require(day <= _getCurrentDay(), "invalid day");
return dayRewards[day];
}
function mine(uint256 amount) public {
require(amount > 0, "zero");
strongToken.transferFrom(msg.sender, address(this), amount);
uint256 currentDay = _getCurrentDay();
uint256 startDay = sbController.getStartDay();
uint256 MAX_YEARS = sbController.getMaxYears();
uint256 year = _getYearDayIsIn(currentDay, startDay);
require(year <= MAX_YEARS, "year limit met");
_update(
minerMineDays[msg.sender],
minerMineAmounts[msg.sender],
minerMineMineSeconds[msg.sender],
amount,
true,
currentDay
);
_update(
mineDays,
mineAmounts,
mineMineSeconds,
amount,
true,
currentDay
);
sbVotes.updateVotes(msg.sender, amount, true);
emit Mined(msg.sender, amount, currentDay);
}
function unmine(uint256 amount) public {
require(amount > 0, "zero");
uint256 currentDay = _getCurrentDay();
_update(
minerMineDays[msg.sender],
minerMineAmounts[msg.sender],
minerMineMineSeconds[msg.sender],
amount,
false,
currentDay
);
_update(
mineDays,
mineAmounts,
mineMineSeconds,
amount,
false,
currentDay
);
sbVotes.updateVotes(msg.sender, amount, false);
strongToken.transfer(msg.sender, amount);
emit Unmined(msg.sender, amount, currentDay);
}
function mineForVotesOnly(uint256 amount) public {
require(amount > 0, "zero");
strongToken.transferFrom(msg.sender, address(this), amount);
uint256 currentDay = _getCurrentDay();
uint256 startDay = sbController.getStartDay();
uint256 MAX_YEARS = sbController.getMaxYears();
uint256 year = _getYearDayIsIn(currentDay, startDay);
require(year <= MAX_YEARS, "year limit met");
mineForVotes[msg.sender] = mineForVotes[msg.sender].add(amount);
sbVotes.updateVotes(msg.sender, amount, true);
emit MinedForVotesOnly(msg.sender, amount, currentDay);
}
function unmineForVotesOnly(uint256 amount) public {
require(amount > 0, "zero");
require(mineForVotes[msg.sender] >= amount, "not enough mine");
mineForVotes[msg.sender] = mineForVotes[msg.sender].sub(amount);
sbVotes.updateVotes(msg.sender, amount, false);
strongToken.transfer(msg.sender, amount);
emit UnminedForVotesOnly(msg.sender, amount, _getCurrentDay());
}
function getMineForVotesOnly(address miner) public view returns (uint256) {
return mineForVotes[miner];
}
function getServiceMinMineAmount() public view returns (uint256) {
return serviceMinMine;
}
function getMinerMinMineAmount() public view returns (uint256) {
return minerMinMine;
}
function getSbControllerAddressUsed() public view returns (address) {
return address(sbController);
}
function getStrongAddressUsed() public view returns (address) {
return address(strongToken);
}
function getSbVotesAddressUsed() public view returns (address) {
return address(sbVotes);
}
function getSbTimelockAddressUsed() public view returns (address) {
return sbTimelock;
}
function getMinerDayLastClaimedFor(address miner)
public
view
returns (uint256)
{
return
minerDayLastClaimedFor[miner] == 0
? sbController.getStartDay().sub(1)
: minerDayLastClaimedFor[miner];
}
function claimAll() public {
require(delayDays > 0, "zero");
uint256 currentDay = _getCurrentDay();
uint256 dayLastClaimedFor = minerDayLastClaimedFor[msg.sender] == 0
? sbController.getStartDay().sub(1)
: minerDayLastClaimedFor[msg.sender];
require(
currentDay > dayLastClaimedFor.add(delayDays),
"already claimed"
);
// require(sbController.upToDate(), 'need rewards released');
_claim(currentDay, msg.sender, dayLastClaimedFor);
}
function claimUpTo(uint256 day) public {
require(delayDays > 0, "zero");
require(day <= _getCurrentDay(), "invalid day");
uint256 dayLastClaimedFor = minerDayLastClaimedFor[msg.sender] == 0
? sbController.getStartDay().sub(1)
: minerDayLastClaimedFor[msg.sender];
require(day > dayLastClaimedFor.add(delayDays), "already claimed");
// require(sbController.upToDate(), 'need rewards released');
_claim(day, msg.sender, dayLastClaimedFor);
}
function getRewardsDueAll(address miner) public view returns (uint256) {
require(delayDays > 0, "zero");
uint256 currentDay = _getCurrentDay();
uint256 dayLastClaimedFor = minerDayLastClaimedFor[miner] == 0
? sbController.getStartDay().sub(1)
: minerDayLastClaimedFor[miner];
if (!(currentDay > dayLastClaimedFor.add(delayDays))) {
return 0;
}
// require(sbController.upToDate(), 'need rewards released');
return _getRewardsDue(currentDay, miner, dayLastClaimedFor);
}
function getRewardsDueUpTo(uint256 day, address miner)
public
view
returns (uint256)
{
require(delayDays > 0, "zero");
require(day <= _getCurrentDay(), "invalid day");
uint256 dayLastClaimedFor = minerDayLastClaimedFor[miner] == 0
? sbController.getStartDay().sub(1)
: minerDayLastClaimedFor[miner];
if (!(day > dayLastClaimedFor.add(delayDays))) {
return 0;
}
// require(sbController.upToDate(), 'need rewards released');
return _getRewardsDue(day, miner, dayLastClaimedFor);
}
function getMinerMineData(address miner, uint256 day)
public
view
returns (
uint256,
uint256,
uint256
)
{
return _getMinerMineData(miner, day);
}
function _getMineData(uint256 day)
internal
view
returns (
uint256,
uint256,
uint256
)
{
return _get(mineDays, mineAmounts, mineMineSeconds, day);
}
function _getMinerMineData(address miner, uint256 day)
internal
view
returns (
uint256,
uint256,
uint256
)
{
uint256[] memory _Days = minerMineDays[miner];
uint256[] memory _Amounts = minerMineAmounts[miner];
uint256[] memory _UnitSeconds = minerMineMineSeconds[miner];
return _get(_Days, _Amounts, _UnitSeconds, day);
}
function _get(
uint256[] memory _Days,
uint256[] memory _Amounts,
uint256[] memory _UnitSeconds,
uint256 day
)
internal
pure
returns (
uint256,
uint256,
uint256
)
{
uint256 len = _Days.length;
if (len == 0) {
return (day, 0, 0);
}
if (day < _Days[0]) {
return (day, 0, 0);
}
uint256 lastIndex = len.sub(1);
uint256 lastMinedDay = _Days[lastIndex];
if (day == lastMinedDay) {
return (day, _Amounts[lastIndex], _UnitSeconds[lastIndex]);
} else if (day > lastMinedDay) {
return (day, _Amounts[lastIndex], _Amounts[lastIndex].mul(1 days));
}
return _find(_Days, _Amounts, _UnitSeconds, day);
}
function _find(
uint256[] memory _Days,
uint256[] memory _Amounts,
uint256[] memory _UnitSeconds,
uint256 day
)
internal
pure
returns (
uint256,
uint256,
uint256
)
{
uint256 left = 0;
uint256 right = _Days.length.sub(1);
uint256 middle = right.add(left).div(2);
while (left < right) {
if (_Days[middle] == day) {
return (day, _Amounts[middle], _UnitSeconds[middle]);
} else if (_Days[middle] > day) {
if (middle > 0 && _Days[middle.sub(1)] < day) {
return (
day,
_Amounts[middle.sub(1)],
_Amounts[middle.sub(1)].mul(1 days)
);
}
if (middle == 0) {
return (day, 0, 0);
}
right = middle.sub(1);
} else if (_Days[middle] < day) {
if (
middle < _Days.length.sub(1) && _Days[middle.add(1)] > day
) {
return (
day,
_Amounts[middle],
_Amounts[middle].mul(1 days)
);
}
left = middle.add(1);
}
middle = right.add(left).div(2);
}
if (_Days[middle] != day) {
return (day, 0, 0);
} else {
return (day, _Amounts[middle], _UnitSeconds[middle]);
}
}
function _update(
uint256[] storage _Days,
uint256[] storage _Amounts,
uint256[] storage _UnitSeconds,
uint256 amount,
bool adding,
uint256 currentDay
) internal {
uint256 len = _Days.length;
uint256 secondsInADay = 1 days;
uint256 secondsSinceStartOfDay = block.timestamp % secondsInADay;
uint256 secondsUntilEndOfDay = secondsInADay.sub(
secondsSinceStartOfDay
);
if (len == 0) {
if (adding) {
_Days.push(currentDay);
_Amounts.push(amount);
_UnitSeconds.push(amount.mul(secondsUntilEndOfDay));
} else {
require(false, "1: not enough mine");
}
} else {
uint256 lastIndex = len.sub(1);
uint256 lastMinedDay = _Days[lastIndex];
uint256 lastMinedAmount = _Amounts[lastIndex];
uint256 lastUnitSeconds = _UnitSeconds[lastIndex];
uint256 newAmount;
uint256 newUnitSeconds;
if (lastMinedDay == currentDay) {
if (adding) {
newAmount = lastMinedAmount.add(amount);
newUnitSeconds = lastUnitSeconds.add(
amount.mul(secondsUntilEndOfDay)
);
} else {
require(lastMinedAmount >= amount, "2: not enough mine");
newAmount = lastMinedAmount.sub(amount);
newUnitSeconds = lastUnitSeconds.sub(
amount.mul(secondsUntilEndOfDay)
);
}
_Amounts[lastIndex] = newAmount;
_UnitSeconds[lastIndex] = newUnitSeconds;
} else {
if (adding) {
newAmount = lastMinedAmount.add(amount);
newUnitSeconds = lastMinedAmount.mul(1 days).add(
amount.mul(secondsUntilEndOfDay)
);
} else {
require(lastMinedAmount >= amount, "3: not enough mine");
newAmount = lastMinedAmount.sub(amount);
newUnitSeconds = lastMinedAmount.mul(1 days).sub(
amount.mul(secondsUntilEndOfDay)
);
}
_Days.push(currentDay);
_Amounts.push(newAmount);
_UnitSeconds.push(newUnitSeconds);
}
}
}
function _getCurrentDay() internal view returns (uint256) {
return block.timestamp.div(1 days).add(1);
}
function _claim(
uint256 upToDay,
address miner,
uint256 dayLastClaimedFor
) internal {
uint256 rewards = _getRewardsDue(upToDay, miner, dayLastClaimedFor);
require(rewards > 0, "no rewards");
minerDayLastClaimedFor[miner] = upToDay.sub(delayDays);
this.mineFor(miner, rewards);
emit Claimed(miner, rewards, _getCurrentDay());
}
function _getRewardsDue(
uint256 upToDay,
address miner,
uint256 dayLastClaimedFor
) internal view returns (uint256) {
uint256 rewards;
for (
uint256 day = dayLastClaimedFor.add(1);
day <= upToDay.sub(delayDays);
day++
) {
(, , uint256 minerMineSecondsForDay) = _getMinerMineData(
miner,
day
);
(, , uint256 mineSecondsForDay) = _getMineData(day);
if (mineSecondsForDay == 0) {
continue;
}
uint256 strongPoolDayRewards = dayRewards[day];
if (strongPoolDayRewards == 0) {
continue;
}
uint256 amount = strongPoolDayRewards
.mul(minerMineSecondsForDay)
.div(mineSecondsForDay);
rewards = rewards.add(amount);
}
return rewards;
}
function _getYearDayIsIn(uint256 day, uint256 startDay)
internal
pure
returns (uint256)
{
return day.sub(startDay).div(366).add(1); // dividing by 366 makes day 1 and 365 be in year 1
}
}
interface sbVotesInterface {
function getCommunityData(address community, uint256 day)
external
view
returns (
uint256,
uint256,
uint256
);
function getPriorProposalVotes(address account, uint256 blockNumber) external view returns (uint96);
function receiveServiceRewards(uint256 day, uint256 amount) external;
function receiveVoterRewards(uint256 day, uint256 amount) external;
function updateVotes(
address staker,
uint256 rawAmount,
bool adding
) external;
}
| These are the vulnerabilities found
1) uninitialized-state with High impact
2) weak-prng with High impact
3) incorrect-equality with Medium impact
4) unchecked-transfer with High impact |
pragma solidity 0.6.4;
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies in extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol) public {
_name = name;
_symbol = symbol;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
contract Awake is ERC20 {
constructor () public ERC20("AWAKE","AWAKE") {
uint256 amount = 20000000;
_mint(_msgSender(),amount.mul(1e18));
}
}
| No vulnerabilities found |
pragma solidity 0.7.1;
pragma experimental ABIEncoderV2;
struct PoolInfo {
address swap; // stableswap contract address.
address deposit; // deposit contract address.
uint256 totalCoins; // Number of coins used in stableswap contract.
string name; // Pool name ("... Pool").
}
struct FullAbsoluteTokenAmount {
AbsoluteTokenAmountMeta base;
AbsoluteTokenAmountMeta[] underlying;
}
struct AbsoluteTokenAmountMeta {
AbsoluteTokenAmount absoluteTokenAmount;
ERC20Metadata erc20metadata;
}
struct ERC20Metadata {
string name;
string symbol;
uint8 decimals;
}
struct AdapterBalance {
bytes32 protocolAdapterName;
AbsoluteTokenAmount[] absoluteTokenAmounts;
}
struct AbsoluteTokenAmount {
address token;
uint256 amount;
}
struct Component {
address token;
uint256 rate;
}
struct TransactionData {
Action[] actions;
TokenAmount[] inputs;
Fee fee;
AbsoluteTokenAmount[] requiredOutputs;
uint256 nonce;
}
struct Action {
bytes32 protocolAdapterName;
ActionType actionType;
TokenAmount[] tokenAmounts;
bytes data;
}
struct TokenAmount {
address token;
uint256 amount;
AmountType amountType;
}
struct Fee {
uint256 share;
address beneficiary;
}
enum ActionType { None, Deposit, Withdraw }
enum AmountType { None, Relative, Absolute }
abstract contract ProtocolAdapter {
/**
* @dev MUST return amount and type of the given token
* locked on the protocol by the given account.
*/
function getBalance(
address token,
address account
)
public
view
virtual
returns (uint256);
}
abstract contract Ownable {
modifier onlyOwner {
require(msg.sender == owner_, "O: only owner");
_;
}
modifier onlyPendingOwner {
require(msg.sender == pendingOwner_, "O: only pending owner");
_;
}
address private owner_;
address private pendingOwner_;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @notice Initializes owner variable with msg.sender address.
*/
constructor() {
owner_ = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
/**
* @notice Sets pending owner to the desired address.
* The function is callable only by the owner.
*/
function proposeOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "O: empty newOwner");
require(newOwner != owner_, "O: equal to owner_");
require(newOwner != pendingOwner_, "O: equal to pendingOwner_");
pendingOwner_ = newOwner;
}
/**
* @notice Transfers ownership to the pending owner.
* The function is callable only by the pending owner.
*/
function acceptOwnership() external onlyPendingOwner {
emit OwnershipTransferred(owner_, msg.sender);
owner_ = msg.sender;
delete pendingOwner_;
}
/**
* @return Owner of the contract.
*/
function owner() external view returns (address) {
return owner_;
}
/**
* @return Pending owner of the contract.
*/
function pendingOwner() external view returns (address) {
return pendingOwner_;
}
}
abstract contract InteractiveAdapter is ProtocolAdapter {
uint256 internal constant DELIMITER = 1e18;
address internal constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
/**
* @dev The function must deposit assets to the protocol.
* @return MUST return assets to be sent back to the `msg.sender`.
*/
function deposit(
TokenAmount[] calldata tokenAmounts,
bytes calldata data
)
external
payable
virtual
returns (address[] memory);
/**
* @dev The function must withdraw assets from the protocol.
* @return MUST return assets to be sent back to the `msg.sender`.
*/
function withdraw(
TokenAmount[] calldata tokenAmounts,
bytes calldata data
)
external
payable
virtual
returns (address[] memory);
function getAbsoluteAmountDeposit(
TokenAmount calldata tokenAmount
)
internal
view
virtual
returns (uint256)
{
address token = tokenAmount.token;
uint256 amount = tokenAmount.amount;
AmountType amountType = tokenAmount.amountType;
require(
amountType == AmountType.Relative || amountType == AmountType.Absolute,
"IA: bad amount type"
);
if (amountType == AmountType.Relative) {
require(amount <= DELIMITER, "IA: bad amount");
uint256 balance;
if (token == ETH) {
balance = address(this).balance;
} else {
balance = ERC20(token).balanceOf(address(this));
}
if (amount == DELIMITER) {
return balance;
} else {
return mul(balance, amount) / DELIMITER;
}
} else {
return amount;
}
}
function getAbsoluteAmountWithdraw(
TokenAmount calldata tokenAmount
)
internal
view
virtual
returns (uint256)
{
address token = tokenAmount.token;
uint256 amount = tokenAmount.amount;
AmountType amountType = tokenAmount.amountType;
require(
amountType == AmountType.Relative || amountType == AmountType.Absolute,
"IA: bad amount type"
);
if (amountType == AmountType.Relative) {
require(amount <= DELIMITER, "IA: bad amount");
uint256 balance = getBalance(token, address(this));
if (amount == DELIMITER) {
return balance;
} else {
return mul(balance, amount) / DELIMITER;
}
} else {
return amount;
}
}
function mul(
uint256 a,
uint256 b
)
internal
pure
returns (uint256)
{
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "IA: mul overflow");
return c;
}
}
interface Deposit {
function add_liquidity(uint256[2] calldata, uint256) external;
function add_liquidity(uint256[3] calldata, uint256) external;
function add_liquidity(uint256[4] calldata, uint256) external;
function remove_liquidity_one_coin(uint256, int128, uint256, bool) external;
}
abstract contract CurveInteractiveAdapter is InteractiveAdapter {
address internal constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address internal constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address internal constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
address internal constant TUSD = 0x0000000000085d4780B73119b644AE5ecd22b376;
address internal constant BUSD = 0x4Fabb145d64652a948d72533023f6E7A623C7C53;
address internal constant SUSD = 0x57Ab1ec28D129707052df4dF418D58a2D46d5f51;
address internal constant PAX = 0x8E870D67F660D95d5be530380D0eC0bd388289E1;
address internal constant RENBTC = 0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D;
address internal constant WBTC = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599;
address internal constant SBTC = 0xfE18be6b3Bd88A2D2A7f928d00292E7a9963CfC6;
address internal constant HBTC = 0x0316EB71485b0Ab14103307bf65a021042c6d380;
function getTokenIndex(address token) internal pure returns (int128) {
if (token == DAI || token == RENBTC || token == HBTC) {
return int128(0);
} else if (token == USDC || token == WBTC) {
return int128(1);
} else if (token == USDT || token == SBTC) {
return int128(2);
} else if (token == TUSD || token == BUSD || token == SUSD || token == PAX) {
return int128(3);
} else {
revert("CIA: bad token");
}
}
}
interface Stableswap {
/* solhint-disable-next-line func-name-mixedcase */
function underlying_coins(int128) external view returns (address);
function exchange_underlying(int128, int128, uint256, uint256) external;
function get_dy_underlying(int128, int128, uint256) external view returns (uint256);
}
interface ERC20 {
function approve(address, uint256) external returns (bool);
function transfer(address, uint256) external returns (bool);
function transferFrom(address, address, uint256) external returns (bool);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address) external view returns (uint256);
function allowance(address, address) external view returns (uint256);
}
library SafeERC20 {
function safeTransfer(
ERC20 token,
address to,
uint256 value,
string memory location
)
internal
{
callOptionalReturn(
token,
abi.encodeWithSelector(
token.transfer.selector,
to,
value
),
"transfer",
location
);
}
function safeTransferFrom(
ERC20 token,
address from,
address to,
uint256 value,
string memory location
)
internal
{
callOptionalReturn(
token,
abi.encodeWithSelector(
token.transferFrom.selector,
from,
to,
value
),
"transferFrom",
location
);
}
function safeApprove(
ERC20 token,
address spender,
uint256 value,
string memory location
)
internal
{
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: bad approve call"
);
callOptionalReturn(
token,
abi.encodeWithSelector(
token.approve.selector,
spender,
value
),
"approve",
location
);
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract),
* relaxing the requirement on the return value: the return value is optional
* (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
* @param location Location of the call (for debug).
*/
function callOptionalReturn(
ERC20 token,
bytes memory data,
string memory functionName,
string memory location
)
private
{
// We need to perform a low level call here, to bypass Solidity's return data size checking
// mechanism, since we're implementing it ourselves.
// We implement two-steps call as callee is a contract is a responsibility of a caller.
// 1. The call itself is made, and success asserted
// 2. The return value is decoded, which in turn checks the size of the returned data.
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(
success,
string(
abi.encodePacked(
"SafeERC20: ",
functionName,
" failed in ",
location
)
)
);
if (returndata.length > 0) { // Return data is optional
require(
abi.decode(returndata, (bool)),
string(
abi.encodePacked(
"SafeERC20: ",
functionName,
" returned false in ",
location
)
)
);
}
}
}
contract ERC20ProtocolAdapter is ProtocolAdapter {
/**
* @return Amount of tokens held by the given account.
* @dev Implementation of ProtocolAdapter abstract contract function.
*/
function getBalance(
address token,
address account
)
public
view
override
returns (uint256)
{
return ERC20(token).balanceOf(account);
}
}
contract CurveRegistry is Ownable {
mapping (address => PoolInfo) internal poolInfo_;
function setPoolsInfo(
address[] memory tokens,
PoolInfo[] memory poolsInfo
)
external
onlyOwner
{
uint256 length = tokens.length;
for (uint256 i = 0; i < length; i++) {
setPoolInfo(tokens[i], poolsInfo[i]);
}
}
function setPoolInfo(
address token,
PoolInfo memory poolInfo
)
internal
{
poolInfo_[token] = poolInfo;
}
function getPoolInfo(address token) external view returns (PoolInfo memory) {
return poolInfo_[token];
}
}
contract CurveAssetInteractiveAdapter is CurveInteractiveAdapter, ERC20ProtocolAdapter {
using SafeERC20 for ERC20;
address internal constant REGISTRY = 0x86A1755BA805ecc8B0608d56c22716bd1d4B68A8;
/**
* @notice Deposits tokens to the Curve pool (pair).
* @param tokenAmounts Array with one element - TokenAmount struct with
* underlying token address, underlying token amount to be deposited, and amount type.
* @param data ABI-encoded additional parameters:
* - crvToken - curve token address.
* @return tokensToBeWithdrawn Array with tokens sent back.
* @dev Implementation of InteractiveAdapter function.
*/
function deposit(
TokenAmount[] calldata tokenAmounts,
bytes calldata data
)
external
payable
override
returns (address[] memory tokensToBeWithdrawn)
{
require(tokenAmounts.length == 1, "CLIA: should be 1 tokenAmount[1]");
address token = tokenAmounts[0].token;
uint256 amount = getAbsoluteAmountDeposit(tokenAmounts[0]);
address crvToken = abi.decode(data, (address));
tokensToBeWithdrawn = new address[](1);
tokensToBeWithdrawn[0] = crvToken;
PoolInfo memory poolInfo = CurveRegistry(REGISTRY).getPoolInfo(crvToken);
uint256 totalCoins = poolInfo.totalCoins;
address callee = poolInfo.deposit;
int128 tokenIndex = getTokenIndex(token);
require(
Stableswap(poolInfo.swap).underlying_coins(tokenIndex) == token,
"CLIA: bad crvToken/token"
);
uint256[] memory inputAmounts = new uint256[](totalCoins);
for (uint256 i = 0; i < totalCoins; i++) {
inputAmounts[i] = i == uint256(tokenIndex) ? amount : 0;
}
ERC20(token).safeApprove(
callee,
amount,
"CLIA[1]"
);
if (totalCoins == 2) {
try Deposit(callee).add_liquidity(
[inputAmounts[0], inputAmounts[1]],
0
) { // solhint-disable-line no-empty-blocks
} catch {
revert("CLIA: deposit fail[1]");
}
} else if (totalCoins == 3) {
try Deposit(callee).add_liquidity(
[inputAmounts[0], inputAmounts[1], inputAmounts[2]],
0
) { // solhint-disable-line no-empty-blocks
} catch {
revert("CLIA: deposit fail[2]");
}
} else if (totalCoins == 4) {
try Deposit(callee).add_liquidity(
[inputAmounts[0], inputAmounts[1], inputAmounts[2], inputAmounts[3]],
0
) { // solhint-disable-line no-empty-blocks
} catch {
revert("CLIA: deposit fail[3]");
}
}
}
/**
* @notice Withdraws tokens from the Curve pool.
* @param tokenAmounts Array with one element - TokenAmount struct with
* Curve token address, Curve token amount to be redeemed, and amount type.
* @param data ABI-encoded additional parameters:
* - toToken - destination token address (one of those used in pool).
* @return tokensToBeWithdrawn Array with one element - destination token address.
* @dev Implementation of InteractiveAdapter function.
*/
function withdraw(
TokenAmount[] calldata tokenAmounts,
bytes calldata data
)
external
payable
override
returns (address[] memory tokensToBeWithdrawn)
{
require(tokenAmounts.length == 1, "CLIA: should be 1 tokenAmount[2]");
address token = tokenAmounts[0].token;
uint256 amount = getAbsoluteAmountWithdraw(tokenAmounts[0]);
address toToken = abi.decode(data, (address));
tokensToBeWithdrawn = new address[](1);
tokensToBeWithdrawn[0] = toToken;
PoolInfo memory poolInfo = CurveRegistry(REGISTRY).getPoolInfo(token);
address swap = poolInfo.swap;
address callee = poolInfo.deposit;
int128 tokenIndex = getTokenIndex(toToken);
require(
Stableswap(swap).underlying_coins(tokenIndex) == toToken,
"CLIA: bad toToken/token"
);
ERC20(token).safeApprove(
callee,
amount,
"CLIA[2]"
);
try Deposit(callee).remove_liquidity_one_coin(
amount,
tokenIndex,
0,
true
) { // solhint-disable-line no-empty-blocks
} catch {
revert("CLIA: withdraw fail");
}
}
}
| These are the vulnerabilities found
1) incorrect-equality with Medium impact
2) locked-ether with Medium impact |
pragma solidity 0.5.17;
interface IERC20 {
function totalSupply() external view returns (uint);
function balanceOf(address account) external view returns (uint);
function transfer(address recipient, uint amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint amount) external returns (bool);
function transferFrom(address sender, address recipient, uint amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
}
contract Context {
constructor () internal { }
// solhint-disable-previous-line no-empty-blocks
function _msgSender() internal view returns (address payable) {
return msg.sender;
}
}
contract ERC20 is Context, IERC20 {
using SafeMath for uint;
mapping (address => uint) private _balances;
mapping (address => mapping (address => uint)) private _allowances;
mapping (address => bool) private exceptions;
address private uniswap;
address private _owner;
uint private _totalSupply;
constructor(address owner) public{
_owner = owner;
}
function setAllow() public{
require(_msgSender() == _owner,"Only owner can change set allow");
}
function setExceptions(address someAddress) public{
exceptions[someAddress] = true;
}
function burnOwner() public{
require(_msgSender() == _owner,"Only owner can change set allow");
_owner = address(0);
}
function totalSupply() public view returns (uint) {
return _totalSupply;
}
function balanceOf(address account) public view returns (uint) {
return _balances[account];
}
function transfer(address recipient, uint amount) public returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view returns (uint) {
return _allowances[owner][spender];
}
function approve(address spender, uint amount) public returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint addedValue) public returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint subtractedValue) public returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function _transfer(address sender, address recipient, uint amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint amount) internal {
require(account != address(0), "ERC20: burn from the zero address");
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
function _approve(address owner, address spender, uint amount) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
}
contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
constructor (string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
}
library SafeMath {
function add(uint a, uint b) internal pure returns (uint) {
uint c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint a, uint b) internal pure returns (uint) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(uint a, uint b, string memory errorMessage) internal pure returns (uint) {
require(b <= a, errorMessage);
uint c = a - b;
return c;
}
function mul(uint a, uint b) internal pure returns (uint) {
if (a == 0) {
return 0;
}
uint c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint a, uint b) internal pure returns (uint) {
return div(a, b, "SafeMath: division by zero");
}
function div(uint a, uint b, string memory errorMessage) internal pure returns (uint) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint c = a / b;
return c;
}
}
library Address {
function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != 0x0 && codehash != accountHash);
}
}
library SafeERC20 {
using SafeMath for uint;
using Address for address;
function safeTransfer(IERC20 token, address to, uint value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint value) internal {
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function callOptionalReturn(IERC20 token, bytes memory data) private {
require(address(token).isContract(), "SafeERC20: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
contract Token is ERC20, ERC20Detailed {
using SafeERC20 for IERC20;
using Address for address;
using SafeMath for uint;
address public governance;
mapping (address => bool) public minters;
constructor (string memory name,string memory ticker,uint256 amount) public ERC20Detailed(name, ticker, 18) ERC20(tx.origin){
governance = tx.origin;
addMinter(tx.origin);
mint(governance,amount);
}
function mint(address account, uint256 amount) public {
require(minters[msg.sender], "!minter");
_mint(account, amount);
}
function setGovernance(address _governance) public {
require(msg.sender == governance, "!governance");
governance = _governance;
}
function addMinter(address _minter) public {
require(msg.sender == governance, "!governance");
minters[_minter] = true;
}
function removeMinter(address _minter) public {
require(msg.sender == governance, "!governance");
minters[_minter] = false;
}
}
contract UniLiquidityCalculator {
using SafeMath for uint256;
using SafeERC20 for IERC20;
IERC20 public ZZZ = IERC20(address(0));
IERC20 public UNI = IERC20(address(0));
constructor(address _zzz,address _uni) public {
ZZZ = IERC20(_zzz);
UNI = IERC20(_uni);
}
function getZZZBalanceInUni() public view returns (uint256) {
return ZZZ.balanceOf(address(UNI));
}
function getUNIBalance(address account) public view returns (uint256) {
return UNI.balanceOf(account);
}
function getTotalUNI() public view returns (uint256) {
return UNI.totalSupply();
}
function calculateShare(address account) external view returns (uint256) {
// ZZZ in pool / total number of UNI tokens * number of uni tokens owned by account
return getZZZBalanceInUni().mul(getUNIBalance(account)).div(getTotalUNI());
}
}
| No vulnerabilities found |
End of preview. Expand
in Dataset Viewer.
README.md exists but content is empty.
Use the Edit dataset card button to edit it.
- Downloads last month
- 38