Skip to content

fix[lang]: fix allowing un-instantiable events - #5206

Open
Sporarum wants to merge 8 commits into
vyperlang:masterfrom
Sporarum:fix-unusable-event
Open

fix[lang]: fix allowing un-instantiable events#5206
Sporarum wants to merge 8 commits into
vyperlang:masterfrom
Sporarum:fix-unusable-event

Conversation

@Sporarum

Copy link
Copy Markdown
Collaborator

What I did

Fix #5137

How I did it

Catch the invalid types in EventT.from_EventDef
Convert the type mismatch at use-site to a CodegenPanic

How to verify it

pytest, includes new tests

Commit message

Event definitions accepted `indexed(T)` for any type T at parse time,
but the `log` codegen only handled primitive words and bytestrings.
Reference types (arrays, structs, dynamic arrays) passed declaration and
then failed at every use-site with a `TypeMismatch`.

Validate indexed argument types in `EventT.from_EventDef`, restricting
them to primitive words and bytestrings. The now-unreachable checks in
the legacy and venom event codegen become `CodegenPanic`.

Description for the changelog

Fix being allowed to create events which are then un-instantiable

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@github-actions

Copy link
Copy Markdown

Gas Changes

No changes detected.

Summary

  • Total tests measured: 560
  • Changed: 0
  • Regressions (gas up): 0
  • Improvements (gas down): 0
  • New tests: 0
  • Deleted tests: 0
  • Newly failing: 0
  • Newly passing: 0

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1df785bc96

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vyper/codegen/events.py
else:
# TODO block at higher level
raise TypeMismatch("Event indexes may only be value types", expr)
raise CodegenPanic("Event indexes may only be value types", expr)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep reachable ABI event errors user-facing

When logging an event imported from a JSON ABI, EventT.from_abi() bypasses the new from_EventDef validation and preserves indexed on array/struct inputs, so this branch is still reachable for inputs like an ABI event E(uint256[3] indexed a). Changing it to CodegenPanic turns a bad user-supplied ABI/use-site into an internal compiler error report instead of the previous TypeMismatch; either validate ABI events before codegen or keep this as a user-facing exception in both backends.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charles-cooper is this likely ?

Where would an invalid JSON ABI come from ?
And if it's possible, shouldn't we error at import time instead ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we should validate at import time

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: b2f36fb

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown

📊 Bytecode Size Changes (venom)

No changes detected.

Full bytecode sizes

Contract legacy-O2 legacy-Os -O2 -O3 -Os
curvefi/legacy/CurveStableSwapMetaNG.vy 24952 23578 20233 19479 18926
curvefi/amm/stableswap/meta_implementation/meta_implementation_v_700.vy 23610 22805 20142 19072 18831
curvefi/amm/stableswap/implementation/implementation_v_700.vy 24962 23769 19506 18676 18276
curvefi/legacy/CurveStableSwapNG.vy 24473 23298 19070 18286 17896
curvefi/amm/tricryptoswap/implementation/implementation_v_200.vy 20724 19959 17385 16851 16459
curvefi/amm/twocryptoswap/implementation/implementation_v_210.vy 17634 16894 15128 14530 14197
yearnfi/VaultV3.vy 19972 19063 14901 13980 13429
curvefi/legacy/CurveCryptoSwap2.vy 18947 18382 14719 14229 14054
yearnfi/VaultV2.vy 16676 15763 13335 12543 12126
curvefi/amm/stableswap/factory/factory_v_100.vy 14558 13978 12055 10863 10963
curvefi/gauge/child_gauge/implementation/implementation_v_110.vy 12338 11561 10033 9376 8987
curvefi/gauge/child_gauge/implementation/implementation_v_100.vy 12017 11249 9764 9114 8728
curvefi/amm/stableswap/views/views_v_120.vy 12784 12368 9697 9074 9285
curvefi/amm/tricryptoswap/math/math_v_200.vy 11189 11126 8993 7941 8134
curvefi/legacy/CurveCryptoMathOptimized3.vy 11188 11125 8992 7941 8134
curvefi/gauge/child_gauge/implementation/implementation_v_020.vy 10665 9947 8860 8274 7888
curvefi/registries/metaregistry/metaregistry_v_110.vy 7590 6732 6523 5742 5635
curvefi/helpers/router/router_v_110.vy 6717 6717 6495 5977 6279
curvefi/amm/tricryptoswap/views/views_v_200.vy 7821 7776 6247 6036 6181
curvefi/helpers/stable_swap_meta_zap/stable_swap_meta_zap_v_100.vy 7302 7067 6193 5706 5926
curvefi/amm/twocryptoswap/views/views_v_200.vy 6991 6946 5807 5610 5741
curvefi/registries/metaregistry/registry_handlers/stableswap/handler_v_110.vy 6633 6259 5696 4851 5401
curvefi/amm/twocryptoswap/math/math_v_210.vy 6800 6800 5506 5012 5039
curvefi/amm/twocryptoswap/factory/factory_v_200.vy 5540 5252 4790 3970 4104
curvefi/amm/tricryptoswap/factory/factory_v_200.vy 5246 5021 4649 3936 4066
curvefi/gauge/child_gauge/factory/factory_v_201.vy 4844 4547 4092 3806 3642
curvefi/registries/metaregistry/registry_handlers/tricryptoswap/handler_v_110.vy 4241 3939 3761 3410 3472
curvefi/registries/metaregistry/registry_handlers/twocryptoswap/handler_v_110.vy 4186 3884 3701 3281 3359
curvefi/gauge/child_gauge/factory/factory_v_100.vy 4183 3914 3594 3270 3097
yearnfi/VaultFactory.vy 3765 3617 3150 2250 2555
curvefi/registries/address_provider/address_provider_v_201.vy 2973 2782 2631 2427 2339
curvefi/helpers/rate_provider/rate_provider_v_101.vy 3260 3260 2570 2298 2331
curvefi/amm/stableswap/math/math_v_100.vy 3067 3046 2442 2237 2293
curvefi/helpers/rate_provider/rate_provider_v_100.vy 2847 2841 2326 2007 2027
curvefi/helpers/deposit_and_stake_zap/deposit_and_stake_zap_v_100.vy 2322 2316 1883 1712 1771
curvefi/governance/relayer/taiko/relayer_v_001.vy 2068 2064 1766 1545 1593
curvefi/governance/relayer/polygon_cdk/relayer_v_101.vy 1556 1523 1554 1348 1371
curvefi/governance/relayer/arb_orbit/relayer_v_101.vy 1266 1262 1253 1077 1126
curvefi/governance/relayer/op_stack/relayer_v_101.vy 1186 1182 1194 1025 1067
curvefi/governance/relayer/not_rollup/relayer_v_100.vy 1168 1153 1185 1022 1048
curvefi/governance/vault/vault_v_100.vy 964 941 873 834 850
curvefi/governance/relayer/relayer_v_100.vy 496 496 593 490 503
curvefi/governance/agent/agent_v_100.vy 541 541 425 397 401
curvefi/governance/agent/agent_v_101.vy 541 541 425 397 401

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 13d60162ff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vyper/semantics/types/user.py Outdated
Comment on lines +322 to +325
typ = type_from_annotation(annotation.args[0])
can_be_indexed = typ._is_prim_word or typ._is_bytestring
if not can_be_indexed:
raise TypeMismatch("Event indexes may only be value types", annotation)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve ABI-only indexed event declarations

