Skip to content

Commit

Permalink
chore: add notes to selector table implementation (#3618)
Browse files Browse the repository at this point in the history
and a couple sanity checks
  • Loading branch information
charles-cooper authored Sep 25, 2023
1 parent 79303fc commit 1e9922d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions vyper/codegen/function_definitions/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ class EntryPointInfo:
min_calldatasize: int # the min calldata required for this entry point
ir_node: IRnode # the ir for this entry point

def __post_init__(self):
# ABI v2 property guaranteed by the spec.
# https://docs.soliditylang.org/en/v0.8.21/abi-spec.html#formal-specification-of-the-encoding states: # noqa: E501
# > Note that for any X, len(enc(X)) is a multiple of 32.
assert self.min_calldatasize >= 4
assert (self.min_calldatasize - 4) % 32 == 0


@dataclass
class ExternalFuncIR(FuncIR):
Expand Down
5 changes: 4 additions & 1 deletion vyper/codegen/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ def _generate_external_entry_points(external_functions, global_ctx):
for code in external_functions:
func_ir = generate_ir_for_function(code, global_ctx)
for abi_sig, entry_point in func_ir.entry_points.items():
method_id = method_id_int(abi_sig)
assert abi_sig not in entry_points
assert method_id not in sig_of

entry_points[abi_sig] = entry_point
sig_of[method_id_int(abi_sig)] = abi_sig
sig_of[method_id] = abi_sig

# stick function common body into final entry point to save a jump
ir_node = IRnode.from_list(["seq", entry_point.ir_node, func_ir.common_ir])
Expand Down

0 comments on commit 1e9922d

Please sign in to comment.