Skip to content

Commit aa8affb

Browse files
feat: close external section with goto fallback (vyperlang#2692)
ensure basic block hygiene by closing with a terminating instruction
1 parent a37bde5 commit aa8affb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

vyper/codegen/module.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,19 @@ def parse_regular_functions(
168168
external_seq.append(["assert", ["iszero", "callvalue"]])
169169
external_seq += nonpayable_funcs
170170

171+
# ensure the external jumptable section gets closed out
172+
# (for basic block hygiene and also for zksync interpreter)
173+
# NOTE: this jump gets optimized out in assembly since the
174+
# fallback label is the immediate next instruction,
175+
close_selector_section = ["goto", "fallback"]
176+
171177
# bytecode is organized by: external functions, fallback fn, internal functions
172178
# this way we save gas and reduce bytecode by not jumping over internal functions
173179
runtime = [
174180
"seq",
175181
func_init_lll(),
176182
["with", "_calldata_method_id", ["mload", 0], external_seq],
183+
close_selector_section,
177184
["label", "fallback", ["var_list"], fallback_lll],
178185
]
179186
runtime.extend(internal_funcs)

0 commit comments

Comments
 (0)