-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
refactor(auth): incorporate set pub key decorator into sig verification decorator #19093
Changes from all commits
4065fb1
3eb372b
52d3c79
62c7452
7e73c97
36d3a42
7143b97
13c5cca
8a5d87c
cfcfd2b
b9b5605
836c760
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,25 +166,6 @@ func TestAnteHandlerSigErrors(t *testing.T) { | |
false, | ||
sdkerrors.ErrUnknownAddress, | ||
}, | ||
{ | ||
"save the first account, but second is still unrecognized", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test is not valid anymore after the change in behaviours, since the pubkey checking step is done separately during sig verification |
||
func(suite *AnteTestSuite) TestCaseArgs { | ||
suite.accountKeeper.SetAccount(suite.ctx, suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr0)) | ||
suite.bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) | ||
|
||
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv0, priv1, priv2}, []uint64{0, 1, 2}, []uint64{0, 0, 0} | ||
|
||
return TestCaseArgs{ | ||
accNums: accNums, | ||
accSeqs: accSeqs, | ||
msgs: msgs, | ||
privs: privs, | ||
} | ||
}, | ||
false, | ||
false, | ||
sdkerrors.ErrUnknownAddress, | ||
}, | ||
{ | ||
"save all the accounts, should pass", | ||
func(suite *AnteTestSuite) TestCaseArgs { | ||
|
@@ -1121,62 +1102,6 @@ func TestAnteHandlerSetPubKey(t *testing.T) { | |
false, | ||
sdkerrors.ErrWrongSequence, | ||
}, | ||
{ | ||
"make sure previous public key has been set after wrong signature", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test is not valid anymore because each account has it's own set pub key step |
||
func(suite *AnteTestSuite) TestCaseArgs { | ||
accs := suite.CreateTestAccounts(2) | ||
suite.bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) | ||
|
||
// Make sure public key has not been set from previous test. | ||
acc1 := suite.accountKeeper.GetAccount(suite.ctx, accs[1].acc.GetAddress()) | ||
require.Nil(t, acc1.GetPubKey()) | ||
|
||
privs, accNums, accSeqs := []cryptotypes.PrivKey{accs[1].priv}, []uint64{accs[1].acc.GetAccountNumber()}, []uint64{accs[1].acc.GetSequence()} | ||
msgs := []sdk.Msg{testdata.NewTestMsg(accs[1].acc.GetAddress())} | ||
err := suite.txBuilder.SetMsgs(msgs...) | ||
require.NoError(t, err) | ||
suite.txBuilder.SetFeeAmount(feeAmount) | ||
suite.txBuilder.SetGasLimit(gasLimit) | ||
|
||
// Manually create tx, and remove signature. | ||
tx, err := suite.CreateTestTx(suite.ctx, privs, accNums, accSeqs, suite.ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT) | ||
require.NoError(t, err) | ||
txBuilder, err := suite.clientCtx.TxConfig.WrapTxBuilder(tx) | ||
require.NoError(t, err) | ||
require.NoError(t, txBuilder.SetSignatures()) | ||
|
||
// Run anteHandler manually, expect ErrNoSignatures. | ||
_, err = suite.anteHandler(suite.ctx, txBuilder.GetTx(), false) | ||
require.Error(t, err) | ||
require.True(t, errors.Is(err, sdkerrors.ErrNoSignatures)) | ||
|
||
// Make sure public key has not been set. | ||
acc1 = suite.accountKeeper.GetAccount(suite.ctx, accs[1].acc.GetAddress()) | ||
require.Nil(t, acc1.GetPubKey()) | ||
|
||
// Set incorrect accSeq, to generate incorrect signature. | ||
privs, accNums, accSeqs = []cryptotypes.PrivKey{accs[1].priv}, []uint64{accs[1].acc.GetAccountNumber()}, []uint64{1} | ||
|
||
suite.ctx, err = suite.DeliverMsgs(t, privs, msgs, feeAmount, gasLimit, accNums, accSeqs, suite.ctx.ChainID(), false) | ||
require.Error(t, err) | ||
|
||
// Make sure public key has been set, as SetPubKeyDecorator | ||
// is called before all signature verification decorators. | ||
acc1 = suite.accountKeeper.GetAccount(suite.ctx, accs[1].acc.GetAddress()) | ||
require.Equal(t, acc1.GetPubKey(), accs[1].priv.PubKey()) | ||
suite.bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) | ||
|
||
return TestCaseArgs{ | ||
accNums: accNums, | ||
accSeqs: accSeqs, | ||
msgs: msgs, | ||
privs: privs, | ||
} | ||
}, | ||
false, | ||
false, | ||
sdkerrors.ErrWrongSequence, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
|
@@ -1206,7 +1131,7 @@ func generatePubKeysAndSignatures(n int, msg []byte, _ bool) (pubkeys []cryptoty | |
// privkey = ed25519.GenPrivKey() | ||
// } else { | ||
// privkey = secp256k1.GenPrivKey() | ||
//} | ||
// } | ||
testinginprod marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
pubkeys[i] = privkey.PubKey() | ||
signatures[i], _ = privkey.Sign(msg) | ||
|
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.
we have almost halved the execution costs since we're not redundantly getting and decoding from state, also the account is saved in state only once instead of twice