Skip to content

fix[lang]: abi-encode with expr CompilerPanic#5154

Open
Sporarum wants to merge 6 commits into
vyperlang:masterfrom
Sporarum:ensure_tuple-panic
Open

fix[lang]: abi-encode with expr CompilerPanic#5154
Sporarum wants to merge 6 commits into
vyperlang:masterfrom
Sporarum:ensure_tuple-panic

Conversation

@Sporarum

Copy link
Copy Markdown
Collaborator

What I did

Fix #5144
But still emits user-visible NotFoldable due to #5153

How I did it

How to verify it

Commit message

fixes the assumption that the argument of 'ensure_tuple' is always a
literal. this is done by querying the folded value instead of the node
itself. the xfail tests are added to document an issue surrounding
constant folding 'empty', which predates this commit. cleanup: some
comments were converted to docstrings for compiler UX.

Description for the changelog

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: 815
  • Changed: 0
  • Regressions (gas up): 0
  • Improvements (gas down): 0
  • New tests: 0
  • Deleted tests: 0
  • Newly failing: 0
  • Newly passing: 0

@github-actions

Copy link
Copy Markdown

📊 Bytecode Size Changes (venom)

No changes detected.

Full bytecode sizes

Contract legacy-O2 legacy-Os -O2 -O3 -Os
curvefi/amm/stableswap/meta_implementation/meta_implementation_v_700.vy 23610 22805 20786 19755 19315
curvefi/legacy/CurveStableSwapMetaNG.vy 24952 23578 20490 19871 19175
curvefi/amm/stableswap/implementation/implementation_v_700.vy 24962 23769 20264 19393 18845
curvefi/legacy/CurveStableSwapNG.vy 24473 23298 19677 18844 18314
curvefi/amm/tricryptoswap/implementation/implementation_v_200.vy 20724 19959 18020 17518 16961
yearnfi/VaultV3.vy 19972 19063 17017 15131 14477
curvefi/amm/twocryptoswap/implementation/implementation_v_210.vy 17634 16894 15685 15132 14648
curvefi/legacy/CurveCryptoSwap2.vy 18947 18382 15634 15092 14711
yearnfi/VaultV2.vy 16676 15763 13863 13405 12574
curvefi/amm/stableswap/factory/factory_v_100.vy 14558 13978 13317 11825 11788
curvefi/gauge/child_gauge/implementation/implementation_v_110.vy 12338 11561 10270 9775 9182
curvefi/gauge/child_gauge/implementation/implementation_v_100.vy 12017 11249 9998 9502 8920
curvefi/amm/stableswap/views/views_v_120.vy 12784 12368 9970 9413 9532
curvefi/amm/tricryptoswap/math/math_v_200.vy 11189 11126 9520 8162 8424
curvefi/legacy/CurveCryptoMathOptimized3.vy 11188 11125 9519 8162 8424
curvefi/gauge/child_gauge/implementation/implementation_v_020.vy 10665 9947 9013 8565 8028
curvefi/helpers/router/router_v_110.vy 6717 6717 7003 6376 6607
curvefi/amm/tricryptoswap/views/views_v_200.vy 7821 7776 6697 6445 6514
curvefi/registries/metaregistry/metaregistry_v_110.vy 7590 6732 6651 5888 5727
curvefi/helpers/stable_swap_meta_zap/stable_swap_meta_zap_v_100.vy 7302 7067 6379 6012 6114
curvefi/amm/twocryptoswap/views/views_v_200.vy 6991 6946 6272 6026 6089
curvefi/amm/twocryptoswap/factory/factory_v_200.vy 5540 5252 5994 4697 4845
curvefi/amm/tricryptoswap/factory/factory_v_200.vy 5246 5021 5923 4926 5039
curvefi/registries/metaregistry/registry_handlers/stableswap/handler_v_110.vy 6633 6259 5859 5094 5562
curvefi/amm/twocryptoswap/math/math_v_210.vy 6800 6800 5581 5107 5112
curvefi/gauge/child_gauge/factory/factory_v_201.vy 4844 4547 4266 4014 3780
yearnfi/VaultFactory.vy 3765 3617 3985 2505 2965
curvefi/registries/metaregistry/registry_handlers/tricryptoswap/handler_v_110.vy 4241 3939 3838 3547 3547
curvefi/registries/metaregistry/registry_handlers/twocryptoswap/handler_v_110.vy 4186 3884 3777 3417 3433
curvefi/gauge/child_gauge/factory/factory_v_100.vy 4183 3914 3694 3428 3213
curvefi/helpers/rate_provider/rate_provider_v_101.vy 3260 3260 2779 2437 2450
curvefi/registries/address_provider/address_provider_v_201.vy 2973 2782 2713 2569 2424
curvefi/amm/stableswap/math/math_v_100.vy 3067 3046 2598 2403 2423
curvefi/helpers/rate_provider/rate_provider_v_100.vy 2847 2841 2357 2050 2058
curvefi/helpers/deposit_and_stake_zap/deposit_and_stake_zap_v_100.vy 2322 2316 2123 1889 1921
curvefi/governance/relayer/taiko/relayer_v_001.vy 2068 2064 1784 1579 1612
curvefi/governance/relayer/polygon_cdk/relayer_v_101.vy 1556 1523 1587 1405 1406
curvefi/governance/relayer/arb_orbit/relayer_v_101.vy 1266 1262 1280 1124 1155
curvefi/governance/relayer/op_stack/relayer_v_101.vy 1186 1182 1219 1066 1094
curvefi/governance/relayer/not_rollup/relayer_v_100.vy 1168 1153 1208 1061 1073
curvefi/governance/vault/vault_v_100.vy 964 941 885 866 864
curvefi/governance/relayer/relayer_v_100.vy 496 496 600 505 510
curvefi/governance/agent/agent_v_100.vy 541 541 443 415 419
curvefi/governance/agent/agent_v_101.vy 541 541 443 415 419

