Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
rpcs.toml
wallets.toml
createRollupManagerOutput.example.json
networks/local/test*

# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
Expand All @@ -22,3 +24,7 @@ wallets.toml

# Go workspace file
go.work
docker/gethData

# Node
node_modules
57 changes: 57 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "deploy rollup manager",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd",
"args": [
"deploy-rm",
"-l1", "local",
"-w", "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", "-wp", "testonly",
"-skip-confirmation",
"-i", "${workspaceFolder}/createRollupManagerParams.example.json",
"-o", "${workspaceFolder}/createRollupManagerOutput.example.json",
"-alias", "test_etrog",
"-scv", "etrog",
]
},
{
"name": "add rollup type",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd",
"args": [
"add-rt",
"-l1", "local",
"-w", "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", "-wp", "testonly",
"-skip-confirmation",
"-i", "${workspaceFolder}/addRollupTypeParams.example.json",
"-alias", "test_etrog",
"-scv", "etrog",
]
},
{
"name": "create rollup",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd",
"args": [
"create-r",
"-l1", "local",
"-w", "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", "-wp", "testonly",
"-skip-confirmation",
"-i", "${workspaceFolder}/createRollupParams.example.json",
"-alias", "test_etrog",
"-scv", "etrog",
]
}
]
}
1 change: 1 addition & 0 deletions 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266.keystore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"f39fd6e51aad88f6f4ce6ab8827279cfffb92266","crypto":{"cipher":"aes-128-ctr","ciphertext":"d005030a7684f3adad2447cbb27f63039eec2224c451eaa445de0d90502b9f3d","cipherparams":{"iv":"dc07a54bc7e388efa89c34d42f2ebdb4"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"cf2ec55ecae11171de575112cfb16963570533a9c46fb774473ceb11519eb24a"},"mac":"3eb180d405a5da6e462b2adc00091c14856c91d574bf27348714506357d6e177"},"id":"035454db-6b6d-477f-8a79-ce24c10b185f","version":3}
63 changes: 62 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,65 @@ Unfortunately the base genesis file cannot be retrieved from L1. Therefore they
- `-output API3.json` file where the genesis will be stored
4. Generate the network config section of the bridge service: `go run ./cmd bridge -l1 sepolia -rm cardona -r API3 -output API3Bridge.toml`

Note that step 1 only needs to be done once, if there are multiple CDKs attaced to the same rollup manager, with a single run it will be enough
Note that step 1 only needs to be done once, if there are multiple CDKs attaced to the same rollup manager, with a single run it will be enough

#### Generate docker image for fork7

1. Start the dimulated L1 `go run ./cmd start-l1`
2. Deploy rollup manager
```bash
go run ./cmd deploy-rm \
-l1 local \
-w 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 -wp testonly \
-skip-confirmation \
-i ./createRollupManagerParams.example.json \
-o ./createRollupManagerOutput.example.json \
-alias test_etrog \
-scv etrog
```
3. Add rollup type
```bash
go run ./cmd add-rt \
-l1 local \
-w 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 -wp testonly \
-skip-confirmation \
-i ./addRollupTypeParams.example.json \
-alias test_etrog \
-scv etrog
```
4. Create rollup
```bash
go run ./cmd create-r \
-l1 local \
-w 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 -wp testonly \
-skip-confirmation \
-i ./createRollupParams.example.json \
-alias test_etrog \
-scv etrog
```
5. Deploy and setup DAC
```bash
go run ./cmd deployset-dac \
-l1 local \
-w 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 -wp testonly \
-skip-confirmation \
-rm-alias test_etrog \
-r-alias zkevm \
-init
```
6. Mint POL tokens for the sequencer
```bash
go run ./cmd mint \
-l1 local \
-w 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 -wp testonly \
-skip-confirmation \
-token 0x5fbdb2315678afecb367f032d93f642f64180aa3 \
-amount 99999999999999999999999999999999999999999
```
7. Export L1 container `go run ./cmd export-l1 -image validium-fork7`
8. Generate genesis config:
```bash
go run ./cmd genesis -l1 local -rm test_etrog -r zkevm -output localtest.genesis.json
```

