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 Aug 31, 2024
2 parents a9fa05e + 9c46873 commit 5950a5b
Show file tree
Hide file tree
Showing 70 changed files with 8,339 additions and 3,564 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1997](https://github.com/NibiruChain/nibiru/pull/1997) - refactor(evm): Remove unnecessary params: "enable_call", "enable_create".
- [#2000](https://github.com/NibiruChain/nibiru/pull/2000) - refactor(evm): simplify ERC-20 keeper methods
- [#2001](https://github.com/NibiruChain/nibiru/pull/2001) - refactor(evm): simplify FunToken methods and tests
- [#2002](https://github.com/NibiruChain/nibiru/pull/2002) - feat(evm): Add the account query to the EVM command. Cover the CLI with tests.
- [#2003](https://github.com/NibiruChain/nibiru/pull/2003) - fix(evm): fix FunToken conversions between Cosmos and EVM
- [#2004](https://github.com/NibiruChain/nibiru/pull/2004) - refactor(evm)!: replace `HexAddr` with `EIP55Addr`
- [#2008](https://github.com/NibiruChain/nibiru/pull/2008) - refactor(evm): clean up precompile setups
- [#2006](https://github.com/NibiruChain/nibiru/pull/2006) - test(evm): e2e tests for eth_* endpoints
- [#2008](https://github.com/NibiruChain/nibiru/pull/2008) - refactor(evm): clean up precompile setups
- [#2013](https://github.com/NibiruChain/nibiru/pull/2013) - chore(evm): Set appropriate gas value for the required gas of the "IFunToken.sol" precompile.
- [#2014](https://github.com/NibiruChain/nibiru/pull/2014) - feat(evm): Emit block bloom event in EndBlock hook.
- [#2017](https://github.com/NibiruChain/nibiru/pull/2017) - fix(evm): Fix DynamicFeeTx gas cap parameters
- [#2019](https://github.com/NibiruChain/nibiru/pull/2019) - chore(evm): enabled debug rpc api on localnet.
- [#2020](https://github.com/NibiruChain/nibiru/pull/2020) - test(evm): e2e tests for debug namespace

#### Dapp modules: perp, spot, oracle, etc

Expand Down
8 changes: 4 additions & 4 deletions app/evmante/evmante_can_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
gethcommon "github.com/ethereum/go-ethereum/common"
gethcore "github.com/ethereum/go-ethereum/core/types"

Expand Down Expand Up @@ -40,7 +40,7 @@ func (ctd CanTransferDecorator) AnteHandle(
msgEthTx, ok := msg.(*evm.MsgEthereumTx)
if !ok {
return ctx, errors.Wrapf(
errortypes.ErrUnknownRequest,
sdkerrors.ErrUnknownRequest,
"invalid message type %T, expected %T", msg, (*evm.MsgEthereumTx)(nil),
)
}
Expand All @@ -62,7 +62,7 @@ func (ctd CanTransferDecorator) AnteHandle(
}
if coreMsg.GasFeeCap().Cmp(baseFee) < 0 {
return ctx, errors.Wrapf(
errortypes.ErrInsufficientFee,
sdkerrors.ErrInsufficientFee,
"max fee per gas less than block base fee (%s < %s)",
coreMsg.GasFeeCap(), baseFee,
)
Expand All @@ -89,7 +89,7 @@ func (ctd CanTransferDecorator) AnteHandle(
!evmInstance.Context.CanTransfer(stateDB, coreMsg.From(), coreMsg.Value()) {
balanceWei := stateDB.GetBalance(coreMsg.From())
return ctx, errors.Wrapf(
errortypes.ErrInsufficientFunds,
sdkerrors.ErrInsufficientFunds,
"failed to transfer %s wei (balance=%s) from address %s using the EVM block context transfer function",
coreMsg.Value(),
balanceWei,
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_emit_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/NibiruChain/nibiru/v2/x/evm"
)
Expand Down Expand Up @@ -36,7 +36,7 @@ func (eeed EthEmitEventDecorator) AnteHandle(
msgEthTx, ok := msg.(*evm.MsgEthereumTx)
if !ok {
return ctx, errorsmod.Wrapf(
errortypes.ErrUnknownRequest,
sdkerrors.ErrUnknownRequest,
"invalid message type %T, expected %T",
msg, (*evm.MsgEthereumTx)(nil),
)
Expand Down
19 changes: 10 additions & 9 deletions app/evmante/evmante_gas_consume.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
gethcommon "github.com/ethereum/go-ethereum/common"

"github.com/NibiruChain/nibiru/v2/eth"
Expand Down Expand Up @@ -34,8 +34,7 @@ func NewAnteDecEthGasConsume(

// AnteHandle validates that the Ethereum tx message has enough to cover
// intrinsic gas (during CheckTx only) and that the sender has enough balance to
// pay for the gas cost. If the balance is not sufficient, it will be attempted
// to withdraw enough staking rewards for the payment.
// pay for the gas cost.
//
// Intrinsic gas for a transaction is the amount of gas that the transaction uses
// before the transaction is executed. The gas is a constant value plus any cost
Expand Down Expand Up @@ -72,13 +71,13 @@ func (anteDec AnteDecEthGasConsume) AnteHandle(

// Use the lowest priority of all the messages as the final one.
minPriority := int64(math.MaxInt64)
baseFee := anteDec.evmKeeper.GetBaseFee(ctx)
baseFeeMicronibiPerGas := anteDec.evmKeeper.GetBaseFee(ctx)

for _, msg := range tx.GetMsgs() {
msgEthTx, ok := msg.(*evm.MsgEthereumTx)
if !ok {
return ctx, errors.Wrapf(
errortypes.ErrUnknownRequest,
sdkerrors.ErrUnknownRequest,
"invalid message type %T, expected %T",
msg, (*evm.MsgEthereumTx)(nil),
)
Expand All @@ -101,7 +100,7 @@ func (anteDec AnteDecEthGasConsume) AnteHandle(
gasWanted += txData.GetGas()
}

fees, err := keeper.VerifyFee(txData, evmDenom, baseFee, ctx.IsCheckTx())
fees, err := keeper.VerifyFee(txData, evmDenom, baseFeeMicronibiPerGas, ctx.IsCheckTx())
if err != nil {
return ctx, errors.Wrapf(err, "failed to verify the fees")
}
Expand All @@ -117,7 +116,7 @@ func (anteDec AnteDecEthGasConsume) AnteHandle(
),
)

priority := evm.GetTxPriority(txData, baseFee)
priority := evm.GetTxPriority(txData, baseFeeMicronibiPerGas)

if priority < minPriority {
minPriority = priority
Expand All @@ -135,7 +134,7 @@ func (anteDec AnteDecEthGasConsume) AnteHandle(
// EthSetupContextDecorator, so it will never exceed the block gas limit.
if gasWanted > blockGasLimit {
return ctx, errors.Wrapf(
errortypes.ErrOutOfGas,
sdkerrors.ErrOutOfGas,
"tx gas (%d) exceeds block gas limit (%d)",
gasWanted,
blockGasLimit,
Expand All @@ -158,7 +157,9 @@ func (anteDec AnteDecEthGasConsume) AnteHandle(

// deductFee checks if the fee payer has enough funds to pay for the fees and deducts them.
// If the spendable balance is not enough, it tries to claim enough staking rewards to cover the fees.
func (anteDec AnteDecEthGasConsume) deductFee(ctx sdk.Context, fees sdk.Coins, feePayer sdk.AccAddress) error {
func (anteDec AnteDecEthGasConsume) deductFee(
ctx sdk.Context, fees sdk.Coins, feePayer sdk.AccAddress,
) error {
if fees.IsZero() {
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions app/evmante/evmante_increment_sender_seq.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package evmante
import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
gethcommon "github.com/ethereum/go-ethereum/common"

Expand Down Expand Up @@ -38,7 +38,7 @@ func (issd AnteDecEthIncrementSenderSequence) AnteHandle(
msgEthTx, ok := msg.(*evm.MsgEthereumTx)
if !ok {
return ctx, errors.Wrapf(
errortypes.ErrUnknownRequest,
sdkerrors.ErrUnknownRequest,
"invalid message type %T, expected %T", msg, (*evm.MsgEthereumTx)(nil),
)
}
Expand All @@ -52,7 +52,7 @@ func (issd AnteDecEthIncrementSenderSequence) AnteHandle(
acc := issd.accountKeeper.GetAccount(ctx, msgEthTx.GetFrom())
if acc == nil {
return ctx, errors.Wrapf(
errortypes.ErrUnknownAddress,
sdkerrors.ErrUnknownAddress,
"account %s is nil", gethcommon.BytesToAddress(msgEthTx.GetFrom().Bytes()),
)
}
Expand All @@ -62,7 +62,7 @@ func (issd AnteDecEthIncrementSenderSequence) AnteHandle(
// with same sender, they'll be accepted.
if txData.GetNonce() != nonce {
return ctx, errors.Wrapf(
errortypes.ErrInvalidSequence,
sdkerrors.ErrInvalidSequence,
"invalid nonce; got %d, expected %d", txData.GetNonce(), nonce,
)
}
Expand Down
25 changes: 16 additions & 9 deletions app/evmante/evmante_mempool_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package evmante

import (
"cosmossdk.io/errors"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/NibiruChain/nibiru/v2/x/evm"
)
Expand Down Expand Up @@ -38,32 +39,38 @@ func (d MempoolGasPriceDecorator) AnteHandle(
}

minGasPrice := ctx.MinGasPrices().AmountOf(d.evmKeeper.GetParams(ctx).EvmDenom)
baseFeeMicronibi := d.evmKeeper.GetBaseFee(ctx)
baseFeeDec := math.LegacyNewDecFromBigInt(baseFeeMicronibi)

// if MinGasPrices is not set, skip the check
if minGasPrice.IsZero() {
return next(ctx, tx, simulate)
} else if minGasPrice.LT(baseFeeDec) {
minGasPrice = baseFeeDec
}

baseFee := d.evmKeeper.GetBaseFee(ctx)

for _, msg := range tx.GetMsgs() {
ethTx, ok := msg.(*evm.MsgEthereumTx)
if !ok {
return ctx, errors.Wrapf(
errortypes.ErrUnknownRequest,
sdkerrors.ErrUnknownRequest,
"invalid message type %T, expected %T",
msg, (*evm.MsgEthereumTx)(nil),
)
}

effectiveGasPrice := ethTx.GetEffectiveGasPrice(baseFee)

if sdk.NewDecFromBigInt(effectiveGasPrice).LT(minGasPrice) {
baseFeeWei := evm.NativeToWei(baseFeeMicronibi)
effectiveGasPriceDec := math.LegacyNewDecFromBigInt(
evm.WeiToNative(ethTx.GetEffectiveGasPrice(baseFeeWei)),
)
if effectiveGasPriceDec.LT(minGasPrice) {
// if sdk.NewDecFromBigInt(effectiveGasPrice).LT(minGasPrice) {
return ctx, errors.Wrapf(
errortypes.ErrInsufficientFee,
sdkerrors.ErrInsufficientFee,
"provided gas price < minimum local gas price (%s < %s). "+
"Please increase the priority tip (for EIP-1559 txs) or the gas prices "+
"(for access list or legacy txs)",
effectiveGasPrice.String(), minGasPrice.String(),
effectiveGasPriceDec, minGasPrice,
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/evmante/evmante_setup_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
errorsmod "cosmossdk.io/errors"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
)

Expand All @@ -31,7 +31,7 @@ func (esc EthSetupContextDecorator) AnteHandle(
_, ok := tx.(authante.GasTx)
if !ok {
return ctx, errorsmod.Wrapf(
errortypes.ErrInvalidType,
sdkerrors.ErrInvalidType,
"invalid transaction type %T, expected GasTx", tx,
)
}
Expand Down
19 changes: 10 additions & 9 deletions app/evmante/evmante_sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
gethcore "github.com/ethereum/go-ethereum/core/types"

"github.com/NibiruChain/nibiru/v2/x/evm"
Expand All @@ -24,11 +24,12 @@ func NewEthSigVerificationDecorator(k EVMKeeper) EthSigVerificationDecorator {
}
}

// AnteHandle validates checks that the registered chain id is the same as the one on the message, and
// that the signer address matches the one defined on the message.
// It's not skipped for RecheckTx, because it set `From` address which is critical from other ante handler to work.
// Failure in RecheckTx will prevent tx to be included into block, especially when CheckTx succeed, in which case user
// won't see the error message.
// AnteHandle validates checks that the registered chain id is the same as the
// one on the message, and that the signer address matches the one defined on the
// message. It's not skipped for RecheckTx, because it set `From` address which
// is critical from other ante handler to work. Failure in RecheckTx will prevent
// tx to be included into block, especially when CheckTx succeed, in which case
// user won't see the error message.
func (esvd EthSigVerificationDecorator) AnteHandle(
ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler,
) (newCtx sdk.Context, err error) {
Expand All @@ -42,7 +43,7 @@ func (esvd EthSigVerificationDecorator) AnteHandle(
msgEthTx, ok := msg.(*evm.MsgEthereumTx)
if !ok {
return ctx, errors.Wrapf(
errortypes.ErrUnknownRequest,
sdkerrors.ErrUnknownRequest,
"invalid message type %T, expected %T", msg, (*evm.MsgEthereumTx)(nil),
)
}
Expand All @@ -51,7 +52,7 @@ func (esvd EthSigVerificationDecorator) AnteHandle(
ethTx := msgEthTx.AsTransaction()
if !allowUnprotectedTxs && !ethTx.Protected() {
return ctx, errors.Wrapf(
errortypes.ErrNotSupported,
sdkerrors.ErrNotSupported,
"rejected unprotected Ethereum transaction. "+
"Please EIP155 sign your transaction to protect it against replay-attacks",
)
Expand All @@ -60,7 +61,7 @@ func (esvd EthSigVerificationDecorator) AnteHandle(
sender, err := signer.Sender(ethTx)
if err != nil {
return ctx, errors.Wrapf(
errortypes.ErrorInvalidSigner,
sdkerrors.ErrorInvalidSigner,
"couldn't retrieve sender address from the ethereum transaction: %s",
err.Error(),
)
Expand Down
Loading

0 comments on commit 5950a5b

Please sign in to comment.