Skip to content

Commit 1ebf85a

Browse files
authored
upgrade go-ethereum (#141)
* upgrade to go-ethereum 1.12 * upgrade to go-ethereum 1.13 fix CanTranfer args * Update expected tracer test output to include instrinsic gas ethereum/go-ethereum#26048 * fix go-ethereum spc * always import types as ethermint * Use Eq to compare uint256 * use uint256.NewInt(0) for clarity * minimal linter fixes * add gosec suppressions/fixes * pass shanghai parameter * more review feedback * fix test output subtracting from 0 balance should result in noop and zero result
1 parent 8db76d7 commit 1ebf85a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+875
-626
lines changed

app/ante/authz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewAuthzLimiterDecorator(disabledMsgTypes []string) AuthzLimiterDecorator {
4949

5050
func (ald AuthzLimiterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
5151
if err := ald.checkDisabledMsgs(tx.GetMsgs(), false, 0); err != nil {
52-
return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, err.Error())
52+
return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, "%v", err)
5353
}
5454
return next(ctx, tx, simulate)
5555
}

app/ante/eth.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package ante
1717

1818
import (
19+
"fmt"
1920
"math"
2021
"math/big"
2122

@@ -24,14 +25,14 @@ import (
2425

2526
sdk "github.com/cosmos/cosmos-sdk/types"
2627
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
28+
"github.com/holiman/uint256"
2729

2830
ethermint "github.com/zeta-chain/ethermint/types"
2931
"github.com/zeta-chain/ethermint/x/evm/keeper"
3032
"github.com/zeta-chain/ethermint/x/evm/statedb"
3133
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
3234

3335
"github.com/ethereum/go-ethereum/common"
34-
ethtypes "github.com/ethereum/go-ethereum/core/types"
3536
)
3637

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

97-
if err := keeper.CheckSenderBalance(sdkmath.NewIntFromBigInt(acct.Balance), txData); err != nil {
98+
if err := keeper.CheckSenderBalance(sdkmath.NewIntFromBigInt(acct.Balance.ToBig()), txData); err != nil {
9899
return ctx, errorsmod.Wrap(err, "failed to check sender balance")
99100
}
100101
}
@@ -156,6 +157,7 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
156157
blockHeight := big.NewInt(ctx.BlockHeight())
157158
homestead := ethCfg.IsHomestead(blockHeight)
158159
istanbul := ethCfg.IsIstanbul(blockHeight)
160+
shanghai := ethCfg.IsShanghai(blockHeight, 1)
159161
var events sdk.Events
160162

161163
// Use the lowest priority of all the messages as the final one.
@@ -186,7 +188,7 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
186188

187189
evmDenom := evmParams.GetEvmDenom()
188190

189-
fees, err := keeper.VerifyFee(txData, evmDenom, baseFee, homestead, istanbul, ctx.IsCheckTx())
191+
fees, err := keeper.VerifyFee(txData, evmDenom, baseFee, homestead, istanbul, shanghai, ctx.IsCheckTx())
190192
if err != nil {
191193
return ctx, errorsmod.Wrapf(err, "failed to verify the fees")
192194
}
@@ -258,7 +260,7 @@ func NewCanTransferDecorator(evmKeeper EVMKeeper) CanTransferDecorator {
258260
func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
259261
params := ctd.evmKeeper.GetParams(ctx)
260262
ethCfg := params.ChainConfig.EthereumConfig(ctd.evmKeeper.ChainID())
261-
signer := ethtypes.MakeSigner(ethCfg, big.NewInt(ctx.BlockHeight()))
263+
signer := ethermint.MakeSigner(ethCfg, big.NewInt(ctx.BlockHeight()))
262264

263265
for _, msg := range tx.GetMsgs() {
264266
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
@@ -283,11 +285,11 @@ func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
283285
"base fee is supported but evm block context value is nil",
284286
)
285287
}
286-
if coreMsg.GasFeeCap().Cmp(baseFee) < 0 {
288+
if coreMsg.GasFeeCap.Cmp(baseFee) < 0 {
287289
return ctx, errorsmod.Wrapf(
288290
errortypes.ErrInsufficientFee,
289291
"max fee per gas less than block base fee (%s < %s)",
290-
coreMsg.GasFeeCap(), baseFee,
292+
coreMsg.GasFeeCap, baseFee,
291293
)
292294
}
293295
}
@@ -303,14 +305,19 @@ func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
303305
stateDB := statedb.New(ctx, ctd.evmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes())))
304306
evm := ctd.evmKeeper.NewEVM(ctx, coreMsg, cfg, evmtypes.NewNoOpTracer(), stateDB)
305307

