Skip to content

Commit

Permalink
[OTE-553] Fix early return during timestamp nonce check bug (#1984)
Browse files Browse the repository at this point in the history
(cherry picked from commit 74288c0)
  • Loading branch information
jerryfan01234 authored and mergify[bot] committed Jul 30, 2024
1 parent 9d56ab8 commit 6a8c04e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
16 changes: 6 additions & 10 deletions protocol/app/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,19 @@ func (svd SigVerificationDecorator) AnteHandle(
// `GoodTilBlock` for replay protection.
if !skipSequenceValidation {
if accountpluskeeper.IsTimestampNonce(sig.Sequence) {
err = svd.akp.ProcessTimestampNonce(ctx, acc, sig.Sequence)

if err == nil {
telemetry.IncrCounterWithLabels(
[]string{metrics.TimestampNonce, metrics.Valid, metrics.Count},
1,
[]gometrics.Label{metrics.GetLabelForIntValue(metrics.ExecMode, int(ctx.ExecMode()))},
)
return ctx, nil
} else {
if err := svd.akp.ProcessTimestampNonce(ctx, acc, sig.Sequence); err != nil {
telemetry.IncrCounterWithLabels(
[]string{metrics.TimestampNonce, metrics.Invalid, metrics.Count},
1,
[]gometrics.Label{metrics.GetLabelForIntValue(metrics.ExecMode, int(ctx.ExecMode()))},
)
return ctx, errorsmod.Wrapf(sdkerrors.ErrWrongSequence, err.Error())
}
telemetry.IncrCounterWithLabels(
[]string{metrics.TimestampNonce, metrics.Valid, metrics.Count},
1,
[]gometrics.Label{metrics.GetLabelForIntValue(metrics.ExecMode, int(ctx.ExecMode()))},
)
} else {
if sig.Sequence != acc.GetSequence() {
labels := make([]gometrics.Label, 0)
Expand Down
16 changes: 16 additions & 0 deletions protocol/app/ante/sigverify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,22 @@ func TestSigVerification(t *testing.T) {
"",
true,
},
{
"timestamp nonce invalid sigs",
testMsgs,
[]cryptotypes.PrivKey{priv1, priv2, priv3},
[]uint64{accs[0].GetAccountNumber(), accs[1].GetAccountNumber(), accs[2].GetAccountNumber()},
[]uint64{
testante.TestBlockTime + 5000, // ts > min(tsNonces)
testante.TestBlockTime + 5000,
testante.TestBlockTime + 5000,
},
!validSigs,
false,
true,
"",
true,
},
}

for i, tc := range testCases {
Expand Down

0 comments on commit 6a8c04e

Please sign in to comment.