Now you can use the generated image `validium-fork7` and the genesis file `localtest.genesis.json` to test a cdk-validium-node using etrog
7 changes: 7 additions & 0 deletions addRollupTypeParams.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"useMockVerifier": true,
"consensusType": "validium",
"forkID": 7,
"genesisRoot": "0x489e44072604e671274ea693d5309e797fb37a3e0d91e5b0f04639c251c05332",
"description": "This is a test. Validium_Etrog_Fork7"
}
235 changes: 235 additions & 0 deletions cmd/addrolluptype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
package main

import (
"encoding/json"
"errors"
"fmt"
"os"
"path"

verifierelderberry "github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/fflonkverifier"
"github.com/0xPolygon/cdk-contracts-tooling/contracts/elderberry/verifierrolluphelpermock"
verifieretrog "github.com/0xPolygon/cdk-contracts-tooling/contracts/etrog/fflonkverifier"
"github.com/0xPolygon/cdk-contracts-tooling/rollup"
"github.com/0xPolygon/cdk-contracts-tooling/rollupmanager"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/urfave/cli/v2"
)

const (
mockVerifierFlagName = "mock-verifier"
addRollupTypeFileFlagName = "add-rollup-type-parameters-file"
rollupConsensus = "rollup"
validiumConsensus = "validium"
)

var (
addRollupTypeCommand = &cli.Command{
Name: "add-rollup-type",
Aliases: []string{"add-rt"},
Usage: "Deploy necessary implementations and add type to a rollup manager",
Action: addRollupTypeCmd,
Flags: []cli.Flag{
l1Flag,
walletFlag,
walletPasswordFlag,
skipConfirmationFlag,
timeoutFlag,
smartContractVersionFlag,
&cli.StringFlag{
Name: rollupManagerAliasFlagName,
Aliases: []string{"alias"},
Usage: "Name of the rollup manager where the rollup type will be added to",
Required: true,
},
&cli.PathFlag{
Name: addRollupTypeFileFlagName,
Aliases: []string{"params", "file-params", "i"},
Usage: `TODO: description`,
Required: true,
},
},
}
)

