feat: extra checks on signatures/pubkeys + check the signature first in antehandle (#18194)
This commit is contained in:
parent
5d83f92ecd
commit
346044afd0
@ -69,7 +69,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
* [#17733](https://github.com/cosmos/cosmos-sdk/pull/17733) Ensure `buf export` exports all proto dependencies
|
||||
* (version) [#18063](https://github.com/cosmos/cosmos-sdk/pull/18063) Include additional information in the Info struct. This change enhances the Info struct by adding support for additional information through the ExtraInfo field
|
||||
* [#18204](https://github.com/cosmos/cosmos-sdk/pull/18204) Use streaming json parser to parse chain-id from genesis file.
|
||||
|
||||
* (crypto | x/auth) [#14372](https://github.com/cosmos/cosmos-sdk/pull/18194) Key checks on signatures antehandle
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* (baseapp) [#18383](https://github.com/cosmos/cosmos-sdk/pull/18383) Fixed a data race inside BaseApp.getContext, found by end-to-end (e2e) tests.
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
"math/big"
|
||||
|
||||
"github.com/cometbft/cometbft/crypto"
|
||||
secp256k1 "github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
secp256k1dcrd "github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
"golang.org/x/crypto/ripemd160" //nolint: staticcheck // keep around for backwards compatibility
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
@ -39,7 +39,8 @@ func (privKey *PrivKey) Bytes() []byte {
|
||||
// PubKey performs the point-scalar multiplication from the privKey on the
|
||||
// generator point to get the pubkey.
|
||||
func (privKey *PrivKey) PubKey() cryptotypes.PubKey {
|
||||
pubkeyObject := secp256k1.PrivKeyFromBytes(privKey.Key).PubKey()
|
||||
pubkeyObject := secp256k1dcrd.PrivKeyFromBytes(privKey.Key).PubKey()
|
||||
|
||||
pk := pubkeyObject.SerializeCompressed()
|
||||
return &PubKey{Key: pk}
|
||||
}
|
||||
@ -100,7 +101,7 @@ func genPrivKey(rand io.Reader) []byte {
|
||||
|
||||
d.SetBytes(privKeyBytes[:])
|
||||
// break if we found a valid point (i.e. > 0 and < N == curverOrder)
|
||||
isValidFieldElement := 0 < d.Sign() && d.Cmp(secp256k1.S256().N) < 0
|
||||
isValidFieldElement := 0 < d.Sign() && d.Cmp(secp256k1dcrd.S256().N) < 0
|
||||
if isValidFieldElement {
|
||||
break
|
||||
}
|
||||
@ -128,7 +129,7 @@ func GenPrivKeyFromSecret(secret []byte) *PrivKey {
|
||||
// https://apps.nsa.gov/iaarchive/library/ia-guidance/ia-solutions-for-classified/algorithm-guidance/suite-b-implementers-guide-to-fips-186-3-ecdsa.cfm
|
||||
// see also https://github.com/golang/go/blob/0380c9ad38843d523d9c9804fe300cb7edd7cd3c/src/crypto/ecdsa/ecdsa.go#L89-L101
|
||||
fe := new(big.Int).SetBytes(secHash[:])
|
||||
n := new(big.Int).Sub(secp256k1.S256().N, one)
|
||||
n := new(big.Int).Sub(secp256k1dcrd.S256().N, one)
|
||||
fe.Mod(fe, n)
|
||||
fe.Add(fe, one)
|
||||
|
||||
|
||||
@ -147,12 +147,12 @@ func TestGRPCQueryBalance(t *testing.T) {
|
||||
|
||||
req := banktypes.NewQueryBalanceRequest(addr, coin.GetDenom())
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.Balance, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Balance, 0, true)
|
||||
})
|
||||
|
||||
fundAccount(f, addr1, coin1)
|
||||
req := banktypes.NewQueryBalanceRequest(addr1, coin1.GetDenom())
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.Balance, 1087, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Balance, 1087, false)
|
||||
}
|
||||
|
||||
func TestGRPCQueryAllBalances(t *testing.T) {
|
||||
@ -174,7 +174,7 @@ func TestGRPCQueryAllBalances(t *testing.T) {
|
||||
fundAccount(f, addr, coins...)
|
||||
|
||||
req := banktypes.NewQueryAllBalancesRequest(addr, testdata.PaginationGenerator(rt, uint64(numCoins)).Draw(rt, "pagination"), false)
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.AllBalances, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.AllBalances, 0, true)
|
||||
})
|
||||
|
||||
coins := sdk.NewCoins(
|
||||
@ -185,7 +185,7 @@ func TestGRPCQueryAllBalances(t *testing.T) {
|
||||
fundAccount(f, addr1, coins...)
|
||||
req := banktypes.NewQueryAllBalancesRequest(addr1, nil, false)
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.AllBalances, 357, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.AllBalances, 357, false)
|
||||
}
|
||||
|
||||
func TestGRPCQuerySpendableBalances(t *testing.T) {
|
||||
@ -212,7 +212,7 @@ func TestGRPCQuerySpendableBalances(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
req := banktypes.NewQuerySpendableBalancesRequest(addr, testdata.PaginationGenerator(rt, uint64(len(denoms))).Draw(rt, "pagination"))
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.SpendableBalances, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.SpendableBalances, 0, true)
|
||||
})
|
||||
|
||||
coins := sdk.NewCoins(
|
||||
@ -224,7 +224,7 @@ func TestGRPCQuerySpendableBalances(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
req := banktypes.NewQuerySpendableBalancesRequest(addr1, nil)
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.SpendableBalances, 2032, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.SpendableBalances, 2032, false)
|
||||
}
|
||||
|
||||
func TestGRPCQueryTotalSupply(t *testing.T) {
|
||||
@ -256,7 +256,7 @@ func TestGRPCQueryTotalSupply(t *testing.T) {
|
||||
Pagination: testdata.PaginationGenerator(rt, uint64(len(initialSupply))).Draw(rt, "pagination"),
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.TotalSupply, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.TotalSupply, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
@ -269,7 +269,7 @@ func TestGRPCQueryTotalSupply(t *testing.T) {
|
||||
assert.NilError(t, f.bankKeeper.MintCoins(f.ctx, minttypes.ModuleName, coins))
|
||||
|
||||
req := &banktypes.QueryTotalSupplyRequest{}
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.TotalSupply, 150, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.TotalSupply, 150, false)
|
||||
}
|
||||
|
||||
func TestGRPCQueryTotalSupplyOf(t *testing.T) {
|
||||
@ -285,14 +285,14 @@ func TestGRPCQueryTotalSupplyOf(t *testing.T) {
|
||||
assert.NilError(t, f.bankKeeper.MintCoins(f.ctx, minttypes.ModuleName, sdk.NewCoins(coin)))
|
||||
|
||||
req := &banktypes.QuerySupplyOfRequest{Denom: coin.GetDenom()}
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.SupplyOf, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.SupplyOf, 0, true)
|
||||
})
|
||||
|
||||
coin := sdk.NewCoin("bar", math.NewInt(100))
|
||||
|
||||
assert.NilError(t, f.bankKeeper.MintCoins(f.ctx, minttypes.ModuleName, sdk.NewCoins(coin)))
|
||||
req := &banktypes.QuerySupplyOfRequest{Denom: coin.GetDenom()}
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.SupplyOf, 1021, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.SupplyOf, 1021, false)
|
||||
}
|
||||
|
||||
func TestGRPCQueryParams(t *testing.T) {
|
||||
@ -314,7 +314,7 @@ func TestGRPCQueryParams(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
req := &banktypes.QueryParamsRequest{}
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.Params, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Params, 0, true)
|
||||
})
|
||||
|
||||
enabledStatus := banktypes.SendEnabled{
|
||||
@ -330,7 +330,7 @@ func TestGRPCQueryParams(t *testing.T) {
|
||||
err := f.bankKeeper.SetParams(f.ctx, params)
|
||||
assert.NilError(t, err)
|
||||
req := &banktypes.QueryParamsRequest{}
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.Params, 1003, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Params, 1003, false)
|
||||
}
|
||||
|
||||
func createAndReturnMetadatas(t *rapid.T, count int) []banktypes.Metadata {
|
||||
@ -385,7 +385,7 @@ func TestGRPCDenomsMetadata(t *testing.T) {
|
||||
Pagination: testdata.PaginationGenerator(rt, uint64(count)).Draw(rt, "pagination"),
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DenomsMetadata, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DenomsMetadata, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
@ -393,7 +393,7 @@ func TestGRPCDenomsMetadata(t *testing.T) {
|
||||
f.bankKeeper.SetDenomMetaData(f.ctx, metadataAtom)
|
||||
|
||||
req := &banktypes.QueryDenomsMetadataRequest{}
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DenomsMetadata, 660, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DenomsMetadata, 660, false)
|
||||
}
|
||||
|
||||
func TestGRPCDenomMetadata(t *testing.T) {
|
||||
@ -409,7 +409,7 @@ func TestGRPCDenomMetadata(t *testing.T) {
|
||||
Denom: denomMetadata[0].Base,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DenomMetadata, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DenomMetadata, 0, true)
|
||||
})
|
||||
|
||||
f.bankKeeper.SetDenomMetaData(f.ctx, metadataAtom)
|
||||
@ -418,7 +418,7 @@ func TestGRPCDenomMetadata(t *testing.T) {
|
||||
Denom: metadataAtom.Base,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DenomMetadata, 1300, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DenomMetadata, 1300, false)
|
||||
}
|
||||
|
||||
func TestGRPCSendEnabled(t *testing.T) {
|
||||
@ -448,7 +448,7 @@ func TestGRPCSendEnabled(t *testing.T) {
|
||||
// Pagination is only taken into account when `denoms` is an empty array
|
||||
Pagination: testdata.PaginationGenerator(rt, uint64(len(allDenoms))).Draw(rt, "pagination"),
|
||||
}
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.SendEnabled, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.SendEnabled, 0, true)
|
||||
})
|
||||
|
||||
coin1 := banktypes.SendEnabled{
|
||||
@ -467,7 +467,7 @@ func TestGRPCSendEnabled(t *testing.T) {
|
||||
Denoms: []string{coin1.GetDenom(), coin2.GetDenom()},
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.SendEnabled, 4063, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.SendEnabled, 4063, false)
|
||||
}
|
||||
|
||||
func TestGRPCDenomOwners(t *testing.T) {
|
||||
@ -493,7 +493,7 @@ func TestGRPCDenomOwners(t *testing.T) {
|
||||
Denom: denom,
|
||||
Pagination: testdata.PaginationGenerator(rt, uint64(numAddr)).Draw(rt, "pagination"),
|
||||
}
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DenomOwners, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DenomOwners, 0, true)
|
||||
})
|
||||
|
||||
denomOwners := []*banktypes.DenomOwner{
|
||||
@ -518,5 +518,5 @@ func TestGRPCDenomOwners(t *testing.T) {
|
||||
req := &banktypes.QueryDenomOwnersRequest{
|
||||
Denom: coin1.GetDenom(),
|
||||
}
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DenomOwners, 2516, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DenomOwners, 2516, false)
|
||||
}
|
||||
|
||||
@ -348,7 +348,7 @@ func TestGRPCValidator(t *testing.T) {
|
||||
ValidatorAddr: val.OperatorAddress,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.Validator, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Validator, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
@ -357,7 +357,7 @@ func TestGRPCValidator(t *testing.T) {
|
||||
ValidatorAddr: val.OperatorAddress,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.Validator, 1915, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Validator, 1915, false)
|
||||
}
|
||||
|
||||
func TestGRPCValidators(t *testing.T) {
|
||||
@ -376,14 +376,14 @@ func TestGRPCValidators(t *testing.T) {
|
||||
Pagination: testdata.PaginationGenerator(rt, uint64(valsCount)).Draw(rt, "pagination"),
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.Validators, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Validators, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
getStaticValidator(t, f)
|
||||
getStaticValidator2(t, f)
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, &stakingtypes.QueryValidatorsRequest{}, f.queryClient.Validators, 2862, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, &stakingtypes.QueryValidatorsRequest{}, f.queryClient.Validators, 2862, false)
|
||||
}
|
||||
|
||||
func TestGRPCValidatorDelegations(t *testing.T) {
|
||||
@ -405,7 +405,7 @@ func TestGRPCValidatorDelegations(t *testing.T) {
|
||||
Pagination: testdata.PaginationGenerator(rt, uint64(numDels)).Draw(rt, "pagination"),
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.ValidatorDelegations, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.ValidatorDelegations, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
@ -422,7 +422,7 @@ func TestGRPCValidatorDelegations(t *testing.T) {
|
||||
ValidatorAddr: validator.OperatorAddress,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.ValidatorDelegations, 14637, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.ValidatorDelegations, 14637, false)
|
||||
}
|
||||
|
||||
func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
|
||||
@ -448,7 +448,7 @@ func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
|
||||
Pagination: testdata.PaginationGenerator(rt, uint64(numDels)).Draw(rt, "pagination"),
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.ValidatorUnbondingDelegations, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.ValidatorUnbondingDelegations, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
@ -470,7 +470,7 @@ func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
|
||||
ValidatorAddr: validator.OperatorAddress,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.ValidatorUnbondingDelegations, 3719, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.ValidatorUnbondingDelegations, 3719, false)
|
||||
}
|
||||
|
||||
func TestGRPCDelegation(t *testing.T) {
|
||||
@ -488,7 +488,7 @@ func TestGRPCDelegation(t *testing.T) {
|
||||
DelegatorAddr: delegator.String(),
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.Delegation, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Delegation, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
@ -502,7 +502,7 @@ func TestGRPCDelegation(t *testing.T) {
|
||||
DelegatorAddr: delegator1,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.Delegation, 4689, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Delegation, 4689, false)
|
||||
}
|
||||
|
||||
func TestGRPCUnbondingDelegation(t *testing.T) {
|
||||
@ -525,7 +525,7 @@ func TestGRPCUnbondingDelegation(t *testing.T) {
|
||||
DelegatorAddr: delegator.String(),
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.UnbondingDelegation, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.UnbondingDelegation, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
@ -542,7 +542,7 @@ func TestGRPCUnbondingDelegation(t *testing.T) {
|
||||
DelegatorAddr: delegator1,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.UnbondingDelegation, 1621, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.UnbondingDelegation, 1621, false)
|
||||
}
|
||||
|
||||
func TestGRPCDelegatorDelegations(t *testing.T) {
|
||||
@ -564,7 +564,7 @@ func TestGRPCDelegatorDelegations(t *testing.T) {
|
||||
Pagination: testdata.PaginationGenerator(rt, uint64(numVals)).Draw(rt, "pagination"),
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DelegatorDelegations, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorDelegations, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
@ -577,7 +577,7 @@ func TestGRPCDelegatorDelegations(t *testing.T) {
|
||||
DelegatorAddr: delegator1,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DelegatorDelegations, 4292, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorDelegations, 4292, false)
|
||||
}
|
||||
|
||||
func TestGRPCDelegatorValidator(t *testing.T) {
|
||||
@ -596,7 +596,7 @@ func TestGRPCDelegatorValidator(t *testing.T) {
|
||||
ValidatorAddr: validator.OperatorAddress,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DelegatorValidator, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorValidator, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
@ -611,7 +611,7 @@ func TestGRPCDelegatorValidator(t *testing.T) {
|
||||
ValidatorAddr: validator.OperatorAddress,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DelegatorValidator, 3563, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorValidator, 3563, false)
|
||||
}
|
||||
|
||||
func TestGRPCDelegatorUnbondingDelegations(t *testing.T) {
|
||||
@ -637,7 +637,7 @@ func TestGRPCDelegatorUnbondingDelegations(t *testing.T) {
|
||||
Pagination: testdata.PaginationGenerator(rt, uint64(numVals)).Draw(rt, "pagination"),
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DelegatorUnbondingDelegations, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorUnbondingDelegations, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
@ -653,7 +653,7 @@ func TestGRPCDelegatorUnbondingDelegations(t *testing.T) {
|
||||
DelegatorAddr: delegator1,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DelegatorUnbondingDelegations, 1302, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorUnbondingDelegations, 1302, false)
|
||||
}
|
||||
|
||||
func TestGRPCHistoricalInfo(t *testing.T) {
|
||||
@ -675,7 +675,7 @@ func TestGRPCHistoricalInfo(t *testing.T) {
|
||||
Height: height,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.HistoricalInfo, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.HistoricalInfo, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
@ -694,7 +694,7 @@ func TestGRPCHistoricalInfo(t *testing.T) {
|
||||
Height: height,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.HistoricalInfo, 1027, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.HistoricalInfo, 1027, false)
|
||||
}
|
||||
|
||||
func TestGRPCDelegatorValidators(t *testing.T) {
|
||||
@ -716,7 +716,7 @@ func TestGRPCDelegatorValidators(t *testing.T) {
|
||||
Pagination: testdata.PaginationGenerator(rt, uint64(numVals)).Draw(rt, "pagination"),
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DelegatorValidators, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorValidators, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
@ -727,7 +727,7 @@ func TestGRPCDelegatorValidators(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
req := &stakingtypes.QueryDelegatorValidatorsRequest{DelegatorAddr: delegator1}
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.DelegatorValidators, 3166, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.DelegatorValidators, 3166, false)
|
||||
}
|
||||
|
||||
func TestGRPCPool(t *testing.T) {
|
||||
@ -737,12 +737,12 @@ func TestGRPCPool(t *testing.T) {
|
||||
rapid.Check(t, func(rt *rapid.T) {
|
||||
createAndSetValidator(t, rt, f)
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, &stakingtypes.QueryPoolRequest{}, f.queryClient.Pool, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, &stakingtypes.QueryPoolRequest{}, f.queryClient.Pool, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
getStaticValidator(t, f)
|
||||
testdata.DeterministicIterations(f.ctx, t, &stakingtypes.QueryPoolRequest{}, f.queryClient.Pool, 6296, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, &stakingtypes.QueryPoolRequest{}, f.queryClient.Pool, 6296, false)
|
||||
}
|
||||
|
||||
func TestGRPCRedelegations(t *testing.T) {
|
||||
@ -788,7 +788,7 @@ func TestGRPCRedelegations(t *testing.T) {
|
||||
}
|
||||
|
||||
req.Pagination = testdata.PaginationGenerator(rt, uint64(numDels)).Draw(rt, "pagination")
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.Redelegations, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Redelegations, 0, true)
|
||||
})
|
||||
|
||||
f = initDeterministicFixture(t) // reset
|
||||
@ -807,7 +807,7 @@ func TestGRPCRedelegations(t *testing.T) {
|
||||
DstValidatorAddr: validator2,
|
||||
}
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, req, f.queryClient.Redelegations, 3920, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.Redelegations, 3920, false)
|
||||
}
|
||||
|
||||
func TestGRPCParams(t *testing.T) {
|
||||
@ -829,7 +829,7 @@ func TestGRPCParams(t *testing.T) {
|
||||
err := f.stakingKeeper.Params.Set(f.ctx, params)
|
||||
assert.NilError(t, err)
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, &stakingtypes.QueryParamsRequest{}, f.queryClient.Params, 0, true)
|
||||
testdata.DeterministicIterations(t, f.ctx, &stakingtypes.QueryParamsRequest{}, f.queryClient.Params, 0, true)
|
||||
})
|
||||
|
||||
params := stakingtypes.Params{
|
||||
@ -845,5 +845,5 @@ func TestGRPCParams(t *testing.T) {
|
||||
err := f.stakingKeeper.Params.Set(f.ctx, params)
|
||||
assert.NilError(t, err)
|
||||
|
||||
testdata.DeterministicIterations(f.ctx, t, &stakingtypes.QueryParamsRequest{}, f.queryClient.Params, 1162, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, &stakingtypes.QueryParamsRequest{}, f.queryClient.Params, 1162, false)
|
||||
}
|
||||
|
||||
2
testutil/testdata/animal.go
vendored
2
testutil/testdata/animal.go
vendored
@ -1,7 +1,5 @@
|
||||
package testdata
|
||||
|
||||
// nolint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
|
||||
3
testutil/testdata/grpc_query.go
vendored
3
testutil/testdata/grpc_query.go
vendored
@ -67,13 +67,14 @@ func (m *TestAnyResponse) UnpackInterfaces(unpacker types.AnyUnpacker) error {
|
||||
// `gasOverwrite` is set to true, we also check that this consumed
|
||||
// gas value is equal to the hardcoded `gasConsumed`.
|
||||
func DeterministicIterations[request, response proto.Message](
|
||||
ctx sdk.Context,
|
||||
t *testing.T,
|
||||
ctx sdk.Context,
|
||||
req request,
|
||||
grpcFn func(context.Context, request, ...grpc.CallOption) (response, error),
|
||||
gasConsumed uint64,
|
||||
gasOverwrite bool,
|
||||
) {
|
||||
t.Helper()
|
||||
before := ctx.GasMeter().GasConsumed()
|
||||
prevRes, err := grpcFn(ctx, req)
|
||||
assert.NilError(t, err)
|
||||
|
||||
7
testutil/testdata/query.pb.go
vendored
7
testutil/testdata/query.pb.go
vendored
@ -6,15 +6,16 @@ package testdata
|
||||
import (
|
||||
context "context"
|
||||
fmt "fmt"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
|
||||
types "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
grpc1 "github.com/cosmos/gogoproto/grpc"
|
||||
proto "github.com/cosmos/gogoproto/proto"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
||||
7
testutil/testdata/testdata.pb.go
vendored
7
testutil/testdata/testdata.pb.go
vendored
@ -5,12 +5,13 @@ package testdata
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
types "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
_ "github.com/cosmos/gogoproto/gogoproto"
|
||||
proto "github.com/cosmos/gogoproto/proto"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
|
||||
types "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
_ "github.com/cosmos/gogoproto/gogoproto"
|
||||
proto "github.com/cosmos/gogoproto/proto"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
||||
7
testutil/testdata/testpb/query.pulsar.go
vendored
7
testutil/testdata/testpb/query.pulsar.go
vendored
@ -3,14 +3,15 @@ package testpb
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
io "io"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
|
||||
runtime "github.com/cosmos/cosmos-proto/runtime"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoiface "google.golang.org/protobuf/runtime/protoiface"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
anypb "google.golang.org/protobuf/types/known/anypb"
|
||||
io "io"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
1
testutil/testdata/testpb/query_grpc.pb.go
vendored
1
testutil/testdata/testpb/query_grpc.pb.go
vendored
@ -8,6 +8,7 @@ package testpb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
|
||||
7
testutil/testdata/testpb/testdata.pulsar.go
vendored
7
testutil/testdata/testpb/testdata.pulsar.go
vendored
@ -3,15 +3,16 @@ package testpb
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
io "io"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
|
||||
runtime "github.com/cosmos/cosmos-proto/runtime"
|
||||
_ "github.com/cosmos/gogoproto/gogoproto"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoiface "google.golang.org/protobuf/runtime/protoiface"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
anypb "google.golang.org/protobuf/types/known/anypb"
|
||||
io "io"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
9
testutil/testdata/testpb/tx.pulsar.go
vendored
9
testutil/testdata/testpb/tx.pulsar.go
vendored
@ -2,17 +2,18 @@
|
||||
package testpb
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
io "io"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
|
||||
_ "cosmossdk.io/api/amino"
|
||||
_ "cosmossdk.io/api/cosmos/msg/v1"
|
||||
fmt "fmt"
|
||||
runtime "github.com/cosmos/cosmos-proto/runtime"
|
||||
_ "github.com/cosmos/gogoproto/gogoproto"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoiface "google.golang.org/protobuf/runtime/protoiface"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
io "io"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
1
testutil/testdata/testpb/tx_grpc.pb.go
vendored
1
testutil/testdata/testpb/tx_grpc.pb.go
vendored
@ -8,6 +8,7 @@ package testpb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
|
||||
13
testutil/testdata/testpb/unknonwnproto.pulsar.go
vendored
13
testutil/testdata/testpb/unknonwnproto.pulsar.go
vendored
@ -2,20 +2,21 @@
|
||||
package testpb
|
||||
|
||||
import (
|
||||
v1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1"
|
||||
binary "encoding/binary"
|
||||
fmt "fmt"
|
||||
io "io"
|
||||
math "math"
|
||||
reflect "reflect"
|
||||
sort "sort"
|
||||
sync "sync"
|
||||
|
||||
v1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1"
|
||||
runtime "github.com/cosmos/cosmos-proto/runtime"
|
||||
_ "github.com/cosmos/gogoproto/gogoproto"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoiface "google.golang.org/protobuf/runtime/protoiface"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
anypb "google.golang.org/protobuf/types/known/anypb"
|
||||
io "io"
|
||||
math "math"
|
||||
reflect "reflect"
|
||||
sort "sort"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
12
testutil/testdata/tx.go
vendored
12
testutil/testdata/tx.go
vendored
@ -6,6 +6,7 @@ import (
|
||||
"gotest.tools/v3/assert"
|
||||
"pgregory.net/rapid"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256r1"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
@ -43,8 +44,9 @@ func KeyTestPubAddr() (cryptotypes.PrivKey, cryptotypes.PubKey, sdk.AccAddress)
|
||||
return key, pub, addr
|
||||
}
|
||||
|
||||
// KeyTestPubAddr generates a new secp256r1 keypair.
|
||||
// KeyTestPubAddrSecp256R1 generates a new secp256r1 keypair.
|
||||
func KeyTestPubAddrSecp256R1(t *testing.T) (cryptotypes.PrivKey, cryptotypes.PubKey, sdk.AccAddress) {
|
||||
t.Helper()
|
||||
key, err := secp256r1.GenPrivKey()
|
||||
assert.NilError(t, err)
|
||||
pub := key.PubKey()
|
||||
@ -52,6 +54,14 @@ func KeyTestPubAddrSecp256R1(t *testing.T) (cryptotypes.PrivKey, cryptotypes.Pub
|
||||
return key, pub, addr
|
||||
}
|
||||
|
||||
// KeyTestPubAddrED25519 generates a new ed25519 keypair.
|
||||
func KeyTestPubAddrED25519() (cryptotypes.PrivKey, cryptotypes.PubKey, sdk.AccAddress) {
|
||||
key := ed25519.GenPrivKey()
|
||||
pub := key.PubKey()
|
||||
addr := sdk.AccAddress(pub.Address())
|
||||
return key, pub, addr
|
||||
}
|
||||
|
||||
// NewTestFeeAmount is a test fee amount.
|
||||
func NewTestFeeAmount() sdk.Coins {
|
||||
return sdk.NewCoins(sdk.NewInt64Coin("atom", 150))
|
||||
|
||||
7
testutil/testdata/tx.pb.go
vendored
7
testutil/testdata/tx.pb.go
vendored
@ -6,6 +6,10 @@ package testdata
|
||||
import (
|
||||
context "context"
|
||||
fmt "fmt"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
|
||||
_ "github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
_ "github.com/cosmos/cosmos-sdk/types/tx/amino"
|
||||
_ "github.com/cosmos/gogoproto/gogoproto"
|
||||
@ -14,9 +18,6 @@ import (
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
||||
7
testutil/testdata/unknonwnproto.pb.go
vendored
7
testutil/testdata/unknonwnproto.pb.go
vendored
@ -6,13 +6,14 @@ package testdata
|
||||
import (
|
||||
encoding_binary "encoding/binary"
|
||||
fmt "fmt"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
|
||||
types "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
tx "github.com/cosmos/cosmos-sdk/types/tx"
|
||||
_ "github.com/cosmos/gogoproto/gogoproto"
|
||||
proto "github.com/cosmos/gogoproto/proto"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
||||
@ -4,8 +4,10 @@ import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
secp256k1dcrd "github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
@ -94,6 +96,9 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b
|
||||
return ctx, errorsmod.Wrapf(sdkerrors.ErrInvalidPubKey,
|
||||
"pubKey does not match signer address %s with signer index: %d", signerStrs[i], i)
|
||||
}
|
||||
if err := verifyIsOnCurve(pk); err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
acc, err := GetSignerAcc(ctx, spkd.ak, signers[i])
|
||||
if err != nil {
|
||||
@ -187,6 +192,12 @@ func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
|
||||
}
|
||||
|
||||
pubKey := signerAcc.GetPubKey()
|
||||
if !simulate && pubKey == nil {
|
||||
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set")
|
||||
}
|
||||
if err := verifyIsOnCurve(pubKey); err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
// In simulate mode the transaction comes with no signatures, thus if the
|
||||
// account's pubkey is nil, both signature verification and gasKVStore.Set()
|
||||
@ -250,6 +261,46 @@ func OnlyLegacyAminoSigners(sigData signing.SignatureData) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func verifyIsOnCurve(pubKey cryptotypes.PubKey) (err error) {
|
||||
switch typedPubKey := pubKey.(type) {
|
||||
case *secp256k1.PubKey:
|
||||
pubKeyObject, err := secp256k1dcrd.ParsePubKey(typedPubKey.Bytes())
|
||||
if err != nil {
|
||||
if errors.Is(err, secp256k1dcrd.ErrPubKeyNotOnCurve) {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "secp256k1 key is not on curve")
|
||||
}
|
||||
return err
|
||||
}
|
||||
if !pubKeyObject.IsOnCurve() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "secp256k1 key is not on curve")
|
||||
}
|
||||
|
||||
case *secp256r1.PubKey:
|
||||
pubKeyObject := typedPubKey.Key.PublicKey
|
||||
if !pubKeyObject.IsOnCurve(pubKeyObject.X, pubKeyObject.Y) {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "secp256r1 key is not on curve")
|
||||
}
|
||||
|
||||
case multisig.PubKey:
|
||||
pubKeysObjects := typedPubKey.GetPubKeys()
|
||||
ok := true
|
||||
for _, pubKeyObject := range pubKeysObjects {
|
||||
if err := verifyIsOnCurve(pubKeyObject); err != nil {
|
||||
ok = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if !ok {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "some keys are not on curve")
|
||||
}
|
||||
|
||||
default:
|
||||
return errorsmod.Wrapf(sdkerrors.ErrInvalidPubKey, "unsupported key type: %T", typedPubKey)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
||||
sigTx, ok := tx.(authsigning.Tx)
|
||||
if !ok {
|
||||
@ -285,7 +336,10 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
|
||||
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set")
|
||||
}
|
||||
|
||||
// Check account sequence number.
|
||||
if err := verifyIsOnCurve(pubKey); err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
if sig.Sequence != acc.GetSequence() {
|
||||
return ctx, errorsmod.Wrapf(
|
||||
sdkerrors.ErrWrongSequence,
|
||||
@ -376,6 +430,14 @@ func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
|
||||
panic(err)
|
||||
}
|
||||
|
||||
pubKey := acc.GetPubKey()
|
||||
if !simulate && pubKey == nil {
|
||||
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on account is not set")
|
||||
}
|
||||
if err := verifyIsOnCurve(pubKey); err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
isd.ak.SetAccount(ctx, acc)
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
secp256k1dcrd "github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@ -341,8 +342,9 @@ func TestIncrementSequenceDecorator(t *testing.T) {
|
||||
tx, err := suite.CreateTestTx(suite.ctx, privs, accNums, accSeqs, suite.ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT)
|
||||
require.NoError(t, err)
|
||||
|
||||
isd := ante.NewIncrementSequenceDecorator(suite.accountKeeper)
|
||||
antehandler := sdk.ChainAnteDecorators(isd)
|
||||
pubKeyDecorator := ante.NewSetPubKeyDecorator(suite.accountKeeper)
|
||||
IncrementSequenceDecorator := ante.NewIncrementSequenceDecorator(suite.accountKeeper)
|
||||
antehandler := sdk.ChainAnteDecorators(pubKeyDecorator, IncrementSequenceDecorator)
|
||||
|
||||
testCases := []struct {
|
||||
ctx sdk.Context
|
||||
@ -357,8 +359,113 @@ func TestIncrementSequenceDecorator(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
_, err := antehandler(tc.ctx, tx, tc.simulate)
|
||||
require.NoError(t, err, "unexpected error; tc #%d, %v", i, tc)
|
||||
require.Equal(t, tc.expectedSeq, suite.accountKeeper.GetAccount(suite.ctx, addr).GetSequence())
|
||||
t.Run(fmt.Sprintf("%d test", i), func(t *testing.T) {
|
||||
_, err = antehandler(tc.ctx, tx, tc.simulate)
|
||||
require.NoError(t, err, "unexpected error; tc #%d, %v", i, tc)
|
||||
require.Equal(t, tc.expectedSeq, suite.accountKeeper.GetAccount(suite.ctx, addr).GetSequence())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnteHandlerChecks(t *testing.T) {
|
||||
suite := SetupTestSuite(t, true)
|
||||
suite.txBankKeeper.EXPECT().DenomMetadataV2(gomock.Any(), gomock.Any()).Return(&bankv1beta1.QueryDenomMetadataResponse{}, nil).AnyTimes()
|
||||
|
||||
feeAmount := testdata.NewTestFeeAmount()
|
||||
gasLimit := testdata.NewTestGasLimit()
|
||||
enabledSignModes := []signing.SignMode{signing.SignMode_SIGN_MODE_DIRECT, signing.SignMode_SIGN_MODE_TEXTUAL, signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON}
|
||||
// Since TEXTUAL is not enabled by default, we create a custom TxConfig
|
||||
// here which includes it.
|
||||
txConfigOpts := authtx.ConfigOptions{
|
||||
TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(suite.clientCtx),
|
||||
EnabledSignModes: enabledSignModes,
|
||||
}
|
||||
|
||||
anteTxConfig, err := authtx.NewTxConfigWithOptions(
|
||||
codec.NewProtoCodec(suite.encCfg.InterfaceRegistry),
|
||||
txConfigOpts,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// make block height non-zero to ensure account numbers part of signBytes
|
||||
suite.ctx = suite.ctx.WithBlockHeight(1)
|
||||
|
||||
// keys and addresses
|
||||
priv1, _, addr1 := testdata.KeyTestPubAddr()
|
||||
|
||||
secp256k1NotOnCurve, _ := secp256k1dcrd.GeneratePrivateKey()
|
||||
secp256k1NotOnCurve.Key.SetInt(0) // Setting the key point to 0, results in an invalid point on the curve.
|
||||
priv12 := &secp256k1.PrivKey{Key: secp256k1NotOnCurve.Serialize()}
|
||||
addr12 := sdk.AccAddress(priv12.PubKey().Address())
|
||||
|
||||
priv2, _, addr2 := testdata.KeyTestPubAddrSecp256R1(t)
|
||||
priv3, _, addr3 := testdata.KeyTestPubAddrED25519()
|
||||
|
||||
addrs := []sdk.AccAddress{addr1, addr12, addr2, addr3}
|
||||
|
||||
msgs := make([]sdk.Msg, len(addrs))
|
||||
accs := make([]sdk.AccountI, len(addrs))
|
||||
// set accounts and create msg for each address
|
||||
for i, addr := range addrs {
|
||||
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr)
|
||||
require.NoError(t, acc.SetAccountNumber(uint64(i)+1000))
|
||||
suite.accountKeeper.SetAccount(suite.ctx, acc)
|
||||
msgs[i] = testdata.NewTestMsg(addr)
|
||||
accs[i] = acc
|
||||
}
|
||||
|
||||
setPubKeyDecorator := ante.NewSetPubKeyDecorator(suite.accountKeeper)
|
||||
sigGasConsumeDecorator := ante.NewSigGasConsumeDecorator(suite.accountKeeper, ante.DefaultSigVerificationGasConsumer)
|
||||
sigVerificationDecorator := ante.NewSigVerificationDecorator(suite.accountKeeper, anteTxConfig.SignModeHandler())
|
||||
IncrementSequenceDecorator := ante.NewIncrementSequenceDecorator(suite.accountKeeper)
|
||||
|
||||
anteHandler := sdk.ChainAnteDecorators(setPubKeyDecorator, sigGasConsumeDecorator, sigVerificationDecorator, IncrementSequenceDecorator)
|
||||
|
||||
type testCase struct {
|
||||
name string
|
||||
privs []cryptotypes.PrivKey
|
||||
msg sdk.Msg
|
||||
accNums []uint64
|
||||
accSeqs []uint64
|
||||
shouldErr bool
|
||||
suported bool
|
||||
}
|
||||
|
||||
// Secp256r1 keys that are not on curve will fail before even doing any operation i.e when trying to get the pubkey
|
||||
testCases := []testCase{
|
||||
{"secp256k1_onCurve", []cryptotypes.PrivKey{priv1}, msgs[0], []uint64{accs[0].GetAccountNumber()}, []uint64{0}, false, true},
|
||||
{"secp256k1_NotOnCurve", []cryptotypes.PrivKey{priv12}, msgs[1], []uint64{accs[1].GetAccountNumber()}, []uint64{1}, true, true},
|
||||
{"secp256r1_onCurve", []cryptotypes.PrivKey{priv2}, msgs[2], []uint64{accs[2].GetAccountNumber()}, []uint64{0}, false, true},
|
||||
{"ed255619", []cryptotypes.PrivKey{priv3}, msgs[3], []uint64{accs[2].GetAccountNumber()}, []uint64{3}, true, false},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
t.Run(fmt.Sprintf("%s key", tc.name), func(t *testing.T) {
|
||||
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() // Create new txBuilder for each test
|
||||
|
||||
require.NoError(t, suite.txBuilder.SetMsgs(tc.msg))
|
||||
|
||||
suite.txBuilder.SetFeeAmount(feeAmount)
|
||||
suite.txBuilder.SetGasLimit(gasLimit)
|
||||
|
||||
tx, err := suite.CreateTestTx(suite.ctx, tc.privs, tc.accNums, tc.accSeqs, suite.ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT)
|
||||
require.NoError(t, err)
|
||||
|
||||
txBytes, err := suite.clientCtx.TxConfig.TxEncoder()(tx)
|
||||
require.NoError(t, err)
|
||||
|
||||
byteCtx := suite.ctx.WithTxBytes(txBytes)
|
||||
_, err = anteHandler(byteCtx, tx, true)
|
||||
if tc.shouldErr {
|
||||
require.NotNil(t, err, "TestCase %d: %s did not error as expected", i, tc.name)
|
||||
if tc.suported {
|
||||
require.ErrorContains(t, err, "not on curve")
|
||||
} else {
|
||||
require.ErrorContains(t, err, "unsupported key type")
|
||||
}
|
||||
} else {
|
||||
require.Nil(t, err, "TestCase %d: %s errored unexpectedly. Err: %v", i, tc.name, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryAccount() {
|
||||
rapid.Check(suite.T(), func(t *rapid.T) {
|
||||
accs := suite.createAndSetAccounts(t, 1)
|
||||
req := &types.QueryAccountRequest{Address: accs[0].GetAddress().String()}
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, suite.queryClient.Account, 0, true)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.Account, 0, true)
|
||||
})
|
||||
|
||||
// Regression tests
|
||||
@ -132,7 +132,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryAccount() {
|
||||
|
||||
req := &types.QueryAccountRequest{Address: acc1.GetAddress().String()}
|
||||
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, suite.queryClient.Account, 1543, false)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.Account, 1543, false)
|
||||
}
|
||||
|
||||
// pubkeyGenerator creates and returns a random pubkey generator using rapid.
|
||||
@ -149,7 +149,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryAccounts() {
|
||||
accs := suite.createAndSetAccounts(t, numAccs)
|
||||
|
||||
req := &types.QueryAccountsRequest{Pagination: testdata.PaginationGenerator(t, uint64(numAccs)).Draw(t, "accounts")}
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, suite.queryClient.Accounts, 0, true)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.Accounts, 0, true)
|
||||
|
||||
for i := 0; i < numAccs; i++ {
|
||||
suite.accountKeeper.RemoveAccount(suite.ctx, accs[i])
|
||||
@ -174,14 +174,14 @@ func (suite *DeterministicTestSuite) TestGRPCQueryAccounts() {
|
||||
suite.accountKeeper.SetAccount(suite.ctx, acc2)
|
||||
|
||||
req := &types.QueryAccountsRequest{}
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, suite.queryClient.Accounts, 1716, false)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.Accounts, 1716, false)
|
||||
}
|
||||
|
||||
func (suite *DeterministicTestSuite) TestGRPCQueryAccountAddressByID() {
|
||||
rapid.Check(suite.T(), func(t *rapid.T) {
|
||||
accs := suite.createAndSetAccounts(t, 1)
|
||||
req := &types.QueryAccountAddressByIDRequest{AccountId: accs[0].GetAccountNumber()}
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, suite.queryClient.AccountAddressByID, 0, true)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.AccountAddressByID, 0, true)
|
||||
})
|
||||
|
||||
// Regression test
|
||||
@ -192,7 +192,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryAccountAddressByID() {
|
||||
|
||||
suite.accountKeeper.SetAccount(suite.ctx, acc1)
|
||||
req := &types.QueryAccountAddressByIDRequest{AccountId: accNum}
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, suite.queryClient.AccountAddressByID, 1123, false)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.AccountAddressByID, 1123, false)
|
||||
}
|
||||
|
||||
func (suite *DeterministicTestSuite) TestGRPCQueryParameters() {
|
||||
@ -208,7 +208,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryParameters() {
|
||||
suite.Require().NoError(err)
|
||||
|
||||
req := &types.QueryParamsRequest{}
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, suite.queryClient.Params, 0, true)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.Params, 0, true)
|
||||
})
|
||||
|
||||
// Regression test
|
||||
@ -218,7 +218,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryParameters() {
|
||||
suite.Require().NoError(err)
|
||||
|
||||
req := &types.QueryParamsRequest{}
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, suite.queryClient.Params, 1042, false)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.Params, 1042, false)
|
||||
}
|
||||
|
||||
func (suite *DeterministicTestSuite) TestGRPCQueryAccountInfo() {
|
||||
@ -227,7 +227,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryAccountInfo() {
|
||||
suite.Require().Len(accs, 1)
|
||||
|
||||
req := &types.QueryAccountInfoRequest{Address: accs[0].GetAddress().String()}
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, suite.queryClient.AccountInfo, 0, true)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.AccountInfo, 0, true)
|
||||
})
|
||||
|
||||
// Regression test
|
||||
@ -238,7 +238,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryAccountInfo() {
|
||||
|
||||
suite.accountKeeper.SetAccount(suite.ctx, acc)
|
||||
req := &types.QueryAccountInfoRequest{Address: acc.GetAddress().String()}
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, suite.queryClient.AccountInfo, 1543, false)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.AccountInfo, 1543, false)
|
||||
}
|
||||
|
||||
func (suite *DeterministicTestSuite) createAndReturnQueryClient(ak keeper.AccountKeeper) types.QueryClient {
|
||||
@ -301,7 +301,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccounts() {
|
||||
|
||||
queryClient := suite.createAndReturnQueryClient(ak)
|
||||
req := &types.QueryModuleAccountsRequest{}
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, queryClient.ModuleAccounts, 0, true)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, queryClient.ModuleAccounts, 0, true)
|
||||
})
|
||||
|
||||
maccs := make([]string, 0, len(suite.maccPerms))
|
||||
@ -313,7 +313,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccounts() {
|
||||
|
||||
queryClient := suite.createAndReturnQueryClient(suite.accountKeeper)
|
||||
req := &types.QueryModuleAccountsRequest{}
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, queryClient.ModuleAccounts, 8565, false)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, queryClient.ModuleAccounts, 8565, false)
|
||||
}
|
||||
|
||||
func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccountByName() {
|
||||
@ -348,7 +348,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccountByName() {
|
||||
|
||||
queryClient := suite.createAndReturnQueryClient(ak)
|
||||
req := &types.QueryModuleAccountByNameRequest{Name: mName}
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, queryClient.ModuleAccountByName, 0, true)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, queryClient.ModuleAccountByName, 0, true)
|
||||
})
|
||||
|
||||
maccs := make([]string, 0, len(suite.maccPerms))
|
||||
@ -360,5 +360,5 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccountByName() {
|
||||
|
||||
queryClient := suite.createAndReturnQueryClient(suite.accountKeeper)
|
||||
req := &types.QueryModuleAccountByNameRequest{Name: "mint"}
|
||||
testdata.DeterministicIterations(suite.ctx, suite.T(), req, queryClient.ModuleAccountByName, 1372, false)
|
||||
testdata.DeterministicIterations(suite.T(), suite.ctx, req, queryClient.ModuleAccountByName, 1372, false)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user