Skip to content

Commit

Permalink
tweak(etrog): remove blueberry/testnet, fixes (ledgerwatch#129)
Browse files Browse the repository at this point in the history
* tweak(etrog): remove blueberry/testnet, fixes

* tweak(etrog): default streamer version to 2 (bigendian)
  • Loading branch information
revitteth committed Feb 14, 2024
1 parent cc4b597 commit 689ee60
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 137 deletions.
34 changes: 2 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,15 @@ In order to enable the zkevm_ namespace, please add 'zkevm' to the http.api flag
## 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`
- Falling behind the network significantly will cause a SMT rebuild - which will take some time for longer chains

***

## Configuration Files
Config files are the easiest way to configure cdk-erigon, there are examples in the repository for each network e.g. `hermezconfig-testnet.yaml.example`.
Config files are the easiest way to configure cdk-erigon, there are examples in the repository for each network e.g. `hermezconfig-mainnet.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
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ var (
DatastreamVersionFlag = cli.IntFlag{
Name: "zkevm.datastream-version",
Usage: "Stream version indicator 1: PreBigEndian, 2: BigEndian.",
Value: 1,
Value: 2,
}
DataStreamPort = cli.UintFlag{
Name: "zkevm.data-stream-port",
Expand Down
4 changes: 0 additions & 4 deletions core/genesis_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,6 @@ func GenesisBlockByChainName(chain string) *types.Genesis {
return HermezMainnetGenesisBlock()
case networkname.HermezLocalDevnetChainName:
return HermezLocalDevnetGenesisBlock()
case networkname.HermezTestnetChainName:
return HermezTestnetGenesisBlock()
case networkname.HermezBlueberryChainName:
return HermezBlueberryGenesisBlock()
case networkname.HermezEtrogChainName:
return HermezEtrogGenesisBlock()
case networkname.HermezCardonaChainName:
Expand Down
20 changes: 0 additions & 20 deletions core/genesis_write_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,6 @@ func HermezMainnetGenesisBlock() *types.Genesis {
}
}

func HermezTestnetGenesisBlock() *types.Genesis {
return &types.Genesis{
Config: params.HermezTestnetChainConfig,
Timestamp: 1677601932,
GasLimit: 0x0,
Difficulty: big.NewInt(0x0),
Alloc: readPrealloc("allocs/hermez-testnet.json"),
}
}

func HermezBlueberryGenesisBlock() *types.Genesis {
return &types.Genesis{
Config: params.HermezBlueberryChainConfig,
Timestamp: 1676996964,
GasLimit: 0x0,
Difficulty: big.NewInt(0x0),
Alloc: readPrealloc("allocs/hermez-blueberry.json"),
}
}

func HermezEtrogGenesisBlock() *types.Genesis {
return &types.Genesis{
Config: params.HermezEtrogChainConfig,
Expand Down
1 change: 1 addition & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ func newEtherMan(cfg *ethconfig.Zk) *etherman.Client {
ethmanConf := etherman.Config{
URL: cfg.L1RpcUrl,
L1ChainID: cfg.L1ChainId,
L2ChainID: cfg.L2ChainId,
PoEAddr: cfg.L1PolygonRollupManager,
MaticAddr: cfg.L1MaticContractAddress,
GlobalExitRootManagerAddr: cfg.L1GERManagerContractAddress,
Expand Down
2 changes: 1 addition & 1 deletion hermezconfig-dev.yaml.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
datadir : '/Volumes/External/hermez/blueberry'
datadir : '/Volumes/External/hermez/dev'
chain : "hermez-dev"
http : true
private.api.addr : "localhost:9093"
Expand Down
25 changes: 0 additions & 25 deletions params/chainspecs/hermez-blueberry.json

This file was deleted.

25 changes: 0 additions & 25 deletions params/chainspecs/hermez-testnet.json

This file was deleted.

19 changes: 0 additions & 19 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ var (
ChiadoGenesisHash = libcommon.HexToHash("0xada44fd8d2ecab8b08f256af07ad3e777f17fb434f8f8e678b312f576212ba9a")
HermezMainnetGenesisHash = libcommon.HexToHash("0x3f86b09b43e3e49a41fc20a07579b79eba044253367817d5c241d23c0e2bc5c9")
HermezLocalDevnetGenesisHash = libcommon.HexToHash("0x65531c46ddeb39ba78d50f4eb6b87a279fa28bb6f683b327779392a4cd4770f3")
HermezTestnetGenesisHash = libcommon.HexToHash("0x13a14c4a8288e782863d7ce916d224546c69dc428fbfa7115a0cc33a27a05b26")
HermezBlueberryGenesisHash = libcommon.HexToHash("0x45cff376044a08f8f33f0244d589f2178ea4f4c5234d912daa2ff3c496b17862")
HermezDevnetGenesisHash = libcommon.HexToHash("0x45cff376044a08f8f33f0244d589f2178ea4f4c5234d912daa2ff3c496b17862")
HermezCardonaGenesisHash = libcommon.HexToHash("0xf1a89745a08cfd1af739b93f960ad89546e3cec2a7babe8607703eb1e4e94b4d")
HermezCardonaInternalGenesisHash = libcommon.HexToHash("0x676657dd8a7dce782f4fe8a97ba794de3ff732b40233fce01da77d1ba1a24ee1")
X1TestnetGenesisHash = libcommon.HexToHash("0xb2fbff62137228e52809081a425bfcd30c0fdc8c1213085278c739676a7669b8")
Expand Down Expand Up @@ -143,10 +140,6 @@ var (

HermezLocalDevnetChainConfig = readChainSpec("chainspecs/hermez-dev.json")

HermezTestnetChainConfig = readChainSpec("chainspecs/hermez-testnet.json")

HermezBlueberryChainConfig = readChainSpec("chainspecs/hermez-blueberry.json")

HermezEtrogChainConfig = readChainSpec("chainspecs/hermez-etrog.json")

HermezCardonaChainConfig = readChainSpec("chainspecs/hermez-cardona.json")
Expand Down Expand Up @@ -239,10 +232,6 @@ func ChainConfigByChainName(chain string) *chain.Config {
return HermezMainnetChainConfig
case networkname.HermezLocalDevnetChainName:
return HermezLocalDevnetChainConfig
case networkname.HermezTestnetChainName:
return HermezTestnetChainConfig
case networkname.HermezBlueberryChainName:
return HermezBlueberryChainConfig
case networkname.HermezEtrogChainName:
return HermezEtrogChainConfig
case networkname.HermezCardonaChainName:
Expand Down Expand Up @@ -280,10 +269,6 @@ func GenesisHashByChainName(chain string) *libcommon.Hash {
return &HermezMainnetGenesisHash
case networkname.HermezLocalDevnetChainName:
return &HermezLocalDevnetGenesisHash
case networkname.HermezTestnetChainName:
return &HermezTestnetGenesisHash
case networkname.HermezBlueberryChainName:
return &HermezBlueberryGenesisHash
case networkname.HermezEtrogChainName:
return &HermezEtrogGenesisHash
case networkname.HermezCardonaChainName:
Expand Down Expand Up @@ -321,10 +306,6 @@ func ChainConfigByGenesisHash(genesisHash libcommon.Hash) *chain.Config {
return HermezMainnetChainConfig
case genesisHash == HermezLocalDevnetGenesisHash:
return HermezLocalDevnetChainConfig
case genesisHash == HermezTestnetGenesisHash:
return HermezTestnetChainConfig
case genesisHash == HermezBlueberryGenesisHash:
return HermezBlueberryChainConfig
case genesisHash == HermezCardonaGenesisHash:
return HermezCardonaChainConfig
case genesisHash == HermezCardonaInternalGenesisHash:
Expand Down
4 changes: 0 additions & 4 deletions params/networkname/network_name_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package networkname
const (
HermezMainnetChainName = "hermez-mainnet"
HermezLocalDevnetChainName = "hermez-dev"
HermezTestnetChainName = "hermez-testnet"
HermezBlueberryChainName = "hermez-blueberry"
HermezCardonaChainName = "hermez-cardona"
HermezCardonaInternalChainName = "hermez-cardona-internal"
X1TestnetChainName = "x1-testnet"
Expand All @@ -14,8 +12,6 @@ const (
var Zkevm = []string{
HermezMainnetChainName,
HermezLocalDevnetChainName,
HermezTestnetChainName,
HermezBlueberryChainName,
HermezEtrogChainName,
HermezCardonaChainName,
HermezCardonaInternalChainName,
Expand Down
2 changes: 1 addition & 1 deletion zk/rpcdaemon/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ type Transaction struct {
// GetSender gets the sender from the transaction's signature
func GetSender(tx types.Transaction) (common.Address, error) {
// TODO: fix the hardcoded chain config for the l2
signer := types.MakeSigner(params.HermezTestnetChainConfig, 0)
signer := types.MakeSigner(params.MainnetChainConfig, 0)

sender, err := signer.Sender(tx)
if err != nil {
Expand Down
17 changes: 15 additions & 2 deletions zk/zkchainconfig/utils.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package zkchainconfig

import "github.com/ledgerwatch/erigon/params/networkname"

var chainIds = []uint64{
195, // x1-testnet
1101, // mainnet
1440, // devnet
1442, // testnet
2440, // cardona internal
2442, // cardona
10010, //etrog testnet
999999, // local devnet
}

var chainIdToName = map[uint64]string{
195: networkname.X1TestnetChainName,
1101: networkname.HermezMainnetChainName,
2440: networkname.HermezCardonaInternalChainName,
2442: networkname.HermezCardonaChainName,
10010: networkname.HermezEtrogChainName,
999999: networkname.HermezLocalDevnetChainName,
}

func IsZk(chainId uint64) bool {
for _, validId := range chainIds {
if chainId == validId {
Expand All @@ -20,6 +29,10 @@ func IsZk(chainId uint64) bool {
return false
}

func GetChainName(chainId uint64) string {
return chainIdToName[chainId]
}

func IsTestnet(chainId uint64) bool {
return chainId == 1442
}
Expand Down
1 change: 1 addition & 0 deletions zkevm/etherman/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type Config struct {
URL string `mapstructure:"URL"`
L1ChainID uint64 `mapstructure:"L1ChainID"`
L2ChainID uint64 `mapstructure:"L2ChainID"`

PoEAddr common.Address `mapstructure:"PoEAddr"`
MaticAddr common.Address `mapstructure:"MaticAddr"`
Expand Down
11 changes: 8 additions & 3 deletions zkevm/etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/ethclient"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/zk/zkchainconfig"
"github.com/ledgerwatch/erigon/zkevm/etherman/smartcontracts/matic"
"github.com/ledgerwatch/erigon/zkevm/etherman/smartcontracts/polygonzkevm"
"github.com/ledgerwatch/erigon/zkevm/etherman/smartcontracts/polygonzkevmglobalexitroot"
Expand Down Expand Up @@ -156,9 +157,13 @@ func NewClient(cfg Config) (*Client, error) {

l1Conf := params.MainnetChainConfig
l2Conf := params.HermezMainnetChainConfig
if cfg.L1ChainID == 5 {
l1Conf = params.GoerliChainConfig
l2Conf = params.HermezTestnetChainConfig

// l2s using sepolia l1
if cfg.L1ChainID == params.SepoliaChainConfig.ChainID.Uint64() {
l1Conf = params.SepoliaChainConfig
l2Conf = params.ChainConfigByChainName(zkchainconfig.GetChainName(cfg.L2ChainID))
} else {
panic(fmt.Sprintf("L1 chain ID %d not supported", cfg.L1ChainID))
}

return &Client{
Expand Down

0 comments on commit 689ee60

Please sign in to comment.