Skip to content

Commit 4bd3c9e

Browse files
authored
Reject empty and non-min-deposit-denom governance deposits (#4708)
`Keeper.AddDeposit` accepts any amount in any denomination. An empty `MsgDeposit` still writes a deposit record, and a deposit can carry denominations that never count towards the minimum deposit, so each extra denomination adds a coin that has to be burned or refunded later. Once incremental tally is enabled, `AddDeposit` now returns early for an empty amount without moving funds or writing a record, and rejects with `ErrInvalidCoins` any amount whose denominations are not all in the proposal's minimum deposit (`GetMinimumDeposit`). The check lives in `AddDeposit`, so the native deposit and submit paths and the gov precompile all go through it. Proposals can still be submitted with no initial deposit. This breaks the app hash: it changes which deposits are accepted and their tx results. It is gated on `IncrementalTallyEnabled`, like the existing voting-period check in `AddDeposit`, so it activates with the v6.8 upgrade. Covered by a keeper test for empty, foreign-denom and mixed-denom deposits; the existing gov and precompile tests pass unchanged.
1 parent 2fc6c1b commit 4bd3c9e

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎sei-cosmos/x/gov/keeper/deposit.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID uint64, depositorAdd
113113
}
114114
}
115115

116+
if keeper.IncrementalTallyEnabled(ctx) {
117+
if depositAmount.Empty() {
118+
return false, nil
119+
}
120+
minDeposit := keeper.GetDepositParams(ctx).GetMinimumDeposit(proposal.IsExpedited)
121+
if !depositAmount.DenomsSubsetOf(minDeposit) {
122+
return false, sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "deposit denoms must be in %s", minDeposit)
123+
}
124+
}
125+
116126
// update the governance module's account coins pool
117127
err := keeper.bankKeeper.SendCoinsFromAccountToModule(ctx, depositorAddr, types.ModuleName, depositAmount)
118128
if err != nil {

‎sei-cosmos/x/gov/keeper/deposit_test.go‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
seiapp "github.com/sei-protocol/sei-chain/app"
1515
sdk "github.com/sei-protocol/sei-chain/sei-cosmos/types"
16+
sdkerrors "github.com/sei-protocol/sei-chain/sei-cosmos/types/errors"
1617
bankkeeper "github.com/sei-protocol/sei-chain/sei-cosmos/x/bank/keeper"
1718
govkeeper "github.com/sei-protocol/sei-chain/sei-cosmos/x/gov/keeper"
1819
)
@@ -244,6 +245,36 @@ func TestRefundDepositsLeavesBlockedRecipientPending(t *testing.T) {
244245
require.Equal(t, depositAmount, app.BankKeeper.GetAllBalances(ctx, app.AccountKeeper.GetModuleAddress(types.ModuleName)))
245246
}
246247

248+
func TestAddDepositIgnoresEmptyAndRejectsOtherDenoms(t *testing.T) {
249+
app := seiapp.Setup(t, false, false, false)
250+
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
251+
require.True(t, app.GovKeeper.IncrementalTallyEnabled(ctx))
252+
depositor := seiapp.AddTestAddrsIncremental(app, ctx, 1, sdk.NewInt(100))[0]
253+
require.NoError(t, app.BankKeeper.AddCoins(ctx, depositor, sdk.NewCoins(sdk.NewInt64Coin("other", 100)), true))
254+
proposal, err := app.GovKeeper.SubmitProposal(ctx, TestProposal)
255+
require.NoError(t, err)
256+
257+
_, err = app.GovKeeper.AddDeposit(ctx, proposal.ProposalId, depositor, sdk.NewCoins())
258+
require.NoError(t, err)
259+
_, found := app.GovKeeper.GetDeposit(ctx, proposal.ProposalId, depositor)
260+
require.False(t, found)
261+
262+
for _, amount := range []sdk.Coins{
263+
sdk.NewCoins(sdk.NewInt64Coin("other", 1)),
264+
sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 1), sdk.NewInt64Coin("other", 1)),
265+
} {
266+
_, err = app.GovKeeper.AddDeposit(ctx, proposal.ProposalId, depositor, amount)
267+
require.ErrorIs(t, err, sdkerrors.ErrInvalidCoins)
268+
}
269+
_, found = app.GovKeeper.GetDeposit(ctx, proposal.ProposalId, depositor)
270+
require.False(t, found)
271+
272+
_, err = app.GovKeeper.AddDeposit(ctx, proposal.ProposalId, depositor, sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 1)))
273+
require.NoError(t, err)
274+
_, found = app.GovKeeper.GetDeposit(ctx, proposal.ProposalId, depositor)
275+
require.True(t, found)
276+
}
277+
247278
func TestSettleDepositsResumesWithinBudget(t *testing.T) {
248279
app := seiapp.Setup(t, false, false, false)
249280
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

0 commit comments

Comments
 (0)