Skip to content

Commit

Permalink
Merge pull request from GHSA-3qp7-gj37-g9rx
Browse files Browse the repository at this point in the history
* dragonberry 🐉 🍓

Co-authored-by: Ethan Buchman <ethan@coinculture.info>
Co-authored-by: Marko Baricevic <markobaricevic3778@gmail.com>
Co-authored-by: Roman <roman@osmosis.team>
Co-authored-by: Ethan Buchman <ethan@coinculture.info>
Co-authored-by: Marko Baricevic <markobaricevic3778@gmail.com>
Co-authored-by: Roman <roman@osmosis.team>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>

Co-authored-by: Julien Robert <julien@rbrt.fr>
Co-authored-by: Marko Baricevic <markobaricevic3778@gmail.com>
Co-authored-by: Roman <roman@osmosis.team>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
  • Loading branch information
5 people committed Oct 14, 2022
1 parent 33dbf6a commit 2b24afa
Show file tree
Hide file tree
Showing 39 changed files with 10,003 additions and 2,517 deletions.
2,071 changes: 1,040 additions & 1,031 deletions CHANGELOG.md

Large diffs are not rendered by default.

21 changes: 15 additions & 6 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# Cosmos SDK v0.44.5 Release Notes
# Cosmos SDK v0.44.5-patch Release Notes - Dragonberry Patch

This release introduces bug fixes and improvements on the Cosmos SDK v0.44 series:
This is a security release for the [Dragonberry security advisory](https://forum.cosmos.network/t/ibc-security-advisory-dragonberry/7702).
Please upgrade ASAP.

- Emit ante handler events for failed transactions: ant events can cause blockchain change (eg tx fees) and related events should be emitted.
- (fix) Upgrade IAVL to 0.17.3 to solve race condition bug in IAVL.
Next to this, we have also included a few minor bugfixes.

See the [Cosmos SDK v0.44.5 Changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.44.5/CHANGELOG.md) for the exhaustive list of all changes.
Chains must add the following to their go.mod for the application:

**Full Changelog**: https://github.com/cosmos/cosmos-sdk/compare/v0.44.4...v0.44.5
```go
replace github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go
```

Bumping the SDK version should be smooth, however, feel free to tag core devs to review your upgrading PR:

- **CET**: @tac0turtle, @okwme, @AdityaSripal, @colin-axner, @julienrbrt
- **EST**: @ebuchman, @alexanderbez, @aaronc
- **PST**: @jtremback, @nicolaslara, @czarcas7ic, @p0mvn
- **CDT**: @ValarDragon, @zmanian
78 changes: 28 additions & 50 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package baseapp

import (
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -122,24 +123,6 @@ func (app *BaseApp) SetOption(req abci.RequestSetOption) (res abci.ResponseSetOp
return
}

// FilterPeerByAddrPort filters peers by address/port.
func (app *BaseApp) FilterPeerByAddrPort(info string) abci.ResponseQuery {
if app.addrPeerFilter != nil {
return app.addrPeerFilter(info)
}

return abci.ResponseQuery{}
}

// FilterPeerByID filters peers by node ID.
func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery {
if app.idPeerFilter != nil {
return app.idPeerFilter(info)
}

return abci.ResponseQuery{}
}

// BeginBlock implements the ABCI application interface.
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
defer telemetry.MeasureSince(time.Now(), "abci", "begin_block")
Expand Down Expand Up @@ -621,9 +604,18 @@ func (app *BaseApp) createQueryContext(height int64, prove bool) (sdk.Context, e
return sdk.Context{}, err
}

lastBlockHeight := app.LastBlockHeight()
if height > lastBlockHeight {
return sdk.Context{},
sdkerrors.Wrap(
sdkerrors.ErrInvalidHeight,
"cannot query with height in the future; please provide a valid height",
)
}

// when a client did not provide a query height, manually inject the latest
if height == 0 {
height = app.LastBlockHeight()
height = lastBlockHeight
}

if height <= 1 && prove {
Expand All @@ -639,7 +631,7 @@ func (app *BaseApp) createQueryContext(height int64, prove bool) (sdk.Context, e
return sdk.Context{},
sdkerrors.Wrapf(
sdkerrors.ErrInvalidRequest,
"failed to load state at height %d; %s (latest height: %d)", height, err, app.LastBlockHeight(),
"failed to load state at height %d; %s (latest height: %d)", height, err, lastBlockHeight,
)
}

Expand Down Expand Up @@ -772,6 +764,22 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res
Value: []byte(app.version),
}

case "snapshots":
var responseValue []byte

response := app.ListSnapshots(abci.RequestListSnapshots{})

responseValue, err := json.Marshal(response)
if err != nil {
sdkerrors.QueryResult(sdkerrors.Wrap(err, fmt.Sprintf("failed to marshal list snapshots response %v", response)))
}

return abci.ResponseQuery{
Codespace: sdkerrors.RootCodespace,
Height: req.Height,
Value: responseValue,
}

default:
return sdkerrors.QueryResult(sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query: %s", path))
}
Expand Down Expand Up @@ -809,36 +817,6 @@ func handleQueryStore(app *BaseApp, path []string, req abci.RequestQuery) abci.R
return resp
}

func handleQueryP2P(app *BaseApp, path []string) abci.ResponseQuery {
// "/p2p" prefix for p2p queries
if len(path) < 4 {
return sdkerrors.QueryResult(
sdkerrors.Wrap(
sdkerrors.ErrUnknownRequest, "path should be p2p filter <addr|id> <parameter>",
),
)
}

var resp abci.ResponseQuery

cmd, typ, arg := path[1], path[2], path[3]
switch cmd {
case "filter":
switch typ {
case "addr":
resp = app.FilterPeerByAddrPort(arg)

case "id":
resp = app.FilterPeerByID(arg)
}

default:
resp = sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "expected second parameter to be 'filter'"))
}