assert compiler.compile_code(good_code) is not None


# UnfoldableNode on legacy, CompilerPanic in venom

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.

where is the compiler panic from?

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.

CompilerPanic: unfoldable boolean kwarg: unwrap_tuple
From _get_bool_kwarg in misc.py

I tried to make it raise an UnfoldableNode as well, but actually the proper fix is to fix #5153
The front-end checks that this is a Constant, so we should never be in a situation were we need to raise in the first place

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.

can we fix the venom pipeline too so that it doesn't panic? what is the point of "fixing" the panic in one pipeline but not the other?

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.

This PR fixes the panic on both backends for cases like:

_abi_decode(x, uint256, unwrap_tuple=(0 < 1))

This xfail test is instead due to #5153
I did not want to burden this PR with some codegen changes just to change the type of VyperInternalException which is reported

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.

Claude-authored explanation of why this happens here (and not on abi_encode):

Semantic analysis passes cleanly, and the kwarg is only consumed at codegen:

  • Legacy codegen: @process_inputs → process_kwarg (vyper/builtins/_signatures.py:37) calls kwarg_node.get_folded_value().value → UnfoldableNode (same underlying failure, just later).
  • Venom codegen: vyper/codegen_venom/builtins/abi.py:36-48's _get_bool_kwarg uses reduced() (which returns self when there's no folded value, no exception), then does an isinstance(kw_node, vy_ast.NameConstant | vy_ast.Int) check. empty(bool) is a Call, falls through, and hits the explicit raise CompilerPanic("unfoldable boolean kwarg: …") at line 48.

Comment thread vyper/builtins/functions.py Outdated
Comment thread vyper/codegen_venom/builtins/abi.py Outdated
Comment thread vyper/codegen_venom/builtins/misc.py Outdated

@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: 39e1b340fe

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

assert compiler.compile_code(good_code) is not None


@pytest.mark.xfail(raises=UnfoldableNode)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Include CompilerPanic in the encode xfail

When the CI matrix runs the experimental pipeline (.github/workflows/test.yml includes --experimental-codegen), this new test reaches venom's _get_bool_kwarg path for empty(bool), which raises CompilerPanic for an unreduced boolean kwarg; the adjacent decode test handles that with raises=(UnfoldableNode, CompilerPanic), but this xfail only permits UnfoldableNode. As a result, the newly added encode regression test fails in every experimental-codegen job instead of being reported as xfailed.

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.

This is empirically wrong, the venom tests pass

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.

abi_encode ensure_tuple non-literal triggers compiler panic

2 participants