Skip to content

feat[codegen]: changed the convert from bytes#5020

Open
HodanPlodky wants to merge 27 commits into
vyperlang:masterfrom
HodanPlodky:feat/codegen/changed_the_convert_from_bytes
Open

feat[codegen]: changed the convert from bytes#5020
HodanPlodky wants to merge 27 commits into
vyperlang:masterfrom
HodanPlodky:feat/codegen/changed_the_convert_from_bytes

Conversation

@HodanPlodky

Copy link
Copy Markdown
Collaborator

What I did

changed behavior of convert when converting from bytes to int

How I did it

Added step before sign extend so that the value passed is converting from max size and not from runtime size (example in tests).

How to verify it

test added in this PR

Commit message

Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)

Description for the changelog

Cute Animal Picture

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

@github-actions

github-actions Bot commented May 29, 2026

Copy link
Copy Markdown

Gas Changes

No changes detected.

Summary

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

@github-actions

github-actions Bot commented May 29, 2026

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 20801 19770 19330
curvefi/legacy/CurveStableSwapMetaNG.vy 24952 23578 20644 20025 19329
curvefi/amm/stableswap/implementation/implementation_v_700.vy 24962 23769 20467 19596 19048
curvefi/legacy/CurveStableSwapNG.vy 24473 23298 19860 19016 18497
curvefi/amm/tricryptoswap/implementation/implementation_v_200.vy 20724 19959 18018 17516 16959
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 15622 15068 14699
yearnfi/VaultV2.vy 16676 15763 13863 13405 12574
curvefi/amm/stableswap/factory/factory_v_100.vy 14558 13978 13250 11856 11829
curvefi/amm/stableswap/views/views_v_120.vy 12784 12368 10291 9734 9853
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/tricryptoswap/math/math_v_200.vy 11189 11126 9506 8143 8410
curvefi/legacy/CurveCryptoMathOptimized3.vy 11188 11125 9505 8143 8410
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 6717 6465 6534
curvefi/registries/metaregistry/metaregistry_v_110.vy 7590 6732 6657 5894 5733
curvefi/helpers/stable_swap_meta_zap/stable_swap_meta_zap_v_100.vy 7302 7067 6540 6173 6275
curvefi/amm/twocryptoswap/views/views_v_200.vy 6991 6946 6274 6028 6091
curvefi/registries/metaregistry/registry_handlers/stableswap/handler_v_110.vy 6633 6259 5859 5094 5562
curvefi/amm/tricryptoswap/factory/factory_v_200.vy 5246 5021 5816 4849 4953
curvefi/amm/twocryptoswap/factory/factory_v_200.vy 5540 5252 5816 4579 4740
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 3901 2453 2913
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 2807 2465 2478
curvefi/registries/address_provider/address_provider_v_201.vy 2973 2782 2719 2575 2430
curvefi/amm/stableswap/math/math_v_100.vy 3067 3046 2598 2403 2423
curvefi/helpers/rate_provider/rate_provider_v_100.vy 2847 2841 2373 2066 2074
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 1647 1532 1565
curvefi/governance/relayer/polygon_cdk/relayer_v_101.vy 1556 1523 1454 1362 1363
curvefi/governance/relayer/arb_orbit/relayer_v_101.vy 1266 1262 1147 1081 1112
curvefi/governance/relayer/op_stack/relayer_v_101.vy 1186 1182 1086 1023 1051
curvefi/governance/relayer/not_rollup/relayer_v_100.vy 1168 1153 1075 1018 1030
curvefi/governance/vault/vault_v_100.vy 964 941 885 866 864
curvefi/governance/relayer/relayer_v_100.vy 496 496 467 462 467
curvefi/governance/agent/agent_v_100.vy 541 541 443 415 419
curvefi/governance/agent/agent_v_101.vy 541 541 443 415 419

@charles-cooper charles-cooper requested a review from Sporarum May 29, 2026 12:32
@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.58333% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.95%. Comparing base (82b09fa) to head (1ce1906).

Files with missing lines Patch % Lines
vyper/codegen_venom/builtins/convert.py 82.85% 5 Missing and 1 partial ⚠️
vyper/builtins/_convert.py 93.44% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5020      +/-   ##
==========================================
+ Coverage   92.92%   92.95%   +0.02%     
==========================================
  Files         188      188              
  Lines       27820    27857      +37     
  Branches     4828     4835       +7     
==========================================
+ Hits        25853    25894      +41     
+ Misses       1316     1311       -5     
- Partials      651      652       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@_input_types(IntegerT)
def to_flag(expr, arg, out_typ):
def to_flag(expr, arg, in_typ, out_typ):
if arg.typ != UINT256_T:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When is arg.typ different from in_typ ?

If the answer is "sometimes", this feels like something which should be fixed in the typer

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.

It should be only in the case the constant.

FOO: constant(Bytes[2]) = b'\xff'

@external
def foo() -> int16:
    return convert(FOO, int16)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In this example, what are the arg.typ and in_typ ?

@HodanPlodky HodanPlodky Jun 2, 2026

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.

arg.typ would be Bytes[1] and and in_typ would be Bytes[2], since the argument is reduced to the b'\xff' at the start.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it would be better to have arg.typ be Bytes[2], which makes sense since the arg is FOO and its type is Bytes[2]

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 would be some where in the typechecker I think. Do you think it should be done like that? Since there was discussion on what semantics the convert should have. Or maybe I could reduce it later in convert

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Note that your implementation also assumes a specific semantics !
I'm not sure what the semantics of convert should be, but I am 100% sure the following should be equivalent:

FOO: constant(Bytes[2]) = b'\xff'
FOO: constant(Bytes[2]) = b'\x00\xff'

Both FOOs should have type Bytes[2] even if their expression has a stricter type.

So we should fix this where appropriate, probably in the typer, since this is not related only to conversions.
(Conversions might be the only place for now where it produces an observable difference however)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wait, what I said is wrong, I am 100% sure the following should be equivalent:

FOO: constant(Bytes[2]) = b'\xff'

_FOO: constant(Bytes[1]) = b'\xff'
FOO: constant(Bytes[2]) = _FOO

Both FOOs should have type Bytes[2].

But in my previous example, both should still have type Bytes[2]

@Sporarum

Copy link
Copy Markdown
Collaborator

Does this bring venom towards current vyper, or away from it ?
In other words, how does the other codegen handle it

@Sporarum

Copy link
Copy Markdown
Collaborator

Please add a test comparing convert(b"\xff", int16) and convert(b"\x00\xff", int16)

)
from vyper.semantics.types.bytestrings import _BytestringT
from vyper.semantics.types.infinity import is_bounded_length
from vyper.semantics.types.primitives import NumericT
@HodanPlodky HodanPlodky marked this pull request as ready for review June 9, 2026 10:04
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.

3 participants