sol
stringlengths
116
877k
report
stringlengths
298
126k
summary
stringlengths
350
3.62k
// SPDX-License-Identifier: MIT pragma solidity ^0.6.0; // A copy of https://github.com/OpenZeppelin/openzeppelin-contracts/blob/ecc66719bd7681ed4eb8bf406f89a7408569ba9b/contracts/drafts/IERC20Permit.sol /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `amount` as the allowance of `spender` over `owner`'s tokens, * given `owner`'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; import "./IERC20Permit.sol"; import "./ECDSA.sol"; import "./EIP712.sol"; // An adapted copy of https://github.com/OpenZeppelin/openzeppelin-contracts/blob/ecc66719bd7681ed4eb8bf406f89a7408569ba9b/contracts/drafts/ERC20Permit.sol /** * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { using Counters for Counters.Counter; mapping (address => Counters.Counter) private _nonces; // solhint-disable-next-line var-name-mixedcase bytes32 private immutable _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); /** * @dev See {IERC20Permit-permit}. */ function permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual override { // solhint-disable-next-line not-rely-on-time require(block.timestamp <= deadline, "ERC20Permit: expired deadline"); bytes32 structHash = keccak256( abi.encode( _PERMIT_TYPEHASH, owner, spender, amount, _nonces[owner].current(), deadline ) ); bytes32 hash = _hashTypedDataV4(structHash); address signer = ECDSA.recover(hash, v, r, s); require(signer == owner, "ERC20Permit: invalid signature"); _nonces[owner].increment(); // SWC-Transaction Order Dependence: L53 _approve(owner, spender, amount); } /** * @dev See {IERC20Permit-nonces}. */ function nonces(address owner) public view override returns (uint256) { return _nonces[owner].current(); } /** * @dev See {IERC20Permit-DOMAIN_SEPARATOR}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view override returns (bytes32) { return _domainSeparatorV4(); } } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; // A copy of https://github.com/OpenZeppelin/openzeppelin-contracts/blob/ecc66719bd7681ed4eb8bf406f89a7408569ba9b/contracts/cryptography/ECDSA.sol /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { // Check the signature length if (signature.length != 65) { revert("ECDSA: invalid signature length"); } // Divide the signature in r, s and v variables bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. // solhint-disable-next-line no-inline-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return recover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover-bytes32-bytes-} that receives the `v`, * `r` and `s` signature fields separately. */ function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ECDSA: invalid signature s value"); require(v == 27 || v == 28, "ECDSA: invalid signature v value"); // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); require(signer != address(0), "ECDSA: invalid signature"); return signer; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * replicates the behavior of the * https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`] * JSON-RPC method. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; // A copy of https://github.com/OpenZeppelin/openzeppelin-contracts/blob/ecc66719bd7681ed4eb8bf406f89a7408569ba9b/contracts/drafts/EIP712.sol /** * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data. * * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible, * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding * they need in their contracts using a combination of `abi.encode` and `keccak256`. * * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA * ({_hashTypedDataV4}). * * The implementation of the domain separator was designed to be as efficient as possible while still properly updating * the chain id to protect against replay attacks on an eventual fork of the chain. * * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. */ abstract contract EIP712 { /* solhint-disable var-name-mixedcase */ // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to // invalidate the cached domain separator if the chain id changes. bytes32 private immutable _CACHED_DOMAIN_SEPARATOR; uint256 private immutable _CACHED_CHAIN_ID; bytes32 private immutable _HASHED_NAME; bytes32 private immutable _HASHED_VERSION; bytes32 private immutable _TYPE_HASH; /* solhint-enable var-name-mixedcase */ /** * @dev Initializes the domain separator and parameter caches. * * The meaning of `name` and `version` is specified in * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]: * * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. * - `version`: the current major version of the signing domain. * * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart * contract upgrade]. */ constructor(string memory name, string memory version) internal { bytes32 hashedName = keccak256(bytes(name)); bytes32 hashedVersion = keccak256(bytes(version)); bytes32 typeHash = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); _HASHED_NAME = hashedName; _HASHED_VERSION = hashedVersion; _CACHED_CHAIN_ID = _getChainId(); _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion); _TYPE_HASH = typeHash; } /** * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view returns (bytes32) { if (_getChainId() == _CACHED_CHAIN_ID) { return _CACHED_DOMAIN_SEPARATOR; } else { return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION); } } function _buildDomainSeparator(bytes32 typeHash, bytes32 name, bytes32 version) private view returns (bytes32) { return keccak256( abi.encode( typeHash, name, version, _getChainId(), address(this) ) ); } /** * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this * function returns the hash of the fully encoded EIP712 message for this domain. * * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: * * ```solidity * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( * keccak256("Mail(address to,string contents)"), * mailTo, * keccak256(bytes(mailContents)) * ))); * address signer = ECDSA.recover(digest, signature); * ``` */ function _hashTypedDataV4(bytes32 structHash) internal view returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), structHash)); } function _getChainId() private pure returns (uint256 chainId) { // solhint-disable-next-line no-inline-assembly assembly { chainId := chainid() } } } // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; import "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "./ERC20Permit.sol"; contract OneInch is ERC20Permit, ERC20Burnable, Ownable { constructor(address _owner) public ERC20("1INCH Token", "1INCH") EIP712("1INCH Token", "1") { _mint(_owner, 1.5e9 ether); transferOwnership(_owner); } function mint(address to, uint256 amount) external onlyOwner { _mint(to, amount); } }
December 23, 20201INCH TOKEN SMART CONTRACT AUDIT CONTENTS 1.INTRODUCTION................................................................... 1 DISCLAIMER.................................................................... 1 PROJECT OVERVIEW.............................................................. 1 SECURITY ASSESSMENT METHODOLOGY............................................... 2 EXECUTIVE SUMMARY............................................................. 4 PROJECT DASHBOARD............................................................. 4 2.FINDINGS REPORT................................................................ 6 2.1.CRITICAL.................................................................. 6 2.2.MAJOR..................................................................... 6 2.3.WARNING................................................................... 6 WRN-1 Potential front running attack or losing of allowance................... 6 2.4.COMMENTS.................................................................. 7 CMT-1 Mismatch of argument name in _PERMIT_TYPEHASH and permit function ...... 7 3.ABOUT MIXBYTES................................................................. 8 1.INTRODUCTION 1.1DISCLAIMER The audit makes no statements or warranties about utility of the code, safety of the code, suitability of the business model, investment advice, endorsement of the platform or its products, regulatory regime for the business model, or any other statements about fitness of the contracts to purpose, or their bug free status. The audit documentation is for discussion purposes only. The information presented in this report is confidential and privileged. If you are reading this report, you agree to keep it confidential, not to copy, disclose or disseminate without the agreement of 1Inch (name of Client). If you are not the intended recipient(s) of this document, please note that any disclosure, copying or dissemination of its content is strictly forbidden. 1.2PROJECT OVERVIEW 1inch is a DeFi aggregator and a decentralized exchange with smart routing. The core protocol connects a large number of decentralized and centralized platforms in order to minimize price slippage and find the optimal trade for the users. 1inch platform provides a variety of features in addition to swaps. Users can trade via limit orders, deposit funds into lending protocols, move coins between different liquidity pools, and this list expands constantly. 11.3SECURITY ASSESSMENT METHODOLOGY At least 2 auditors are involved in the work on the audit who check the provided source code independently of each other in accordance with the methodology described below: 01"Blind" audit includes: >Manual code study >"Reverse" research and study of the architecture of the code based on the source code only Stage goal: Building an independent view of the project's architecture Finding logical flaws 02Checking the code against the checklist of known vulnerabilities includes: >Manual code check for vulnerabilities from the company's internal checklist >The company's checklist is constantly updated based on the analysis of hacks, research and audit of the clients' code Stage goal: Eliminate typical vulnerabilities (e.g. reentrancy, gas limit, flashloan attacks, etc.) 03Checking the logic, architecture of the security model for compliance with the desired model, which includes: >Detailed study of the project documentation >Examining contracts tests >Examining comments in code >Comparison of the desired model obtained during the study with the reversed view obtained during the blind audit Stage goal: Detection of inconsistencies with the desired model 04Consolidation of the reports from all auditors into one common interim report document >Cross check: each auditor reviews the reports of the others >Discussion of the found issues by the auditors >Formation of a general (merged) report Stage goal: Re-check all the problems for relevance and correctness of the threat level Provide the client with an interim report 05Bug fixing & re-check. >Client fixes or comments on every issue >Upon completion of the bug fixing, the auditors double-check each fix and set the statuses with a link to the fix Stage goal: Preparation of the final code version with all the fixes 06Preparation of the final audit report and delivery to the customer. 2Findings discovered during the audit are classified as follows: FINDINGS SEVERITY BREAKDOWN Level Description Required action CriticalBugs leading to assets theft, fund access locking, or any other loss funds to be transferred to any partyImmediate action to fix issue Major Bugs that can trigger a contract failure. Further recovery is possible only by manual modification of the contract state or replacement.Implement fix as soon as possible WarningBugs that can break the intended contract logic or expose it to DoS attacksTake into consideration and implement fix in certain period CommentOther issues and recommendations reported to/acknowledged by the teamTake into consideration Based on the feedback received from the Customer's team regarding the list of findings discovered by the Contractor, they are assigned the following statuses: Status Description Fixed Recommended fixes have been made to the project code and no longer affect its security. AcknowledgedThe project team is aware of this finding. Recommendations for this finding are planned to be resolved in the future. This finding does not affect the overall safety of the project. No issue Finding does not affect the overall safety of the project and does not violate the logic of its work. 31.4EXECUTIVE SUMMARY The audited contract is a standard ERC-20 token with an additional permit method that implements EIP-712. This improvement allows users to sign allowance for token spending without a transaction. In other words, a spender can issue a signed allowance and provide it by an off-chain to another spender or any other user, then this allowance can be applied without the participation of the original sender and it will not spend any gas from his account. 1.5PROJECT DASHBOARD Client 1Inch Audit name 1Inch Token Initial version 99fd056f91005ca521a02a005f7bcd8f77e06afc Final version 5332caa9b91403a022e74b49c9d0fc9c6d5419f4 SLOC 48 Date 2020-12-22 - 2020-12-23 Auditors engaged 2 auditors FILES LISTING ERC20Permit.sol ERC20Permit.sol OneInch.sol OneInch.sol ECDSA.sol ECDSA.sol EIP712.sol EIP712.sol IERC20Permit.sol IERC20Permit.sol 4FINDINGS SUMMARY Level Amount Critical 0 Major 0 Warning 1 Comment 1 CONCLUSION The smart contract has been audited and no critical and major issues have been found. The contract massively uses libraries from a widely known OpenZeppelin set of contracts which are safe and of high quality. All spotted issues are minor and the contract itself assumed as safe to use according to our security criteria. For the following files from the scope only consistency with their original copies from openzeppelin repository is checked (used commit: ecc66719bd7681ed4eb8bf406f89a7408569ba9b ): https://github.com/1inch-exchange/1inch- token/blob/99fd056f91005ca521a02a005f7bcd8f77e06afc/contracts/ECDSA.sol https://github.com/1inch-exchange/1inch- token/blob/99fd056f91005ca521a02a005f7bcd8f77e06afc/contracts/EIP712.sol https://github.com/1inch-exchange/1inch- token/blob/99fd056f91005ca521a02a005f7bcd8f77e06afc/contracts/IERC20Permit.sol 52.FINDINGS REPORT 2.1CRITICAL Not Found 2.2MAJOR Not Found 2.3WARNING WRN-1 Potential front running attack or losing of allowance File ERC20Permit.sol Severity Warning Status Acknowledged DESCRIPTION At the line ERC20Permit.sol#L53 _approve method replaces the allowance, so there are two potential problems here: 1.If a signer wants to increase the allowance from A to B , a receiver may withdraw A+B using the front-running attack. 2.If a signer wants to send A and B , but a receiver forgot to withdraw A , the receiver will lose ability to withdraw A . RECOMMENDATION We suggest to add permitIncrease , permitDecrease methods and use it instead of the permit . 62.4COMMENTS CMT-1 Mismatch of argument name in _PERMIT_TYPEHASH and permit function File ERC20Permit.sol Severity Comment Status Fixed at 5332caa9 DESCRIPTION At the line ERC20Permit.sol#L27 the value argument is used but at the line ERC20Permit.sol#L32 the argument name is amount . RECOMMENDATION We suggest to rename amount to value in the permit function. CLIENT'S COMMENTARY Created PR at OpenZeppelin's repo: PR-2445 73.ABOUT MIXBYTES MixBytes is a team of blockchain developers, auditors and analysts keen on decentralized systems. We build open-source solutions, smart contracts and blockchain protocols, perform security audits, work on benchmarking and software testing solutions, do research and tech consultancy. BLOCKCHAINS Ethereum EOS Cosmos SubstrateTECH STACK Python Rust Solidity C++ CONTACTS https://github.com/mixbytes/audits_public https://mixbytes.io/ hello@mixbytes.io https://t.me/MixBytes https://twitter.com/mixbytes 8
Issues Count of Minor/Moderate/Major/Critical Minor: 1 Moderate: 0 Major: 0 Critical: 1 Minor Issues 2.a Problem (one line with code reference) CMT-1 Mismatch of argument name in _PERMIT_TYPEHASH and permit function (Line 7) 2.b Fix (one line with code reference) Fix the argument name in _PERMIT_TYPEHASH and permit function (Line 7) Moderate: 0 Major 0 Critical 5.a Problem (one line with code reference) WRN-1 Potential front running attack or losing of allowance (Line 6) 5.b Fix (one line with code reference) Implement a mechanism to prevent front running attack or losing of allowance (Line 6) Observations The audit found no major or moderate issues with the code. The only issue found was a minor issue related to the mismatch of argument name in _PERMIT_TYPEHASH and permit function (Line 7). Conclusion The audit concluded that the code is secure and there are no major or moderate Issues Count of Minor/Moderate/Major/Critical - Minor: 0 - Moderate: 0 - Major: 0 - Critical: 0 Observations - No issues were found during the audit. Conclusion - The audit was successful and no issues were found. Issues Count of Minor/Moderate/Major/Critical - Minor: 0 - Moderate: 0 - Major: 0 - Critical: 0 Observations - The audited contract is a standard ERC-20 token with an additional permit method that implements EIP-712. - The contract massively uses libraries from a widely known OpenZeppelin set of contracts which are safe and of high quality. Conclusion The smart contract has been audited and no critical and major issues have been found.
// SPDX-License-Identifier: MIT pragma solidity 0.8.7; import '@openzeppelin/contracts/token/ERC20/ERC20.sol'; import '@openzeppelin/contracts/access/Ownable.sol'; contract LuckyToken is ERC20, Ownable { string private _name = "Lucky"; string private _symbol = "LUCKY"; uint256 private constant FAIR_LAUNCH = 1 * 1000000 * 10**18; //1 * 1000000 * 10**_decimals; uint256 private constant WAR_CHEST = 5 * 1000000 * 10**18; uint256 private constant ECOSYSTEM = 20 * 1000000 * 10**18; uint256 private constant CAP = 100 * 1000000 * 10**18; //max supply address Owner; address WarChest; address Ecosystem; constructor (address _Owner, address _Warchest, address _Ecosystem) ERC20(_name, _symbol) { //set wallet address Owner = _Owner; WarChest = _Warchest; Ecosystem = _Ecosystem; //mint to Owner's Wallet for Fairlunch _mint(Owner, FAIR_LAUNCH); //mint to WarChest's Wallet _mint(WarChest, WAR_CHEST); //mint to Ecosystem's Wallet _mint(Ecosystem, ECOSYSTEM); //transfer to real owner transferOwnership(_Owner); } /** * @dev Returns the cap on the token's total supply. */ function cap() public view virtual returns (uint256) { return CAP; } function mint(address _to, uint256 _amount) external onlyOwner { _mint(_to, _amount); } /** * @dev See {ERC20-_mint}. */ /// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef). //SWC-Code With No Effects: L54 function _mint(address _to, uint256 _amount) internal virtual onlyOwner override { require(ERC20.totalSupply() + _amount <= cap(), "ERC20Capped: cap exceeded"); super._mint(_to, _amount); } }
Public SMART CONTRACT AUDIT REPORT for LuckyToken Prepared By: Yiqun Chen PeckShield September 19, 2021 1/16 PeckShield Audit Report #: 2021-283Public Document Properties Client Lucky Lion Title Smart Contract Audit Report Target LuckyToken Version 1.0 Author Xiaotao Wu Auditors Xiaotao Wu, Xuxian Jiang Reviewed by Yiqun Chen Approved by Xuxian Jiang Classification Public Version Info Version Date Author Description 1.0 September 19, 2021 Xiaotao Wu Final Release Contact For more information about this document and its contents, please contact PeckShield Inc. Name Yiqun Chen Phone +86 183 5897 7782 Email contact@peckshield.com 2/16 PeckShield Audit Report #: 2021-283Public Contents 1 Introduction 4 1.1 About LuckyToken . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.2 About PeckShield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.3 Methodology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.4 Disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2 Findings 8 2.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.2 Key Findings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3 BEP20 Compliance Checks 10 4 Detailed Results 13 4.1 Redundant Code Removal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4.2 Trust Issue Of Admin Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5 Conclusion 15 References 16 3/16 PeckShield Audit Report #: 2021-283Public 1 | Introduction Given the opportunity to review the design document and related source code of the LuckyToken contract, we outline in the report our systematic method to evaluate potential security issues in the smart contract implementation, expose possible semantic inconsistency between smart contract code and the documentation, and provide additional suggestions or recommendations for improvement. Our results show that the given version of the smart contract is well implemented. In the meantime, the current implementation can be further improved due to the presence of some issues related to BEP20-compliance, security, or performance. This document outlines our audit results. 1.1 About LuckyToken The LuckyToken is a BEP20-compliant token contract deployable on Binance Smart Chain (BSC) . It is the main token distributed as a reward for the Lucky Lion users. The Lucky Lion users can invest the value of their Luckytoken in one of three ways: stake in yield farms, play iGaming, or earn from the revenue sharing pool. This audit validates the BEP20-compliance of its token contract as well as examines other known BEP20 pitfalls/vulnerabilities, if any, in current implementation. The basic information of LuckyToken is as follows: Table 1.1: Basic Information of LuckyToken ItemDescription IssuerLucky Lion Website https://www.luckylion.io/ TypeBEP20Token Contract Platform Solidity Audit Method Whitebox Audit Completion Date September 19, 2021 In the following, we show the Git repository of reviewed file and the commit hash value used in this audit. 4/16 PeckShield Audit Report #: 2021-283Public •https://github.com/LuckyLionIO/Lucky-Token (c9deec5) 1.2 About PeckShield PeckShield Inc. [6] is a leading blockchain security company with the goal of elevating the security, privacy, and usability of current blockchain ecosystem by offering top-notch, industry-leading ser- vices and products (including the service of smart contract auditing). We are reachable at Telegram (https://t.me/peckshield),Twitter( http://twitter.com/peckshield),orEmail( contact@peckshield.com). 1.3 Methodology To standardize the evaluation, we define the following terminology based on OWASP Risk Rating Methodology [5]: •Likelihood represents how likely a particular vulnerability is to be uncovered and exploited in the wild; •Impact measures the technical loss and business damage of a successful attack; •Severity demonstrates the overall criticality of the risk; Likelihood and impact are categorized into three ratings: H,MandL, i.e., high,mediumand lowrespectively. Severity is determined by likelihood and impact and can be classified into four categories accordingly, i.e., Critical,High,Medium,Lowshown in Table 1.2. Table 1.2: Vulnerability Severity ClassificationImpactHigh Critical High Medium Medium High Medium Low Low Medium Low Low High Medium Low Likelihood We perform the audit according to the following procedures: 5/16 PeckShield Audit Report #: 2021-283Public •BasicCodingBugs: We first statically analyze given smart contracts with our proprietary static code analyzer for known coding bugs, and then manually verify (reject or confirm) all the issues found by our tool. •BEP20Compliance Checks: We then manually check whether the implementation logic of the audited smart contract(s) follows the standard BEP20 specification and other best practices. •Additional Recommendations: We also provide additional suggestions regarding the coding and development of smart contracts from the perspective of proven programming practices. Table 1.3: The Full List of Check Items Category Check Item Basic Coding BugsConstructor Mismatch Ownership Takeover Redundant Fallback Function Overflows & Underflows Reentrancy Money-Giving Bug Blackhole Unauthorized Self-Destruct Revert DoS Unchecked External Call Gasless Send Send Instead of Transfer Costly Loop (Unsafe) Use of Untrusted Libraries (Unsafe) Use of Predictable Variables Transaction Ordering Dependence Deprecated Uses Approve / TransferFrom Race Condition BEP20 Compliance Checks Compliance Checks (Section 3) Additional RecommendationsAvoiding Use of Variadic Byte Array Using Fixed Compiler Version Making Visibility Level Explicit Making Type Inference Explicit Adhering To Function Declaration Strictly Following Other Best Practices To evaluate the risk, we go through a list of check items and each would be labeled with a severity category. For one check item, if our tool does not identify any issue, the contract is considered safe 6/16 PeckShield Audit Report #: 2021-283Public regarding the check item. For any discovered issue, we might further deploy contracts on our private testnet and run tests to confirm the findings. If necessary, we would additionally build a PoC to demonstrate the possibility of exploitation. The concrete list of check items is shown in Table 1.3. 1.4 Disclaimer Note that this security audit is not designed to replace functional tests required before any software release, and does not give any warranties on finding all possible security issues of the given smart contract(s) or blockchain software, i.e., the evaluation result does not guarantee the nonexistence of any further findings of security issues. As one audit-based assessment cannot be considered comprehensive, we always recommend proceeding with several independent audits and a public bug bounty program to ensure the security of smart contract(s). Last but not least, this security audit should not be used as investment advice. 7/16 PeckShield Audit Report #: 2021-283Public 2 | Findings 2.1 Summary Here is a summary of our findings after analyzing the LuckyToken contract. During the first phase of our audit, we study the smart contract source code and run our in-house static code analyzer through the codebase. The purpose here is to statically identify known coding bugs, and then manually verify (reject or confirm) issues reported by our tool. We further manually review business logics, examine systemoperations, andplaceBEP20-relatedaspectsunderscrutinytouncoverpossiblepitfallsand/or bugs. Severity # of Findings Critical 0 High 0 Medium 1 Low 0 Informational 1 Total 2 Moreover, we explicitly evaluate whether the given contracts follow the standard BEP20 specifi- cation and other known best practices, and validate its compatibility with other similar BEP20 tokens and current DeFi protocols. The detailed BEP20 compliance checks are reported in Section 3. After that, we examine a few identified issues of varying severities that need to be brought up and paid more attention to. (The findings are categorized in the above table.) Additional information can be found in the next subsection, and the detailed discussions are in Section 4. 8/16 PeckShield Audit Report #: 2021-283Public 2.2 Key Findings Overall, a minor BEP20 compliance issue was found and our detailed checklist can be found in Section 3. Overall, there is no critical or high severity issue, although the implementation can be improved by resolving the identified issues (shown in Table 2.1), including 1medium-severity vulnerability and 1informational recommendation. Table 2.1: Key LuckyToken Audit Findings ID Severity Title Category Status PVE-001 Informational Redundant Code Removal Coding Practices Confirmed PVE-002 Medium Trust Issue Of Admin Roles Security Features Confirmed Besides recommending specific countermeasures to mitigate these issues, we also emphasize that it is always important to develop necessary risk-control mechanisms and make contingency plans, which may need to be exercised before the mainnet deployment. The risk-control mechanisms need to kick in at the very moment when the contracts are being deployed in mainnet. Please refer to Section 3 for our detailed compliance checks and Section 4 for elaboration of reported issues. 9/16 PeckShield Audit Report #: 2021-283Public 3 | BEP20 Compliance Checks TheBEP20specificationdefinesalistofAPIfunctions(andrelevantevents)thateachtokencontract is expected to implement (and emit). The failure to meet these requirements means the token contract cannot be considered to be BEP20-compliant. Naturally, as the first step of our audit, we examine the list of API functions defined by the BEP20 specification and validate whether there exist any inconsistency or incompatibility in the implementation or the inherent business logic of the audited contract(s). Table 3.1: Basic View-Only Functions Defined in The BEP20 Specification Item Description Status name()Is declared as a public view function ✓ Returns a string, for example “Tether USD” ✓ symbol()Is declared as a public view function ✓ Returns the symbol by which the token contract should be known, for example “USDT”. It is usually 3or4characters in length✓ decimals()Is declared as a public view function ✓ Returns decimals, which refers to how divisible a token can be, from 0 (not at all divisible) to 18(pretty much continuous) and even higher if required✓ totalSupply()Is declared as a public view function ✓ Returns the number of total supplied tokens, including the total minted tokens (minus the total burned tokens) ever since the deployment✓ balanceOf()Is declared as a public view function ✓ Anyone can query any address’ balance, as all data on the blockchain is public✓ allowance()Is declared as a public view function ✓ Returns the amount which the spender is still allowed to withdraw from the owner✓ getOwner()Is declared as a public view function × Returns the bep20 token owner which is necessary for binding with bep2 token.× Our analysis shows that there is a minor BEP20 inconsistency or incompatibility issue found 10/16 PeckShield Audit Report #: 2021-283Public in the audited LuckyToken contract. Specifically, the getOwner() function is an extended method of EIP20and is currently not defined. Tokens that do not implement this method will not be able to flow across the Binance Chain and Binance Smart Chain (BSC).1In the surrounding two tables, we outline the respective list of basic view-only functions (Table 3.1) and key state-changing functions (Table 3.2) according to the widely-adopted BEP20 specification. Table 3.2: Key State-Changing Functions Defined in The BEP20 Specification Item Description Status transfer()Is declared as a public function ✓ Returns a boolean value which accurately reflects the token transfer status ✓ Reverts if the caller does not have enough tokens to spend ✓ Allows zero amount transfers ✓ Emits Transfer() event when tokens are transferred successfully (include 0 amount transfers)✓ Reverts while transferring to zero address ✓ transferFrom()Is declared as a public function ✓ Returns a boolean value which accurately reflects the token transfer status ✓ Reverts if the spender does not have enough token allowances to spend ✓ Updates the spender’s token allowances when tokens are transferred suc- cessfully✓ Reverts if the from address does not have enough tokens to spend ✓ Allows zero amount transfers ✓ Emits Transfer() event when tokens are transferred successfully (include 0 amount transfers)✓ Reverts while transferring from zero address ✓ Reverts while transferring to zero address ✓ approve()Is declared as a public function ✓ Returnsabooleanvaluewhichaccuratelyreflectsthetokenapprovalstatus ✓ Emits Approval() event when tokens are approved successfully ✓ Reverts while approving to zero address ✓ Transfer() eventIs emitted when tokens are transferred, including zero value transfers ✓ Is emitted with the from address set to 𝑎𝑑𝑑𝑟𝑒𝑠𝑠 (0𝑥0)when new tokens are generated✓ Approval() eventIs emitted on any successful call to approve() ✓ In addition, we perform a further examination on certain features that are permitted by the BEP20 specification or even further extended in follow-up refinements and enhancements, but not requiredforimplementation. Thesefeaturesaregenerallyhelpful, butmayalsoimpactorbringcertain incompatibility with current DeFi protocols. Therefore, we consider it is important to highlight them as well. This list is shown in Table 3.3. 1This issue has been resolved by adding the required getOwner() function. 11/16 PeckShield Audit Report #: 2021-283Public Table 3.3: Additional Opt-inFeatures Examined in Our Audit Feature Description Opt-in Deflationary Part of the tokens are burned or transferred as fee while on trans- fer()/transferFrom() calls— Rebasing The balanceOf() function returns a re-based balance instead of the actual stored amount of tokens owned by the specific address— Pausable The token contract allows the owner or privileged users to pause the token transfers and other operations— Blacklistable The token contract allows the owner or privileged users to blacklist a specific address such that token transfers and other operations related to that address are prohibited— Mintable The token contract allows the owner or privileged users to mint tokens to a specific address✓ Burnable The token contract allows the owner or privileged users to burn tokens of a specific address— 12/16 PeckShield Audit Report #: 2021-283Public 4 | Detailed Results 4.1 Redundant Code Removal •ID: PVE-001 •Severity: Informational •Likelihood: N/A •Impact: N/A•Target: LuckyToken •Category: Coding Practices [4] •CWE subcategory: CWE-563 [2] Description As an ERC20-compliant token contract, the LuckyToken contract provides the external mint()function for the privileged _owneraccount to mint more tokens into circulation. This function internally calls the low-level helper routine, i.e., _mint(), to mint the specified amount of Luckytoken for a specified account and also to limit the total token supply does not exceed the capvalue. While reviewing the implementation of this _mint()routine, we observe the presence of un- necessary redundancy that can be safely removed. Specifically, the onlyOwner modifier (line 53) is redundant since the _mint()routine is defined as an internal function. In current LuckyToken imple- mentation, this routine will only be called by the constructor and the external mint()function. Since theonlyOwner modifier is also applied to the external mint()function (line 45), we suggest to remove this redundant modifier for the _mint()routine. 45 function mint ( address _to , uint256 _amount ) external onlyOwner { 46 _mint (_to , _amount ); 47 } 48 49 /** 50 * @dev See {ERC20 - _mint }. 51 */ 52 /// @notice Creates ‘_amount ‘ token to ‘_to ‘. Must only be called by the owner ( MasterChef ). 53 function _mint ( address _to , uint256 _amount ) internal virtual onlyOwner override { 54 require ( ERC20 . totalSupply () + _amount <= cap () , " ERC20Capped : cap exceeded "); 55 super . _mint (_to , _amount ); 13/16 PeckShield Audit Report #: 2021-283Public 56 } Listing 4.1: LuckyToken::mint()/_mint() Recommendation Consider the removal of the redundant onlyOwner modifier for the internal _mintfunction. Status This issue has been confirmed. 4.2 Trust Issue Of Admin Roles •ID: PVE-002 •Severity: Medium •Likelihood: Medium •Impact:Medium•Target: LuckyToken •Category: Security Features [3] •CWE subcategory: CWE-287 [1] Description InLuckyToken , there is a privileged _ownerthat plays a critical role, i.e., minting additional tokens into circulation. In the following, we show the code snippet of the mint()function that is affected by the privileged account. 45 function mint ( address _to , uint256 _amount ) external onlyOwner { 46 _mint (_to , _amount ); 47 } Listing 4.2: LuckyToken::mint() We emphasize that the privilege assignment is necessary and consistent with the protocol design. At the same time the extra power to the owner may also be a counter-party risk to the token users. Therefore, we list this concern as an issue here from the audit perspective and highly recommend making these onlyOwner privileges explicit or raising necessary awareness among token users. Recommendation Make the list of extra privileges granted to _ownerexplicit to LuckyToken users. Status This issue has been confirmed. The team confirms that LuckyToken ’s ownership will be transferred to the Masterchef for LP farming. 14/16 PeckShield Audit Report #: 2021-283Public 5 | Conclusion In this security audit, we have examined the LuckyToken design and implementation. During our audit, we first checked all respects related to the compatibility of the BEP20 specification and other known BEP20 pitfalls/vulnerabilities and found no issue in these areas. We then proceeded to examine other areas such as coding practices and business logics. Overall, although no critical or high level vulnerabilities were discovered, we identified two medium/informational severity issues that were promptly confirmed and addressed by the team. Meanwhile, as disclaimed in Section 1.4, we appreciate any constructive feedbacks or suggestions about our findings, procedures, audit scope, etc. 15/16 PeckShield Audit Report #: 2021-283Public References [1] MITRE. CWE-287: Improper Authentication. https://cwe.mitre.org/data/definitions/287.html. [2] MITRE. CWE-563: Assignment to Variable without Use. https://cwe.mitre.org/data/ definitions/563.html. [3] MITRE. CWE CATEGORY: 7PK - Security Features. https://cwe.mitre.org/data/definitions/ 254.html. [4] MITRE. CWE CATEGORY: Bad Coding Practices. https://cwe.mitre.org/data/definitions/ 1006.html. [5] OWASP. RiskRatingMethodology. https://www.owasp.org/index.php/OWASP_Risk_Rating_ Methodology. [6] PeckShield. PeckShield Inc. https://www.peckshield.com. 16/16 PeckShield Audit Report #: 2021-283
Issues Count of Minor/Moderate/Major/Critical - Minor: 2 - Moderate: 1 - Major: 0 - Critical: 0 Minor Issues 2.a Problem (one line with code reference) - Unnecessary code in the contract (Lines 11-14) 2.b Fix (one line with code reference) - Remove unnecessary code (Lines 11-14) Moderate 3.a Problem (one line with code reference) - Lack of trust issue of admin roles (Lines 15-17) 3.b Fix (one line with code reference) - Add trust issue of admin roles (Lines 15-17) Major - None Critical - None Observations - The LuckyToken contract is well implemented and BEP20-compliant. - There are some minor and moderate issues that can be improved. Conclusion The LuckyToken contract is well implemented and BEP20-compliant. However, there are some minor and moderate issues that can be improved. We recommend that the client address these issues to ensure the security and performance of the contract. Issues Count of Minor/Moderate/Major/Critical: - Minor: 2 - Moderate: 0 - Major: 0 - Critical: 0 Minor Issues: 2.a Problem: Lack of a function to check the total supply of tokens (OWASP A9) 2.b Fix: Add a function to check the total supply of tokens Observations: - No Moderate, Major, or Critical issues were found Conclusion: The audit of the LuckyToken smart contract revealed two minor issues, which have been addressed. No Moderate, Major, or Critical issues were found. Issues Count of Minor/Moderate/Major/Critical: Minor: 0 Moderate: 0 Major: 0 Critical: 0 Observations: No issues were found in the LuckyToken contract. Conclusion: The LuckyToken contract is secure and follows best practices.
"// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity 0.8.3;\n\nimport {ERC20} from \"@open(...TRUNCATED)
"  \n8 8 m p h v 3  \nS e c u r i t y A s s e s s m e n t  \nAugust 6, 2021  \n (...TRUNCATED)
"\nIssues Count of Minor/Moderate/Major/Critical\n- Minor: 8\n- Moderate: 4\n- Major: 3\n- Critical:(...TRUNCATED)
"// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.13;\n\nimport \"./Interfaces/IBAIToken.sol\"(...TRUNCATED)
"Public\nSMART CONTRACT AUDIT REPORT\nfor\nAstridDAO\nPrepared By: Xiaomi Huang\nPeckShield\nMay 22,(...TRUNCATED)
"\nIssues Count of Minor/Moderate/Major/Critical:\n- Minor: 4\n- Moderate: 4\n- Major: 1\n- Critical(...TRUNCATED)
"// SPDX-License-Identifier: MIT\npragma solidity ^0.7.3;\n\nimport \"@openzeppelin/contracts-upgrad(...TRUNCATED)
"Zer0 - zNS\nZer0 - zNS\nDate\nDate\nMay 2021\nLead Auditor\nLead Auditor\nDavid Oz Kashi\nCo-audito(...TRUNCATED)
"\nIssues Count of Minor/Moderate/Major/Critical\n- Minor: 2\n- Moderate: 3\n- Major: 0\n- Critical:(...TRUNCATED)
"pragma solidity >=0.4.21 <0.6.0;\n\ncontract Migrations {\n address public owner;\n uint public l(...TRUNCATED)
"February 3rd 2020— Quantstamp Verified AirSwap\nThis smart contract audit was prepared by Quantst(...TRUNCATED)
"\nIssues Count of Minor/Moderate/Major/Critical\n- Minor: 4\n- Moderate: 2\n- Major: 1\n- Critical:(...TRUNCATED)
"pragma solidity >=0.4.21 <0.6.0;\n\ncontract Migrations {\n address public owner;\n uint public l(...TRUNCATED)
"Public\nSMART CONTRACT AUDIT REPORT\nfor\nAirSwap Protocol\nPrepared By: Yiqun Chen\nPeckShield\nFe(...TRUNCATED)
"\nIssues Count of Minor/Moderate/Major/Critical\n- Minor: 4\n- Moderate: 2\n- Major: 1\n- Critical:(...TRUNCATED)
"pragma solidity >=0.4.21 <0.6.0;\n\ncontract Migrations {\n address public owner;\n uint public l(...TRUNCATED)
"February 3rd 2020— Quantstamp Verified AirSwap\nThis smart contract audit was prepared by Quantst(...TRUNCATED)
"\nIssues Count of Minor/Moderate/Major/Critical\n- Minor: 4\n- Moderate: 2\n- Major: 1\n- Critical:(...TRUNCATED)
"pragma solidity >=0.4.21 <0.6.0;\n\ncontract Migrations {\n address public owner;\n uint public l(...TRUNCATED)
"Public\nSMART CONTRACT AUDIT REPORT\nfor\nAirSwap Protocol\nPrepared By: Yiqun Chen\nPeckShield\nFe(...TRUNCATED)
"\nIssues Count of Minor/Moderate/Major/Critical\n- Minor: 4\n- Moderate: 2\n- Major: 1\n- Critical:(...TRUNCATED)
"pragma solidity >=0.4.21 <0.6.0;\n\ncontract Migrations {\n address public owner;\n uint public l(...TRUNCATED)
"February 3rd 2020— Quantstamp Verified AirSwap\nThis smart contract audit was prepared by Quantst(...TRUNCATED)
"\nIssues Count of Minor/Moderate/Major/Critical\n- Minor: 4\n- Moderate: 2\n- Major: 1\n- Critical:(...TRUNCATED)
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
2
Edit dataset card