Skip to content

Commit

Permalink
use custom sigverify ante handler to prevent same tx inclusion (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-yeo committed May 12, 2022
1 parent 512954b commit 25d6113
Show file tree
Hide file tree
Showing 5 changed files with 1,001 additions and 1 deletion.
2 changes: 1 addition & 1 deletion custom/auth/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
cosmosante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
cosmosante.NewValidateSigCountDecorator(options.AccountKeeper),
cosmosante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
cosmosante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),

This comment has been minimized.

Copy link
@ukrit-himakoon

ukrit-himakoon May 13, 2022

hello not sure if it's a typo?

This comment has been minimized.

Copy link
@yun-yeo

yun-yeo May 13, 2022

Author Contributor

to use custom sigverifier have to remove cosmosante

This comment has been minimized.

Copy link
@ukrit-himakoon

ukrit-himakoon May 13, 2022

noted thx

NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
cosmosante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewAnteDecorator(options.IBCChannelKeeper),
), nil
Expand Down
41 changes: 41 additions & 0 deletions custom/auth/ante/ante_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ante_test

import (
"fmt"
"strings"
"testing"

"github.com/stretchr/testify/suite"
Expand All @@ -11,12 +13,14 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/auth/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

terraapp "github.com/terra-money/core/app"
Expand Down Expand Up @@ -115,3 +119,40 @@ func (suite *AnteTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []
func TestAnteTestSuite(t *testing.T) {
suite.Run(t, new(AnteTestSuite))
}

func generatePubKeysAndSignatures(n int, msg []byte, _ bool) (pubkeys []cryptotypes.PubKey, signatures [][]byte) {
pubkeys = make([]cryptotypes.PubKey, n)
signatures = make([][]byte, n)
for i := 0; i < n; i++ {
var privkey cryptotypes.PrivKey = secp256k1.GenPrivKey()

// TODO: also generate ed25519 keys as below when ed25519 keys are
// actually supported, https://github.com/cosmos/cosmos-sdk/issues/4789
// for now this fails:
//if rand.Int63()%2 == 0 {
// privkey = ed25519.GenPrivKey()
//} else {
// privkey = secp256k1.GenPrivKey()
//}

pubkeys[i] = privkey.PubKey()
signatures[i], _ = privkey.Sign(msg)
}
return
}

func expectedGasCostByKeys(pubkeys []cryptotypes.PubKey) uint64 {
cost := uint64(0)
for _, pubkey := range pubkeys {
pubkeyType := strings.ToLower(fmt.Sprintf("%T", pubkey))
switch {
case strings.Contains(pubkeyType, "ed25519"):
cost += types.DefaultParams().SigVerifyCostED25519
case strings.Contains(pubkeyType, "secp256k1"):
cost += types.DefaultParams().SigVerifyCostSecp256k1
default:
panic("unexpected key type")
}
}
return cost
}
Loading

0 comments on commit 25d6113

Please sign in to comment.