func addRollupTypeCmd(cliCtx *cli.Context) error {
// Load configs
baseDir, err := checkWorkingDir()
if err != nil {
return err
}
_, auth, client, err := loadAuthAndClient(cliCtx)
if err != nil {
return err
}
params, err := loadAddRollupTypeParams(cliCtx.String(addRollupTypeFileFlagName))
if err != nil {
return err
}
rmAlias := cliCtx.String(rollupManagerAliasFlagName)
l1Network := cliCtx.String(l1FlagName)
rollupManagerPath := path.Join(baseDir, "networks", l1Network, rmAlias)
rm, err := rollupmanager.LoadFromFile(client, path.Join(rollupManagerPath, "rollupManager.json"))
if err != nil {
return err
}
if _, err := os.Stat(path.Join(baseDir, "genesis", params.GenesisRoot.Hex()+".json")); errors.Is(err, os.ErrNotExist) {
return fmt.Errorf(
"no genesis file found for root %s. Please add genesis file to the genesis directory",
params.GenesisRoot.Hex(),
)
}
contractsVersion := cliCtx.String(smartContractVersionFlagName)

// Check permissions
hasRole, err := rm.Contract.HasRole(nil, rollupmanager.ADD_ROLLUP_TYPE_ROLE, auth.From)
if err != nil {
return err
}
if !hasRole {
_, err = sendTxWithConfirmation(
cliCtx, client, fmt.Sprintf(
"Send tx to grant ADD_ROLLUP_TYPE_ROLE role to %s",
auth.From,
),
func() (*types.Transaction, error) {
return rm.Contract.GrantRole(auth, rollupmanager.ADD_ROLLUP_TYPE_ROLE, auth.From)
},
)
if err != nil {
return err
}
}

// if ((await rollupManagerContract.hasRole(ADD_ROLLUP_TYPE_ROLE, deployer.address)) == false)
// await rollupManagerContract.grantRole(ADD_ROLLUP_TYPE_ROLE, deployer.address);

// Verifier
if params.VerifierImplementation != zeroAddr {
fmt.Println("using verifier:", params.VerifierImplementation)
} else {
fmt.Println("deploying verifier")
var deployFn func(auth *bind.TransactOpts, backend bind.ContractBackend) (*types.Transaction, error)
if params.UseMockVerifier {
deployFn = func(auth *bind.TransactOpts, backend bind.ContractBackend) (*types.Transaction, error) {
_, tx, _, err := verifierrolluphelpermock.DeployVerifierrolluphelpermock(auth, client)
return tx, err
}
} else {
switch contractsVersion {
case etrog:
deployFn = func(auth *bind.TransactOpts, backend bind.ContractBackend) (*types.Transaction, error) {
_, tx, _, err := verifieretrog.DeployFflonkverifier(auth, client)
return tx, err
}
case elderbeerry:
deployFn = func(auth *bind.TransactOpts, backend bind.ContractBackend) (*types.Transaction, error) {
_, tx, _, err := verifierelderberry.DeployFflonkverifier(auth, client)
return tx, err
}
}
}
addr, err := deploy(
cliCtx, auth, client, deployFn,
"Do you want to send the tx that will deploy the verifier?",
)
if err != nil {
return err
}
fmt.Println("Verifier implementation deployed at:", addr)
params.VerifierImplementation = addr
}

// Consensus
if params.ConsensusImplementation != zeroAddr {
fmt.Println("using consensus:", params.ConsensusImplementation)
} else {
consensus, err := rollup.GetConsensus(
contractsVersion, params.ConsensusType, client, auth, rm, nil,
)
if err != nil {
return err
}

addr, err := deploy(
cliCtx, auth, client, consensus.Deploy,
"Do you want to send the tx that will deploy the consensus?",
)
if err != nil {
return err
}
fmt.Println("Consensus implementation deployed at:", addr)
params.ConsensusImplementation = addr
}

// Last rollup type ID
rollupTypeCounterBeforeTx, err := rm.Contract.RollupTypeCount(nil)
if err != nil {
return err
}

// Add rollup type
_, err = sendTxWithConfirmation(
cliCtx, client, fmt.Sprintf(
"Send add rollup type tx? Following params are going to be used:\n"+
"- consensus implementation: %s\n"+
"- verifier implementation: %s\n"+
"- fork ID: %d\n"+
"- rollup compatibility ID: 0\n"+
"- genesis root: %s\n"+
"- description: %s\n",
params.ConsensusImplementation, params.VerifierImplementation,
params.ForkID, params.GenesisRoot, params.Description,
),
func() (*types.Transaction, error) {
return rm.Contract.AddNewRollupType(
auth,
params.ConsensusImplementation, params.VerifierImplementation,
params.ForkID, 0, params.GenesisRoot, params.Description,
)
},
)
if err != nil {
return err
}
rollupTypeCounterAfterTx, err := rm.Contract.RollupTypeCount(nil)
if err != nil {
return err
}
if rollupTypeCounterBeforeTx == rollupTypeCounterAfterTx {
return errors.New("something went wrong, rollup type counter is still the same after sending the tx")
}
fmt.Println("Rollup type added with ID:", rollupTypeCounterAfterTx)
rt, err := rm.Contract.RollupTypeMap(nil, rollupTypeCounterAfterTx)
if err != nil {
return err
}
fmt.Println(common.Hash(rt.Genesis).Hex())
// TODO: assert that the rt output matches the expected inputs
return nil
}

type AddRollupTypeParams struct {
// If provided, will use this instead of deploying a new verifier implementation
VerifierImplementation common.Address `json:"verifierImplementation"`
// If true will deploy a mock verifier instead of a real one
UseMockVerifier bool `json:"useMockVerifier"`
// If provided, will use this instead of deploying a new consensus implementation
ConsensusImplementation common.Address `json:"consensusImplementation"`
// Consensus type. Supported values: [rollup, validium]
ConsensusType string `json:"consensusType"`
ForkID uint64 `json:"forkID"`
GenesisRoot common.Hash `json:"genesisRoot"`
Description string `json:"description"`
}

func loadAddRollupTypeParams(file string) (*AddRollupTypeParams, error) {
data, err := os.ReadFile(file)
if err != nil {
return nil, err
}
var params AddRollupTypeParams
return &params, json.Unmarshal(data, &params)
}
Loading