BCSkill (Block chain skill )
区块链中文技术社区

只讨论区块链底层技术
遵守一切相关法律政策!

Windows WSL 安装docker

1. Add the necessary repository

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

2. Install the necessary dependencies

sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y

3. Install Docker

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli docker-compose containerd.io -y
sudo apt install gnome-keyring

4. Add your user to the Docker group

sudo usermod -aG docker $USER
sudo chmod 666 /var/run/docker.sock
sudo service docker restart

5. Testing the installation

docker version
docker pull hello-world

6.fix "System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down"

sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfig

sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target

exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME

snap version

参考文档

https://www.zdnet.com/article/docker-101-how-to-install-docker-on-ubuntu-server-22-04/
https://gist.github.com/alyleite/ca8b10581dbecd722d9dcc35b50d9b2b
https://docs.docker.com/engine/install/ubuntu/

精选的 zkEVM 资源、库、工具等精选列表

Awesome zkEVM Awesome

zkEVM is a Fully EVM equivalent and zk friendly virtual machine.

Contents

Article - Video

Rollup

zkEVM

zk-hardware

Zero-Knowledge-Proofs

zk-SNARK

Plonk

Halo2

Resources - libraries, tools

Early Rollup

Scroll and Appliedzkp(PSE)

Polygon Hermez

Polygon Zero

zkSync

StarkWare

Zero-Knowledge-Proofs

Halo2

zkp Acceleration

Different Solutions

Native zkEVM

Compiler-Based zkEVM

Transpiler-Based zkEVM

Other

Contributing

Contributions are very welcome!

Please have a look at contributing.md for guidelines.

英文原文:https://github.com/LuozhuZhang/awesome-zkevm

梳理Polygon zkEVM node 本地启动测试环境及配置

测试硬件环境

OS: Mac Pro {cpu intel} v11.7.5
注意:目前,Executor/Prover 不能在 ARM 驱动的 Mac 上运行。对于 Windows 用户,不建议使用 WSL/WSL2。

测试环境搭建

先按官方的测试环境进行部署,熟悉下部署细节,然后再做针对性补充
主要参考文章如下

官方是已Docker环境进行演示介绍的,我们精简下,主要说下关键操作

安装基础环境

自行安装go,dockerdocker-compose
可以参考以下官方文档,查看对应平台的安装方法:
https://go.dev/doc/install
https://www.docker.com/get-started
https://docs.docker.com/compose/install/

克隆代码

git clone https://github.com/0xPolygonHermez/zkevm-node.git

构建Docker镜像

cd zkevm-node/
make build-docker

运行 zkNode 环境

cd test/
make run

其他操作

make stop // 停止 zkNode
make restart // 重启整个 zkNode 环境

执行后,会创建和启动如下容器

  • zkevm-state-db
  • zkevm-pool-db
  • zkevm-mock-l1-network
  • zkevm-prover
  • zkevm-approve
  • zkevm-sync
  • zkevm-eth-tx-manager
  • zkevm-sequencer
  • zkevm-l2gaspricer
  • zkevm-aggregator
  • zkevm-json-rpc

根据Docker环境抽离各个模块配置

//TODO

L1网络配置

L2网络配置

访问环境

关键地址私钥

L1 Addresses

Address Description
0xa513E6E4b8f2a923D98304ec87F64353C4D5C853 Proof of Efficiency
0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 Bridge
0x5FbDB2315678afecb367f032d93F642f64180aa3 Matic token
0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 GlobalExitRootManager

Deployer Account

Address Private Key
0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

Sequencer Account

Address Private Key
0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D 0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e

Accounts

