Skip to content

Commit

Permalink
feat(header): Check app version in eh validation and return err on mi…
Browse files Browse the repository at this point in the history
…smatch (#2138)

As recommended by @cmwaters, we should ensure (as a rudimentary check)
that the headers being passed to us from core match in app versions as
upgraded app versions can indicate breaking changes.

We should error out if the app version does not match.

This PR is still draft until celestia-app has a version out where they
export the AppVersion as a const that we can depend on.

Eventually we should support several versions via #2137 but for now,
this is a good enough check.

TODO: 
- [x] depend on const from app
- [x] test

---------

Co-authored-by: Hlib Kanunnikov <[email protected]>
  • Loading branch information
renaynay and Wondertan authored Jun 21, 2023
1 parent 9adb61e commit ce8ccb3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ require (
)

replace (
github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.13.0-sdk-v0.46.11
github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.14.0-sdk-v0.46.11
github.com/filecoin-project/dagstore => github.com/celestiaorg/dagstore v0.0.0-20230413141458-735ab09a15d6
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.21.2-tm-v0.34.27
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ github.com/celestiaorg/celestia-app v1.0.0-rc2 h1:/u7eespYtBpQtBSz3P8/rKfz9rW7QO
github.com/celestiaorg/celestia-app v1.0.0-rc2/go.mod h1:uiTWKTtRpVwvSiFDl2zausrU1ZBHBWgk7z52pfzJqJU=
github.com/celestiaorg/celestia-core v1.21.2-tm-v0.34.27 h1:nmr9O5BflgNR1aWehs1ZFw4obA//M/+g+SrSMK9sOBA=
github.com/celestiaorg/celestia-core v1.21.2-tm-v0.34.27/go.mod h1:GVo91Wifg9KL/nFx9nPkpl0UIFdvvs4fhnly9GhGxZU=
github.com/celestiaorg/cosmos-sdk v1.13.0-sdk-v0.46.11 h1:Rd5EvJx1nG3KurBspVN51RVmvif0Lp2UVURbG2ad3Cs=
github.com/celestiaorg/cosmos-sdk v1.13.0-sdk-v0.46.11/go.mod h1:xCG6OUkJy5KUMEg20Zk010lra9XjkmKS3+bk0wp7bd8=
github.com/celestiaorg/cosmos-sdk v1.14.0-sdk-v0.46.11 h1:xDLC0ZvIwj9S2gTs9b8EespilL/u/vOGcqJuHz1r/eA=
github.com/celestiaorg/cosmos-sdk v1.14.0-sdk-v0.46.11/go.mod h1:IwvD2nN3vEMkjxhTw/SF5tyJ0+x3GB0EdyQJyteK06U=
github.com/celestiaorg/dagstore v0.0.0-20230413141458-735ab09a15d6 h1:/yCwMCoOPcYCiG18u8/1pv5eXF04xczoQO3sR0bKsgM=
github.com/celestiaorg/dagstore v0.0.0-20230413141458-735ab09a15d6/go.mod h1:ta/DlqIH10bvhwqJIw51Nq3QU4XVMp6pz3f0Deve9fM=
github.com/celestiaorg/go-fraud v0.1.0 h1:v6mZvlmf2J5ELZfPnrtmmOvKbaYIUs/erDWPO8NbZyY=
Expand Down
6 changes: 6 additions & 0 deletions header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
tmjson "github.com/tendermint/tendermint/libs/json"
core "github.com/tendermint/tendermint/types"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/da"
libhead "github.com/celestiaorg/go-header"
"github.com/celestiaorg/rsmt2d"
Expand Down Expand Up @@ -115,6 +116,11 @@ func (eh *ExtendedHeader) Validate() error {
return fmt.Errorf("ValidateBasic error on RawHeader at height %d: %w", eh.Height(), err)
}

if eh.RawHeader.Version.App != appconsts.LatestVersion {
return fmt.Errorf("app version mismatch, expected: %d, got %d", appconsts.LatestVersion,
eh.RawHeader.Version.App)
}

err = eh.Commit.ValidateBasic()
if err != nil {
return fmt.Errorf("ValidateBasic error on Commit at height %d: %w", eh.Height(), err)
Expand Down
8 changes: 8 additions & 0 deletions header/headertest/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/assert"
tmrand "github.com/tendermint/tendermint/libs/rand"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
libhead "github.com/celestiaorg/go-header"
)

Expand Down Expand Up @@ -80,6 +81,13 @@ func TestVerify(t *testing.T) {
},
err: true,
},
{
prepare: func() libhead.Header {
untrustedAdj.RawHeader.Version.App = appconsts.LatestVersion + 1
return untrustedAdj
},
err: true,
},
}

for i, test := range tests {
Expand Down

0 comments on commit ce8ccb3

Please sign in to comment.