Merge PR #4396: Use TxSigLimit instead of default constant value
This commit is contained in:
parent
40518cb655
commit
4f197ff904
|
@ -0,0 +1,2 @@
|
||||||
|
#4394 Fix signature count check to use the TxSigLimit param instead of
|
||||||
|
a default.
|
|
@ -86,6 +86,10 @@ func NewAnteHandler(ak AccountKeeper, fck FeeCollectionKeeper, sigGasConsumer Si
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if res := ValidateSigCount(stdTx, params); !res.IsOK() {
|
||||||
|
return newCtx, res, true
|
||||||
|
}
|
||||||
|
|
||||||
if err := tx.ValidateBasic(); err != nil {
|
if err := tx.ValidateBasic(); err != nil {
|
||||||
return newCtx, err.Result(), true
|
return newCtx, err.Result(), true
|
||||||
}
|
}
|
||||||
|
@ -154,6 +158,24 @@ func GetSignerAcc(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) (Accou
|
||||||
return nil, sdk.ErrUnknownAddress(fmt.Sprintf("account %s does not exist", addr)).Result()
|
return nil, sdk.ErrUnknownAddress(fmt.Sprintf("account %s does not exist", addr)).Result()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateSigCount validates that the transaction has a valid cumulative total
|
||||||
|
// amount of signatures.
|
||||||
|
func ValidateSigCount(stdTx StdTx, params Params) sdk.Result {
|
||||||
|
stdSigs := stdTx.GetSignatures()
|
||||||
|
|
||||||
|
sigCount := 0
|
||||||
|
for i := 0; i < len(stdSigs); i++ {
|
||||||
|
sigCount += countSubKeys(stdSigs[i].PubKey)
|
||||||
|
if uint64(sigCount) > params.TxSigLimit {
|
||||||
|
return sdk.ErrTooManySignatures(
|
||||||
|
fmt.Sprintf("signatures: %d, limit: %d", sigCount, params.TxSigLimit),
|
||||||
|
).Result()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sdk.Result{}
|
||||||
|
}
|
||||||
|
|
||||||
// ValidateMemo validates the memo size.
|
// ValidateMemo validates the memo size.
|
||||||
func ValidateMemo(stdTx StdTx, params Params) sdk.Result {
|
func ValidateMemo(stdTx StdTx, params Params) sdk.Result {
|
||||||
memoLength := len(stdTx.GetMemo())
|
memoLength := len(stdTx.GetMemo())
|
||||||
|
|
|
@ -56,16 +56,6 @@ func (tx StdTx) ValidateBasic() sdk.Error {
|
||||||
return sdk.ErrUnauthorized("wrong number of signers")
|
return sdk.ErrUnauthorized("wrong number of signers")
|
||||||
}
|
}
|
||||||
|
|
||||||
sigCount := 0
|
|
||||||
for i := 0; i < len(stdSigs); i++ {
|
|
||||||
sigCount += countSubKeys(stdSigs[i].PubKey)
|
|
||||||
if uint64(sigCount) > DefaultTxSigLimit {
|
|
||||||
return sdk.ErrTooManySignatures(
|
|
||||||
fmt.Sprintf("signatures: %d, limit: %d", sigCount, DefaultTxSigLimit),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,12 +63,6 @@ func TestTxValidateBasic(t *testing.T) {
|
||||||
// keys and addresses
|
// keys and addresses
|
||||||
priv1, _, addr1 := keyPubAddr()
|
priv1, _, addr1 := keyPubAddr()
|
||||||
priv2, _, addr2 := keyPubAddr()
|
priv2, _, addr2 := keyPubAddr()
|
||||||
priv3, _, addr3 := keyPubAddr()
|
|
||||||
priv4, _, addr4 := keyPubAddr()
|
|
||||||
priv5, _, addr5 := keyPubAddr()
|
|
||||||
priv6, _, addr6 := keyPubAddr()
|
|
||||||
priv7, _, addr7 := keyPubAddr()
|
|
||||||
priv8, _, addr8 := keyPubAddr()
|
|
||||||
|
|
||||||
// msg and signatures
|
// msg and signatures
|
||||||
msg1 := newTestMsg(addr1, addr2)
|
msg1 := newTestMsg(addr1, addr2)
|
||||||
|
@ -101,17 +95,6 @@ func TestTxValidateBasic(t *testing.T) {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Equal(t, sdk.CodeUnauthorized, err.Result().Code)
|
require.Equal(t, sdk.CodeUnauthorized, err.Result().Code)
|
||||||
|
|
||||||
// require to fail validation when there are too many signatures
|
|
||||||
privs = []crypto.PrivKey{priv1, priv2, priv3, priv4, priv5, priv6, priv7, priv8}
|
|
||||||
accNums, seqs = []uint64{0, 0, 0, 0, 0, 0, 0, 0}, []uint64{0, 0, 0, 0, 0, 0, 0, 0}
|
|
||||||
badMsg := newTestMsg(addr1, addr2, addr3, addr4, addr5, addr6, addr7, addr8)
|
|
||||||
badMsgs := []sdk.Msg{badMsg}
|
|
||||||
tx = newTestTx(ctx, badMsgs, privs, accNums, seqs, fee)
|
|
||||||
|
|
||||||
err = tx.ValidateBasic()
|
|
||||||
require.Error(t, err)
|
|
||||||
require.Equal(t, sdk.CodeTooManySignatures, err.Result().Code)
|
|
||||||
|
|
||||||
// require to fail with invalid gas supplied
|
// require to fail with invalid gas supplied
|
||||||
badFee = newStdFee()
|
badFee = newStdFee()
|
||||||
badFee.Gas = 9223372036854775808
|
badFee.Gas = 9223372036854775808
|
||||||
|
|
Loading…
Reference in New Issue