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

implements does not respect public getter of interface type #3954

Open
pcaversaccio opened this issue Apr 15, 2024 · 1 comment · Fixed by #3956 · May be fixed by #3961
Open

implements does not respect public getter of interface type #3954

pcaversaccio opened this issue Apr 15, 2024 · 1 comment · Fixed by #3956 · May be fixed by #3961
Labels
bug - typechecker issue with typechecker bug - UX a bug related to UX

Comments

@pcaversaccio
Copy link
Collaborator

pcaversaccio commented Apr 15, 2024

Public getter of interface type is currently not respected by implements if implemented as module:

# lib.vy
# pragma version ~=0.4.0rc2

from ethereum.ercs import IERC20

asset: public(immutable(IERC20))

@deploy
def __init__(asset_: IERC20):
    asset = asset_
# main.vy
# pragma version ~=0.4.0rc2

from ethereum.ercs import IERC20

import lib
initializes: lib

interface IAsset:
    def asset() -> IERC20: view

implements: IAsset

exports: lib.__interface__ # exports the external getter function for `asset`

@deploy
def __init__(asset_: IERC20):
    lib.__init__(asset_)

will throw with:

vyper.exceptions.InterfaceViolation: Contract does not implement all interface functions: asset

  contract "main.vy:11", line 11:0
       10
  ---> 11 implements: IAsset
  --------^
       12
@pcaversaccio
Copy link
Collaborator Author

pcaversaccio commented Apr 16, 2024

@charles-cooper it's not fully fixed yet IMHO.

PoC

# lib.vy
# pragma version ~=0.4.0rc2

from ethereum.ercs import IERC20

asset: public(immutable(IERC20))

@deploy
def __init__(asset_: IERC20):
    asset = asset_
# main.vy
# pragma version ~=0.4.0rc2

from ethereum.ercs import IERC20

import lib
initializes: lib

interface IAsset:
    def asset() -> address: view #  --> Vyper returns the `address` type for interface types by default.

implements: IAsset

exports: lib.__interface__ # exports the external getter function for `asset`

@deploy
def __init__(asset_: IERC20):
    lib.__init__(asset_)

This won't compile:

vyper.exceptions.InterfaceViolation: Contract does not implement all interface functions: asset()

  contract "main.vy:12", line 12:0 
       11
  ---> 12 implements: IAsset
  --------^
       13

The underlying issue I currently face is that I use the built-in ERC4626 interface:

# Functions
@view
@external
def asset() -> address:
...

declare it in a module via (the module itself compiles):

asset: public(immutable(IERC20))

and I import into my my main contract, export everything and initialise it. But it throws with the error above. The compiler tells me however, if I do something like exports: (erc4626.__interface__, erc4626.asset), that it's already exported vyper.exceptions.StructureException: already exported!, but it seems that the return type of address and IERC20 has an internal conflict. You can fully repro via my PR here: pcaversaccio/snekmate#236.

@pcaversaccio pcaversaccio reopened this Apr 16, 2024
pcaversaccio added a commit to pcaversaccio/snekmate that referenced this issue May 8, 2024
### 🕓 Changelog

This PR refactors the `ERC4626` contract to make it module-friendly and
ready for the breaking `0.4.0` release. Please note that due to an open
issue (see vyperlang/vyper#3954) on how to
handle public getters of interface types in conjunction with
`implements`, we fix this issue by storing the interface object as an
`immutable` variable called `_ASSET` and assigning `asset` a `public`
`immutable` `address` type, which gets assigned at contract creation
time via the `.address` member of `_ASSET`:

```vy
asset: public(immutable(address))
_ASSET: immutable(IERC20)

@Deploy
@payable
def __init__(..., asset_: IERC20, ...):
    _ASSET = asset_
    asset = _ASSET.address

    ....
```

---------

Signed-off-by: Pascal Marco Caversaccio <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - typechecker issue with typechecker bug - UX a bug related to UX
Projects
None yet
2 participants