Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CORE-538] Upgrade to Cosmos 0.50.1 and CometBFT 0.38 #867

Merged
merged 20 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions proto/dydxprotocol/sending/transfer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ message MsgDepositToSubaccount {
// MsgWithdrawFromSubaccount represents a single transfer from an
// `x/subaccounts` subaccount to an `x/bank` account.
message MsgWithdrawFromSubaccount {
option (cosmos.msg.v1.signer) = "sender";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that we are specifying the sender should be sender.owner in CustomGetSigner here.

Should we remove this option, given that sender is not a valid signer (i.e. it's not an address string)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cosmos SDK was meant to support these recursively but didn't do it quite right since sender is supposed to go into that message and then use owner to find the appropriate address string. I filed cosmos/cosmos-sdk#18722 and they have fixed this but it won't be available till a future Cosmos SDK release.

I'd like to leave this for now and once able we can remove the CustomGetSigners implementation.


// The sender subaccount ID.
dydxprotocol.subaccounts.SubaccountId sender = 2
[ (gogoproto.nullable) = false ];
Expand Down
6 changes: 3 additions & 3 deletions protocol/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ test-unit:
@VERSION=$(VERSION) go test -mod=readonly -tags='test_ledger_mock $(build_tags)' ./...

test-race:
@VERSION=$(VERSION) go test -mod=readonly -race -tags='test_ledger_mock $(build_tags)' ./...
@VERSION=$(VERSION) go test -mod=readonly -timeout 20m -race -tags='test_ledger_mock $(build_tags)' ./...

test-cover:
@VERSION=$(VERSION) go test -mod=readonly -timeout 12m -coverprofile=coverage.out -covermode=atomic -coverpkg=github.com/dydxprotocol/v4-chain/protocol/... -tags='test_ledger_mock $(build_tags)' ./...
Expand Down Expand Up @@ -409,7 +409,7 @@ update-swagger-docs: statik
.PHONY: update-swagger-docs

###############################################################################
### Sample Prengenesis ###
### Sample Pregenesis ###
###############################################################################

# Run at `./protocol` directory.
Expand All @@ -421,7 +421,7 @@ update-sample-pregenesis:

check-sample-pregenesis-up-to-date:
$(MAKE) localnet-build
@docker build . -t check-sample-pregenesis -f scripts/genesis/Dockerfile --no-cache
@docker build . -t check-sample-pregenesis -f scripts/genesis/Dockerfile --no-cache
@docker run -v $(CURDIR):/workspace check-sample-pregenesis

.PHONY: update-sample-pregenesis check-sample-pregenesis-up-to-date
6 changes: 3 additions & 3 deletions protocol/app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

anteDecorators := newAnteDecoratorChain(options)
anteDecorators := NewAnteDecoratorChain(options)

// TODO(STAB-24): This change can be reverted to using ChainAnteDecorators again once
// https://github.com/cosmos/cosmos-sdk/pull/16076 is merged, released, and we pick-up the SDK version containing
Expand All @@ -65,8 +65,8 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
return anteHandlers[0], nil
}

// newAnteDecoratorChain returns a list of AnteDecorators in the expected application chain ordering
func newAnteDecoratorChain(options HandlerOptions) []sdk.AnteDecorator {
// NewAnteDecoratorChain returns a list of AnteDecorators in the expected application chain ordering
func NewAnteDecoratorChain(options HandlerOptions) []sdk.AnteDecorator {
return []sdk.AnteDecorator{
// Note: app-injected messages, and clob transactions don't require Gas fees.
libante.NewAppInjectedMsgAnteWrapper(
Expand Down
23 changes: 17 additions & 6 deletions protocol/app/ante/basic_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ante_test

import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
"testing"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
Expand All @@ -19,6 +21,8 @@ import (
// Forked from:
// https://github.com/cosmos/cosmos-sdk/blob/1e8e923d3174cdfdb42454a96c27251ad72b6504/x/auth/ante/basic.go#L18
func TestValidateBasic_AppInjectedMsgWrapper(t *testing.T) {
// The Ante suite and test setup from Cosmos SDK has "cosmos" hardcoded in it as the address codec which
// is why we are required to use it below.
tests := map[string]struct {
msgOne sdk.Msg
msgTwo sdk.Msg
Expand All @@ -39,28 +43,28 @@ func TestValidateBasic_AppInjectedMsgWrapper(t *testing.T) {
expectedErr: nil,
},
"valid ValidateBasic: single msg, NO AppInjected msg": {
msgOne: &testdata.TestMsg{Signers: []string{"meh"}},
msgOne: &testdata.TestMsg{Signers: []string{constants.AliceAccAddress.String()}},
txHasSignature: true, // this should allow ValidateBasic to pass.

expectedErr: nil,
},
"fails ValidateBasic: mult msgs, AppInjected msg": {
msgOne: &pricestypes.MsgUpdateMarketPrices{}, // AppInjected.
msgTwo: &testdata.TestMsg{Signers: []string{"meh"}},
msgTwo: &testdata.TestMsg{Signers: []string{constants.AliceAccAddress.String()}},
txHasSignature: true,

expectedErr: nil,
},
"valid: mult msgs, NO AppInjected msg": {
msgOne: &testdata.TestMsg{Signers: []string{"meh"}},
msgTwo: &testdata.TestMsg{Signers: []string{"meh"}},
msgOne: &testdata.TestMsg{Signers: []string{constants.AliceAccAddress.String()}},
msgTwo: &testdata.TestMsg{Signers: []string{constants.AliceAccAddress.String()}},
txHasSignature: true, // this should allow ValidateBasic to pass.

expectedErr: nil,
},
"skip ValidateBasic: recheck": {
msgOne: &pricestypes.MsgUpdateMarketPrices{}, // AppInjected.
msgTwo: &testdata.TestMsg{Signers: []string{"meh"}},
msgTwo: &testdata.TestMsg{Signers: []string{constants.AliceAccAddress.String()}},
isRecheck: true,
txHasSignature: false, // this should cause ValidateBasic to fail, but this is skipped.

Expand Down Expand Up @@ -98,7 +102,14 @@ func TestValidateBasic_AppInjectedMsgWrapper(t *testing.T) {
privs, accNums, accSeqs = []cryptotypes.PrivKey{}, []uint64{}, []uint64{}
}

tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.Ctx.ChainID())
tx, err := suite.CreateTestTx(
suite.Ctx,
privs,
accNums,
accSeqs,
suite.Ctx.ChainID(),
signing.SignMode_SIGN_MODE_DIRECT,
)
require.NoError(t, err)

if tc.isRecheck {
Expand Down
10 changes: 9 additions & 1 deletion protocol/app/ante/gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ante_test
import (
"cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app"
assets "github.com/dydxprotocol/v4-chain/protocol/x/assets/types"
Expand Down Expand Up @@ -120,7 +121,14 @@ func TestValidateMsgType_FreeInfiniteGasDecorator(t *testing.T) {
// Empty private key, so tx's signature should be empty.
privs, accNums, accSeqs := []cryptotypes.PrivKey{}, []uint64{}, []uint64{}

tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.Ctx.ChainID())
tx, err := suite.CreateTestTx(
suite.Ctx,
privs,
accNums,
accSeqs,
suite.Ctx.ChainID(),
signing.SignMode_SIGN_MODE_DIRECT,
)
require.NoError(t, err)

resultCtx, err := antehandler(suite.Ctx, tx, false)
Expand Down
10 changes: 9 additions & 1 deletion protocol/app/ante/msg_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"

customante "github.com/dydxprotocol/v4-chain/protocol/app/ante"
appmsgs "github.com/dydxprotocol/v4-chain/protocol/app/msgs"
Expand Down Expand Up @@ -485,7 +486,14 @@ func runTest(t *testing.T, name string, msgs []sdk.Msg, mode txMode, expectedErr
require.NoError(t, suite.TxBuilder.SetMsgs(msgs...))
// Empty private key, so tx's signature should be empty.
privs, accNums, accSeqs := []cryptotypes.PrivKey{}, []uint64{}, []uint64{}
tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.Ctx.ChainID())
tx, err := suite.CreateTestTx(
suite.Ctx,
privs,
accNums,
accSeqs,
suite.Ctx.ChainID(),
signing.SignMode_SIGN_MODE_DIRECT,
)
require.NoError(t, err)
suite.Ctx = getCtxWithTxMode(mode, suite)

Expand Down
60 changes: 38 additions & 22 deletions protocol/app/ante/sigverify.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
package ante

import (
errorsmod "cosmossdk.io/errors"
"fmt"

gometrics "github.com/armon/go-metrics"
errorsmod "cosmossdk.io/errors"
txsigning "cosmossdk.io/x/tx/signing"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
sdkante "github.com/cosmos/cosmos-sdk/x/auth/ante"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/dydxprotocol/v4-chain/protocol/lib/metrics"
gometrics "github.com/hashicorp/go-metrics"
"google.golang.org/protobuf/types/known/anypb"
)

// Verify all signatures for a tx and return an error if any are invalid. Note,
// SigVerificationDecorator verifies all signatures for a tx and return an error if any are invalid. Note,
Copy link
Contributor Author

@lcwik lcwik Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was updated with the copy from Cosmo 0.50 with the SkipSequenceValidation changes ported over.

// the SigVerificationDecorator will not check signatures on ReCheck.
//
// CONTRACT: Pubkeys are set in context for all signers before this decorator runs
// CONTRACT: Tx must implement SigVerifiableTx interface
type SigVerificationDecorator struct {
ak sdkante.AccountKeeper
signModeHandler authsigning.SignModeHandler
signModeHandler *txsigning.HandlerMap
}

func NewSigVerificationDecorator(
ak sdkante.AccountKeeper,
signModeHandler authsigning.SignModeHandler,
signModeHandler *txsigning.HandlerMap,
) SigVerificationDecorator {
return SigVerificationDecorator{
ak: ak,
Expand All @@ -39,7 +42,7 @@ func (svd SigVerificationDecorator) AnteHandle(
simulate bool,
next sdk.AnteHandler,
) (newCtx sdk.Context, err error) {
sigTx, ok := tx.(authsigning.SigVerifiableTx)
sigTx, ok := tx.(authsigning.Tx)
if !ok {
return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
}
Expand All @@ -51,14 +54,17 @@ func (svd SigVerificationDecorator) AnteHandle(
return ctx, err
}

signerAddrs := sigTx.GetSigners()
signers, err := sigTx.GetSigners()
if err != nil {
return ctx, err
}

// check that signer length and signature length are the same
if len(sigs) != len(signerAddrs) {
if len(sigs) != len(signers) {
err := errorsmod.Wrapf(
sdkerrors.ErrUnauthorized,
"invalid number of signer; expected: %d, got %d",
len(signerAddrs),
len(signers),
len(sigs),
)
return ctx, err
Expand All @@ -69,7 +75,7 @@ func (svd SigVerificationDecorator) AnteHandle(
skipSequenceValidation := ShouldSkipSequenceValidation(tx.GetMsgs())

for i, sig := range sigs {
acc, err := sdkante.GetSignerAcc(ctx, svd.ak, signerAddrs[i])
acc, err := sdkante.GetSignerAcc(ctx, svd.ak, signers[i])
if err != nil {
return ctx, err
}
Expand Down Expand Up @@ -109,23 +115,32 @@ func (svd SigVerificationDecorator) AnteHandle(
if !genesis {
accNum = acc.GetAccountNumber()
}
signerData := authsigning.SignerData{
Address: acc.GetAddress().String(),
ChainID: chainID,
AccountNumber: accNum,
Sequence: acc.GetSequence(),
PubKey: pubKey,
}

// no need to verify signatures on recheck tx
if !simulate && !ctx.IsReCheckTx() {
err := authsigning.VerifySignature(pubKey, signerData, sig.Data, svd.signModeHandler, tx)
anyPk, _ := codectypes.NewAnyWithValue(pubKey)

signerData := txsigning.SignerData{
Address: acc.GetAddress().String(),
ChainID: chainID,
AccountNumber: accNum,
Sequence: acc.GetSequence(),
PubKey: &anypb.Any{
TypeUrl: anyPk.TypeUrl,
Value: anyPk.Value,
},
}
adaptableTx, ok := tx.(authsigning.V2AdaptableTx)
if !ok {
return ctx, fmt.Errorf("expected tx to implement V2AdaptableTx, got %T", tx)
}
txData := adaptableTx.GetSigningTxData()
err = authsigning.VerifySignature(ctx, pubKey, signerData, sig.Data, svd.signModeHandler, txData)
if err != nil {
var errMsg string
if sdkante.OnlyLegacyAminoSigners(sig.Data) {
// If all signers are using SIGN_MODE_LEGACY_AMINO, we rely on VerifySignature to
// check account sequence number, and therefore communicate sequence number as a
// potential cause of error.
// If all signers are using SIGN_MODE_LEGACY_AMINO, we rely on VerifySignature to check account sequence number,
// and therefore communicate sequence number as a potential cause of error.
errMsg = fmt.Sprintf(
"signature verification failed; please verify account number (%d), sequence (%d)"+
" and chain-id (%s)",
Expand All @@ -135,9 +150,10 @@ func (svd SigVerificationDecorator) AnteHandle(
)
} else {
errMsg = fmt.Sprintf(
"signature verification failed; please verify account number (%d) and chain-id (%s)",
"signature verification failed; please verify account number (%d) and chain-id (%s): (%s)",
accNum,
chainID,
err.Error(),
)
}
return ctx, errorsmod.Wrap(sdkerrors.ErrUnauthorized, errMsg)
Expand Down
Loading
Loading