Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Internal Transaction Panic #1242

Closed
facs95 opened this issue Aug 12, 2022 · 4 comments
Closed

Internal Transaction Panic #1242

facs95 opened this issue Aug 12, 2022 · 4 comments
Labels
C:JSON-RPC JSON-RPC client help wanted Extra attention is needed

Comments

@facs95
Copy link
Contributor

facs95 commented Aug 12, 2022

Steps to reproduce:

  1. Run the following query:
curl -X POST --data '{"jsonrpc":"2.0","method":"debug_traceTransaction","params":["0x597018c25068a165ac17921623ec4b12c47038f3108544f0fa47df7f8e5ccb8d"],"id":1}' -H "Content-Type: application/json" https://cluster2.bd.evmos.org:8545

Expected behavior: Run a successful trace

Actual behavior:

{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"rpc error: code = Unknown desc = runtime error: invalid memory address or nil pointer dereference: panic"}}

Additional info: This was reproduce against Evmos mainnet network

@facs95 facs95 added Type: Bug C:JSON-RPC JSON-RPC client labels Aug 12, 2022
@fedekunze fedekunze added the help wanted Extra attention is needed label Aug 12, 2022
@danburck danburck moved this to 📋 Backlog in Ethermint Board Aug 12, 2022
@VictorTrustyDev
Copy link
Contributor

VictorTrustyDev commented Sep 10, 2022

Really weird, when I try to call contract with old block height as context, I got the same issue

It got crashed somewhere because, let's see this code of method EthCall in grpc_query.go at ethermint's x/evm/keeper/grpc_query.go, I added some lines of comment within the code

	var args types.TransactionArgs
	err := json.Unmarshal(req.Args, &args)
	if err != nil {
		return nil, status.Error(codes.InvalidArgument, err.Error())
	}

	cfg, err := k.EVMConfig(ctx)
	if err != nil {
		// I added check and it didn't reach here because there was no error
		return nil, status.Error(codes.Internal, err.Error())
	}

	nonce := k.GetNonce(ctx, args.GetFrom())
	args.Nonce = (*hexutil.Uint64)(&nonce)

	msg, err := args.ToMessage(req.GasCap, cfg.BaseFee)
	if err != nil {
		return nil, status.Error(codes.InvalidArgument, err.Error())
	}

	txConfig := statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash()))

	// I added check and it still pass this line

	res, err := k.ApplyMessageWithConfig(ctx, msg, nil, false, cfg, txConfig)
	if err != nil {
		// I added check and it didn't reach here
		return nil, status.Error(codes.Internal, err.Error())
	}

	return res, nil

As you can see, I added debug code in 3 places so it must be crashed somewhere

The method I used to check is I call method get name of contract 0x3f75ceabcdfed1aca03257dc6bdc0408e2b4b026 at height = 59501 (one block after it was created)

This was reproduced on Evmos mainnet network

@VictorTrustyDev
Copy link
Contributor

VictorTrustyDev commented Sep 10, 2022

So I already addressed where the issue comes from. Let take a look at the following stack trace and DO NOT care about the line number because I edited the ethermint lib to add something

runtime/debug.Stack()
	runtime/debug/stack.go:24 +0x65
github.com/evmos/ethermint/x/evm/keeper.Keeper.EthCall.func1()
	github.com/evmos/ethermint@v0.18.0/x/evm/keeper/grpc_query.go:??? +0x2f
panic({0x1d10ac0, 0x3977260})
	runtime/panic.go:838 +0x207
math/big.(*Int).Mul(0xc0c222c260, 0xc0c222c220, 0x0)
	math/big/int.go:168 +0x9f
github.com/cosmos/cosmos-sdk/types.Dec.Mul({0x2a78f08?}, {0xc00012e020?})
	github.com/cosmos/cosmos-sdk@v0.45.5/types/decimal.go:250 +0x3d
github.com/evmos/ethermint/x/evm/keeper.(*Keeper).ApplyMessageWithConfig(_, {{0x2a78f08, 0xc00012e020}, {0x2a86de0, 0xc0fb947900}, {{0xb, 0x0}, {0xc0c12dca50, 0xc}, 0xe86d, ...}, ...}, ...)
	github.com/evmos/ethermint@v0.18.0/x/evm/keeper/state_transition.go:??? +0xe16
github.com/evmos/ethermint/x/evm/keeper.Keeper.EthCall({{0x2a85468, 0xc000e00fe0}, {0x2a63418, 0xc00c028a70}, {0x2a63468, 0xc00c028b00}, {{0x2a85468, 0xc000e00fe0}, 0xc000564b68, {0x2a63418, ...}, ...}, ...}, ...)
	github.com/evmos/ethermint@v0.18.0/x/evm/keeper/grpc_query.go:??? +0x999

The thing lead to the nil pointer error is this one

minGasMultiplier := k.GetMinGasMultiplier(ctx)
minimumGasUsed := gasLimit.Mul(minGasMultiplier)

Click here to go to source code

That minGasMultiplier is nil

So when I changed

minGasMultiplier := k.GetMinGasMultiplier(ctx)

into

minGasMultiplier := k.GetMinGasMultiplier(ctx)
if minGasMultiplier.IsNil() {
	minGasMultiplier = sdk.NewDecWithPrec(5, 1) // 0.5
}

The code runs gracefully
@facs95

@VictorTrustyDev
Copy link
Contributor

This issue already resolved in #1354

@4rgon4ut
Copy link
Contributor

@facs95 close?

@facs95 facs95 closed this as completed Nov 24, 2022
Repository owner moved this from 📋 Backlog to ❌ Canceled in Ethermint Board Nov 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C:JSON-RPC JSON-RPC client help wanted Extra attention is needed
Projects
No open projects
Status: Canceled
Development

No branches or pull requests

5 participants