We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Function selector collision is not detected with the "0" selector
### Version Information

* vyper Version (output of `vyper --version`): 0.1.0-beta.12

### What's your issue about?

Vyper has an edge case in function selector collision detection. If a function with selector `0x00000000` exists, the `__default__` function is overwritten in the resulting contract. Here's an example: 

```
owner: public(address)

@public
def __init__():
    self.owner = msg.sender

@public
@payable
def blockHashAskewLimitary(v: uint256): # function selector: 0x00000000
    send(self.owner, self.balance)

@public
@payable
def __default__():
    assert msg.value != 0
    send(msg.sender, self.balance)
```

Calls made to the above contract with no calldata trigger `blockHashAskewLimitary(uint)`, rather than the default function. It seems that `v` is also successfully decoded, even without calldata.

### How can it be fixed?

Solidity uses `CALLDATASIZE` to differentiate between functions with the "0" selector, and the fallback function. As for the variable unpacking from empty calldata, a check should be in place that each function has some minimum `CALLDATASIZE`.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `vyper/parser/parser.py`
Content:
```
1 from typing import (
2     Any,
3     List,
4 )
5 
6 from vyper import ast
7 from vyper.ast_utils import (
8     parse_to_ast,
9 )
10 from vyper.exceptions import (
11     EventDeclarationException,
12     FunctionDeclarationException,
13     StructureException,
14 )
15 from vyper.parser.function_definitions import (
16     is_default_func,
17     is_initializer,
18     parse_function,
19 )
20 from vyper.parser.global_context import (
21     GlobalContext,
22 )
23 from vyper.parser.lll_node import (
24     LLLnode,
25 )
26 from vyper.signatures import (
27     sig_utils,
28 )
29 from vyper.signatures.event_signature import (
30     EventSignature,
31 )
32 from vyper.signatures.function_signature import (
33     FunctionSignature,
34 )
35 from vyper.signatures.interface import (
36     check_valid_contract_interface,
37 )
38 from vyper.utils import (
39     LOADED_LIMIT_MAP,
40 )
41 
42 if not hasattr(ast, 'AnnAssign'):
43     raise Exception("Requires python 3.6 or higher for annotation support")
44 
45 # Header code
46 STORE_CALLDATA: List[Any] = ['seq', ['mstore', 28, ['calldataload', 0]]]
47 # Store limit constants at fixed addresses in memory.
48 LIMIT_MEMORY_SET: List[Any] = [
49     ['mstore', pos, limit_size]
50     for pos, limit_size in LOADED_LIMIT_MAP.items()
51 ]
52 FUNC_INIT_LLL = LLLnode.from_list(
53     STORE_CALLDATA + LIMIT_MEMORY_SET, typ=None
54 )
55 INIT_FUNC_INIT_LLL = LLLnode.from_list(
56     ['seq'] + LIMIT_MEMORY_SET, typ=None
57 )
58 
59 
60 # Header code
61 INITIALIZER_LIST = ['seq', ['mstore', 28, ['calldataload', 0]]]
62 # Store limit constants at fixed addresses in memory.
63 INITIALIZER_LIST += [['mstore', pos, limit_size] for pos, limit_size in LOADED_LIMIT_MAP.items()]
64 INITIALIZER_LLL = LLLnode.from_list(INITIALIZER_LIST, typ=None)
65 
66 
67 def parse_events(sigs, global_ctx):
68     for event in global_ctx._events:
69         sigs[event.target.id] = EventSignature.from_declaration(event, global_ctx)
70     return sigs
71 
72 
73 def parse_external_contracts(external_contracts, global_ctx):
74     for _contractname in global_ctx._contracts:
75         _contract_defs = global_ctx._contracts[_contractname]
76         _defnames = [_def.name for _def in _contract_defs]
77         contract = {}
78         if len(set(_defnames)) < len(_contract_defs):
79             raise FunctionDeclarationException(
80                 "Duplicate function name: %s" % (
81                     [name for name in _defnames if _defnames.count(name) > 1][0]
82                 )
83             )
84 
85         for _def in _contract_defs:
86             constant = False
87             # test for valid call type keyword.
88             if len(_def.body) == 1 and \
89                isinstance(_def.body[0], ast.Expr) and \
90                isinstance(_def.body[0].value, ast.Name) and \
91                _def.body[0].value.id in ('modifying', 'constant'):
92                 constant = True if _def.body[0].value.id == 'constant' else False
93             else:
94                 raise StructureException('constant or modifying call type must be specified', _def)
95             # Recognizes already-defined structs
96             sig = FunctionSignature.from_definition(
97                 _def,
98                 contract_def=True,
99                 constant_override=constant,
100                 custom_structs=global_ctx._structs,
101                 constants=global_ctx._constants
102             )
103             contract[sig.name] = sig
104         external_contracts[_contractname] = contract
105 
106     for interface_name, interface in global_ctx._interfaces.items():
107         external_contracts[interface_name] = {
108             sig.name: sig
109             for sig in interface
110             if isinstance(sig, FunctionSignature)
111         }
112 
113     return external_contracts
114 
115 
116 def parse_other_functions(o,
117                           otherfuncs,
118                           sigs,
119                           external_contracts,
120                           origcode,
121                           global_ctx,
122                           default_function,
123                           runtime_only):
124     sub = ['seq', FUNC_INIT_LLL]
125     add_gas = FUNC_INIT_LLL.gas
126 
127     for _def in otherfuncs:
128         sub.append(
129             parse_function(_def, {**{'self': sigs}, **external_contracts}, origcode, global_ctx)
130         )
131         sub[-1].total_gas += add_gas
132         add_gas += 30
133         for sig in sig_utils.generate_default_arg_sigs(_def, external_contracts, global_ctx):
134             sig.gas = sub[-1].total_gas
135             sigs[sig.sig] = sig
136 
137     # Add fallback function
138     if default_function:
139         default_func = parse_function(
140             default_function[0],
141             {**{'self': sigs}, **external_contracts},
142             origcode,
143             global_ctx,
144         )
145         sub.append(default_func)
146     else:
147         sub.append(LLLnode.from_list(['revert', 0, 0], typ=None, annotation='Default function'))
148     if runtime_only:
149         return sub
150     else:
151         o.append(['return', 0, ['lll', sub, 0]])
152         return o
153 
154 
155 # Main python parse tree => LLL method
156 def parse_tree_to_lll(code, origcode, runtime_only=False, interface_codes=None):
157     global_ctx = GlobalContext.get_global_context(code, interface_codes=interface_codes)
158     _names_def = [_def.name for _def in global_ctx._defs]
159     # Checks for duplicate function names
160     if len(set(_names_def)) < len(_names_def):
161         raise FunctionDeclarationException(
162             "Duplicate function name: %s" % (
163                 [name for name in _names_def if _names_def.count(name) > 1][0]
164             )
165         )
166     _names_events = [_event.target.id for _event in global_ctx._events]
167     # Checks for duplicate event names
168     if len(set(_names_events)) < len(_names_events):
169         raise EventDeclarationException(
170             "Duplicate event name: %s" % (
171                 [name for name in _names_events if _names_events.count(name) > 1][0]
172             )
173         )
174     # Initialization function
175     initfunc = [_def for _def in global_ctx._defs if is_initializer(_def)]
176     # Default function
177     defaultfunc = [_def for _def in global_ctx._defs if is_default_func(_def)]
178     # Regular functions
179     otherfuncs = [
180         _def
181         for _def
182         in global_ctx._defs
183         if not is_initializer(_def) and not is_default_func(_def)
184     ]
185     sigs = {}
186     external_contracts = {}
187     # Create the main statement
188     o = ['seq']
189     if global_ctx._events:
190         sigs = parse_events(sigs, global_ctx)
191     if global_ctx._contracts or global_ctx._interfaces:
192         external_contracts = parse_external_contracts(external_contracts, global_ctx)
193     # If there is an init func...
194     if initfunc:
195         o.append(INIT_FUNC_INIT_LLL)
196         o.append(parse_function(
197             initfunc[0],
198             {**{'self': sigs}, **external_contracts},
199             origcode,
200             global_ctx,
201         ))
202 
203     # If there are regular functions...
204     if otherfuncs or defaultfunc:
205         o = parse_other_functions(
206             o, otherfuncs, sigs, external_contracts, origcode, global_ctx, defaultfunc, runtime_only
207         )
208 
209     # Check if interface of contract is correct.
210     check_valid_contract_interface(global_ctx, sigs)
211 
212     return LLLnode.from_list(o, typ=None)
213 
214 
215 def parse_to_lll(kode, runtime_only=False, interface_codes=None):
216     code = parse_to_ast(kode)
217     return parse_tree_to_lll(code, kode, runtime_only=runtime_only, interface_codes=interface_codes)
218
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/vyper/parser/parser.py b/vyper/parser/parser.py
--- a/vyper/parser/parser.py
+++ b/vyper/parser/parser.py
@@ -43,7 +43,13 @@
     raise Exception("Requires python 3.6 or higher for annotation support")
 
 # Header code
-STORE_CALLDATA: List[Any] = ['seq', ['mstore', 28, ['calldataload', 0]]]
+STORE_CALLDATA: List[Any] = \
+        ['seq',
+            # check that calldatasize is at least 4, otherwise
+            # calldataload will load zeros (cf. yellow paper).
+            ['if', ['lt', 'calldatasize', 4],
+                ['goto', 'fallback']],
+            ['mstore', 28, ['calldataload', 0]]]
 # Store limit constants at fixed addresses in memory.
 LIMIT_MEMORY_SET: List[Any] = [
     ['mstore', pos, limit_size]
@@ -57,13 +63,6 @@
 )
 
 
-# Header code
-INITIALIZER_LIST = ['seq', ['mstore', 28, ['calldataload', 0]]]
-# Store limit constants at fixed addresses in memory.
-INITIALIZER_LIST += [['mstore', pos, limit_size] for pos, limit_size in LOADED_LIMIT_MAP.items()]
-INITIALIZER_LLL = LLLnode.from_list(INITIALIZER_LIST, typ=None)
-
-
 def parse_events(sigs, global_ctx):
     for event in global_ctx._events:
         sigs[event.target.id] = EventSignature.from_declaration(event, global_ctx)
@@ -142,9 +141,10 @@
             origcode,
             global_ctx,
         )
-        sub.append(default_func)
+        fallback = default_func
     else:
-        sub.append(LLLnode.from_list(['revert', 0, 0], typ=None, annotation='Default function'))
+        fallback = LLLnode.from_list(['revert', 0, 0], typ=None, annotation='Default function')
+    sub.append(['seq_unchecked', ['label', 'fallback'], fallback])
     if runtime_only:
         return sub
     else:

{"golden_diff": "diff --git a/vyper/parser/parser.py b/vyper/parser/parser.py\n--- a/vyper/parser/parser.py\n+++ b/vyper/parser/parser.py\n@@ -43,7 +43,13 @@\n     raise Exception(\"Requires python 3.6 or higher for annotation support\")\n \n # Header code\n-STORE_CALLDATA: List[Any] = ['seq', ['mstore', 28, ['calldataload', 0]]]\n+STORE_CALLDATA: List[Any] = \\\n+        ['seq',\n+            # check that calldatasize is at least 4, otherwise\n+            # calldataload will load zeros (cf. yellow paper).\n+            ['if', ['lt', 'calldatasize', 4],\n+                ['goto', 'fallback']],\n+            ['mstore', 28, ['calldataload', 0]]]\n # Store limit constants at fixed addresses in memory.\n LIMIT_MEMORY_SET: List[Any] = [\n     ['mstore', pos, limit_size]\n@@ -57,13 +63,6 @@\n )\n \n \n-# Header code\n-INITIALIZER_LIST = ['seq', ['mstore', 28, ['calldataload', 0]]]\n-# Store limit constants at fixed addresses in memory.\n-INITIALIZER_LIST += [['mstore', pos, limit_size] for pos, limit_size in LOADED_LIMIT_MAP.items()]\n-INITIALIZER_LLL = LLLnode.from_list(INITIALIZER_LIST, typ=None)\n-\n-\n def parse_events(sigs, global_ctx):\n     for event in global_ctx._events:\n         sigs[event.target.id] = EventSignature.from_declaration(event, global_ctx)\n@@ -142,9 +141,10 @@\n             origcode,\n             global_ctx,\n         )\n-        sub.append(default_func)\n+        fallback = default_func\n     else:\n-        sub.append(LLLnode.from_list(['revert', 0, 0], typ=None, annotation='Default function'))\n+        fallback = LLLnode.from_list(['revert', 0, 0], typ=None, annotation='Default function')\n+    sub.append(['seq_unchecked', ['label', 'fallback'], fallback])\n     if runtime_only:\n         return sub\n     else:\n", "issue": "Function selector collision is not detected with the \"0\" selector\n### Version Information\r\n\r\n* vyper Version (output of `vyper --version`): 0.1.0-beta.12\r\n\r\n### What's your issue about?\r\n\r\nVyper has an edge case in function selector collision detection. If a function with selector `0x00000000` exists, the `__default__` function is overwritten in the resulting contract. Here's an example: \r\n\r\n```\r\nowner: public(address)\r\n\r\n@public\r\ndef __init__():\r\n    self.owner = msg.sender\r\n\r\n@public\r\n@payable\r\ndef blockHashAskewLimitary(v: uint256): # function selector: 0x00000000\r\n    send(self.owner, self.balance)\r\n\r\n@public\r\n@payable\r\ndef __default__():\r\n    assert msg.value != 0\r\n    send(msg.sender, self.balance)\r\n```\r\n\r\nCalls made to the above contract with no calldata trigger `blockHashAskewLimitary(uint)`, rather than the default function. It seems that `v` is also successfully decoded, even without calldata.\r\n\r\n### How can it be fixed?\r\n\r\nSolidity uses `CALLDATASIZE` to differentiate between functions with the \"0\" selector, and the fallback function. As for the variable unpacking from empty calldata, a check should be in place that each function has some minimum `CALLDATASIZE`.\r\n\n", "before_files": [{"content": "from typing import (\n    Any,\n    List,\n)\n\nfrom vyper import ast\nfrom vyper.ast_utils import (\n    parse_to_ast,\n)\nfrom vyper.exceptions import (\n    EventDeclarationException,\n    FunctionDeclarationException,\n    StructureException,\n)\nfrom vyper.parser.function_definitions import (\n    is_default_func,\n    is_initializer,\n    parse_function,\n)\nfrom vyper.parser.global_context import (\n    GlobalContext,\n)\nfrom vyper.parser.lll_node import (\n    LLLnode,\n)\nfrom vyper.signatures import (\n    sig_utils,\n)\nfrom vyper.signatures.event_signature import (\n    EventSignature,\n)\nfrom vyper.signatures.function_signature import (\n    FunctionSignature,\n)\nfrom vyper.signatures.interface import (\n    check_valid_contract_interface,\n)\nfrom vyper.utils import (\n    LOADED_LIMIT_MAP,\n)\n\nif not hasattr(ast, 'AnnAssign'):\n    raise Exception(\"Requires python 3.6 or higher for annotation support\")\n\n# Header code\nSTORE_CALLDATA: List[Any] = ['seq', ['mstore', 28, ['calldataload', 0]]]\n# Store limit constants at fixed addresses in memory.\nLIMIT_MEMORY_SET: List[Any] = [\n    ['mstore', pos, limit_size]\n    for pos, limit_size in LOADED_LIMIT_MAP.items()\n]\nFUNC_INIT_LLL = LLLnode.from_list(\n    STORE_CALLDATA + LIMIT_MEMORY_SET, typ=None\n)\nINIT_FUNC_INIT_LLL = LLLnode.from_list(\n    ['seq'] + LIMIT_MEMORY_SET, typ=None\n)\n\n\n# Header code\nINITIALIZER_LIST = ['seq', ['mstore', 28, ['calldataload', 0]]]\n# Store limit constants at fixed addresses in memory.\nINITIALIZER_LIST += [['mstore', pos, limit_size] for pos, limit_size in LOADED_LIMIT_MAP.items()]\nINITIALIZER_LLL = LLLnode.from_list(INITIALIZER_LIST, typ=None)\n\n\ndef parse_events(sigs, global_ctx):\n    for event in global_ctx._events:\n        sigs[event.target.id] = EventSignature.from_declaration(event, global_ctx)\n    return sigs\n\n\ndef parse_external_contracts(external_contracts, global_ctx):\n    for _contractname in global_ctx._contracts:\n        _contract_defs = global_ctx._contracts[_contractname]\n        _defnames = [_def.name for _def in _contract_defs]\n        contract = {}\n        if len(set(_defnames)) < len(_contract_defs):\n            raise FunctionDeclarationException(\n                \"Duplicate function name: %s\" % (\n                    [name for name in _defnames if _defnames.count(name) > 1][0]\n                )\n            )\n\n        for _def in _contract_defs:\n            constant = False\n            # test for valid call type keyword.\n            if len(_def.body) == 1 and \\\n               isinstance(_def.body[0], ast.Expr) and \\\n               isinstance(_def.body[0].value, ast.Name) and \\\n               _def.body[0].value.id in ('modifying', 'constant'):\n                constant = True if _def.body[0].value.id == 'constant' else False\n            else:\n                raise StructureException('constant or modifying call type must be specified', _def)\n            # Recognizes already-defined structs\n            sig = FunctionSignature.from_definition(\n                _def,\n                contract_def=True,\n                constant_override=constant,\n                custom_structs=global_ctx._structs,\n                constants=global_ctx._constants\n            )\n            contract[sig.name] = sig\n        external_contracts[_contractname] = contract\n\n    for interface_name, interface in global_ctx._interfaces.items():\n        external_contracts[interface_name] = {\n            sig.name: sig\n            for sig in interface\n            if isinstance(sig, FunctionSignature)\n        }\n\n    return external_contracts\n\n\ndef parse_other_functions(o,\n                          otherfuncs,\n                          sigs,\n                          external_contracts,\n                          origcode,\n                          global_ctx,\n                          default_function,\n                          runtime_only):\n    sub = ['seq', FUNC_INIT_LLL]\n    add_gas = FUNC_INIT_LLL.gas\n\n    for _def in otherfuncs:\n        sub.append(\n            parse_function(_def, {**{'self': sigs}, **external_contracts}, origcode, global_ctx)\n        )\n        sub[-1].total_gas += add_gas\n        add_gas += 30\n        for sig in sig_utils.generate_default_arg_sigs(_def, external_contracts, global_ctx):\n            sig.gas = sub[-1].total_gas\n            sigs[sig.sig] = sig\n\n    # Add fallback function\n    if default_function:\n        default_func = parse_function(\n            default_function[0],\n            {**{'self': sigs}, **external_contracts},\n            origcode,\n            global_ctx,\n        )\n        sub.append(default_func)\n    else:\n        sub.append(LLLnode.from_list(['revert', 0, 0], typ=None, annotation='Default function'))\n    if runtime_only:\n        return sub\n    else:\n        o.append(['return', 0, ['lll', sub, 0]])\n        return o\n\n\n# Main python parse tree => LLL method\ndef parse_tree_to_lll(code, origcode, runtime_only=False, interface_codes=None):\n    global_ctx = GlobalContext.get_global_context(code, interface_codes=interface_codes)\n    _names_def = [_def.name for _def in global_ctx._defs]\n    # Checks for duplicate function names\n    if len(set(_names_def)) < len(_names_def):\n        raise FunctionDeclarationException(\n            \"Duplicate function name: %s\" % (\n                [name for name in _names_def if _names_def.count(name) > 1][0]\n            )\n        )\n    _names_events = [_event.target.id for _event in global_ctx._events]\n    # Checks for duplicate event names\n    if len(set(_names_events)) < len(_names_events):\n        raise EventDeclarationException(\n            \"Duplicate event name: %s\" % (\n                [name for name in _names_events if _names_events.count(name) > 1][0]\n            )\n        )\n    # Initialization function\n    initfunc = [_def for _def in global_ctx._defs if is_initializer(_def)]\n    # Default function\n    defaultfunc = [_def for _def in global_ctx._defs if is_default_func(_def)]\n    # Regular functions\n    otherfuncs = [\n        _def\n        for _def\n        in global_ctx._defs\n        if not is_initializer(_def) and not is_default_func(_def)\n    ]\n    sigs = {}\n    external_contracts = {}\n    # Create the main statement\n    o = ['seq']\n    if global_ctx._events:\n        sigs = parse_events(sigs, global_ctx)\n    if global_ctx._contracts or global_ctx._interfaces:\n        external_contracts = parse_external_contracts(external_contracts, global_ctx)\n    # If there is an init func...\n    if initfunc:\n        o.append(INIT_FUNC_INIT_LLL)\n        o.append(parse_function(\n            initfunc[0],\n            {**{'self': sigs}, **external_contracts},\n            origcode,\n            global_ctx,\n        ))\n\n    # If there are regular functions...\n    if otherfuncs or defaultfunc:\n        o = parse_other_functions(\n            o, otherfuncs, sigs, external_contracts, origcode, global_ctx, defaultfunc, runtime_only\n        )\n\n    # Check if interface of contract is correct.\n    check_valid_contract_interface(global_ctx, sigs)\n\n    return LLLnode.from_list(o, typ=None)\n\n\ndef parse_to_lll(kode, runtime_only=False, interface_codes=None):\n    code = parse_to_ast(kode)\n    return parse_tree_to_lll(code, kode, runtime_only=runtime_only, interface_codes=interface_codes)\n", "path": "vyper/parser/parser.py"}], "after_files": [{"content": "from typing import (\n    Any,\n    List,\n)\n\nfrom vyper import ast\nfrom vyper.ast_utils import (\n    parse_to_ast,\n)\nfrom vyper.exceptions import (\n    EventDeclarationException,\n    FunctionDeclarationException,\n    StructureException,\n)\nfrom vyper.parser.function_definitions import (\n    is_default_func,\n    is_initializer,\n    parse_function,\n)\nfrom vyper.parser.global_context import (\n    GlobalContext,\n)\nfrom vyper.parser.lll_node import (\n    LLLnode,\n)\nfrom vyper.signatures import (\n    sig_utils,\n)\nfrom vyper.signatures.event_signature import (\n    EventSignature,\n)\nfrom vyper.signatures.function_signature import (\n    FunctionSignature,\n)\nfrom vyper.signatures.interface import (\n    check_valid_contract_interface,\n)\nfrom vyper.utils import (\n    LOADED_LIMIT_MAP,\n)\n\nif not hasattr(ast, 'AnnAssign'):\n    raise Exception(\"Requires python 3.6 or higher for annotation support\")\n\n# Header code\nSTORE_CALLDATA: List[Any] = \\\n        ['seq',\n            # check that calldatasize is at least 4, otherwise\n            # calldataload will load zeros (cf. yellow paper).\n            ['if', ['lt', 'calldatasize', 4],\n                ['goto', 'fallback']],\n            ['mstore', 28, ['calldataload', 0]]]\n# Store limit constants at fixed addresses in memory.\nLIMIT_MEMORY_SET: List[Any] = [\n    ['mstore', pos, limit_size]\n    for pos, limit_size in LOADED_LIMIT_MAP.items()\n]\nFUNC_INIT_LLL = LLLnode.from_list(\n    STORE_CALLDATA + LIMIT_MEMORY_SET, typ=None\n)\nINIT_FUNC_INIT_LLL = LLLnode.from_list(\n    ['seq'] + LIMIT_MEMORY_SET, typ=None\n)\n\n\ndef parse_events(sigs, global_ctx):\n    for event in global_ctx._events:\n        sigs[event.target.id] = EventSignature.from_declaration(event, global_ctx)\n    return sigs\n\n\ndef parse_external_contracts(external_contracts, global_ctx):\n    for _contractname in global_ctx._contracts:\n        _contract_defs = global_ctx._contracts[_contractname]\n        _defnames = [_def.name for _def in _contract_defs]\n        contract = {}\n        if len(set(_defnames)) < len(_contract_defs):\n            raise FunctionDeclarationException(\n                \"Duplicate function name: %s\" % (\n                    [name for name in _defnames if _defnames.count(name) > 1][0]\n                )\n            )\n\n        for _def in _contract_defs:\n            constant = False\n            # test for valid call type keyword.\n            if len(_def.body) == 1 and \\\n               isinstance(_def.body[0], ast.Expr) and \\\n               isinstance(_def.body[0].value, ast.Name) and \\\n               _def.body[0].value.id in ('modifying', 'constant'):\n                constant = True if _def.body[0].value.id == 'constant' else False\n            else:\n                raise StructureException('constant or modifying call type must be specified', _def)\n            # Recognizes already-defined structs\n            sig = FunctionSignature.from_definition(\n                _def,\n                contract_def=True,\n                constant_override=constant,\n                custom_structs=global_ctx._structs,\n                constants=global_ctx._constants\n            )\n            contract[sig.name] = sig\n        external_contracts[_contractname] = contract\n\n    for interface_name, interface in global_ctx._interfaces.items():\n        external_contracts[interface_name] = {\n            sig.name: sig\n            for sig in interface\n            if isinstance(sig, FunctionSignature)\n        }\n\n    return external_contracts\n\n\ndef parse_other_functions(o,\n                          otherfuncs,\n                          sigs,\n                          external_contracts,\n                          origcode,\n                          global_ctx,\n                          default_function,\n                          runtime_only):\n    sub = ['seq', FUNC_INIT_LLL]\n    add_gas = FUNC_INIT_LLL.gas\n\n    for _def in otherfuncs:\n        sub.append(\n            parse_function(_def, {**{'self': sigs}, **external_contracts}, origcode, global_ctx)\n        )\n        sub[-1].total_gas += add_gas\n        add_gas += 30\n        for sig in sig_utils.generate_default_arg_sigs(_def, external_contracts, global_ctx):\n            sig.gas = sub[-1].total_gas\n            sigs[sig.sig] = sig\n\n    # Add fallback function\n    if default_function:\n        default_func = parse_function(\n            default_function[0],\n            {**{'self': sigs}, **external_contracts},\n            origcode,\n            global_ctx,\n        )\n        fallback = default_func\n    else:\n        fallback = LLLnode.from_list(['revert', 0, 0], typ=None, annotation='Default function')\n    sub.append(['seq_unchecked', ['label', 'fallback'], fallback])\n    if runtime_only:\n        return sub\n    else:\n        o.append(['return', 0, ['lll', sub, 0]])\n        return o\n\n\n# Main python parse tree => LLL method\ndef parse_tree_to_lll(code, origcode, runtime_only=False, interface_codes=None):\n    global_ctx = GlobalContext.get_global_context(code, interface_codes=interface_codes)\n    _names_def = [_def.name for _def in global_ctx._defs]\n    # Checks for duplicate function names\n    if len(set(_names_def)) < len(_names_def):\n        raise FunctionDeclarationException(\n            \"Duplicate function name: %s\" % (\n                [name for name in _names_def if _names_def.count(name) > 1][0]\n            )\n        )\n    _names_events = [_event.target.id for _event in global_ctx._events]\n    # Checks for duplicate event names\n    if len(set(_names_events)) < len(_names_events):\n        raise EventDeclarationException(\n            \"Duplicate event name: %s\" % (\n                [name for name in _names_events if _names_events.count(name) > 1][0]\n            )\n        )\n    # Initialization function\n    initfunc = [_def for _def in global_ctx._defs if is_initializer(_def)]\n    # Default function\n    defaultfunc = [_def for _def in global_ctx._defs if is_default_func(_def)]\n    # Regular functions\n    otherfuncs = [\n        _def\n        for _def\n        in global_ctx._defs\n        if not is_initializer(_def) and not is_default_func(_def)\n    ]\n    sigs = {}\n    external_contracts = {}\n    # Create the main statement\n    o = ['seq']\n    if global_ctx._events:\n        sigs = parse_events(sigs, global_ctx)\n    if global_ctx._contracts or global_ctx._interfaces:\n        external_contracts = parse_external_contracts(external_contracts, global_ctx)\n    # If there is an init func...\n    if initfunc:\n        o.append(INIT_FUNC_INIT_LLL)\n        o.append(parse_function(\n            initfunc[0],\n            {**{'self': sigs}, **external_contracts},\n            origcode,\n            global_ctx,\n        ))\n\n    # If there are regular functions...\n    if otherfuncs or defaultfunc:\n        o = parse_other_functions(\n            o, otherfuncs, sigs, external_contracts, origcode, global_ctx, defaultfunc, runtime_only\n        )\n\n    # Check if interface of contract is correct.\n    check_valid_contract_interface(global_ctx, sigs)\n\n    return LLLnode.from_list(o, typ=None)\n\n\ndef parse_to_lll(kode, runtime_only=False, interface_codes=None):\n    code = parse_to_ast(kode)\n    return parse_tree_to_lll(code, kode, runtime_only=runtime_only, interface_codes=interface_codes)\n", "path": "vyper/parser/parser.py"}]}