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

upgrade go-ethereum #141

Merged
merged 12 commits into from
Nov 5, 2024
22 changes: 14 additions & 8 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package ante

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

Expand All @@ -24,14 +25,14 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/holiman/uint256"

ethermint "github.com/zeta-chain/ethermint/types"
"github.com/zeta-chain/ethermint/x/evm/keeper"
"github.com/zeta-chain/ethermint/x/evm/statedb"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"

"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
)

// EthAccountVerificationDecorator validates an account balance checks
Expand Down Expand Up @@ -94,7 +95,7 @@ func (avd EthAccountVerificationDecorator) AnteHandle(
"the sender is not EOA: address %s, codeHash <%s>", fromAddr, acct.CodeHash)
}

if err := keeper.CheckSenderBalance(sdkmath.NewIntFromBigInt(acct.Balance), txData); err != nil {
if err := keeper.CheckSenderBalance(sdkmath.NewIntFromBigInt(acct.Balance.ToBig()), txData); err != nil {
gartnera marked this conversation as resolved.
Show resolved Hide resolved
return ctx, errorsmod.Wrap(err, "failed to check sender balance")
}
}
Expand Down Expand Up @@ -258,7 +259,7 @@ func NewCanTransferDecorator(evmKeeper EVMKeeper) CanTransferDecorator {
func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
params := ctd.evmKeeper.GetParams(ctx)
ethCfg := params.ChainConfig.EthereumConfig(ctd.evmKeeper.ChainID())
signer := ethtypes.MakeSigner(ethCfg, big.NewInt(ctx.BlockHeight()))
signer := ethermint.MakeSigner(ethCfg, big.NewInt(ctx.BlockHeight()))

for _, msg := range tx.GetMsgs() {
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
Expand All @@ -283,11 +284,11 @@ func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
"base fee is supported but evm block context value is nil",
)
}
if coreMsg.GasFeeCap().Cmp(baseFee) < 0 {
if coreMsg.GasFeeCap.Cmp(baseFee) < 0 {
return ctx, errorsmod.Wrapf(
errortypes.ErrInsufficientFee,
"max fee per gas less than block base fee (%s < %s)",
coreMsg.GasFeeCap(), baseFee,
coreMsg.GasFeeCap, baseFee,
gartnera marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
Expand All @@ -303,14 +304,19 @@ func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
stateDB := statedb.New(ctx, ctd.evmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes())))
evm := ctd.evmKeeper.NewEVM(ctx, coreMsg, cfg, evmtypes.NewNoOpTracer(), stateDB)

valueU256, isOverflow := uint256.FromBig(coreMsg.Value)
if isOverflow {
return ctx, fmt.Errorf("%v is not a valid uint256", coreMsg.Value)
}
gartnera marked this conversation as resolved.
Show resolved Hide resolved

// 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 && !evm.Context.CanTransfer(stateDB, coreMsg.From(), coreMsg.Value()) {
if coreMsg.Value.Sign() > 0 && !evm.Context.CanTransfer(stateDB, coreMsg.From, valueU256) {
return ctx, errorsmod.Wrapf(
errortypes.ErrInsufficientFunds,
"failed to transfer %s from address %s using the EVM block context transfer function",
coreMsg.Value(),
coreMsg.From(),
coreMsg.Value,
coreMsg.From,
gartnera marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
Expand Down
17 changes: 9 additions & 8 deletions app/ante/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/big"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/holiman/uint256"

"github.com/zeta-chain/ethermint/app/ante"
"github.com/zeta-chain/ethermint/server/config"
Expand Down Expand Up @@ -68,7 +69,7 @@ func (suite AnteTestSuite) TestNewEthAccountVerificationDecorator() {
"success new account",
tx,
func() {
vmdb.AddBalance(addr, big.NewInt(1000000))
vmdb.AddBalance(addr, uint256.NewInt(1000000))
},
true,
true,
Expand All @@ -80,7 +81,7 @@ func (suite AnteTestSuite) TestNewEthAccountVerificationDecorator() {
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr.Bytes())
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

vmdb.AddBalance(addr, big.NewInt(1000000))
vmdb.AddBalance(addr, uint256.NewInt(1000000))
},
true,
true,
Expand Down Expand Up @@ -241,7 +242,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
tx2,
0,
func() {
vmdb.AddBalance(addr, big.NewInt(1000000))
vmdb.AddBalance(addr, uint256.NewInt(1000000))
},
false, true,
0,
Expand All @@ -251,7 +252,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
tx2,
0,
func() {
vmdb.AddBalance(addr, big.NewInt(1000000))
vmdb.AddBalance(addr, uint256.NewInt(1000000))
suite.ctx = suite.ctx.WithBlockGasMeter(sdk.NewGasMeter(1))
},
false, true,
Expand All @@ -262,7 +263,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
tx2,
tx2GasLimit, // it's capped
func() {
vmdb.AddBalance(addr, big.NewInt(1001000000000000))
vmdb.AddBalance(addr, uint256.NewInt(1001000000000000))
suite.ctx = suite.ctx.WithBlockGasMeter(sdk.NewGasMeter(10000000000000000000))
},
true, false,
Expand All @@ -273,7 +274,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
dynamicFeeTx,
tx2GasLimit, // it's capped
func() {
vmdb.AddBalance(addr, big.NewInt(1001000000000000))
vmdb.AddBalance(addr, uint256.NewInt(1001000000000000))
suite.ctx = suite.ctx.WithBlockGasMeter(sdk.NewGasMeter(10000000000000000000))
},
true, false,
Expand All @@ -284,7 +285,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
dynamicFeeTx,
0, // for reCheckTX mode, gas limit should be set to 0
func() {
vmdb.AddBalance(addr, big.NewInt(1001000000000000))
vmdb.AddBalance(addr, uint256.NewInt(1001000000000000))
suite.ctx = suite.ctx.WithIsReCheckTx(true)
},
true, false,
Expand Down Expand Up @@ -378,7 +379,7 @@ func (suite AnteTestSuite) TestCanTransferDecorator() {
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr.Bytes())
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

vmdb.AddBalance(addr, big.NewInt(1000000))
vmdb.AddBalance(addr, uint256.NewInt(1000000))
},
true,
},
Expand Down
2 changes: 1 addition & 1 deletion app/ante/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type EVMKeeper interface {
statedb.Keeper
DynamicFeeEVMKeeper

NewEVM(ctx sdk.Context, msg core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger, stateDB vm.StateDB) *vm.EVM
NewEVM(ctx sdk.Context, msg *core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger, stateDB vm.StateDB) *vm.EVM
DeductTxCostsFromUserBalance(ctx sdk.Context, fees sdk.Coins, from common.Address) error
GetBalance(ctx sdk.Context, addr common.Address) *big.Int
ResetTransientGasUsed(ctx sdk.Context)
Expand Down
3 changes: 2 additions & 1 deletion app/ante/sigs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ante_test
import (
"math/big"

"github.com/holiman/uint256"
"github.com/zeta-chain/ethermint/tests"
"github.com/zeta-chain/ethermint/x/evm/statedb"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
Expand All @@ -17,7 +18,7 @@ func (suite AnteTestSuite) TestSignatures() {

acc := statedb.NewEmptyAccount()
acc.Nonce = 1
acc.Balance = big.NewInt(10000000000)
acc.Balance = uint256.NewInt(10000000000)

suite.app.EvmKeeper.SetAccount(suite.ctx, addr, *acc)
msgEthereumTx := evmtypes.NewTx(suite.app.EvmKeeper.ChainID(), 1, &to, big.NewInt(10), 100000, big.NewInt(1), nil, nil, nil, nil)
Expand Down
4 changes: 2 additions & 2 deletions app/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
ethtypes "github.com/ethereum/go-ethereum/core/types"
ethermint "github.com/zeta-chain/ethermint/types"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
)

Expand All @@ -48,7 +48,7 @@ func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s
chainCfg := evmParams.GetChainConfig()
ethCfg := chainCfg.EthereumConfig(chainID)
blockNum := big.NewInt(ctx.BlockHeight())
signer := ethtypes.MakeSigner(ethCfg, blockNum)
signer := ethermint.MakeSigner(ethCfg, blockNum)

for _, msg := range tx.GetMsgs() {
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
Expand Down
3 changes: 2 additions & 1 deletion ethereum/eip712/encoding_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

apitypes "github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/zeta-chain/ethermint/types"
ethermint "github.com/zeta-chain/ethermint/types"
)

type aminoMessage struct {
Expand Down Expand Up @@ -178,7 +179,7 @@ func legacyDecodeProtobufSignDoc(signDocBytes []byte) (apitypes.TypedData, error

signerInfo := authInfo.SignerInfos[0]

chainID, err := types.ParseChainID(signDoc.ChainId)
chainID, err := ethermint.ParseChainID(signDoc.ChainId)
if err != nil {
return apitypes.TypedData{}, fmt.Errorf("invalid chain ID passed as argument: %w", err)
gartnera marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Loading
Loading