Skip to content

Commit

Permalink
Merge pull request #9051 from Agoric/9036-antefix-cosmos
Browse files Browse the repository at this point in the history
fix: eliminate fee double-charge by using configurable decorator
  • Loading branch information
mergify[bot] authored and gibson042 committed Mar 11, 2024
2 parents 32bff4b + 35e8fd4 commit 9c0255b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 103 deletions.
74 changes: 74 additions & 0 deletions a3p-integration/proposals/a:upgrade-14/ante-fees.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import test from 'ava';

import { CHAINID, GOV1ADDR, GOV2ADDR, agd } from '@agoric/synthetic-chain';

test(`ante handler sends fee only to vbank/reserve`, async t => {
const [feeCollector, vbankReserve] = await Promise.all(
// Look up addresses for fee collector and reserve accounts.
['fee_collector', 'vbank/reserve'].map(async name => {
const {
account: {
'@type': moduleAcct,
base_account: { address },
},
} = await agd.query('auth', 'module-account', name);

t.is(
moduleAcct,
'/cosmos.auth.v1beta1.ModuleAccount',
`${name} is a module account`,
);
return address;
}),
);

const getBalances = addresses =>
Promise.all(
addresses.map(async address => {
const { balances } = await agd.query('bank', 'balances', address);
return balances;
}),
);

const [feeCollectorStartBalances, vbankReserveStartBalances] =
await getBalances([feeCollector, vbankReserve]);

// Send a transaction with a known fee.
const feeAmount = 999n;
const feeDenom = 'uist';
const result = await agd.tx(
`bank send ${GOV1ADDR} ${GOV2ADDR} 1234ubld --fees=${feeAmount}${feeDenom} \
--from=${GOV1ADDR} --chain-id=${CHAINID} --keyring-backend=test --yes`,
);
t.like(result, { code: 0 });

const [feeCollectorEndBalances, vbankReserveEndBalances] = await getBalances([
feeCollector,
vbankReserve,
]);
t.deepEqual(feeCollectorEndBalances, feeCollectorStartBalances);

// The reserve balances should have increased by exactly the fee (possibly
// from zero, in which case start balances wouldn't include its denomination).
const feeDenomIndex = vbankReserveStartBalances.findIndex(
({ denom }) => denom === feeDenom,
);
const preFeeAmount =
feeDenomIndex < 0
? 0n
: BigInt(vbankReserveStartBalances[feeDenomIndex].amount);
const beforeCount =
feeDenomIndex < 0 ? vbankReserveStartBalances.length : feeDenomIndex;

const vbankReserveExpectedBalances = [
...vbankReserveStartBalances.slice(0, beforeCount),
{ amount: String(preFeeAmount + feeAmount), denom: feeDenom },
...vbankReserveStartBalances.slice(beforeCount + 1),
];

t.deepEqual(
vbankReserveEndBalances,
vbankReserveExpectedBalances,
'vbank/reserve should receive the fee',
);
});
5 changes: 1 addition & 4 deletions golang/cosmos/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(),
ante.NewExtensionOptionsDecorator(nil), // reject all extensions
// former ante.NewMempoolFeeDecorator()
// replaced as in https://github.com/provenance-io/provenance/pull/1016
ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, nil),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(opts.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper),
NewInboundDecorator(opts.SwingsetKeeper),
NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.FeeCollectorName),
ante.NewDeductFeeDecoratorWithName(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, nil, opts.FeeCollectorName),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(opts.AccountKeeper),
ante.NewValidateSigCountDecorator(opts.AccountKeeper),
Expand Down
96 changes: 0 additions & 96 deletions golang/cosmos/ante/fee.go

This file was deleted.

2 changes: 1 addition & 1 deletion golang/cosmos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ replace (
github.com/confio/ics23/go => github.com/agoric-labs/cosmos-sdk/ics23/go v0.8.0-alpha.agoric.1

// We need a fork of cosmos-sdk until all of the differences are merged.
github.com/cosmos/cosmos-sdk => github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2
github.com/cosmos/cosmos-sdk => github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2.1

// https://pkg.go.dev/vuln/GO-2023-2409
github.com/dvsekhvalnov/jose2go => github.com/dvsekhvalnov/jose2go v1.5.1-0.20231206184617-48ba0b76bc88
Expand Down
4 changes: 2 additions & 2 deletions golang/cosmos/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBA
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/agoric-labs/cometbft v0.34.30-alpha.agoric.1 h1:tqCNL72pQXdUmBzgv1md5SN2U3K/PaYQ4qZ5pFv8v6w=
github.com/agoric-labs/cometbft v0.34.30-alpha.agoric.1/go.mod h1:myvkihZD8eg9jKE3WFaugkNoL5nvEqlP7Jbjg98pCek=
github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2 h1:iHHqpYC0JzMbH4UYnQrcwVjLyHJuQphB0ogHbuLz44c=
github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2/go.mod h1:zUe5lsg/X7SeSO1nGkzOh9EGKO295szfrxIxYmeLYic=
github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2.1 h1:VZFX9Mogwt4cVTnkdt9zA6UJue4XYXdBURNhlTWw71Q=
github.com/agoric-labs/cosmos-sdk v0.46.16-alpha.agoric.2.1/go.mod h1:zUe5lsg/X7SeSO1nGkzOh9EGKO295szfrxIxYmeLYic=
github.com/agoric-labs/cosmos-sdk/ics23/go v0.8.0-alpha.agoric.1 h1:2jvHI/2d+psWAZy6FQ0vXJCHUtfU3ZbbW+pQFL04arQ=
github.com/agoric-labs/cosmos-sdk/ics23/go v0.8.0-alpha.agoric.1/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
Expand Down

0 comments on commit 9c0255b

Please sign in to comment.