308+
valueU256, isOverflow := uint256.FromBig(coreMsg.Value)
309+
if isOverflow {
310+
return ctx, fmt.Errorf("%v is not a valid uint256", coreMsg.Value)
311+
}
312+
306313
// check that caller has enough balance to cover asset transfer for **topmost** call
307314
// NOTE: here the gas consumed is from the context with the infinite gas meter
308-
if coreMsg.Value().Sign() > 0 && !evm.Context.CanTransfer(stateDB, coreMsg.From(), coreMsg.Value()) {
315+
if coreMsg.Value.Sign() > 0 && !evm.Context.CanTransfer(stateDB, coreMsg.From, valueU256) {
309316
return ctx, errorsmod.Wrapf(
310317
errortypes.ErrInsufficientFunds,
311318
"failed to transfer %s from address %s using the EVM block context transfer function",
312-
coreMsg.Value(),
313-
coreMsg.From(),
319+
coreMsg.Value,
320+
coreMsg.From,
314321
)
315322
}
316323
}

app/ante/eth_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"math/big"
66

77
sdk "github.com/cosmos/cosmos-sdk/types"
8+
"github.com/holiman/uint256"
89

910
"github.com/zeta-chain/ethermint/app/ante"
1011
"github.com/zeta-chain/ethermint/server/config"
@@ -68,7 +69,7 @@ func (suite AnteTestSuite) TestNewEthAccountVerificationDecorator() {
6869
"success new account",
6970
tx,
7071
func() {
71-
vmdb.AddBalance(addr, big.NewInt(1000000))
72+
vmdb.AddBalance(addr, uint256.NewInt(1000000))
7273
},
7374
true,
7475
true,
@@ -80,7 +81,7 @@ func (suite AnteTestSuite) TestNewEthAccountVerificationDecorator() {
8081
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr.Bytes())
8182
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
8283

83-
vmdb.AddBalance(addr, big.NewInt(1000000))
84+
vmdb.AddBalance(addr, uint256.NewInt(1000000))
8485
},
8586
true,
8687
true,
@@ -241,7 +242,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
241242
tx2,
242243
0,
243244
func() {
244-
vmdb.AddBalance(addr, big.NewInt(1000000))
245+
vmdb.AddBalance(addr, uint256.NewInt(1000000))
245246
},
246247
false, true,
247248
0,
@@ -251,7 +252,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
251252
tx2,
252253
0,
253254
func() {
254-
vmdb.AddBalance(addr, big.NewInt(1000000))
255+
vmdb.AddBalance(addr, uint256.NewInt(1000000))
255256
suite.ctx = suite.ctx.WithBlockGasMeter(sdk.NewGasMeter(1))
256257
},
257258
false, true,
@@ -262,7 +263,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
262263
tx2,
263264
tx2GasLimit, // it's capped
264265
func() {
265-
vmdb.AddBalance(addr, big.NewInt(1001000000000000))
266+
vmdb.AddBalance(addr, uint256.NewInt(1001000000000000))
266267
suite.ctx = suite.ctx.WithBlockGasMeter(sdk.NewGasMeter(10000000000000000000))
267268
},
268269
true, false,
@@ -273,7 +274,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
273274
dynamicFeeTx,
274275
tx2GasLimit, // it's capped
275276
func() {
276-
vmdb.AddBalance(addr, big.NewInt(1001000000000000))
277+
vmdb.AddBalance(addr, uint256.NewInt(1001000000000000))
277278
suite.ctx = suite.ctx.WithBlockGasMeter(sdk.NewGasMeter(10000000000000000000))
278279
},
279280
true, false,
@@ -284,7 +285,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
284285
dynamicFeeTx,
285286
0, // for reCheckTX mode, gas limit should be set to 0
286287
func() {
287-
vmdb.AddBalance(addr, big.NewInt(1001000000000000))
288+
vmdb.AddBalance(addr, uint256.NewInt(1001000000000000))
288289
suite.ctx = suite.ctx.WithIsReCheckTx(true)
289290
},
290291
true, false,
@@ -378,7 +379,7 @@ func (suite AnteTestSuite) TestCanTransferDecorator() {
378379
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr.Bytes())
379380
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
380381

