Skip to content

Commit

Permalink
fix: validate checksum upon setup and start (#1215)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Jan 1, 2025
1 parent 99c2f70 commit 72de46a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/rollapp/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ RollApp's IRO time: %v`,
pterm.Error.Println("failed to validate genesis: ", err)
}
err = genesis.ValidateGenesis(
localRollerConfig,
localRollerConfig.RollappID,
localRollerConfig.HubData,
)
Expand Down
17 changes: 17 additions & 0 deletions cmd/rollapp/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/dymensionxyz/roller/sequencer"
"github.com/dymensionxyz/roller/utils/bash"
"github.com/dymensionxyz/roller/utils/filesystem"
genesisutils "github.com/dymensionxyz/roller/utils/genesis"
"github.com/dymensionxyz/roller/utils/healthagent"
"github.com/dymensionxyz/roller/utils/logging"
"github.com/dymensionxyz/roller/utils/migrations"
Expand Down Expand Up @@ -68,6 +69,22 @@ Consider using 'services' if you want to run a 'systemd'(unix) or 'launchd'(mac)
return
}

isChecksumValid, err := genesisutils.CompareGenesisChecksum(
rollappConfig.Home,
rollappConfig.RollappID,
rollappConfig.HubData,
)

if !isChecksumValid {
pterm.Error.Println("genesis checksum mismatch")
return
}

if err != nil {
pterm.Error.Println("failed to compare genesis checksum: ", err)
return
}

if rollappConfig.HubData.ID != consts.MockHubID {
raUpgrade, err := upgrades.NewRollappUpgrade(string(rollappConfig.RollappVMType))
if err != nil {
Expand Down
17 changes: 16 additions & 1 deletion utils/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -396,13 +397,27 @@ const (
ValidateGenesisURL = "https://genesis-validator.rollapp.network/validate-genesis"
)

func ValidateGenesis(raID string, hd consts.HubData) error {
func ValidateGenesis(raCfg roller.RollappConfig, raID string, hd consts.HubData) error {
req := ValidateGenesisRequest{
RollappID: raID,
SettlementChainID: hd.ID,
SettlementNodeAddress: hd.RpcUrl,
}

isChecksumValid, err := CompareGenesisChecksum(
raCfg.Home,
raID,
hd,
)

if !isChecksumValid {
return errors.New("genesis checksum mismatch")
}

if err != nil {
return err
}

b, err := json.Marshal(req)
if err != nil {
return err
Expand Down

0 comments on commit 72de46a

Please sign in to comment.