-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OTE-553] Timestamp nonce #1970
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a2d9900
Create accountplus module with timestamp nonce proto and genesis
jerryfan01234 42a35ef
Address PR comments
jerryfan01234 d24dc06
fix proto comment
jerryfan01234 741c8cd
Add remainder of module scaffolding
jerryfan01234 f1a8c12
fix merge conflict
jerryfan01234 3e469e6
Add unit test
jerryfan01234 03b7ed1
Add additional scaffolding
jerryfan01234 952dfdc
Merge branch 'main' into timestamp-nonce
jerryfan01234 207a4db
Skip increment sequence for timestamp nonce
jerryfan01234 a6ae93c
Address PR comments
jerryfan01234 3fdb5b8
resolve merge conflict
jerryfan01234 9e4e31b
resovle merge conflict from local branch
jerryfan01234 721f00b
Add unit tests
jerryfan01234 0742da7
Add ts nonce validation and update to ante handler
jerryfan01234 9d56920
Resolve merge conflict
jerryfan01234 2e193fb
Resolve merge conflict
jerryfan01234 23a90c2
Full implementation of ts nonce in ante handler with tests
jerryfan01234 5d057b7
Merge branch 'main' into timestamp-nonce
jerryfan01234 5625b2e
Refactor timestamp nonce ante handler and sigverify
jerryfan01234 fe97218
address pr comments
jerryfan01234 d866fa7
revision
jerryfan01234 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ante | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" | ||
accountpluskeeper "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/keeper" | ||
) | ||
|
||
// IsTimestampNonceTx returns `true` if the supplied `tx` consist of a single signature that uses a timestamp nonce | ||
// value for sequence | ||
func IsTimestampNonceTx(ctx sdk.Context, tx sdk.Tx) (bool, error) { | ||
sigTx, ok := tx.(authsigning.SigVerifiableTx) | ||
if !ok { | ||
return false, errorsmod.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type") | ||
} | ||
signatures, err := sigTx.GetSignaturesV2() | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
if len(signatures) != 1 { | ||
return false, errorsmod.Wrap(sdkerrors.ErrTxDecode, "more than one signature") | ||
} | ||
|
||
return accountpluskeeper.IsTimestampNonce(signatures[0].Sequence), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package ante_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
"github.com/cosmos/cosmos-sdk/testutil/testdata" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/tx/signing" | ||
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" | ||
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants" | ||
sdktest "github.com/dydxprotocol/v4-chain/protocol/testutil/sdk" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/accountplus/ante" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/accountplus/keeper" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIsTimestampNonceTx(t *testing.T) { | ||
tests := map[string]struct { | ||
seqs []uint64 | ||
expectedResult bool | ||
expectedErr bool | ||
}{ | ||
"Returns false for non-ts nonce": { | ||
seqs: []uint64{0}, | ||
expectedResult: false, | ||
expectedErr: false, | ||
}, | ||
"Returns true for ts nonce": { | ||
seqs: []uint64{keeper.TimestampNonceSequenceCutoff}, | ||
expectedResult: true, | ||
expectedErr: false, | ||
}, | ||
"Returns error for more than one signature": { | ||
seqs: []uint64{keeper.TimestampNonceSequenceCutoff, keeper.TimestampNonceSequenceCutoff}, | ||
expectedResult: false, | ||
expectedErr: true, | ||
}, | ||
} | ||
|
||
// Run tests. | ||
for name, tc := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
// Initialize some test setup which builds a test transaction from a slice of messages. | ||
var reg codectypes.InterfaceRegistry | ||
protoCfg := authtx.NewTxConfig(codec.NewProtoCodec(reg), authtx.DefaultSignModes) | ||
builder := protoCfg.NewTxBuilder() | ||
err := builder.SetMsgs([]sdk.Msg{constants.Msg_Send}...) | ||
require.NoError(t, err) | ||
|
||
// Create signatures | ||
var signatures []signing.SignatureV2 | ||
for _, seq := range tc.seqs { | ||
signatures = append(signatures, getSignature(seq)) | ||
} | ||
err = builder.SetSignatures(signatures...) | ||
|
||
require.NoError(t, err) | ||
tx := builder.GetTx() | ||
ctx, _, _ := sdktest.NewSdkContextWithMultistore() | ||
|
||
// Invoke the function under test. | ||
result, err := ante.IsTimestampNonceTx(ctx, tx) | ||
|
||
// Assert the results. | ||
if tc.expectedErr { | ||
require.NotNil(t, err) | ||
} | ||
require.Equal(t, tc.expectedResult, result) | ||
}) | ||
} | ||
} | ||
|
||
func getSignature(seq uint64) signing.SignatureV2 { | ||
_, pubKey, _ := testdata.KeyTestPubAddr() | ||
return signing.SignatureV2{ | ||
PubKey: pubKey, | ||
Data: &signing.SingleSignatureData{ | ||
SignMode: signing.SignMode_SIGN_MODE_DIRECT, | ||
Signature: nil, | ||
}, | ||
Sequence: seq, | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider logging the timestamp nonce check for better debugging.
The check for timestamp nonce transactions can be logged for better debugging and monitoring.