381-
vmdb.AddBalance(addr, big.NewInt(1000000))
382+
vmdb.AddBalance(addr, uint256.NewInt(1000000))
382383
},
383384
true,
384385
},

app/ante/fee_checker.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.FeeTx) (sdk.Coi
120120

121121
// Determine the required fees by multiplying each required minimum gas
122122
// price by the gas limit, where fee = ceil(minGasPrice * gasLimit).
123+
// #nosec G115 always in range
123124
glDec := sdk.NewDec(int64(gas))
124125

125126
for i, gp := range minGasPrices {
@@ -132,6 +133,7 @@ func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.FeeTx) (sdk.Coi
132133
}
133134
}
134135

136+
// #nosec G115 always in range
135137
priority := getTxPriority(feeCoins, int64(gas))
136138
return feeCoins, priority, nil
137139
}

app/ante/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type EVMKeeper interface {
4242
statedb.Keeper
4343
DynamicFeeEVMKeeper
4444

45-
NewEVM(ctx sdk.Context, msg core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger, stateDB vm.StateDB) *vm.EVM
45+
NewEVM(ctx sdk.Context, msg *core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger, stateDB vm.StateDB) *vm.EVM
4646
DeductTxCostsFromUserBalance(ctx sdk.Context, fees sdk.Coins, from common.Address) error
4747
GetBalance(ctx sdk.Context, addr common.Address) *big.Int
4848
ResetTransientGasUsed(ctx sdk.Context)

app/ante/setup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func (eeed EthEmitEventDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat
8585
ctx.EventManager().EmitEvent(sdk.NewEvent(
8686
evmtypes.EventTypeEthereumTx,
8787
sdk.NewAttribute(evmtypes.AttributeKeyEthereumTxHash, msgEthTx.Hash),
88+
// #nosec G115 index always positive
8889
sdk.NewAttribute(evmtypes.AttributeKeyTxIndex, strconv.FormatUint(txIndex+uint64(i), 10)),
8990
))
9091
}

app/ante/sigs_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ante_test
33
import (
44
"math/big"
55

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

1819
acc := statedb.NewEmptyAccount()
1920
acc.Nonce = 1
20-
acc.Balance = big.NewInt(10000000000)
21+
acc.Balance = uint256.NewInt(10000000000)
2122

2223
suite.app.EvmKeeper.SetAccount(suite.ctx, addr, *acc)
2324
msgEthereumTx := evmtypes.NewTx(suite.app.EvmKeeper.ChainID(), 1, &to, big.NewInt(10), 100000, big.NewInt(1), nil, nil, nil, nil)

app/ante/sigverify.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
errorsmod "cosmossdk.io/errors"
2222
sdk "github.com/cosmos/cosmos-sdk/types"
2323
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
24-
ethtypes "github.com/ethereum/go-ethereum/core/types"
24+
ethermint "github.com/zeta-chain/ethermint/types"
2525
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
2626
)
2727

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

5353
for _, msg := range tx.GetMsgs() {
5454
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)

ethereum/eip712/domain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func createEIP712Domain(chainID uint64) apitypes.TypedDataDomain {
2525
domain := apitypes.TypedDataDomain{
2626
Name: "Cosmos Web3",
2727
Version: "1.0.0",
28-
ChainId: math.NewHexOrDecimal256(int64(chainID)), // #nosec G701
28+
ChainId: math.NewHexOrDecimal256(int64(chainID)), // #nosec G701 G115
2929
VerifyingContract: "cosmos",
3030
Salt: "0",
3131
}

ethereum/eip712/eip712_legacy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ func LegacyWrapTxToTypedData(
5959
}
6060

6161
domain := apitypes.TypedDataDomain{
62-
Name: "Cosmos Web3",
63-
Version: "1.0.0",
62+
Name: "Cosmos Web3",
63+
Version: "1.0.0",
64+
// #nosec G115 chainID always positive
6465
ChainId: math.NewHexOrDecimal256(int64(chainID)),
6566
VerifyingContract: "cosmos",
6667
Salt: "0",

ethereum/eip712/encoding.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
txTypes "github.com/cosmos/cosmos-sdk/types/tx"
2626

2727
apitypes "github.com/ethereum/go-ethereum/signer/core/apitypes"
28-
"github.com/zeta-chain/ethermint/types"
28+
ethermint "github.com/zeta-chain/ethermint/types"
2929

3030
"github.com/cosmos/cosmos-sdk/codec"
3131
)
@@ -39,7 +39,7 @@ var (
3939
// The process of unmarshaling SignDoc bytes into a SignDoc object requires having a codec
4040
// populated with all relevant message types. As a result, we must call this method on app
4141
// initialization with the app's encoding config.
42-
func SetEncodingConfig(cfg types.EncodingConfig) {
42+
func SetEncodingConfig(cfg ethermint.EncodingConfig) {
4343
aminoCodec = cfg.Amino
4444
protoCodec = codec.NewProtoCodec(cfg.InterfaceRegistry)
4545
}
@@ -115,7 +115,7 @@ func decodeAminoSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
115115
return apitypes.TypedData{}, err
116116
}
117117

118-
chainID, err := types.ParseChainID(aminoDoc.ChainID)
118+
chainID, err := ethermint.ParseChainID(aminoDoc.ChainID)
119119
if err != nil {
120120
return apitypes.TypedData{}, errors.New("invalid chain ID passed as argument")
121121
}
@@ -179,7 +179,7 @@ func decodeProtobufSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
179179

180180
signerInfo := authInfo.SignerInfos[0]
181181

182-
chainID, err := types.ParseChainID(signDoc.ChainId)
182+
chainID, err := ethermint.ParseChainID(signDoc.ChainId)
183183
if err != nil {
184184
return apitypes.TypedData{}, fmt.Errorf("invalid chain ID passed as argument: %w", err)
185185
}

ethereum/eip712/encoding_legacy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
txTypes "github.com/cosmos/cosmos-sdk/types/tx"
2727

2828
apitypes "github.com/ethereum/go-ethereum/signer/core/apitypes"
29-
"github.com/zeta-chain/ethermint/types"
29+
ethermint "github.com/zeta-chain/ethermint/types"
3030
)
3131

3232
type aminoMessage struct {
@@ -108,7 +108,7 @@ func legacyDecodeAminoSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
108108
FeePayer: feePayer,
109109
}
110110

111-
chainID, err := types.ParseChainID(aminoDoc.ChainID)
111+
chainID, err := ethermint.ParseChainID(aminoDoc.ChainID)
112112
if err != nil {
113113
return apitypes.TypedData{}, errors.New("invalid chain ID passed as argument")
114114
}
@@ -178,7 +178,7 @@ func legacyDecodeProtobufSignDoc(signDocBytes []byte) (apitypes.TypedData, error
178178

179179
signerInfo := authInfo.SignerInfos[0]
180180

181-
chainID, err := types.ParseChainID(signDoc.ChainId)
181+
chainID, err := ethermint.ParseChainID(signDoc.ChainId)
182182
if err != nil {
183183
return apitypes.TypedData{}, fmt.Errorf("invalid chain ID passed as argument: %w", err)
184184
}

0 commit comments

Comments
 (0)