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

Various fallback improvements #1611

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

seanyoung
Copy link
Contributor

@seanyoung seanyoung commented Dec 16, 2023

Allow the following:

contract A {
	// Take raw calldata as argument and return return data
	fallback(bytes calldata input) external payable (bytes memory) {}
}

Allow a function to be called fallback:

contract A {
	// Will give a warning that's not a fallback function,
	// just a regular functon
	function fallback() public {}
}

This should make proxy contracts much easier to implement.

Also fixes all fallback/receive related failures in the evm tests.

Copy link

codecov bot commented Dec 17, 2023

Codecov Report

Attention: 35 lines in your changes are missing coverage. Please review.

Comparison is base (00bcabb) 88.44% compared to head (1a4cef6) 88.42%.

Files Patch % Lines
src/lir/converter/expression.rs 0.00% 23 Missing ⚠️
src/codegen/cfg.rs 0.00% 10 Missing ⚠️
src/codegen/mod.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1611      +/-   ##
==========================================
- Coverage   88.44%   88.42%   -0.03%     
==========================================
  Files         150      150              
  Lines       68322    68503     +181     
==========================================
+ Hits        60429    60572     +143     
- Misses       7893     7931      +38     

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

@@ -384,6 +384,11 @@ is executed. This made clear in the declarations; ``receive()`` must be declared
with value and no ``receive()`` function is defined, then the call reverts, likewise if
call is made without value and no ``fallback()`` is defined, then the call also reverts.

The fallback function can defined in two ways. First, it can have no parameters or return
values. Alternatively, it must have a ``bytes`` parameter and ``bytes`` return value. In this
case, the parameter contains the undecoded input (also known as calldata or instruction data),
Copy link
Contributor

Choose a reason for hiding this comment

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

undecoded = encoded?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The wording is not great. What I mean is the raw bytes data before going through borsh/scale/eth decoding.

Allow the following:

	contract A {
		// Take raw calldata as argument and return return data
		fallback(bytes calldata input) external payable (bytes memory) {}
	}

Allow a function to be called fallback:

	contract A {
		// Will give a warning that's not a fallback function,
		// just a regular functon
		function fallback() public {}
	}

Signed-off-by: Sean Young <sean@mess.org>
@xermicus
Copy link
Contributor

@seanyoung I'll be preparing a release in the upcoming days, I think this would be nice to have in :)

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.

None yet

3 participants