matter-labs / matter-labs/block-explorer
Vyper Interfaces Verification
@popzxc is already working on this.
Since Dec 6, 2024.
- Dominant language
- TypeScript
- Stars
- 139
- Forks
- 145
- Avg merge
- 8h 3m
- Merged PRs (30d)
- 3
Description
### 🐛 Bug Report
If a smart contract in vyper uses an interface, the ZKsync explorer will throw an error.
```
{'status': 'failed', 'error': 'zkvyper error: ./etc/vyper-bin/0.4.0/vyper error: vyper.exceptions.ModuleNotFound: interfaces.IERC20Permit\n\n contract "/tmp/.tmp9OzJyE/lib/pypi/snekmate/tokens/erc20.vy:71", line 71:0 \n 70 # syntax.\n ---> 71 import interfaces.IERC20Permit as IERC20Permit\n --------^\n 72 implements: IERC20Permit\n\n[30563] Failed to execute script \'vyper_compile\' due to unhandled exception!\n'}
```
However, `zkvyper` compiles successfully. This is because the explorer verification process is not correctly understanding the python paths.
#### 🔄 Reproduction Steps
1. Download [moccasin](https://github.com/Cyfrin/moccasin)
Easiest way is to download [uv](https://docs.astral.sh/uv/getting-started/installation/), then download mox
```bash
curl -LsSf https://astral.sh/uv/install.sh | sh # downloads uv
uv tool install moccasin # downloads moccasin/mox
```
Make sure you have [zkvyper](https://github.com/matter-labs/zkvyper-bin) and [era_test_node](https://github.com/matter-labs/era-test-node) also installed
2. Create a new moccasin project
```
mkdir verify_erc20
cd verify_erc20
mox init
```
3. Add erc20 details
First, install [snekmate](https://github.com/pcaversaccio/snekmate) with:
```
mox install snekmate
```
Then create a file called `snek_token.vy` and add:
```python
# pragma version 0.4.0
"""
@license MIT
@title snek_token
@author You!
@notice This is my ERC20 token!
"""
# ------------------------------------------------------------------
# IMPORTS
# ------------------------------------------------------------------
from ethereum.ercs import IERC20
implements: IERC20
from ethereum.ercs import IERC20Detailed
implements: IERC20Detailed
from snekmate.auth import ownable as ow
# from pcaversaccio.snekmate.src.snekmate.auth import ownable as ow
initializes: ow
from snekmate.tokens import erc20
initializes: erc20[ownable := ow]
exports: erc20.__interface__
# ------------------------------------------------------------------
# STATE VARIABLES
# ------------------------------------------------------------------
# Constants & Immutables
NAME: constant(String[25]) = "snek_token"
SYMBOL: constant(String[5]) = "SNEK"
DECIMALS: constant(uint8) = 18
EIP712_VERSOIN: constant(String[20]) = "1"
# Storage - none!
# ------------------------------------------------------------------
# FUNCTIONS
# ------------------------------------------------------------------
@deploy
def __init__(initial_supply: uint256):
ow.__init__()
erc20.__init__(NAME, SYMBOL, DECIMALS, NAME, EIP712_VERSOIN)
erc20._mint(msg.sender, initial_supply)
```
5. Add zksync network details
Add the following to your `moccasin.toml`
```toml
[networks.zksync]
url = "$ZKSYNC_RPC_URL"
is_zksync = true
explorer_uri = "https://zksync2-mainnet-explorer.zksync.io"
explorer_type = "zksyncexplorer"
prompt_live = false
```
Where `ZKSYNC_RPC_URL` is your zksync mainnet RPC URL.
6. Create a file called `verify.py` in your `script` folder with this code:
```python
from eth_utils import to_wei, to_bytes
from moccasin.boa_tools import VyperContract
from moccasin.config import get_active_network
from src import snek_token
def moccasin_main():
contract_addy = "0x60074aD7A8e789d4fDeebB40Eb04B5000d6fE6eE"
snek = snek_token.at(contract_addy)
snek.constructor_calldata = to_bytes(
hexstr="0x00000000000000000000000000000000000000000000003635c9adc5dea00000"
)
active_network = get_active_network()
result = active_network.moccasin_verify(snek)
result.wait_for_verification()
```
7. Run it
```
mox run verify --network zksync
```
You'll get the error. This is an error on the explorer's side. This contract should be able to be installed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.