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

A contract should revert when no fn selector matches #444

Closed
AlicanC opened this issue Dec 7, 2021 · 5 comments · Fixed by #639
Closed

A contract should revert when no fn selector matches #444

AlicanC opened this issue Dec 7, 2021 · 5 comments · Fixed by #639
Labels
bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged

Comments

@AlicanC
Copy link
Contributor

AlicanC commented Dec 7, 2021

ATM, when you specify an invalid function selector when calling a contract, the contract just ends up doing a RET $r0. A revert sounds better.

@adlerjohn adlerjohn added bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged labels Dec 9, 2021
@SilentCicero
Copy link
Member

@AlicanC this should be easy to implement and important for consistency.

@sezna
Copy link
Contributor

sezna commented Jan 13, 2022

We seem to have a disagreement here with this comment:

#97 (comment)

@adlerjohn -- what do you think? RVRT or RET with some error code that represents "no selectors matched"? If the latter, we should make an issue to standardize error codes.

@adlerjohn
Copy link
Contributor

adlerjohn commented Jan 13, 2022

I personally prefer returning a Result or something. Then the caller can handle as it wants, instead of forcing the panic. That being said, that might involve the compiler knowing about the Result in the standard library, which maybe is a leaky abstraction?

RET $zero is definitely wrong though. So pending a Result, RVRT is fine.

@sezna
Copy link
Contributor

sezna commented Jan 13, 2022

I agree that using Result directly would be leaky, but what Rust does is it has a trait which types can opt into for converting program error types into standard out return codes. E.g., Result<_, _> will return a non-zero exit code if it is an Err.

We could do something like that, but unless we have a separate opcode or domain separator metadata, it will be impossible for the caller to know if the contract wanted to return that integer value as a genuine result of computation or as an error code.

There's a lot of ambiguity here, I think the cleanest and safest option would be RVRT. Thoughts?

@adlerjohn
Copy link
Contributor

adlerjohn commented Jan 13, 2022

Cleanest is definitely RVRT for now. Can revisit in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants