Skip to content

Commit

Permalink
Problem: can't support prevrando opcode by default (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe authored Apr 2, 2024
1 parent 2740d1f commit 028760e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 26 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ Ref: https://keepachangelog.com/en/1.0.0/

# Changelog

## Unreleased
## v0.22.x-cronos

### State Machine Breaking

* (rpc) [#449](https://github.com/crypto-org-chain/ethermint/pull/449) Remove forkEnabled callback to keep zero random as default.

## v0.21.x-cronos

### Bug Fixes

Expand All @@ -47,7 +53,6 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (rpc) [#443](https://github.com/crypto-org-chain/ethermint/pull/443) Keep behavior of random opcode as before.


## v0.21.x-cronos

### Features
Expand Down
1 change: 0 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ func NewEthermintApp(
tracer,
evmSs, nil,
allKeys,
nil,
)

// Create IBC Keeper
Expand Down
6 changes: 2 additions & 4 deletions tests/integration_tests/test_call.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json

import pytest
from hexbytes import HexBytes
from web3 import Web3
from web3._utils.contracts import encode_transaction_data
Expand Down Expand Up @@ -103,6 +102,5 @@ def test_opcode(ethermint):
ethermint.w3,
CONTRACTS["Random"],
)
with pytest.raises(ValueError) as e_info:
contract.caller.randomTokenId()
assert "invalid memory address or nil pointer dereference" in str(e_info.value)
res = contract.caller.randomTokenId()
assert res > 0, res
10 changes: 0 additions & 10 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ type Keeper struct {
// a set of store keys that should cover all the precompile use cases,
// or ideally just pass the application's all stores.
keys map[string]storetypes.StoreKey

forkEnabledFunc func(sdk.Context) bool
}

// NewKeeper generates new evm module keeper
Expand All @@ -96,7 +94,6 @@ func NewKeeper(
ss paramstypes.Subspace,
customContractFns []CustomContractFn,
keys map[string]storetypes.StoreKey,
forkEnabledFunc func(sdk.Context) bool,
) *Keeper {
// ensure evm module account is set
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
Expand All @@ -108,12 +105,6 @@ func NewKeeper(
panic(err)
}

if forkEnabledFunc == nil {
forkEnabledFunc = func(sdk.Context) bool {
return false
}
}

// NOTE: we pass in the parameter space to the CommitStateDB in order to use custom denominations for the EVM operations
return &Keeper{
cdc: cdc,
Expand All @@ -128,7 +119,6 @@ func NewKeeper(
ss: ss,
customContractFns: customContractFns,
keys: keys,
forkEnabledFunc: forkEnabledFunc,
}
}

Expand Down
11 changes: 3 additions & 8 deletions x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func (k *Keeper) NewEVM(
msg core.Message,
cfg *EVMConfig,
stateDB vm.StateDB,
random *common.Hash,
) *vm.EVM {
zero := common.BigToHash(big.NewInt(0))
blockCtx := vm.BlockContext{
CanTransfer: core.CanTransfer,
Transfer: core.Transfer,
Expand All @@ -63,7 +63,7 @@ func (k *Keeper) NewEVM(
Time: uint64(ctx.BlockHeader().Time.Unix()),
Difficulty: big.NewInt(0), // unused. Only required in PoW context
BaseFee: cfg.BaseFee,
Random: random, // not supported
Random: &zero, // not supported
}
if cfg.BlockOverrides != nil {
cfg.BlockOverrides.Apply(&blockCtx)
Expand Down Expand Up @@ -362,12 +362,7 @@ func (k *Keeper) ApplyMessageWithConfig(
return nil, errorsmod.Wrap(err, "failed to apply state override")
}
}
var random *common.Hash
if k.forkEnabledFunc(ctx) {
zero := common.BigToHash(big.NewInt(0))
random = &zero
}
evm = k.NewEVM(ctx, msg, cfg, stateDB, random)
evm = k.NewEVM(ctx, msg, cfg, stateDB)
leftoverGas := msg.GasLimit
sender := vm.AccountRef(msg.From)
// Allow the tracer captures the tx level events, mainly the gas consumption.
Expand Down
1 change: 0 additions & 1 deletion x/evm/statedb/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,6 @@ func newTestKeeper(t *testing.T, cms sdk.MultiStore) (sdk.Context, *evmkeeper.Ke
"",
paramstypes.Subspace{}, nil,
allKeys,
nil,
)

ctx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger())
Expand Down

0 comments on commit 028760e

Please sign in to comment.