Skip to content

Commit

Permalink
Merge branch 'main' into chore/update-chain-ids
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yang authored Jan 28, 2025
2 parents 3b41f92 + bc29b88 commit 3d85f88
Show file tree
Hide file tree
Showing 166 changed files with 10,974 additions and 3,342 deletions.
936 changes: 72 additions & 864 deletions CHANGELOG.md

Large diffs are not rendered by default.

837 changes: 837 additions & 0 deletions LEGACY-CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/ante/fixed_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (suite *AnteTestSuite) TestOraclePostPriceTransactionsHaveFixedPrice() {
Amount: sdk.NewCoins(sdk.NewInt64Coin(appconst.BondDenom, 200)),
},
},
expectedGas: 38175,
expectedGas: 67193,
expectedErr: nil,
},
}
Expand Down
7 changes: 6 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ func init() {
}

// GetWasmOpts build wasm options
func GetWasmOpts(nibiru NibiruApp, appOpts servertypes.AppOptions) []wasmkeeper.Option {
func GetWasmOpts(
nibiru NibiruApp,
appOpts servertypes.AppOptions,
wasmMsgHandlerArgs wasmext.MsgHandlerArgs,
) []wasmkeeper.Option {
var wasmOpts []wasmkeeper.Option
if cast.ToBool(appOpts.Get("telemetry.enabled")) {
wasmOpts = append(wasmOpts, wasmkeeper.WithVMCacheMetrics(prometheus.DefaultRegisterer))
Expand All @@ -129,6 +133,7 @@ func GetWasmOpts(nibiru NibiruApp, appOpts servertypes.AppOptions) []wasmkeeper.
return append(wasmOpts, wasmext.NibiruWasmOptions(
nibiru.GRPCQueryRouter(),
nibiru.appCodec,
wasmMsgHandlerArgs,
)...)
}

Expand Down
48 changes: 18 additions & 30 deletions app/evmante/evmante_can_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
gethcommon "github.com/ethereum/go-ethereum/common"
gethcore "github.com/ethereum/go-ethereum/core/types"

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

// CanTransferDecorator checks if the sender is allowed to transfer funds according to the EVM block
Expand All @@ -25,7 +24,6 @@ type CanTransferDecorator struct {
func (ctd CanTransferDecorator) AnteHandle(
ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler,
) (sdk.Context, error) {
params := ctd.GetParams(ctx)
ethCfg := evm.EthereumConfig(ctd.EVMKeeper.EthChainID(ctx))
signer := gethcore.MakeSigner(ethCfg, big.NewInt(ctx.BlockHeight()))

Expand All @@ -40,7 +38,7 @@ func (ctd CanTransferDecorator) AnteHandle(

baseFeeWeiPerGas := evm.NativeToWei(ctd.EVMKeeper.BaseFeeMicronibiPerGas(ctx))

coreMsg, err := msgEthTx.AsMessage(signer, baseFeeWeiPerGas)
evmMsg, err := msgEthTx.AsMessage(signer, baseFeeWeiPerGas)
if err != nil {
return ctx, errors.Wrapf(
err,
Expand All @@ -59,37 +57,27 @@ func (ctd CanTransferDecorator) AnteHandle(
return ctx, errors.Wrapf(
sdkerrors.ErrInsufficientFee,
"gas fee cap (wei) less than block base fee (wei); (%s < %s)",
coreMsg.GasFeeCap(), baseFeeWeiPerGas,
evmMsg.GasFeeCap(), baseFeeWeiPerGas,
)
}

cfg := &statedb.EVMConfig{
ChainConfig: ethCfg,
Params: params,
// Note that we use an empty coinbase here because the field is not
// used during this Ante Handler.
BlockCoinbase: gethcommon.Address{},
BaseFeeWei: baseFeeWeiPerGas,
}

stateDB := ctd.NewStateDB(
ctx,
statedb.NewEmptyTxConfig(gethcommon.BytesToHash(ctx.HeaderHash().Bytes())),
)
evmInstance := ctd.EVMKeeper.NewEVM(ctx, coreMsg, cfg, evm.NewNoOpTracer(), stateDB)

// check that caller has enough balance to cover asset transfer for **topmost** call
// NOTE: here the gas consumed is from the context with the infinite gas meter
if coreMsg.Value().Sign() > 0 &&
!evmInstance.Context.CanTransfer(stateDB, coreMsg.From(), coreMsg.Value()) {
balanceWei := stateDB.GetBalance(coreMsg.From())
return ctx, errors.Wrapf(
sdkerrors.ErrInsufficientFunds,
"failed to transfer %s wei (balance=%s) from address %s using the EVM block context transfer function",
coreMsg.Value(),
balanceWei,
coreMsg.From(),
)

if evmMsg.Value().Sign() > 0 {
nibiruAddr := eth.EthAddrToNibiruAddr(evmMsg.From())
balanceNative := ctd.Bank.GetBalance(ctx, nibiruAddr, evm.EVMBankDenom).Amount.BigInt()
balanceWei := evm.NativeToWei(balanceNative)

if balanceWei.Cmp(evmMsg.Value()) < 0 {
return ctx, errors.Wrapf(
sdkerrors.ErrInsufficientFunds,
"failed to transfer %s wei ( balance=%s )from address %s using the EVM block context transfer function",
evmMsg.Value(),
balanceWei,
evmMsg.From(),
)
}
}
}

Expand Down
6 changes: 1 addition & 5 deletions app/evmante/evmante_can_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import (
func (s *TestSuite) TestCanTransferDecorator() {
testCases := []struct {
name string
txSetup func(deps *evmtest.TestDeps) sdk.FeeTx
ctxSetup func(deps *evmtest.TestDeps)
beforeTxSetup func(deps *evmtest.TestDeps, sdb *statedb.StateDB)
txSetup func(deps *evmtest.TestDeps) sdk.FeeTx
wantErr string
}{
{
Expand Down Expand Up @@ -92,9 +91,6 @@ func (s *TestSuite) TestCanTransferDecorator() {
anteDec := evmante.CanTransferDecorator{deps.App.AppKeepers.EvmKeeper}
tx := tc.txSetup(&deps)

if tc.ctxSetup != nil {
tc.ctxSetup(&deps)
}
if tc.beforeTxSetup != nil {
tc.beforeTxSetup(&deps, stateDB)
err := stateDB.Commit()
Expand Down
3 changes: 0 additions & 3 deletions app/evmante/evmante_setup_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,5 @@ func (esc EthSetupContextDecorator) AnteHandle(
WithKVGasConfig(storetypes.GasConfig{}).
WithTransientKVGasConfig(storetypes.GasConfig{})

// Reset transient gas used to prepare the execution of current cosmos tx.
// Transient gas-used is necessary to sum the gas-used of cosmos tx, when it contains multiple eth msgs.
esc.evmKeeper.ResetTransientGasUsed(ctx)
return next(newCtx, tx, simulate)
}
8 changes: 0 additions & 8 deletions app/evmante/evmante_setup_ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ func (s *TestSuite) TestEthSetupContextDecorator() {
s.Require().NoError(stateDB.Commit())
tx := evmtest.HappyCreateContractTx(&deps)

// Set block gas used to non 0 to check that handler resets it
deps.App.EvmKeeper.EvmState.BlockGasUsed.Set(deps.Ctx, 1000)

// Ante handler returns new context
newCtx, err := anteDec.AnteHandle(
deps.Ctx, tx, false, evmtest.NextNoOpAnteHandler,
Expand All @@ -35,9 +32,4 @@ func (s *TestSuite) TestEthSetupContextDecorator() {
defaultGasConfig := storetypes.GasConfig{}
s.Require().Equal(defaultGasConfig, newCtx.KVGasConfig())
s.Require().Equal(defaultGasConfig, newCtx.TransientKVGasConfig())

// Check that block gas used is reset to 0
gas, err := deps.App.EvmKeeper.EvmState.BlockGasUsed.Get(newCtx)
s.Require().NoError(err)
s.Require().Equal(gas, uint64(0))
}
3 changes: 1 addition & 2 deletions app/evmante/evmante_sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ func (esvd EthSigVerificationDecorator) AnteHandle(
)
}

allowUnprotectedTxs := false
ethTx := msgEthTx.AsTransaction()
if !allowUnprotectedTxs && !ethTx.Protected() {
if !ethTx.Protected() {
return ctx, errors.Wrapf(
sdkerrors.ErrNotSupported,
"rejected unprotected Ethereum transaction. "+
Expand Down
4 changes: 3 additions & 1 deletion app/evmante/evmante_validate_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
)
}

// Compute fees using effective fee to enforce 1unibi minimum gas price
effectiveFeeMicronibi := evm.WeiToNative(txData.EffectiveFeeWei(evm.BASE_FEE_WEI))
txFee = txFee.Add(
sdk.Coin{
Denom: evm.EVMBankDenom,
Amount: sdkmath.NewIntFromBigInt(txData.Fee()),
Amount: sdkmath.NewIntFromBigInt(effectiveFeeMicronibi),
},
)
}
Expand Down
28 changes: 17 additions & 11 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
Expand Down Expand Up @@ -110,6 +108,7 @@ import (
// Nibiru Custom Modules

"github.com/NibiruChain/nibiru/v2/app/keepers"
"github.com/NibiruChain/nibiru/v2/app/wasmext"
"github.com/NibiruChain/nibiru/v2/eth"
"github.com/NibiruChain/nibiru/v2/x/common"
"github.com/NibiruChain/nibiru/v2/x/devgas/v1"
Expand Down Expand Up @@ -467,25 +466,35 @@ func (app *NibiruApp) InitKeepers(
panic(err)
}

wmha := wasmext.MsgHandlerArgs{
Router: app.MsgServiceRouter(),
Ics4Wrapper: app.ibcFeeKeeper,
ChannelKeeper: app.ibcKeeper.ChannelKeeper,
CapabilityKeeper: app.ScopedWasmKeeper,
BankKeeper: app.BankKeeper,
Unpacker: appCodec,
PortSource: app.ibcTransferKeeper,
}
app.WasmMsgHandlerArgs = wmha
app.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
keys[wasmtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
distrkeeper.NewQuerier(app.DistrKeeper),
app.ibcFeeKeeper, // ISC4 Wrapper: fee IBC middleware
app.ibcKeeper.ChannelKeeper,
wmha.Ics4Wrapper, // ISC4 Wrapper: fee IBC middleware
wmha.ChannelKeeper,
&app.ibcKeeper.PortKeeper,
app.ScopedWasmKeeper,
app.ibcTransferKeeper,
app.MsgServiceRouter(),
wmha.CapabilityKeeper,
wmha.PortSource,
wmha.Router,
app.GRPCQueryRouter(),
wasmDir,
wasmConfig,
supportedFeatures,
govModuleAddr,
append(GetWasmOpts(*app, appOpts), wasmkeeper.WithWasmEngine(wasmVM))...,
append(GetWasmOpts(*app, appOpts, wmha), wasmkeeper.WithWasmEngine(wasmVM))...,
)

app.WasmClientKeeper = ibcwasmkeeper.NewKeeperWithVM(
Expand Down Expand Up @@ -633,7 +642,6 @@ func (app *NibiruApp) initAppModules(
encodingConfig.TxConfig,
),
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
capability.NewAppModule(appCodec, *app.capabilityKeeper, false),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
Expand Down Expand Up @@ -715,7 +723,6 @@ func orderedModuleNames() []string {
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,

// --------------------------------------------------------------------
// Native x/ Modules
Expand Down Expand Up @@ -831,7 +838,6 @@ func ModuleBasicManager() module.BasicManager {
evidence.AppModuleBasic{},
authzmodule.AppModuleBasic{},
groupmodule.AppModuleBasic{},
vesting.AppModuleBasic{},
// ibc 'AppModuleBasic's
ibc.AppModuleBasic{},
ibctransfer.AppModuleBasic{},
Expand Down
5 changes: 4 additions & 1 deletion app/keepers/all_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
// ---------------------------------------------------------------
// Nibiru Custom Modules

"github.com/NibiruChain/nibiru/v2/app/wasmext"
devgaskeeper "github.com/NibiruChain/nibiru/v2/x/devgas/v1/keeper"
epochskeeper "github.com/NibiruChain/nibiru/v2/x/epochs/keeper"
evmkeeper "github.com/NibiruChain/nibiru/v2/x/evm/keeper"
Expand Down Expand Up @@ -67,7 +68,9 @@ type PublicKeepers struct {
EvmKeeper *evmkeeper.Keeper

// WASM keepers
WasmKeeper wasmkeeper.Keeper
WasmKeeper wasmkeeper.Keeper
WasmMsgHandlerArgs wasmext.MsgHandlerArgs

ScopedWasmKeeper capabilitykeeper.ScopedKeeper
WasmClientKeeper ibcwasmkeeper.Keeper
}
4 changes: 2 additions & 2 deletions app/wasmext/stargate_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package wasmext_test
import (
"fmt"
"strings"
"testing"

"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -36,7 +35,8 @@ Given only the `PB_MSG.PACKAGE` and the `PB_MSG.NAME` of either the query
request or response, we should know the `QueryRequest::Stargate.path`
deterministically.
*/
func TestWasmAcceptedStargateQueries(t *testing.T) {
func (s *Suite) TestWasmAcceptedStargateQueries() {
t := s.T()
t.Log("stargateQueryPaths: Add nibiru query paths from GRPC service descriptions")
queryServiceDescriptions := []grpc.ServiceDesc{
epochs.GrpcQueryServiceDesc(),
Expand Down
Loading

0 comments on commit 3d85f88

Please sign in to comment.