fix: do not allow unordered txs to have sequence values set (#24581)
Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io> Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com>
This commit is contained in:
co-authored by
Alex | Interchain Labs
Aaron Craelius
parent
a158c24b38
commit
f9f3bfb066
@@ -120,11 +120,21 @@ func (spkd SetPubKeyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate b
|
||||
return ctx, err
|
||||
}
|
||||
|
||||
isUnordered := false
|
||||
utx, ok := tx.(sdk.TxWithUnordered)
|
||||
if ok && utx.GetUnordered() {
|
||||
isUnordered = true
|
||||
}
|
||||
|
||||
var events sdk.Events
|
||||
for i, sig := range sigs {
|
||||
events = append(events, sdk.NewEvent(sdk.EventTypeTx,
|
||||
sdk.NewAttribute(sdk.AttributeKeyAccountSequence, fmt.Sprintf("%s/%d", signerStrs[i], sig.Sequence)),
|
||||
))
|
||||
// this shouldn't happen, but if we somehow got a tx with both a sequence set, and is unordered,
|
||||
// we shouldn't emit the event, as this is a false sequence, and won't actually be used.
|
||||
if !isUnordered {
|
||||
events = append(events, sdk.NewEvent(sdk.EventTypeTx,
|
||||
sdk.NewAttribute(sdk.AttributeKeyAccountSequence, fmt.Sprintf("%s/%d", signerStrs[i], sig.Sequence)),
|
||||
))
|
||||
}
|
||||
|
||||
sigBzs, err := signatureDataToBz(sig.Data)
|
||||
if err != nil {
|
||||
@@ -334,6 +344,9 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
|
||||
}
|
||||
|
||||
for i, sig := range sigs {
|
||||
if sig.Sequence > 0 && isUnordered {
|
||||
return ctx, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "sequence is not allowed for unordered transactions")
|
||||
}
|
||||
acc, err := GetSignerAcc(ctx, svd.ak, signers[i])
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
|
||||
@@ -72,6 +72,35 @@ func TestSetPubKey(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestSetPubKey_UnorderedNoEvents tests that when the tx is unordered, the sequence event is not emitted.
|
||||
func TestSetPubKey_UnorderedNoEvents(t *testing.T) {
|
||||
suite := SetupTestSuite(t, true)
|
||||
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()
|
||||
|
||||
// prepare accounts for tx
|
||||
priv1, _, addr1 := testdata.KeyTestPubAddr()
|
||||
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr1)
|
||||
require.NoError(t, acc.SetAccountNumber(uint64(1000)))
|
||||
suite.accountKeeper.SetAccount(suite.ctx, acc)
|
||||
require.NoError(t, suite.txBuilder.SetMsgs(testdata.NewTestMsg(addr1)))
|
||||
|
||||
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}
|
||||
tx, err := suite.CreateTestUnorderedTx(suite.ctx, privs, accNums, accSeqs, suite.ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT, true, time.Unix(100, 0))
|
||||
require.NoError(t, err)
|
||||
|
||||
spkd := ante.NewSetPubKeyDecorator(suite.accountKeeper)
|
||||
antehandler := sdk.ChainAnteDecorators(spkd)
|
||||
|
||||
ctx, err := antehandler(suite.ctx.WithBlockTime(time.Unix(95, 0)), tx, false)
|
||||
require.NoError(t, err)
|
||||
events := ctx.EventManager().Events()
|
||||
for _, event := range events {
|
||||
// if this event were emitted, the tx search by address/sequence would break when an unordered
|
||||
// transaction uses the same sequence number as another transaction from the same sender.
|
||||
require.NotContains(t, event.Attributes, sdk.AttributeKeyAccountSequence)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConsumeSignatureVerificationGas(t *testing.T) {
|
||||
suite := SetupTestSuite(t, true)
|
||||
params := types.DefaultParams()
|
||||
|
||||
Reference in New Issue
Block a user