Address Private Key
0x70997970C51812dc3A010C7d01b50e0d17dc79C8 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
0x90F79bf6EB2c4f870365E785982E1f101E93b906 0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6
0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65 0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a
0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc 0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba
0x976EA74026E726554dB657fA54763abd0C3a0aa9 0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e
0x14dC79964da2C08b23698B3D3cc7Ca32193d9955 0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356
0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f 0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97
0xa0Ee7A142d267C1f36714E4a8F75612F20a79720 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6
0xBcd4042DE499D14e55001CcbB24a551F3b954096 0xf214f2b2cd398c806f84e317254e0f0b801d0643303237d97a22a48e01628897
0x71bE63f3384f5fb98995898A86B02Fb2426c5788 0x701b615bbdfb9de65240bc28bd21bbc0d996645a3dd57e7b12bc2bdf6f192c82
0xFABB0ac9d68B0B445fB7357272Ff202C5651694a 0xa267530f49f8280200edf313ee7af6b827f2a8bce2897751d06a843f644967b1
0x1CBd3b2770909D4e10f157cABC84C7264073C9Ec 0x47c99abed3324a2707c28affff1267e45918ec8c3f20b8aa892e8b065d2942dd
0xdF3e18d64BC6A983f673Ab319CCaE4f1a57C7097 0xc526ee95bf44d8fc405a158bb884d9d1238d99f0612e9f33d006bb0789009aaa
0xcd3B766CCDd6AE721141F452C550Ca635964ce71 0x8166f546bab6da521a8369cab06c5d2b9e46670292d85c875ee9ec20e84ffb61
0x2546BcD3c84621e976D8185a91A922aE77ECEc30 0xea6c44ac03bff858b476bba40716402b03e41b8e97e276d1baec7c37d42484a0
0xbDA5747bFD65F08deb54cb465eB87D40e51B197E 0x689af8efa8c651a91ad287602527f3af2fe9f6501a7ac4b061667b5a93e037fd
0xdD2FD4581271e230360230F9337D5c0430Bf44C0 0xde9be858da4a475276426320d5e9262ecfc3ba460bfac56360bfa6c4c28b4ee0
0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199 0xdf57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e

Polygon zkEVM节点代码解析

1. 引言

源代码:https://github.com/0xPolygonHermez/zkevm-node (Go语言)

Polygon zkEVM节点提供的主要服务模块有:

  • 1)JSON-RPC服务
  • 2)Sequencer服务
  • 3)Aggregator服务
  • 4)Synchronizer服务
  • 5)Broadcast服务

2. JSON-RPC服务

以太坊JSON-RPC接口Polygon zkEVM中的JSON-RPC接口 对比情况为:

序号 RPC接口名 以太坊 Hermez 2.0 备注
1 GetBlockByHash
2 GetBlockByNumber
3 GetBlockTransactionCountByHash
4 GetBlockTransactionCountByNumber
5 getUncleCountByBlockHash
6 getUncleCountByBlockNumber
7 ChainId
8 Syncing
9 Coinbase X
10 Accounts X
11 BlockNumber
12 Call
13 EstimateGas
14 CreateAccessList X EIP-2930:新交易类型,需以更贵的方式访问清单(地址或storage keys)外的内容。
15 GasPrice
16 MaxPriorityFeePerGas X
17 FeeHistory X
18 NewFilter
19 NewBlockFilter
20 NewPendingTransactionFilter
21 UninstallFilter
22 GetFilterChanges
23 GetFilterLogs
24 GetLogs
25 Mining X
26 Hashrate X
27 GetWork X
28 SubmitWork X
29 SubmitHashrate X
30 Sign X
31 SignTransaction X
32 GetBalance
33 GetStorageAt
34 GetTransactionCount
35 GetCode
36 GetProof X
37 SendTransaction X
38 SendRawTransaction
39 GetTransactionByHash
40 GetTransactionByBlockHashAndIndex
41 GetTransactionByBlockNumberAndIndex
42 GetTransactionReceipt
43 GetCompilers
44 GetUncleByBlockHashAndIndex
45 GetUncleByBlockNumberAndIndex
46 ProtocolVersion

Hermez 2.0(zkEVM)除实现了以上与以太坊兼容的RPC接口之外,还额外实现了一些与state交互、与pool交互的接口

// jsonRPCTxPool contains the methods required to interact with the tx pool.
type jsonRPCTxPool interface {
    AddTx(ctx context.Context, tx types.Transaction) error
    GetPendingTxs(ctx context.Context, isClaims bool, limit uint64) ([]pool.Transaction, error)
    GetGasPrice(ctx context.Context) (uint64, error)
    GetPendingTxHashesSince(ctx context.Context, since time.Time) ([]common.Hash, error)
}