This validation runs for every EventDef, including .vyi/inline interface events and contract events that are only exported in the ABI, before any log codegen is involved. As a result, a valid ABI/source interface such as event E: a: indexed(uint256[3]) is rejected even though the same event still imports from JSON via EventT.from_abi() and can be part of an external contract interface; the legacy use-site limitation does not justify rejecting ABI declarations that are never emitted. Please either limit this check to events that are actually logged, keeping a user-facing error at that use site, or make source interfaces match JSON ABI handling.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the point of this PR

Comment thread vyper/semantics/types/user.py Outdated
validate_call_args(annotation, 1)

typ = type_from_annotation(annotation.args[0])
can_be_indexed = typ._is_prim_word or typ._is_bytestring

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should just be a property on the type typ._can_be_index, also i think we already have some property like this somewhere?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right there was _as_hashmap_key, let me know what you think of ef34b9a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep _as_hashmap_key and add a property _as_event_index which resolves to _as_hashmap_key, e.g.

@property
def _as_event_index(self):
    return self._as_hashmap_key

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: cfc01e9

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cfc01e9d01

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vyper/semantics/types/user.py Outdated
Comment on lines +262 to +265
if indexed_count > 3:
raise EventDeclarationException(
"Event cannot have more than three indexed arguments", decl_node
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow anonymous ABI events to use the fourth topic

This constructor is also reached by EventT.from_abi(), but from_abi() discards the ABI's anonymous flag before this new unconditional three-index limit is applied. When a valid Solidity JSON ABI contains an anonymous event with four indexed parameters, importing that ABI now raises EventDeclarationException and blocks the interface even if the Vyper contract only needs its functions; anonymous events have no signature topic, so they can use all four log topics. Please carry the anonymous flag into this validation or keep the three-index limit only for non-anonymous/Vyper-declared events.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: 893f34b

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 893f34b3ca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

members[item["name"]] = type_from_abi(item)
return cls(abi["name"], members, indexed)

return cls(abi["name"], members, indexed, is_anonymous=abi.get("anonymous", False))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve anonymous status for emitted ABI events

When the imported ABI has anonymous: true, this line only passes the flag into __init__ for the indexed-count check; EventT never stores it, while both log-lowering paths still always prepend event.event_id as the first topic. The fresh evidence is the new test_json_abi_anonymous_four_indexed_log: for an anonymous event with four indexed args, validation now accepts it, but emitting it builds five topics and hits the len(topics) <= 4 assertion or produces a non-anonymous log instead of four indexed topics. Please persist the anonymous flag on EventT and skip the signature topic in both backends.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: b0f5704

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Indexed struct event field accepted then unusable

2 participants