Skip to content

Commit

Permalink
Erigon for zkEVM support alpha flat patch.
Browse files Browse the repository at this point in the history
  • Loading branch information
mandrigin committed Dec 14, 2023
1 parent 69a3396 commit 459c01f
Show file tree
Hide file tree
Showing 447 changed files with 68,153 additions and 1,480 deletions.
3 changes: 0 additions & 3 deletions .gitattributes

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build and Push Docker

on:
push:
branches:
- main
workflow_dispatch:

env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
IMAGE_NAME: gatewayfm/zkevm-erigon
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}

- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.IMAGE_NAME }}:${{ github.sha }}

- name: Verify Image
run: docker run --rm ${{ env.IMAGE_NAME }}:${{ github.sha }} --version
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ erigon-lib/
docker-compose.*.yml
.env
coverage.out
hermezconfig*.yaml
rpcConfig.yaml
local.yml

dist
__debug_bin
__debug_bin
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ COPY --from=tools-builder /app/build/bin/mdbx_stat /usr/local/bin/mdbx_stat
## then give each binary its own layer
COPY --from=builder /app/build/bin/devnet /usr/local/bin/devnet
COPY --from=builder /app/build/bin/downloader /usr/local/bin/downloader
COPY --from=builder /app/build/bin/erigon /usr/local/bin/erigon
COPY --from=builder /app/build/bin/zkevm-erigon /usr/local/bin/zkevm-erigon
COPY --from=builder /app/build/bin/erigon-cl /usr/local/bin/erigon-cl
COPY --from=builder /app/build/bin/evm /usr/local/bin/evm
COPY --from=builder /app/build/bin/hack /usr/local/bin/hack
Expand Down Expand Up @@ -95,13 +95,13 @@ ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.description="Erigon Ethereum Client" \
org.label-schema.name="Erigon" \
org.label-schema.description="Erigon ZKEVM Client" \
org.label-schema.name="ZKEVM Erigon" \
org.label-schema.schema-version="1.0" \
org.label-schema.url="https://torquem.ch" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/ledgerwatch/erigon.git" \
org.label-schema.vcs-url="https://github.com/gateway-fm/zkevm-erigon.git" \
org.label-schema.vendor="Torquem" \
org.label-schema.version=$VERSION

ENTRYPOINT ["erigon"]
ENTRYPOINT ["zkevm-erigon"]
10 changes: 5 additions & 5 deletions Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ COPY --from=tools-builder /app/build/bin/mdbx_stat /usr/local/bin/mdbx_stat
## then give each binary its own layer
COPY --from=builder /app/build/bin/devnet /usr/local/bin/devnet
COPY --from=builder /app/build/bin/downloader /usr/local/bin/downloader
COPY --from=builder /app/build/bin/erigon /usr/local/bin/erigon
COPY --from=builder /app/build/bin/zkevm-erigon /usr/local/bin/zkevm-erigon
COPY --from=builder /app/build/bin/erigon-cl /usr/local/bin/erigon-cl
COPY --from=builder /app/build/bin/evm /usr/local/bin/evm
COPY --from=builder /app/build/bin/hack /usr/local/bin/hack
Expand Down Expand Up @@ -92,13 +92,13 @@ ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.description="Erigon Ethereum Client" \
org.label-schema.name="Erigon" \
org.label-schema.description="Erigon ZKEVM Client" \
org.label-schema.name="ZKEVM Erigon" \
org.label-schema.schema-version="1.0" \
org.label-schema.url="https://torquem.ch" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/ledgerwatch/erigon.git" \
org.label-schema.vcs-url="https://github.com/gateway-fm/zkevm-erigon.git" \
org.label-schema.vendor="Torquem" \
org.label-schema.version=$VERSION

ENTRYPOINT ["erigon"]
ENTRYPOINT ["zkevm-erigon"]
2 changes: 1 addition & 1 deletion Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ RUN apk add --no-cache ca-certificates && \
COPY erigon /usr/local/bin/

EXPOSE 8545 8551 8546 30303 30303/udp 42069 42069/udp 8080 9090 6060
ENTRYPOINT ["erigon"]
ENTRYPOINT ["zkevm-erigon"]
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DOCKER := $(shell command -v docker 2> /dev/null)

GIT_COMMIT ?= $(shell git rev-list -1 HEAD)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
GIT_TAG ?= $(shell git describe --tags '--match=v*' --dirty)
GIT_TAG ?= $(shell git describe --tags '--match=v*' --dirty 2>/dev/null || echo "untagged")
ERIGON_USER ?= erigon
# if using volume-mounting data dir, then must exist on host OS
DOCKER_UID ?= $(shell id -u)
Expand Down Expand Up @@ -98,11 +98,8 @@ dbg:
@cd ./cmd/$* && $(GOBUILD) -o $(GOBIN)/$*
@echo "Run \"$(GOBIN)/$*\" to launch $*."