return resp
}

func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) abci.ResponseQuery {
// path[0] should be "custom" because "/custom" prefix is required for keeper
// queries.
Expand Down
80 changes: 69 additions & 11 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package baseapp

import (
"fmt"
"encoding/json"
"testing"

"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmprototypes "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

Expand Down Expand Up @@ -118,24 +119,81 @@ func TestGetBlockRentionHeight(t *testing.T) {
}
}

// Test and ensure that negative heights always cause errors.
// See issue https://github.com/cosmos/cosmos-sdk/issues/7662.
func TestBaseAppCreateQueryContextRejectsNegativeHeights(t *testing.T) {
// Test and ensure that invalid block heights always cause errors.
// See issues:
// - https://github.com/cosmos/cosmos-sdk/issues/11220
// - https://github.com/cosmos/cosmos-sdk/issues/7662
func TestBaseAppCreateQueryContext(t *testing.T) {
t.Parallel()

logger := defaultLogger()
db := dbm.NewMemDB()
name := t.Name()
app := NewBaseApp(name, logger, db, nil)

proves := []bool{
false, true,
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 1}})
app.Commit()

app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 2}})
app.Commit()

testCases := []struct {
name string
height int64
prove bool
expErr bool
}{
{"valid height", 2, true, false},
{"future height", 10, true, true},
{"negative height, prove=true", -1, true, true},
{"negative height, prove=false", -1, false, true},
}
for _, prove := range proves {
t.Run(fmt.Sprintf("prove=%t", prove), func(t *testing.T) {
sctx, err := app.createQueryContext(-10, true)
require.Error(t, err)
require.Equal(t, sctx, sdk.Context{})

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
_, err := app.createQueryContext(tc.height, tc.prove)
if tc.expErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}

type paramStore struct {
db *dbm.MemDB
}

func (ps *paramStore) Set(_ sdk.Context, key []byte, value interface{}) {
bz, err := json.Marshal(value)
if err != nil {
panic(err)
}

ps.db.Set(key, bz)
}

func (ps *paramStore) Has(_ sdk.Context, key []byte) bool {
ok, err := ps.db.Has(key)
if err != nil {
panic(err)
}

return ok
}

func (ps *paramStore) Get(_ sdk.Context, key []byte, ptr interface{}) {
bz, err := ps.db.Get(key)
if err != nil {
panic(err)
}

if len(bz) == 0 {
return
}

if err := json.Unmarshal(bz, ptr); err != nil {
panic(err)
}
}
Loading

0 comments on commit 2b24afa

Please sign in to comment.