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

VIP: disallow the use of self as an address #3701

Open
charles-cooper opened this issue Dec 19, 2023 · 9 comments · May be fixed by #3961
Open

VIP: disallow the use of self as an address #3701

charles-cooper opened this issue Dec 19, 2023 · 9 comments · May be fixed by #3961

Comments

@charles-cooper
Copy link
Member

charles-cooper commented Dec 19, 2023

Simple Summary

in vyper, self has type address. this VIP disallows that behavior and replaces it with self.address or context.address.

Motivation

can flesh out more but basically, it is not immediately clear what the type of self is (it deviates from the pattern set for other contract-like things, for interface addresses are accessed using the .address member).

Specification

change the type of self to the module type of the executing context. (not sure if this is practical because of ordering of steps in analysis, but it should look more or less like a module type). replace the current uses of self with self.address or maybe a new special variable context.address.

Backwards Compatibility

breaking change

Dependencies

If this VIP depends on any other VIPs being implemented, please mention them.

References

Add any references that this VIP might reference (other VIPs/issues, links to blog posts, etc.)

Copyright

Copyright and related rights waived via CC0

@fubuloubu
Copy link
Member

I'm for this

Wonder if self should have a type Self (which is a special module type refering to itself)

@charles-cooper
Copy link
Member Author

I'm for this

Wonder if self should have a type Self (which is a special module type refering to itself)

it would be more like Self is a special interface type refering to itself

actually i wonder if we should un-ban calling external functions. especially with #2856, there will be a syntactic distinction between self.internal_foo() and call self.external_foo()

@fubuloubu
Copy link
Member

I'm for this
Wonder if self should have a type Self (which is a special module type refering to itself)

it would be more like Self is a special interface type refering to itself

actually i wonder if we should un-ban calling external functions. especially with #2856, there will be a syntactic distinction between self.internal_foo() and call self.external_foo()

Don't have a problem with this, I think originally there is just a difference between internal and external calls (especially with dynamic types) and we wanted to avoid too much complexity in internal dispatching at least until the internals were refactored significantly

In solidity there is public interface decorator, I think we also wanted to avoid the waste of making a function public if it doesn't have to be (the compiler should handle this as well as function dispatch optimization)

@charles-cooper
Copy link
Member Author

yeah i don't think we need the public thing -- it's pretty easy to factor code into internal implementation/external wrapper

@pcaversaccio
Copy link
Collaborator

I second this. Since the context is similar, I quickly link to my issue here: #3279. We should generally stop doing implicit address assignments IMO.

@michwill
Copy link

michwill commented Jan 6, 2024

Doesn't matter a ton, but I like it when self is an address. And yes, I'd also like if contracts could be used as addresses!

@charles-cooper
Copy link
Member Author

Doesn't matter a ton, but I like it when self is an address. And yes, I'd also like if contracts could be used as addresses!

hmm, well at least they should be consistent!

@charles-cooper
Copy link
Member Author

charles-cooper commented Feb 11, 2024

And yes, I'd also like if contracts could be used as addresses!

it looks like prior to v0.2.0, this was actually the default behavior. the following (v0.1.17b!) vyper contract demonstrates:

contract Factory:
   def getExchange(token_addr: address) -> address: constant

factory: Factory
token: Factory

@public
def test():
   assert self.factory.getExchange(self.token) == self

this compiles in v0.1.17b. by v0.2.0, this contract (after updating the syntax) is rejected.

cf. #1375 (comment)

@charles-cooper
Copy link
Member Author

haven't made a decision yet here but leaning towards allowing (syntactically free) downcasting from interfaces to addresses. this is something we can do as a non-breaking change in the 0.4.x series.

@charles-cooper charles-cooper linked a pull request Apr 18, 2024 that will close this issue
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 a pull request may close this issue.

4 participants