## geth: run erigon (TODO: remove?)
geth: erigon

## erigon: build erigon
erigon: go-version erigon.cmd
zkevm-erigon: go-version zkevm-erigon.cmd
@rm -f $(GOBIN)/tg # Remove old binary to prevent confusion where users still use it because of the scripts

COMMANDS += devnet
Expand All @@ -128,7 +125,7 @@ COMMANDS += erigon-el
$(COMMANDS): %: %.cmd

## all: run erigon with all commands
all: erigon $(COMMANDS)
all: zkevm-erigon $(COMMANDS)

## db-tools: build db tools
db-tools:
Expand Down Expand Up @@ -214,7 +211,7 @@ git-submodules:
@git submodule sync --quiet --recursive || true
@git submodule update --quiet --init --recursive --force || true

PACKAGE_NAME := github.com/ledgerwatch/erigon
PACKAGE_NAME := github.com/gateway-fm/zkevm-erigon
GOLANG_CROSS_VERSION ?= v1.20.2

.PHONY: release-dry-run
Expand Down
107 changes: 106 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,109 @@
# Erigon
# zkEVM-Erigon

zkEVM-Erigon is a fork of Erigon, currently in Alpha, optimized for syncing with the Polygon Hermez zkEVM network.

***

## zkevm-specific API Support

In order to enable the zkevm_ namespace, please add 'zkevm' to the http.api flag (see the example config below).

### Supported
- `zkevm_batchNumber`
- `zkevm_batchNumberByBlockNumber`
- `zkevm_consolidatedBlockNumber`
- `zkevm_getBatchByNumber`
- `zkevm_isBlockConsolidated`
- `zkevm_verifiedBatchNumber`


### Not yet supported
- `zkevm_isBlockVirtualized`
- `zkevm_virtualBatchNumber`
- `zkevm_getFullBlockByHash`
- `zkevm_getFullBlockByNumber`
- `zkevm_getNativeBlockHashesInRange`

***

## Limitations/Warnings

- The golden poseidon hashing will be much faster on x86, so developers on Mac may experience slowness on Apple silicone
- Falling behind by > 500 blocks (at some point this will be configurable) will cause a SMT rebuild - which will take some time for longer chains

***

## Chain Configs
- Testnet - this is the formal testnet
- chain: `hermez-testnet`
- Mainnet - this runs against L1 Ethereum Mainnet
- chain: `hermez-mainnet`

***

## Configuration Files
Config files are the easiest way to configure zKEVM-Erigon, there are examples in the repository for each network e.g. `hermezconfig-testnet.yaml.example`.

Depending on the RPC provider you are using, you may wish to alter `zkevm.rpc-ratelimit`.

Here is an example of the testnet config `hermezconfig-testnet.yaml`:

