Skip to content
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

fix(bank): add additional missing bank keeper method overrides to sync with StateDB #2142

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#2119](https://github.com/NibiruChain/nibiru/pull/2119) - fix(evm): Guarantee
that gas consumed during any send operation of the "NibiruBankKeeper" depends
only on the "bankkeeper.BaseKeeper"'s gas consumption.
- [#2120](https://github.com/NibiruChain/nibiru/pull/2120) - fix: Use canonical hexadecimal strings for Eip155 address encoding
- [#2120](https://github.com/NibiruChain/nibiru/pull/2120) - fix: Use canonical hexadecimal strings for Eip155 address encoding
- [#2122](https://github.com/NibiruChain/nibiru/pull/2122) - test(evm): more bank extension tests and EVM ABCI integration tests to prevent regressions
- [#2124](https://github.com/NibiruChain/nibiru/pull/2124) - refactor(evm):
Remove unnecessary argument in the `VerifyFee` function, which returns the token
payment required based on the effective fee from the tx data. Improve
documentation.
- [#2125](https://github.com/NibiruChain/nibiru/pull/2125) - feat(evm-precompile):Emit EVM events created to reflect the ABCI events that occur outside the EVM to make sure that block explorers and indexers can find indexed ABCI event information.
- [#2125](https://github.com/NibiruChain/nibiru/pull/2125) - feat(evm-precompile):Emit EVM events created to reflect the ABCI events that occur outside the EVM to make sure that block explorers and indexers can find indexed ABCI event information.
- [#2129](https://github.com/NibiruChain/nibiru/pull/2129) - fix(evm): issue with infinite recursion in erc20 funtoken contracts
- [#2134](https://github.com/NibiruChain/nibiru/pull/2134) - fix(evm): query of NIBI should use bank state, not the StateDB
- [#2142](https://github.com/NibiruChain/nibiru/pull/2142) - fix(bank): add additional missing methods to the NibiruBankKeeper

#### Nibiru EVM | Before Audit 2 - 2024-12-06

Expand Down
69 changes: 65 additions & 4 deletions x/evm/keeper/bank_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
auth "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/NibiruChain/nibiru/v2/eth"
"github.com/NibiruChain/nibiru/v2/x/evm"
"github.com/NibiruChain/nibiru/v2/x/evm/statedb"
)

var (
_ bankkeeper.Keeper = &NibiruBankKeeper{}
_ bankkeeper.SendKeeper = &NibiruBankKeeper{}
)
var _ bankkeeper.Keeper = &NibiruBankKeeper{}

type NibiruBankKeeper struct {
bankkeeper.BaseKeeper
Expand All @@ -29,6 +27,69 @@ func (evmKeeper *Keeper) NewStateDB(
return stateDB
}

func (bk NibiruBankKeeper) InputOutputCoins(
ctx sdk.Context,
input []banktypes.Input,
output []banktypes.Output,
) error {
return bk.ForceGasInvariant(
ctx,
func(ctx sdk.Context) error {
return bk.BaseKeeper.InputOutputCoins(ctx, input, output)
},
func(ctx sdk.Context) {
for _, input := range input {
if findEtherBalanceChangeFromCoins(input.Coins) {
bk.SyncStateDBWithAccount(ctx, sdk.MustAccAddressFromBech32(input.Address))
}
}
for _, output := range output {
if findEtherBalanceChangeFromCoins(output.Coins) {
bk.SyncStateDBWithAccount(ctx, sdk.MustAccAddressFromBech32(output.Address))
}
}
},
)
}

func (bk NibiruBankKeeper) DelegateCoins(
ctx sdk.Context,
delegatorAddr sdk.AccAddress,
moduleBech32Addr sdk.AccAddress,
coins sdk.Coins,
) error {
return bk.ForceGasInvariant(
ctx,
func(ctx sdk.Context) error {
return bk.BaseKeeper.DelegateCoins(ctx, delegatorAddr, moduleBech32Addr, coins)
},
func(ctx sdk.Context) {
if findEtherBalanceChangeFromCoins(coins) {
bk.SyncStateDBWithAccount(ctx, delegatorAddr)
}
},
)
}

func (bk NibiruBankKeeper) UndelegateCoins(
ctx sdk.Context,
delegatorAddr sdk.AccAddress,
moduleBech32Addr sdk.AccAddress,
coins sdk.Coins,
) error {
return bk.ForceGasInvariant(
ctx,
func(ctx sdk.Context) error {
return bk.BaseKeeper.UndelegateCoins(ctx, delegatorAddr, moduleBech32Addr, coins)
},
func(ctx sdk.Context) {
if findEtherBalanceChangeFromCoins(coins) {
bk.SyncStateDBWithAccount(ctx, delegatorAddr)
}
},
)
}

func (bk NibiruBankKeeper) MintCoins(
ctx sdk.Context,
moduleName string,
Expand Down
Loading