fixed: The owner would receive significantlymore tokens than they should (the owner does get 20% for exchange to carbon credits), fixed: Arbitrary token minting by the owner (with function getETH at line 286), fixed: Outdated Syntax (now at 0.5.3), fixed: Unlocked Pragma, fixed: lines 247 and 243 repeatcomputations,fixed: the field startDate appears to be unused

This commit is contained in:
David E. Perez Negron Rocha 2019-11-01 15:00:02 -06:00
parent 6d08410143
commit 872a28108a
2 changed files with 520 additions and 36 deletions

View File

@ -106,35 +106,20 @@ contract Owned {
// token transfers // token transfers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
contract DECAToken is ERC20Interface, Owned, SafeMath { contract DECAToken is ERC20Interface, Owned, SafeMath {
string public symbol; string public symbol = "DECA";
string public name; string public name = "DEcentralized CArbon tokens";
uint8 public decimals; uint8 public decimals = 18;
uint public totalSupply; uint public totalSupply;
uint public startDate; //for testing change weeks for hours...
uint public preICOEnds; uint public preICOEnds = now + 1 hours;
uint public bonus1Ends; uint public bonus1Ends = now + 3 hours;
uint public bonus2Ends; uint public bonus2Ends = now + 6 hours;
uint public endDate; uint public endDate = now + 11 hours;
mapping(address => uint) balances; mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed; mapping(address => mapping(address => uint)) allowed;
//functions that helps against Allowance Double-Spend Exploit
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor () public {
symbol = "DECA";
name = "DEcentralized CArbon tokens";
decimals = 18;
//for testing change weeks for days...
preICOEnds = now + 1 days;
bonus1Ends = now + 3 days;
bonus2Ends = now + 6 days;
endDate = now + 11 days;
}
modifier onlyValidAddress(address addr) { modifier onlyValidAddress(address addr) {
require(addr != address(0), "Address cannot be zero"); require(addr != address(0), "Address cannot be zero");
_; _;
@ -271,31 +256,37 @@ contract DECAToken is ERC20Interface, Owned, SafeMath {
// 1,000 DECA Tokens per 1 ETH // 1,000 DECA Tokens per 1 ETH
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
function () external payable { function () external payable {
require(now >= startDate && now <= endDate); require(now <= endDate);
uint tokens; uint tokens;
uint toOwner; uint toOwner;
uint toSender; uint toSender;
uint percentage; uint divBy;
// division to get 20% of the total supply for carbon credits
percentage = 2; // percentage that goes to the owner divBy = 4;
if (now <= preICOEnds) { if (now <= preICOEnds) {
tokens = msg.value * 2000; tokens = msg.value * 200;
} else if (now > preICOEnds && now <= bonus1Ends ) { } else if (now > preICOEnds && now <= bonus1Ends ) {
tokens = msg.value * 1500; tokens = msg.value * 150;
} else if (now > bonus1Ends && now <= bonus2Ends) { } else if (now > bonus1Ends && now <= bonus2Ends) {
tokens = msg.value * 1250; tokens = msg.value * 125;
} else { } else {
tokens = msg.value * 1000; tokens = msg.value * 100;
} }
toOwner = safeDiv(tokens, percentage); // percentage assigned to the contract owner (DAO) toOwner = safeDiv(tokens, divBy); // divBy to get the percentage assigned to the contract owner (for exchange to Cabron Credits)
toSender = tokens; // tokens goes to sender toSender = tokens; //tokens that goes to the sender
balances[msg.sender] = safeAdd(balances[msg.sender], toSender); balances[msg.sender] = safeAdd(balances[msg.sender], toSender);
balances[owner] = safeAdd(balances[owner], toOwner); balances[owner] = safeAdd(balances[owner], toOwner);
totalSupply = safeAdd(totalSupply, safeAdd(tokens,safeDiv(tokens, percentage))); totalSupply = safeAdd(totalSupply, safeAdd(toSender,toOwner));
emit Transfer(address(0), msg.sender, toSender); emit Transfer(address(0), msg.sender, toSender);
emit Transfer(address(0), owner, toOwner); emit Transfer(address(0), owner, toOwner);
address(owner).transfer(msg.value); }
//Close down the ICO and claim the Ether.
function getETH() public onlyOwner {
require(now >= endDate );
// transfer the ETH balance in the contract to the owner
owner.transfer(address(this).balance);
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------

493
DECA_IERC20_0.5.3.json Normal file
View File

@ -0,0 +1,493 @@
[
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "spender",
"type": "address"
},
{
"name": "tokens",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "getETH",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "from",
"type": "address"
},
{
"name": "to",
"type": "address"
},
{
"name": "tokens",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "spender",
"type": "address"
},
{
"name": "addedValue",
"type": "uint256"
}
],
"name": "increaseAllowance",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "tokenOwner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "balance",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "acceptOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_CCDBAddress",
"type": "string"
}
],
"name": "updateCCDBAddress",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "spender",
"type": "address"
},
{
"name": "subtractedValue",
"type": "uint256"
}
],
"name": "decreaseAllowance",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "to",
"type": "address"
},
{
"name": "tokens",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "endDate",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getTotalSupply",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "spender",
"type": "address"
},
{
"name": "tokens",
"type": "uint256"
},
{
"name": "data",
"type": "bytes"
}
],
"name": "approveAndCall",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "newOwner",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "CCDBAddress",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "tokenAddress",
"type": "address"
},
{
"name": "tokens",
"type": "uint256"
}
],
"name": "transferAnyERC20Token",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "tokenOwner",
"type": "address"
},
{
"name": "spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"name": "remaining",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "bonus1Ends",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "bonus2Ends",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "preICOEnds",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"payable": true,
"stateMutability": "payable",
"type": "fallback"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_from",
"type": "address"
},
{
"indexed": true,
"name": "_to",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "from",
"type": "address"
},
{
"indexed": true,
"name": "to",
"type": "address"
},
{
"indexed": false,
"name": "tokens",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "tokenOwner",
"type": "address"
},
{
"indexed": true,
"name": "spender",
"type": "address"
},
{
"indexed": false,
"name": "tokens",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
}
]