Skip to content

Commit 7998121

Browse files
fix: Fix denom exponent checks (cosmos#800)
* Fix denom exponent checks * Add changelog
1 parent df55652 commit 7998121

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- [\#772](https://github.com/cosmos/evm/pull/772) Avoid panic on close if evm mempool not used.
2525
- [\#774](https://github.com/cosmos/evm/pull/774) Emit proper allowance amount in erc20 event.
2626
- [\#790](https://github.com/cosmos/evm/pull/790) fix panic in historical query due to missing EvmCoinInfo.
27+
- [\#800](https://github.com/cosmos/evm/pull/800) Fix denom exponent validation in virtual fee deduct in vm module.
2728

2829
## v0.5.0
2930

x/vm/keeper/fees.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ func DeductFees(bankKeeper types.BankKeeper, vmKeeper types.VMKeeper, ctx sdk.Co
139139
continue
140140
}
141141
for _, du := range md.DenomUnits {
142-
if du.Denom == evmCoinInfo.Denom && du.Exponent != evmCoinInfo.Decimals {
142+
if du.Denom == evmCoinInfo.DisplayDenom && du.Exponent != types.EighteenDecimals.Uint32() {
143143
panic(
144144
fmt.Sprintf(
145-
"Cannot use virtual fee collection for denom, %s, which has a different exponent, %d, than the evm coin's %d",
146-
du.Denom, du.Exponent, evmCoinInfo.Decimals))
145+
"Cannot use virtual fee collection for denom %s, which has a display denom that has %d exponent",
146+
du.Denom, du.Exponent))
147147
}
148148
}
149149
}

x/vm/keeper/fees_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,26 @@ func TestDeductFees(t *testing.T) {
3030
expectedErr error
3131
}{
3232
{
33-
name: "happy path coins matching",
33+
name: "happy path coins",
3434
feeCoin: sdk.NewCoin("feecoin", sdkmath.NewInt(100)),
3535
sdkDenom: banktypes.DenomUnit{Denom: "feecoin", Exponent: 18},
36-
evmCoinInfo: vmtypes.EvmCoinInfo{Denom: "feecoin", Decimals: 18},
36+
evmCoinInfo: vmtypes.EvmCoinInfo{DisplayDenom: "feecoin"},
3737
expectedPanic: false,
3838
expectedErr: nil,
3939
},
4040
{
41-
name: "panic on decimal mismatch",
41+
name: "panic on exponent mismatch",
4242
feeCoin: sdk.NewCoin("feecoin", sdkmath.NewInt(100)),
4343
sdkDenom: banktypes.DenomUnit{Denom: "feecoin", Exponent: 6},
44-
evmCoinInfo: vmtypes.EvmCoinInfo{Denom: "feecoin", Decimals: 18},
44+
evmCoinInfo: vmtypes.EvmCoinInfo{DisplayDenom: "feecoin"},
4545
expectedPanic: true,
4646
expectedErr: nil,
4747
},
4848
{
4949
name: "error on bank call failure",
5050
feeCoin: sdk.NewCoin("feecoin", sdkmath.NewInt(100)),
5151
sdkDenom: banktypes.DenomUnit{Denom: "feecoin", Exponent: 18},
52-
evmCoinInfo: vmtypes.EvmCoinInfo{Denom: "feecoin", Decimals: 18},
52+
evmCoinInfo: vmtypes.EvmCoinInfo{DisplayDenom: "feecoin"},
5353
expectedPanic: false,
5454
expectedErr: errors.New("foo"),
5555
},

0 commit comments

Comments
 (0)