Skip to content

feat[lang]: @raw_return decorator#4568

Merged
charles-cooper merged 20 commits intovyperlang:masterfrom
charles-cooper:feat/lang/raw-return-decorator
Jun 16, 2025
Merged

feat[lang]: @raw_return decorator#4568
charles-cooper merged 20 commits intovyperlang:masterfrom
charles-cooper:feat/lang/raw-return-decorator

Conversation

@charles-cooper
Copy link
Copy Markdown
Member

@charles-cooper charles-cooper commented Apr 9, 2025

What I did

address #4525. the original raw_return() builtin was implemented in #4527 and rejected because it can obfuscate control flow. this approach decorates the function (and is only allowed on external functions); the user is responsible for making sure each returning path has the same encoding.

How I did it

How to verify it

ex.

@external
@raw_return
def foo() -> Bytes[32]:
    return b"asdlkfj"

Commit message

this commit adds a `@raw_return` decorator which allows a contract
to directly return bytes without the compiler adding ABI-encoding
routines. this is particularly useful for calling proxies or other
helper contracts, where you want to return the output bytes directly to
the user without adding another layer of `(bytes)` encoding.

a `raw_return()` builtin was considered, which would essentially
compile directly to an EVM `return` instruction, but it was rejected
since it can obfuscate control flow (e.g., calling `raw_return()`
in a deeply nested internal function will terminate execution and
commit state changes, which might not be obvious to a caller). the
`@raw_return` decorator was chosen because, a) we can control that it
only gets applied to `@external` functions, and b), so that all paths
in the raw-returning function are treated equally w.r.t encoding of the
return data.

Description for the changelog

Cute Animal Picture

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

@charles-cooper charles-cooper force-pushed the feat/lang/raw-return-decorator branch from 450bc53 to 83089d0 Compare April 9, 2025 11:58
)
from vyper.semantics.data_locations import DataLocation
from vyper.semantics.types.base import KwargSettings, VyperType
from vyper.semantics.types.bytestrings import BytesT

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
vyper.semantics.types.bytestrings
begins an import cycle.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.94%. Comparing base (14a4ca6) to head (0ac29f0).
⚠️ Report is 36 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4568   +/-   ##
=======================================
  Coverage   92.93%   92.94%           
=======================================
  Files         131      131           
  Lines       19006    19030   +24     
  Branches     3300     3306    +6     
=======================================
+ Hits        17663    17687   +24     
  Misses        905      905           
  Partials      438      438           

☔ View full report in Codecov by Sentry.
📢 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.

@charles-cooper charles-cooper enabled auto-merge (squash) June 16, 2025 09:44
@charles-cooper charles-cooper merged commit 46732b6 into vyperlang:master Jun 16, 2025
159 checks passed
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