Skip to content

Commit

Permalink
Merge branch 'main' into releases/v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yang committed Jan 18, 2025
2 parents acbf6d7 + 13c71a7 commit 82302cc
Show file tree
Hide file tree
Showing 122 changed files with 7,585 additions and 3,078 deletions.
936 changes: 67 additions & 869 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
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))
}
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
5 changes: 0 additions & 5 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,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 @@ -610,7 +608,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 @@ -691,7 +688,6 @@ func orderedModuleNames() []string {
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,

// --------------------------------------------------------------------
// Native x/ Modules
Expand Down Expand Up @@ -806,7 +802,6 @@ func ModuleBasicManager() module.BasicManager {
evidence.AppModuleBasic{},
authzmodule.AppModuleBasic{},
groupmodule.AppModuleBasic{},
vesting.AppModuleBasic{},
// ibc 'AppModuleBasic's
ibc.AppModuleBasic{},
ibctransfer.AppModuleBasic{},
Expand Down
4 changes: 3 additions & 1 deletion app/wasmext/wasm_cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,7 @@ func (s *TestSuite) requiredDeployedContractsLen(total int) {
}

func TestIntegrationTestSuite(t *testing.T) {
suite.Run(t, new(TestSuite))
testutil.RetrySuiteRunIfDbClosed(t, func() {
suite.Run(t, new(TestSuite))
}, 2)
}
11 changes: 9 additions & 2 deletions eth/eip55.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eth

import (
"encoding/json"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -42,7 +43,7 @@ func (h EIP55Addr) Marshal() ([]byte, error) {
// Implements the gogo proto custom type interface.
// Ref: https://github.com/cosmos/gogoproto/blob/v1.5.0/custom_types.md
func (h EIP55Addr) MarshalJSON() ([]byte, error) {
return []byte(h.String()), nil
return json.Marshal(h.String())
}

// MarshalTo serializes a EIP55Addr directly into a pre-allocated byte slice ("data").
Expand All @@ -68,7 +69,13 @@ func (h *EIP55Addr) Unmarshal(data []byte) error {
// UnmarshalJSON implements the gogo proto custom type interface.
// Ref: https://github.com/cosmos/gogoproto/blob/v1.5.0/custom_types.md
func (h *EIP55Addr) UnmarshalJSON(bz []byte) error {
addr, err := NewEIP55AddrFromStr(string(bz))
var addrStr string
if err := json.Unmarshal(bz, &addrStr); err != nil {
return fmt.Errorf(
"EIP55AddrError: UnmarhsalJSON had invalid input %s: %w", bz, err,
)
}
addr, err := NewEIP55AddrFromStr(addrStr)
if err != nil {
return err
}
Expand Down
14 changes: 8 additions & 6 deletions eth/eip55_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package eth_test

import (
"fmt"
"strconv"
"strings"
"testing"

gethcommon "github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -116,15 +118,15 @@ func (s *EIP55AddrSuite) TestProtobufEncoding() {
}{
{
input: threeValidAddrs[0],
expectedJson: "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed",
expectedJson: `"0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"`,
},
{
input: threeValidAddrs[1],
expectedJson: "0xAe967917c465db8578ca9024c205720b1a3651A9",
expectedJson: `"0xAe967917c465db8578ca9024c205720b1a3651A9"`,
},
{
input: threeValidAddrs[2],
expectedJson: "0x1111111111111111111112222222222223333323",
expectedJson: `"0x1111111111111111111112222222222223333323"`,
},
} {
s.Run(strconv.Itoa(tcIdx), func() {
Expand All @@ -140,7 +142,7 @@ func (s *EIP55AddrSuite) TestProtobufEncoding() {

bz, err := tc.input.Marshal()
s.NoError(err)
s.Equal(tc.expectedJson, string(bz),
s.Equal(strings.Trim(tc.expectedJson, `"`), string(bz),
"Marshaling to bytes gives different value than the test case specifies. test case #%d", tcIdx)

err = eip55Addr.Unmarshal(bz)
Expand Down Expand Up @@ -188,10 +190,10 @@ func (s *EIP55AddrSuite) TestStringEncoding() {

bz, err := addr.MarshalJSON()
s.NoError(err)
s.Equal(addrHex, string(bz))
s.Equal(fmt.Sprintf(`"%s"`, addrHex), string(bz))

addrb := new(eth.EIP55Addr)
err = addrb.UnmarshalJSON([]byte(addrHex))
err = addrb.UnmarshalJSON([]byte(fmt.Sprintf(`"%s"`, addrHex)))
s.NoError(err)
s.EqualValues(addrb, addr)
}
2 changes: 2 additions & 0 deletions eth/indexer/evm_tx_indexer_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package indexer_test

import (
"fmt"
"math/big"
"testing"

Expand Down Expand Up @@ -109,6 +110,7 @@ func TestEVMTxIndexer(t *testing.T) {
{Key: "gas_used", Value: `"21000"`},
{Key: "index", Value: `"0"`},
{Key: "hash", Value: `"14A84ED06282645EFBF080E0B7ED80D8D8D6A36337668A12B5F229F81CDD3F57"`},
{Key: "eth_hash", Value: fmt.Sprintf(`"%s"`, txHash.Hex())},
},
},
},
Expand Down
Loading

0 comments on commit 82302cc

Please sign in to comment.