Skip to content

Commit

Permalink
refactor(header): Validate should check that the raw header's app v…
Browse files Browse the repository at this point in the history
…ersion is not greater than latest app version (#3589)

Co-authored-by: Callum Waters <cmwaters19@gmail.com>
  • Loading branch information
renaynay and cmwaters committed Aug 8, 2024
1 parent 3a8eff2 commit 6032885
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 25 deletions.
6 changes: 3 additions & 3 deletions blob/commitment_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"fmt"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v2/pkg/proof"
"github.com/celestiaorg/go-square/inclusion"
"github.com/celestiaorg/nmt"
"github.com/celestiaorg/nmt/namespace"

Expand Down Expand Up @@ -98,7 +98,7 @@ func (commitmentProof *CommitmentProof) Verify(root []byte, subtreeRootThreshold
// the subtree roots width is defined in ADR-013:
//
//https://github.com/celestiaorg/celestia-app/blob/main/docs/architecture/adr-013-non-interactive-default-rules-for-zero-padding.md
subtreeRootsWidth := shares.SubTreeWidth(numberOfShares, subtreeRootThreshold)
subtreeRootsWidth := inclusion.SubTreeWidth(numberOfShares, subtreeRootThreshold)

// verify the proof of the subtree roots
subtreeRootsCursor := 0
Expand Down
5 changes: 3 additions & 2 deletions blob/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
squareblob "github.com/celestiaorg/go-square/blob"
"github.com/celestiaorg/go-square/namespace"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestBlobsToShares(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
pkgproof "github.com/celestiaorg/celestia-app/v2/pkg/proof"
"github.com/celestiaorg/go-square/inclusion"
appns "github.com/celestiaorg/go-square/namespace"
Expand Down
12 changes: 12 additions & 0 deletions core/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package core

import (
"context"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/rand"

"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"

"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/header/headertest"
"github.com/celestiaorg/celestia-node/share"
Expand Down Expand Up @@ -48,3 +51,12 @@ func TestMismatchedDataHash_ComputedRoot(t *testing.T) {
assert.Contains(t, err.Error(), "mismatch between data hash commitment from"+
" core header and computed data root")
}

func TestBadAppVersion(t *testing.T) {
header := headertest.RandExtendedHeader(t)
header.RawHeader.Version.App = appconsts.LatestVersion + 1

err := header.Validate()
assert.Contains(t, err.Error(), fmt.Sprintf("has version %d, this node supports up to version %d. Please "+
"upgrade to support new version", header.RawHeader.Version.App, appconsts.LatestVersion))
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/BurntSushi/toml v1.4.0
github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b
github.com/benbjohnson/clock v1.3.5
github.com/celestiaorg/celestia-app v1.13.0
github.com/celestiaorg/celestia-app/v2 v2.0.0
github.com/celestiaorg/go-fraud v0.2.1
github.com/celestiaorg/go-header v0.6.2
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,6 @@ github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOC
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 h1:h1Y4V3EMQ2mFmNtWt2sIhZIuyASInj1a9ExI8xOsTOw=
github.com/celestiaorg/blobstream-contracts/v3 v3.1.0/go.mod h1:x4DKyfKOSv1ZJM9NwV+Pw01kH2CD7N5zTFclXIVJ6GQ=
github.com/celestiaorg/celestia-app v1.13.0 h1:7MWEox6lim6WDyiP84Y2/ERfWUJxWPfZlKxzO6OFcig=
github.com/celestiaorg/celestia-app v1.13.0/go.mod h1:CF9VZwWAlTU0Is/BOsmxqkbkYnnmrgl0YRlSBIzr0m0=
github.com/celestiaorg/celestia-app/v2 v2.0.0 h1:cGrkLbqbaNqj+g+LhvmQ0iFKFyrD/GdU5z3WQI/bq8E=
github.com/celestiaorg/celestia-app/v2 v2.0.0/go.mod h1:0wP0W+GLghvsODxLhAYToKsy0RFKeg1HdZftQG90W5A=
github.com/celestiaorg/celestia-core v1.38.0-tm-v0.34.29 h1:HwbA4OegRvXX0aNchBA7Cmu+oIxnH7xRcOhISuDP0ak=
Expand Down
14 changes: 5 additions & 9 deletions header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
"github.com/tendermint/tendermint/light"
core "github.com/tendermint/tendermint/types"

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

if eh.RawHeader.Version.App != v1.Version && eh.RawHeader.Version.App != v2.Version {
return fmt.Errorf(
"app version mismatch, expected: %d or %d, got %d",
v1.Version,
v2.Version,
eh.RawHeader.Version.App,
)
if eh.RawHeader.Version.App == 0 || eh.RawHeader.Version.App > appconsts.LatestVersion {
return fmt.Errorf("header received at height %d has version %d, this node supports up "+
"to version %d. Please upgrade to support new version. Note, 0 is not a valid version",
eh.RawHeader.Height, eh.RawHeader.Version.App, appconsts.LatestVersion)
}

err = eh.Commit.ValidateBasic()
Expand Down
16 changes: 10 additions & 6 deletions header/headertest/validate_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package headertest

import (
"fmt"
"strconv"
"testing"
"time"
Expand All @@ -19,26 +18,31 @@ import (
func TestValidate(t *testing.T) {
testCases := []struct {
extendedHeader *header.ExtendedHeader
wantErr error
wantErr string
}{
{
extendedHeader: getExtendedHeader(t, 1),
wantErr: nil,
wantErr: "",
},
{
extendedHeader: getExtendedHeader(t, 2),
wantErr: nil,
wantErr: "",
},
{
extendedHeader: getExtendedHeader(t, 3),
wantErr: fmt.Errorf("app version mismatch, expected: 1 or 2, got 3"),
wantErr: "has version 3, this node supports up to version 2. " +
"Please upgrade to support new version. Note, 0 is not a valid version",
},
}

for i, tc := range testCases {
t.Run(strconv.Itoa(i), func(t *testing.T) {
got := tc.extendedHeader.Validate()
assert.Equal(t, tc.wantErr, got)
if tc.wantErr == "" {
assert.NoError(t, got)
return
}
assert.ErrorContains(t, got, tc.wantErr)
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion nodebuilder/blobstream/module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package blobstream

import "go.uber.org/fx"
import (
"go.uber.org/fx"
)

func ConstructModule() fx.Option {
return fx.Module("blobstream",
Expand Down

0 comments on commit 6032885

Please sign in to comment.