Skip to content

Commit

Permalink
Move Sourcify docs from otterscan repo (#3)
Browse files Browse the repository at this point in the history
* Import Sourcify contents from otterscan README

* Split sourcify docs into proper sections
  • Loading branch information
wmitsuda authored Sep 2, 2024
1 parent 35a142b commit 2e6be50
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- [What is Otterscan?](./intro/what.md)
- [Architecture](./intro/architecture.md)
- [Supported networks](./intro/networks.md)
- [Contract verification](./intro/verification.md)
- [Contract verification](./intro/contract-verification.md)
- [Installation](./install/README.md)
- [Erigon](./install/erigon.md)
- [Otterscan](./install/dockerhub.md)
Expand All @@ -27,11 +27,18 @@
- [Optimism](./config/options/optimism.md)
- [Price oracles](./config/options/oracles.md)
- [Recognizing nonstandard chains](./config/options/chains.md)
- [Sourcify](./config/options/sourcify.md)
- [User guide]()
- [API Spec](./api-docs/README.md)
- [FAQ](./api-docs/faq.md)
- [ots namespace spec](./api-docs/ots-api.md)
- [ots2 EXPERIMENTAL namespace spec](./api-docs/ots2-api.md)
- [Contract verification](./contract-verification/README.md)
- [Sourcify](./contract-verification/sourcify/README.md)
- [Integration modes](./contract-verification/sourcify/integration-modes.md)
- [Self-hosted Sourcify](./contract-verification/self-hosted-sourcify/README.md)
- [Setup](./contract-verification/self-hosted-sourcify/setup.md)
- [Verification](./contract-verification/self-hosted-sourcify/verification.md)
- [Public instances](./public_instances.md)
- [Commercial offerings](./commercial_offerings.md)
- [Getting in touch](./contacts.md)
Expand Down
4 changes: 4 additions & 0 deletions src/config/options/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ Price resolvers can be customized as well.
If you are running Otterscan against a non-standard chain, but you are sure Erigon can run it, you can explicitly specify the configuration.

- [Recognizing nonstandard chains](./chains.md)

In case you are running your own Sourcify instance, that's configurable as well.

- [Alternative Sourcify sources](./sourcify.md)
12 changes: 12 additions & 0 deletions src/config/options/sourcify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Alternative Sourcify sources

Rather than using the default `ipfs.io` and `repo.sourcify.dev` sites for accessing Sourcify, you may specify your own Sourcify root URLs in the configuration file by adding the `sourcifySources` key and changing the URLs accordingly:

```json
"sourcifySources": {
"ipfs": "https://ipfs.io/ipns/repo.sourcify.dev",
"central_server": "https://repo.sourcify.dev"
}
```

This is useful if you have your own Sourcify repository hosted locally, in which case all of your Otterscan activity will be private.
13 changes: 13 additions & 0 deletions src/contract-verification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Contract verification

In this chapter we explain how contract verification works in Otterscan.

> 💡 If you are not interested in how contract verification works under the hood, you can skip this chapter.
We use Sourcify and the next section explains how the integration works.

- [Sourcify](./sourcify/)

In case you want to run Sourcify against a devnet or a custom chain not enabled in Sourcify's official hosted service, you can run your own instance of Sourcify and point Otterscan to it.

- [Self-hosted Sourcify](./self-hosted-sourcify/)
11 changes: 11 additions & 0 deletions src/contract-verification/self-hosted-sourcify/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Self-hosted Sourcify

This section presents a short guide to self-host a local Sourcify instance.

Set up a local Sourcify instance.

- [Set up local Sourcify](./setup.md)

Verify a contract on a Sourcify instance.

- [Verify](./verification.md)
75 changes: 75 additions & 0 deletions src/contract-verification/self-hosted-sourcify/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Setup

## Run a local Sourcify instance on your dev network

### Launch a local chain

Launch an Otterscan-compatible local Ethereum RPC node hosting your development server.

- Erigon:
- `./erigon --chain=dev --datadir=dev --http.api eth,erigon,trace,ots,ots2 --http.corsdomain "*" --http.vhosts "*" --mine --fakepow`
- Note: The Erigon devnet only supports a pre-Shanghai (pre-Merge) version of Ethereum. When compiling your contracts, you'll have to set the `evmTarget` to `london` for them to run at all on the devnet.
- You'll have to create a full-fledged Ethereum test network in Erigon if you want to run a modern version of the EVM.
- Foundry's [Anvil](https://book.getfoundry.sh/reference/anvil/):
- `anvil`
- Note: Anvil does not support ots2 RPC methods, so make sure `experimental` is set to `false` in your Otterscan config.

### Sourcify

1. Clone the Sourcify repository:

```shell
git clone https://github.com/ethereum/sourcify.git
```

2. To add support for your local blockchain, create a JSON file `services/server/src/sourcify-chains.json`:

```json
{
"1337": {
"sourcifyName": "Local chain",
"supported": true,
"rpc": [
"http://localhost:8545"
]
}
}
```

You can adjust the chain ID `1337` and the RPC host `http://localhost:8545` as needed. The default chain ID for the Erigon devnet is 1337, and the default for Anvil is 31337.

3. Adjust the repository URL in `ui/.env.development` since for simplicity we aren't using Sourcify's h5ai-nginx file viewer:

```shell
REACT_APP_REPOSITORY_SERVER_URL=http://localhost:5555/repository
```

4. Build all necessary Sourcify components, notably the server and the UI:

```shell
npm run build:clean
```

5. Start the Sourcify server:

```shell
NODE_ENV=development npm run server:start
```

6. Start the Sourcify UI:

```shell
npm run ui:start
```

### Otterscan configuration

To use the local Sourcify instance, you need to point to it in Otterscan's configuration file.
In your Otterscan configuration JSON, specify your local Sourcify repository as the Sourcify source:

```json
"sourcifySources": {
"ipfs": "http://localhost:5555/repository",
"central_server": "http://localhost:5555/repository"
}
```
27 changes: 27 additions & 0 deletions src/contract-verification/self-hosted-sourcify/verification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Verification

## Verifying through the Sourcify UI

You can verify contracts using the Sourcify UI by going to <http://localhost:3000/#/verifier> in your browser.

## Verifying with Forge

1. If you deploy using a [Forge script](https://book.getfoundry.sh/reference/forge/forge-script), you should add the following contract verification arguments to the command:

```shell
forge script Deploy.s.sol .... --verify --verifier sourcify --verifier-url http://localhost:5555
```

2. If you want to deploy a contract without a script, you can use `forge create` to create the deployment transaction. Create a folder named `contracts` and put your contract files in there.

Here is how you would deploy a smart contract called `MyContract` with constructor arguments `0x67b1d87101671b127f5f8714789C7192f7ad340e` and `123456`:

```shell
./forge create --verify --verifier sourcify --verifier-url http://localhost:5555/ --interactive --optimize --rpc-url http://localhost:8545/ MyContract --constructor-args 0x67b1d87101671b127f5f8714789C7192f7ad340e 123456
```

3. To verify a contract that already has been deployed, you can use `forge verify-contract`. Here is an example of a verification of the above `MyContract` contract example to address `0xADC11306fcD68F47698D66047d923a52816Ee44F`. Forge can usually infer constructor arguments automatically:

```shell
./forge verify-contract --verifier sourcify --verifier-url http://localhost:5555/ --optimizer-runs 200 --rpc-url http://localhost:8545/ 0xADC11306fcD68F47698D66047d923a52816Ee44F MyContract
```
13 changes: 13 additions & 0 deletions src/contract-verification/sourcify/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sourcify

Otterscan consumes verified smart contract source code and metadata from [Sourcify](https://sourcify.dev/).

> Sourcify is open source, their data is public and they host a public instance of the verifier.
Otterscan supports multiple ways to consume verified contract data.

- [Integration modes](./integration-modes.md)

To learn how to verify a smart contract on Sourcify, take a look at the Sourcify docs:

- [How to verify contracts on Sourcify](https://docs.sourcify.dev/docs/how-to-verify/)
43 changes: 43 additions & 0 deletions src/contract-verification/sourcify/integration-modes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Integration modes

Otterscan supports multiple ways to consume Sourcify data, each one with pros and cons:

## Direct HTTP connection to Sourcify's repository

Standard HTTP connection to the official Sourcify repository at <https://repo.sourcify.dev/>

Fast access to freshly verified data. On the other hand, it is centralized and leaks all addresses you visit in Otterscan to the Sourcify server.

> 💡 This is the default method Otterscan uses out of the box.
## IPFS

We resolve the public Sourcify IPNS to get the latest known IPFS root hash of their repository.

The downside is that recently verified contracts may not have been added yet to the root hash and republished into IPNS.

It uses the public gateway at <https://ipfs.io> by default.

Please see our [ipfs integration docs](./ipfs.md) for more info about how we handle all IPFS integrations and privacy concerns.

## Local snapshot *(deprecated; soon to be removed)*

> ☠️ This method is deprecated and will be removed in the future. The repository is outdated and kept only for historical reasons.
As a midterm solution, we are making available a snapshot docker image of their repository, containing only mainnet full verified contracts.

This would allow you to play with existing contracts up to the snapshot date/time locally, not depending on their service or IPFS connectivity availability.

The Sourcify snapshot is provided as a nginx image at: <https://hub.docker.com/repository/docker/otterscan/sourcify-snapshot>

You can run it with:

```shell
docker run --rm -d -p 3006:80 --name sourcify-snapshot otterscan/sourcify-snapshot:2021-09
```

Stop it with:

```
docker stop sourcify-snapshot
```
5 changes: 5 additions & 0 deletions src/intro/contract-verification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Contract Verification

We display verified contracts using information from [Sourcify](https://sourcify.dev/).

For more details on how the integration works, please check the [Contract verification](../contract-verification/) chapter.
3 changes: 0 additions & 3 deletions src/intro/verification.md

This file was deleted.

0 comments on commit 2e6be50

Please sign in to comment.