Skip to content

Commit

Permalink
Add config to disable seqno (#385)
Browse files Browse the repository at this point in the history
This reverts commit 1c5a372.

## Describe your changes and provide context

## Testing performed to validate your change
  • Loading branch information
philipsu522 authored and yzang2019 committed Feb 5, 2024
1 parent 81a029f commit 3bae5dd
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 54 deletions.
2 changes: 1 addition & 1 deletion baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
}
// check block gas is always consumed - this value may change if we update the logic for
// how gas is consumed
baseGas := uint64(58406) // baseGas is the gas consumed before tx msg
baseGas := uint64(62766) // baseGas is the gas consumed before tx msg
expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas)
if expGasConsumed > txtypes.MaxGasWanted {
// capped by gasLimit
Expand Down
1 change: 1 addition & 0 deletions proto/cosmos/auth/v1beta1/auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ message Params {
[(gogoproto.customname) = "SigVerifyCostED25519", (gogoproto.moretags) = "yaml:\"sig_verify_cost_ed25519\""];
uint64 sig_verify_cost_secp256k1 = 5
[(gogoproto.customname) = "SigVerifyCostSecp256k1", (gogoproto.moretags) = "yaml:\"sig_verify_cost_secp256k1\""];
bool disable_seqno_check = 6;
}
58 changes: 58 additions & 0 deletions x/auth/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1152,3 +1152,61 @@ func (suite *AnteTestSuite) TestAnteHandlerReCheck() {
_, err = suite.anteHandler(suite.ctx, tx, false)
suite.Require().NotNil(err, "antehandler on recheck did not fail once feePayer no longer has sufficient funds")
}

func (suite *AnteTestSuite) TestDisableSeqNo() {
suite.SetupTest(false) // setup
authParams := types.Params{
MaxMemoCharacters: types.DefaultMaxMemoCharacters,
TxSigLimit: types.DefaultTxSigLimit,
TxSizeCostPerByte: types.DefaultTxSizeCostPerByte,
SigVerifyCostED25519: types.DefaultSigVerifyCostED25519,
SigVerifyCostSecp256k1: types.DefaultSigVerifyCostSecp256k1,
DisableSeqnoCheck: true,
}
suite.app.AccountKeeper.SetParams(suite.ctx, authParams)

// Same data for every test cases
accounts := suite.CreateTestAccounts(1)
feeAmount := testdata.NewTestFeeAmount()
gasLimit := testdata.NewTestGasLimit()

// Variable data per test case
var (
accNums []uint64
msgs []sdk.Msg
privs []cryptotypes.PrivKey
accSeqs []uint64
)

testCases := []TestCase{
{
"good tx from one signer",
func() {
msg := testdata.NewTestMsg(accounts[0].acc.GetAddress())
msgs = []sdk.Msg{msg}

privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
},
false,
true,
nil,
},
{
"test sending it again succeeds (disable seqno check is true)",
func() {
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
},
false,
true,
nil,
},
}
for _, tc := range testCases {
suite.Run(fmt.Sprintf("Case %s", tc.desc), func() {
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()
tc.malleate()

suite.RunTestCase(privs, msgs, feeAmount, gasLimit, accNums, accSeqs, suite.ctx.ChainID(), tc)
})
}
}
13 changes: 8 additions & 5 deletions x/auth/ante/batch_sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,14 @@ func (v *SR25519BatchVerifier) VerifyTxs(ctx sdk.Context, txs []sdk.Tx) {

sig := sigsList[i][j]
if sig.Sequence != seqNum {
v.errors[i] = sdkerrors.Wrapf(
sdkerrors.ErrWrongSequence,
"account sequence mismatch, expected %d, got %d", acc.GetSequence(), sig.Sequence,
)
continue
params := v.ak.GetParams(ctx)
if !params.GetDisableSeqnoCheck() {
v.errors[i] = sdkerrors.Wrapf(
sdkerrors.ErrWrongSequence,
"account sequence mismatch, expected %d, got %d", acc.GetSequence(), sig.Sequence,
)
continue
}
}

switch data := sig.Data.(type) {
Expand Down
11 changes: 7 additions & 4 deletions x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,13 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul

// Check account sequence number.
if sig.Sequence != acc.GetSequence() {
return ctx, sdkerrors.Wrapf(
sdkerrors.ErrWrongSequence,
"account sequence mismatch, expected %d, got %d", acc.GetSequence(), sig.Sequence,
)
params := svd.ak.GetParams(ctx)
if !params.GetDisableSeqnoCheck() {
return ctx, sdkerrors.Wrapf(
sdkerrors.ErrWrongSequence,
"account sequence mismatch, expected %d, got %d", acc.GetSequence(), sig.Sequence,
)
}
}

// retrieve signer data
Expand Down
1 change: 1 addition & 0 deletions x/auth/legacy/v040/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func TestMigrate(t *testing.T) {
}
],
"params": {
"disable_seqno_check": false,
"max_memo_characters": "10",
"sig_verify_cost_ed25519": "40",
"sig_verify_cost_secp256k1": "50",
Expand Down
133 changes: 89 additions & 44 deletions x/auth/types/auth.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions x/auth/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
KeyTxSizeCostPerByte = []byte("TxSizeCostPerByte")
KeySigVerifyCostED25519 = []byte("SigVerifyCostED25519")
KeySigVerifyCostSecp256k1 = []byte("SigVerifyCostSecp256k1")
KeyDisableSeqnoCheck = []byte("KeyDisableSeqnoCheck")
)

var _ paramtypes.ParamSet = &Params{}
Expand Down Expand Up @@ -55,6 +56,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(KeyTxSizeCostPerByte, &p.TxSizeCostPerByte, validateTxSizeCostPerByte),
paramtypes.NewParamSetPair(KeySigVerifyCostED25519, &p.SigVerifyCostED25519, validateSigVerifyCostED25519),
paramtypes.NewParamSetPair(KeySigVerifyCostSecp256k1, &p.SigVerifyCostSecp256k1, validateSigVerifyCostSecp256k1),
paramtypes.NewParamSetPair(KeyDisableSeqnoCheck, &p.DisableSeqnoCheck, func(i interface{}) error { return nil }),
}
}

Expand Down

0 comments on commit 3bae5dd

Please sign in to comment.