├── README.md ├── doc ├── en │ ├── solidity-in-depth.rst │ ├── logo.svg │ ├── bugs.rst │ ├── structure-of-a-contract.rst │ ├── utils │ │ └── SolidityLexer.py │ ├── contributing.rst │ ├── metadata.rst │ ├── Makefile │ ├── index.rst │ ├── make.bat │ ├── grammar.txt │ ├── layout-of-source-files.rst │ ├── bugs.json │ ├── conf.py │ ├── units-and-global-variables.rst │ └── installing-solidity.rst └── zh │ ├── solidity-in-depth.rst │ ├── logo.svg │ ├── bugs.rst │ ├── structure-of-a-contract.rst │ ├── utils │ └── SolidityLexer.py │ ├── contributing.rst │ ├── index.rst │ ├── metadata.rst │ ├── Makefile │ ├── make.bat │ ├── grammar.txt │ ├── layout-of-source-files.rst │ ├── installing-solidity.rst │ ├── bugs.json │ ├── conf.py │ ├── units-and-global-variables.rst │ ├── introduction-to-smart-contracts.rst │ └── common-patterns.rst └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | ## Solidity 中文文档 2 | 3 | 官方地址: 4 | 中文社区: 5 | 6 | ## 相关地址 7 | 8 | Solidity 中文社区: http://solidity.apachecn.org/ 9 | Solidity 中文文档: http://solidity.apachecn.org/cn/doc/v0.4.21 10 | Solidity 英文文档: https://solidity.readthedocs.io/en/v0.4.20/ 11 | 12 | ## 项目负责人 13 | 14 | [@那伊抹微笑](https://github.com/wangyangting) 15 | -------------------------------------------------------------------------------- /doc/en/solidity-in-depth.rst: -------------------------------------------------------------------------------- 1 | ################# 2 | Solidity in Depth 3 | ################# 4 | 5 | This section should provide you with all you need to know about Solidity. 6 | If something is missing here, please contact us on 7 | `Gitter `_ or make a pull request on 8 | `Github `_. 9 | 10 | .. toctree:: 11 | :maxdepth: 2 12 | 13 | layout-of-source-files.rst 14 | structure-of-a-contract.rst 15 | types.rst 16 | units-and-global-variables.rst 17 | control-structures.rst 18 | contracts.rst 19 | assembly.rst 20 | miscellaneous.rst 21 | -------------------------------------------------------------------------------- /doc/zh/solidity-in-depth.rst: -------------------------------------------------------------------------------- 1 | ################# 2 | 深入理解 Solidity 3 | ################# 4 | 5 | This section should provide you with all you need to know about Solidity. 6 | If something is missing here, please contact us on 7 | `Gitter `_ or make a pull request on 8 | `Github `_. 9 | 10 | .. toctree:: 11 | :maxdepth: 2 12 | 13 | layout-of-source-files.rst 14 | structure-of-a-contract.rst 15 | types.rst 16 | units-and-global-variables.rst 17 | control-structures.rst 18 | contracts.rst 19 | assembly.rst 20 | miscellaneous.rst 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | -------------------------------------------------------------------------------- /doc/en/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | Vector 1 8 | Created with Sketch. 9 | 10 | 11 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /doc/zh/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | Vector 1 8 | Created with Sketch. 9 | 10 | 11 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /doc/zh/bugs.rst: -------------------------------------------------------------------------------- 1 | .. index:: Bugs 2 | 3 | .. _known_bugs: 4 | 5 | ################## 6 | 已知 Bugs 列表 7 | ################## 8 | 9 | Below, you can find a JSON-formatted list of some of the known security-relevant bugs in the 10 | Solidity compiler. The file itself is hosted in the `Github repository 11 | `_. 12 | The list stretches back as far as version 0.3.0, bugs known to be present only 13 | in versions preceding that are not listed. 14 | 15 | There is another file called `bugs_by_version.json 16 | `_, 17 | which can be used to check which bugs affect a specific version of the compiler. 18 | 19 | Contract source verification tools and also other tools interacting with 20 | contracts should consult this list according to the following criteria: 21 | 22 | - It is mildly suspicious if a contract was compiled with a nightly 23 | compiler version instead of a released version. This list does not keep 24 | track of unreleased or nightly versions. 25 | - It is also mildly suspicious if a contract was compiled with a version that was 26 | not the most recent at the time the contract was created. For contracts 27 | created from other contracts, you have to follow the creation chain 28 | back to a transaction and use the date of that transaction as creation date. 29 | - It is highly suspicious if a contract was compiled with a compiler that 30 | contains a known bug and the contract was created at a time where a newer 31 | compiler version containing a fix was already released. 32 | 33 | The JSON file of known bugs below is an array of objects, one for each bug, 34 | with the following keys: 35 | 36 | name 37 | Unique name given to the bug 38 | summary 39 | Short description of the bug 40 | description 41 | Detailed description of the bug 42 | link 43 | URL of a website with more detailed information, optional 44 | introduced 45 | The first published compiler version that contained the bug, optional 46 | fixed 47 | The first published compiler version that did not contain the bug anymore 48 | publish 49 | The date at which the bug became known publicly, optional 50 | severity 51 | Severity of the bug: very low, low, medium, high. Takes into account 52 | discoverability in contract tests, likelihood of occurrence and 53 | potential damage by exploits. 54 | conditions 55 | Conditions that have to be met to trigger the bug. Currently, this 56 | is an object that can contain a boolean value ``optimizer``, which 57 | means that the optimizer has to be switched on to enable the bug. 58 | If no conditions are given, assume that the bug is present. 59 | 60 | .. literalinclude:: bugs.json 61 | :language: js 62 | -------------------------------------------------------------------------------- /doc/en/bugs.rst: -------------------------------------------------------------------------------- 1 | .. index:: Bugs 2 | 3 | .. _known_bugs: 4 | 5 | ################## 6 | List of Known Bugs 7 | ################## 8 | 9 | Below, you can find a JSON-formatted list of some of the known security-relevant bugs in the 10 | Solidity compiler. The file itself is hosted in the `Github repository 11 | `_. 12 | The list stretches back as far as version 0.3.0, bugs known to be present only 13 | in versions preceding that are not listed. 14 | 15 | There is another file called `bugs_by_version.json 16 | `_, 17 | which can be used to check which bugs affect a specific version of the compiler. 18 | 19 | Contract source verification tools and also other tools interacting with 20 | contracts should consult this list according to the following criteria: 21 | 22 | - It is mildly suspicious if a contract was compiled with a nightly 23 | compiler version instead of a released version. This list does not keep 24 | track of unreleased or nightly versions. 25 | - It is also mildly suspicious if a contract was compiled with a version that was 26 | not the most recent at the time the contract was created. For contracts 27 | created from other contracts, you have to follow the creation chain 28 | back to a transaction and use the date of that transaction as creation date. 29 | - It is highly suspicious if a contract was compiled with a compiler that 30 | contains a known bug and the contract was created at a time where a newer 31 | compiler version containing a fix was already released. 32 | 33 | The JSON file of known bugs below is an array of objects, one for each bug, 34 | with the following keys: 35 | 36 | name 37 | Unique name given to the bug 38 | summary 39 | Short description of the bug 40 | description 41 | Detailed description of the bug 42 | link 43 | URL of a website with more detailed information, optional 44 | introduced 45 | The first published compiler version that contained the bug, optional 46 | fixed 47 | The first published compiler version that did not contain the bug anymore 48 | publish 49 | The date at which the bug became known publicly, optional 50 | severity 51 | Severity of the bug: very low, low, medium, high. Takes into account 52 | discoverability in contract tests, likelihood of occurrence and 53 | potential damage by exploits. 54 | conditions 55 | Conditions that have to be met to trigger the bug. Currently, this 56 | is an object that can contain a boolean value ``optimizer``, which 57 | means that the optimizer has to be switched on to enable the bug. 58 | If no conditions are given, assume that the bug is present. 59 | 60 | .. literalinclude:: bugs.json 61 | :language: js 62 | -------------------------------------------------------------------------------- /doc/en/structure-of-a-contract.rst: -------------------------------------------------------------------------------- 1 | .. index:: contract, state variable, function, event, struct, enum, function;modifier 2 | 3 | .. _contract_structure: 4 | 5 | *********************** 6 | Structure of a Contract 7 | *********************** 8 | 9 | Contracts in Solidity are similar to classes in object-oriented languages. 10 | Each contract can contain declarations of :ref:`structure-state-variables`, :ref:`structure-functions`, 11 | :ref:`structure-function-modifiers`, :ref:`structure-events`, :ref:`structure-struct-types` and :ref:`structure-enum-types`. 12 | Furthermore, contracts can inherit from other contracts. 13 | 14 | .. _structure-state-variables: 15 | 16 | State Variables 17 | =============== 18 | 19 | State variables are values which are permanently stored in contract storage. 20 | 21 | :: 22 | 23 | pragma solidity ^0.4.0; 24 | 25 | contract SimpleStorage { 26 | uint storedData; // State variable 27 | // ... 28 | } 29 | 30 | See the :ref:`types` section for valid state variable types and 31 | :ref:`visibility-and-getters` for possible choices for 32 | visibility. 33 | 34 | .. _structure-functions: 35 | 36 | Functions 37 | ========= 38 | 39 | Functions are the executable units of code within a contract. 40 | 41 | :: 42 | 43 | pragma solidity ^0.4.0; 44 | 45 | contract SimpleAuction { 46 | function bid() public payable { // Function 47 | // ... 48 | } 49 | } 50 | 51 | :ref:`function-calls` can happen internally or externally 52 | and have different levels of visibility (:ref:`visibility-and-getters`) 53 | towards other contracts. 54 | 55 | .. _structure-function-modifiers: 56 | 57 | Function Modifiers 58 | ================== 59 | 60 | Function modifiers can be used to amend the semantics of functions in a declarative way 61 | (see :ref:`modifiers` in contracts section). 62 | 63 | :: 64 | 65 | pragma solidity ^0.4.11; 66 | 67 | contract Purchase { 68 | address public seller; 69 | 70 | modifier onlySeller() { // Modifier 71 | require(msg.sender == seller); 72 | _; 73 | } 74 | 75 | function abort() public onlySeller { // Modifier usage 76 | // ... 77 | } 78 | } 79 | 80 | .. _structure-events: 81 | 82 | Events 83 | ====== 84 | 85 | Events are convenience interfaces with the EVM logging facilities. 86 | 87 | :: 88 | 89 | pragma solidity ^0.4.21; 90 | 91 | contract SimpleAuction { 92 | event HighestBidIncreased(address bidder, uint amount); // Event 93 | 94 | function bid() public payable { 95 | // ... 96 | emit HighestBidIncreased(msg.sender, msg.value); // Triggering event 97 | } 98 | } 99 | 100 | See :ref:`events` in contracts section for information on how events are declared 101 | and can be used from within a dapp. 102 | 103 | .. _structure-struct-types: 104 | 105 | Struct Types 106 | ============= 107 | 108 | Structs are custom defined types that can group several variables (see 109 | :ref:`structs` in types section). 110 | 111 | :: 112 | 113 | pragma solidity ^0.4.0; 114 | 115 | contract Ballot { 116 | struct Voter { // Struct 117 | uint weight; 118 | bool voted; 119 | address delegate; 120 | uint vote; 121 | } 122 | } 123 | 124 | .. _structure-enum-types: 125 | 126 | Enum Types 127 | ========== 128 | 129 | Enums can be used to create custom types with a finite set of values (see 130 | :ref:`enums` in types section). 131 | 132 | :: 133 | 134 | pragma solidity ^0.4.0; 135 | 136 | contract Purchase { 137 | enum State { Created, Locked, Inactive } // Enum 138 | } 139 | -------------------------------------------------------------------------------- /doc/zh/structure-of-a-contract.rst: -------------------------------------------------------------------------------- 1 | .. index:: contract, state variable, function, event, struct, enum, function;modifier 2 | 3 | .. _contract_structure: 4 | 5 | *********************** 6 | Structure of a Contract 7 | *********************** 8 | 9 | Contracts in Solidity are similar to classes in object-oriented languages. 10 | Each contract can contain declarations of :ref:`structure-state-variables`, :ref:`structure-functions`, 11 | :ref:`structure-function-modifiers`, :ref:`structure-events`, :ref:`structure-struct-types` and :ref:`structure-enum-types`. 12 | Furthermore, contracts can inherit from other contracts. 13 | 14 | .. _structure-state-variables: 15 | 16 | State Variables 17 | =============== 18 | 19 | State variables are values which are permanently stored in contract storage. 20 | 21 | :: 22 | 23 | pragma solidity ^0.4.0; 24 | 25 | contract SimpleStorage { 26 | uint storedData; // State variable 27 | // ... 28 | } 29 | 30 | See the :ref:`types` section for valid state variable types and 31 | :ref:`visibility-and-getters` for possible choices for 32 | visibility. 33 | 34 | .. _structure-functions: 35 | 36 | Functions 37 | ========= 38 | 39 | Functions are the executable units of code within a contract. 40 | 41 | :: 42 | 43 | pragma solidity ^0.4.0; 44 | 45 | contract SimpleAuction { 46 | function bid() public payable { // Function 47 | // ... 48 | } 49 | } 50 | 51 | :ref:`function-calls` can happen internally or externally 52 | and have different levels of visibility (:ref:`visibility-and-getters`) 53 | towards other contracts. 54 | 55 | .. _structure-function-modifiers: 56 | 57 | Function Modifiers 58 | ================== 59 | 60 | Function modifiers can be used to amend the semantics of functions in a declarative way 61 | (see :ref:`modifiers` in contracts section). 62 | 63 | :: 64 | 65 | pragma solidity ^0.4.11; 66 | 67 | contract Purchase { 68 | address public seller; 69 | 70 | modifier onlySeller() { // Modifier 71 | require(msg.sender == seller); 72 | _; 73 | } 74 | 75 | function abort() public onlySeller { // Modifier usage 76 | // ... 77 | } 78 | } 79 | 80 | .. _structure-events: 81 | 82 | Events 83 | ====== 84 | 85 | Events are convenience interfaces with the EVM logging facilities. 86 | 87 | :: 88 | 89 | pragma solidity ^0.4.21; 90 | 91 | contract SimpleAuction { 92 | event HighestBidIncreased(address bidder, uint amount); // Event 93 | 94 | function bid() public payable { 95 | // ... 96 | emit HighestBidIncreased(msg.sender, msg.value); // Triggering event 97 | } 98 | } 99 | 100 | See :ref:`events` in contracts section for information on how events are declared 101 | and can be used from within a dapp. 102 | 103 | .. _structure-struct-types: 104 | 105 | Struct Types 106 | ============= 107 | 108 | Structs are custom defined types that can group several variables (see 109 | :ref:`structs` in types section). 110 | 111 | :: 112 | 113 | pragma solidity ^0.4.0; 114 | 115 | contract Ballot { 116 | struct Voter { // Struct 117 | uint weight; 118 | bool voted; 119 | address delegate; 120 | uint vote; 121 | } 122 | } 123 | 124 | .. _structure-enum-types: 125 | 126 | Enum Types 127 | ========== 128 | 129 | Enums can be used to create custom types with a finite set of values (see 130 | :ref:`enums` in types section). 131 | 132 | :: 133 | 134 | pragma solidity ^0.4.0; 135 | 136 | contract Purchase { 137 | enum State { Created, Locked, Inactive } // Enum 138 | } 139 | -------------------------------------------------------------------------------- /doc/en/utils/SolidityLexer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import re 4 | import copy 5 | 6 | from pygments.lexer import RegexLexer, ExtendedRegexLexer, bygroups, using, \ 7 | include, this 8 | from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 9 | Number, Other, Punctuation, Literal 10 | 11 | __all__ = ['SolidityLexer'] 12 | 13 | class SolidityLexer(RegexLexer): 14 | name = "Solidity" 15 | aliases = ['sol', 'solidity'] 16 | filenames = ['*.sol'] 17 | mimetypes = [] 18 | flags = re.DOTALL 19 | tokens = { 20 | 'commentsandwhitespace': [ 21 | (r'\s+', Text), 22 | (r'