// gasPriceEstimator contains the methods required to interact with gas price estimator
type gasPriceEstimator interface {
    GetAvgGasPrice(ctx context.Context) (*big.Int, error)
}

// stateInterface gathers the methods required to interact with the state.
type stateInterface interface {
    BeginStateTransaction(ctx context.Context) (pgx.Tx, error)

    GetLastConsolidatedL2BlockNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
    GetTransactionByHash(ctx context.Context, transactionHash common.Hash, dbTx pgx.Tx) (*types.Transaction, error)
    GetTransactionReceipt(ctx context.Context, transactionHash common.Hash, dbTx pgx.Tx) (*types.Receipt, error)
    GetLastL2BlockNumber(ctx context.Context, dbTx pgx.Tx) (uint64, error)
    GetLastL2Block(ctx context.Context, dbTx pgx.Tx) (*types.Block, error)
    GetLastL2BlockHeader(ctx context.Context, dbTx pgx.Tx) (*types.Header, error)
    EstimateGas(transaction *types.Transaction, senderAddress common.Address) (uint64, error)
    GetBalance(ctx context.Context, address common.Address, blockNumber uint64, dbTx pgx.Tx) (*big.Int, error)
    GetL2BlockByHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (*types.Block, error)
    GetL2BlockByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*types.Block, error)
    GetCode(ctx context.Context, address common.Address, blockNumber uint64, dbTx pgx.Tx) ([]byte, error)
    GetStorageAt(ctx context.Context, address common.Address, position *big.Int, blockNumber uint64, dbTx pgx.Tx) (*big.Int, error)
    GetSyncingInfo(ctx context.Context, dbTx pgx.Tx) (state.SyncingInfo, error)
    GetTransactionByL2BlockHashAndIndex(ctx context.Context, blockHash common.Hash, index uint64, dbTx pgx.Tx) (*types.Transaction, error)
    GetTransactionByL2BlockNumberAndIndex(ctx context.Context, blockNumber uint64, index uint64, dbTx pgx.Tx) (*types.Transaction, error)
    GetNonce(ctx context.Context, address common.Address, blockNumber uint64, dbTx pgx.Tx) (uint64, error)
    GetL2BlockHeaderByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (*types.Header, error)
    GetL2BlockTransactionCountByHash(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (uint64, error)
    GetL2BlockTransactionCountByNumber(ctx context.Context, blockNumber uint64, dbTx pgx.Tx) (uint64, error)
    GetLogs(ctx context.Context, fromBlock uint64, toBlock uint64, addresses []common.Address, topics [][]common.Hash, blockHash *common.Hash, since *time.Time, dbTx pgx.Tx) ([]*types.Log, error)
    GetL2BlockHashesSince(ctx context.Context, since time.Time, dbTx pgx.Tx) ([]common.Hash, error)
    DebugTransaction(ctx context.Context, transactionHash common.Hash, tracer string) (*runtime.ExecutionResult, error)
    ProcessUnsignedTransaction(ctx context.Context, tx *types.Transaction, senderAddress common.Address, blockNumber uint64, dbTx pgx.Tx) *runtime.ExecutionResult
    IsL2BlockConsolidated(ctx context.Context, blockNumber int, dbTx pgx.Tx) (bool, error)
    IsL2BlockVirtualized(ctx context.Context, blockNumber int, dbTx pgx.Tx) (bool, error)
}

type storageInterface interface {
    NewLogFilter(filter LogFilter) (uint64, error)
    NewBlockFilter() (uint64, error)
    NewPendingTransactionFilter() (uint64, error)
    GetFilter(filterID uint64) (*Filter, error)
    UpdateFilterLastPoll(filterID uint64) error
    UninstallFilter(filterID uint64) (bool, error)
}

3. Sequencer服务



当前代码库中,暂未实现permissionless sequencer功能,ProofOfEfficiency.sol合约中也暂未实现registerSequencer等接口。

参考资料

[1] Ethereum JSON-RPC Specification
[2] PoE
[3] zkProver debugging
[4] Hermez 1.5 - Merkle Tree spec
[5] PoE - 1.5

附录:Polygon Hermez 2.0 zkEVM系列博客

转载:https://blog.csdn.net/mutourend/article/details/126409344