Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[lang]: add revert_on_failure keyword for all external calls #4517

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

z80dev
Copy link
Contributor

@z80dev z80dev commented Mar 13, 2025

What I did

Added a revert_on_failure keyword parameter to all external contract calls that allows capturing the success state of a call without reverting. When revert_on_failure=False, the return type becomes either:

  • bool (for functions with no return value)
  • tuple[bool, ReturnType] (for functions with return values)

How I did it

  • Implemented kwarg parsing for revert_on_failure in normal ext calls in semantics/types/function.py
  • Implemented IR generation for cases when revert_on_failure=False, modeled on current behavior for raw_call's revert_on_failure as well as IR generation for normal external calls with tuple return types
  • Added test verifying behavior with basic no-return-type and returns (uint256) external functions

How to verify it

./quicktest.sh -n0 -m "not fuzzing" tests/functional/codegen/calling_convention/test_external_contract_calls.py -k revert_on_failure -s

or check out this branch and compile something like

interface Target:
    def fail(should_raise: bool): nonpayable
    def return_value(should_raise: bool) -> uint256: nonpayable

@external
def call_target_fail(target: address, should_raise: bool) -> bool:
    success: bool = extcall Target(target).fail(should_raise, revert_on_failure=False)
    return success

@external
def call_target_return(target: address, should_raise: bool) -> (bool, uint256):
    success: bool = False
    result: uint256 = 0
    success, result = extcall Target(target).return_value(should_raise, revert_on_failure=False)

    return success, result

Commit message

Adds a revert_on_failure keyword parameter to all external contract calls that allows capturing the success state of a call without reverting. When revert_on_failure=False, the return type becomes either:

  • bool (for functions with no return value)
  • tuple[bool, ReturnType] (for functions with return values)

Description for the changelog

Implement revert_on_failure for all external calls

Cute Animal Picture

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

Adds a revert_on_failure keyword parameter to  all external contract calls
that allows capturing the success state of a call without reverting.
When revert_on_failure=False, the return type becomes either:
- bool (for functions with no return value)
- tuple[bool, ReturnType] (for functions with return values)
Copy link

codecov bot commented Mar 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.16%. Comparing base (41108f9) to head (5fd3bdb).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4517      +/-   ##
==========================================
+ Coverage   92.15%   92.16%   +0.01%     
==========================================
  Files         123      123              
  Lines       17469    17494      +25     
  Branches     2957     2962       +5     
==========================================
+ Hits        16099    16124      +25     
  Misses        958      958              
  Partials      412      412              

☔ 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.

[
"if",
success_loc, # If success
["mstore", ["add", tuple_loc, 32], ["mload", ret_unpacker[2]]], # Use returned data
Copy link
Member

Choose a reason for hiding this comment

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

what does this do?

@cyberthirst cyberthirst added this to the v0.4.2 milestone Mar 17, 2025
@charles-cooper charles-cooper added the release - tentative items still being considered for release inclusion label Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release - tentative items still being considered for release inclusion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants