Skip to content

Commit

Permalink
Problem: no proper error msg for unsupported opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Mar 28, 2024
1 parent 213ddbc commit e2c076a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (feemarket) [#433](https://github.com/crypto-org-chain/ethermint/pull/433) Fix sdk int conversion panic with baseFee.
* (rpc) [#434](https://github.com/crypto-org-chain/ethermint/pull/434) No need gasPrice when patch gasUsed for `eth_getTransactionReceipt`.
* (rpc) [#439](https://github.com/crypto-org-chain/ethermint/pull/439), [#441](https://github.com/crypto-org-chain/ethermint/pull/441) Align trace response for failed tx with go-ethereum.
* (rpc) [#443](https://github.com/crypto-org-chain/ethermint/pull/443) Return proper error msg for unsupported opcode.

### Features

Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/expected_constants.py

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions tests/integration_tests/hardhat/contracts/Random.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

contract Random {
function randomTokenId() public returns (uint256) {
return uint256(keccak256(abi.encodePacked(block.prevrandao)));
}
}
9 changes: 9 additions & 0 deletions tests/integration_tests/hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import "@nomiclabs/hardhat-ethers";
const config: HardhatUserConfig = {
solidity: {
compilers: [
{
version: "0.8.21",
settings: {
optimizer: {
enabled: true
},
evmVersion: "shanghai"
}
},
{
version: "0.8.10",
settings: {
Expand Down
11 changes: 11 additions & 0 deletions tests/integration_tests/test_call.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

import pytest
from hexbytes import HexBytes
from web3 import Web3
from web3._utils.contracts import encode_transaction_data
Expand Down Expand Up @@ -93,3 +94,13 @@ def test_override_state(ethermint):
},
)
assert ("",) == w3.codec.decode(("string",), result)


def test_opcode(ethermint):
contract, _ = deploy_contract(
ethermint.w3,
CONTRACTS["Random"],
)
with pytest.raises(ValueError) as e_info:
contract.caller.randomTokenId()
assert "RANDOM opcode is currently not supported" in str(e_info.value)
1 change: 1 addition & 0 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"TestMessageCall": "TestMessageCall.sol",
"Calculator": "Calculator.sol",
"Caller": "Caller.sol",
"Random": "Random.sol",
}


Expand Down
12 changes: 11 additions & 1 deletion x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (k *Keeper) ApplyMessageWithConfig(
msg core.Message,
cfg *EVMConfig,
commit bool,
) (*types.MsgEthereumTxResponse, error) {
) (res *types.MsgEthereumTxResponse, err error) {
var (
ret []byte // return bytes from evm execution
vmErr error // vm errors do not effect consensus and are therefore not assigned to err
Expand All @@ -362,6 +362,16 @@ func (k *Keeper) ApplyMessageWithConfig(
}
}
evm = k.NewEVM(ctx, msg, cfg, stateDB)
defer func() {
if e := recover(); e != nil {
if evm.Context.Random == nil {
k.Logger(ctx).Error("panic", "error", e)
err = fmt.Errorf("RANDOM opcode is currently not supported")
} else {
panic(e)

Check warning on line 371 in x/evm/keeper/state_transition.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/state_transition.go#L367-L371

Added lines #L367 - L371 were not covered by tests
}
}
}()
leftoverGas := msg.GasLimit
sender := vm.AccountRef(msg.From)
// Allow the tracer captures the tx level events, mainly the gas consumption.
Expand Down

0 comments on commit e2c076a

Please sign in to comment.