```yaml
datadir : '/Path/to/your/datadirs/hermez-testnet'
chain : "hermez-testnet"
http : true
private.api.addr : "localhost:9091"
zkevm.l2-chain-id: 1442
zkevm.l2-sequencer-rpc-url: "https://rpc.public.zkevm-test.net"
zkevm.l2-datastreamer-url: "stream.zkevm-test.net:6900"
zkevm.l1-chain-id: 5
zkevm.l1-rpc-url: "https://rpc.goerli.eth.gateway.fm"
zkevm.l1-contract-address: "0xa997cfD539E703921fD1e3Cf25b4c241a27a4c7A"
zkevm.l1-matic-contract-address: "0x1319D23c2F7034F52Eb07399702B040bA278Ca49"
zkevm.l1-ger-manager-contract-address: "0x4d9427DCA0406358445bC0a8F88C26b704004f74"
zkevm.l1-first-block: 8577775
zkevm.rpc-ratelimit: 250

externalcl: true
http.api : ["eth","debug","net","trace","web3","erigon", "zkevm"]
```
***
## Running zKEVM Erigon
- Build using ``'make zkevm-erigon'`
- Set up your config file (copy an example and edit as required)
- run `./build/bin/zkevm-erigon --config="./hermezconfig-{network}.yaml"` (complete the name of your config file as required)

NB: `--externalcl` flag is removed in upstream erigon so beware of re-using commands/config

***

## Networks

| Network Name | Chain ID | ForkID | Genesis File | RPC URL | Rootchain | Smart Contract Address |
|---------------------|----------|--------|--------------|---------|------------|------------------------|
| zkEVM Mainnet | 1101 | 5 | [Link](https://hackmd.io/bpmxb5QaSFafV0nB4i-KZA) | [Mainnet RPC](https://zkevm-rpc.com/) | Ethereum Mainnet | `0x5132A183E9F3CB7C848b0AAC5Ae0c4f0491B7aB2` |
| zkEVM Public Testnet| 1442 | 5 | [Link](https://hackmd.io/Ug9pB613SvevJgnXRC4YJA) | [Testnet RPC](https://rpc.public.zkevm-test.net/) | Goerli | `0xa997cfD539E703921fD1e3Cf25b4c241a27a4c7A` |

***

## Additional Resources

- Block Explorers:
- Testnet: [PolygonScan Testnet](https://testnet-zkevm.polygonscan.com/)
- Mainnet: [PolygonScan Mainnet](https://zkevm.polygonscan.com/)

***
## Funding for Testing

Use the Goerli faucet to obtain ETH for testing: [Goerli Faucet](https://goerlifaucet.com). Transfer ETH to L2 using the bridge contract page. ENS is not supported on the L2.
<br><br>

***
***

# Upstream Erigon README

Erigon is an implementation of Ethereum (execution client with light client for consensus layer), on the efficiency
frontier. [Archive Node](https://ethereum.org/en/developers/docs/nodes-and-clients/archive-nodes/#what-is-an-archive-node)
Expand Down
8 changes: 6 additions & 2 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (
"time"

"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon-lib/kv"
state2 "github.com/ledgerwatch/erigon-lib/state"
types2 "github.com/ledgerwatch/erigon-lib/types"
"github.com/ledgerwatch/erigon/chain"
"github.com/ledgerwatch/erigon/eth/ethconfig"
"github.com/ledgerwatch/log/v3"

Expand All @@ -51,6 +51,7 @@ import (
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
"github.com/ledgerwatch/erigon/turbo/stages"
zktypes "github.com/ledgerwatch/erigon/zk/types"
)

// This nil assignment ensures at compile time that SimulatedBackend implements bind.ContractBackend.
Expand Down Expand Up @@ -725,7 +726,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx types.Transac
b.pendingState, state.NewNoopWriter(),
b.pendingHeader, tx,
&b.pendingHeader.GasUsed, vm.Config{},
b.pendingHeader.ParentExcessDataGas(b.getHeader)); err != nil {
b.pendingHeader.ParentExcessDataGas(b.getHeader), 0); err != nil {
return err
}
//fmt.Printf("==== Start producing block %d\n", (b.prependBlock.NumberU64() + 1))
Expand Down Expand Up @@ -806,6 +807,9 @@ func (m callMsg) Value() *uint256.Int { return m.CallMsg.Value }
func (m callMsg) Data() []byte { return m.CallMsg.Data }
func (m callMsg) AccessList() types2.AccessList { return m.CallMsg.AccessList }
func (m callMsg) IsFree() bool { return false }
func (m callMsg) EffectiveGasPricePercentage() uint8 {
return zktypes.EFFECTIVE_GAS_PRICE_PERCENTAGE_DISABLED
}

/*
// filterBackend implements filters.Backend to support filtering for logs without
Expand Down
31 changes: 31 additions & 0 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"errors"
"fmt"
"math/big"
"strings"
"sync"

"github.com/holiman/uint256"
libcommon "github.com/ledgerwatch/erigon-lib/common"
Expand Down Expand Up @@ -56,6 +58,8 @@ type TransactOpts struct {
GasLimit uint64 // Gas limit to set for the transaction execution (0 = estimate)

Context context.Context // Network context to support cancellation and timeouts (nil = no timeout)

NoSend bool // Do all transact steps but do not send the transaction
}

// FilterOpts is the collection of options to fine tune filtering for events
Expand Down Expand Up @@ -269,6 +273,10 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *libcommon.Address
if err != nil {
return nil, err
}
// Do all transact steps but do not send the transaction
if opts.NoSend {
return signedTx, nil
}
if err := c.transactor.SendTransaction(ensureContext(opts.Context), signedTx); err != nil {
return nil, err
}
Expand Down Expand Up @@ -392,3 +400,26 @@ func ensureContext(ctx context.Context) context.Context {
}
return ctx
}

// MetaData collects all metadata for a bound contract.
type MetaData struct {
mu sync.Mutex
Sigs map[string]string
Bin string
ABI string
ab *abi.ABI
}

func (m *MetaData) GetAbi() (*abi.ABI, error) {
m.mu.Lock()
defer m.mu.Unlock()
if m.ab != nil {
return m.ab, nil
}
if parsed, err := abi.JSON(strings.NewReader(m.ABI)); err != nil {
return nil, err
} else {
m.ab = &parsed
}
return m.ab, nil
}
Loading

0 comments on commit 459c01f

Please sign in to comment.