mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
Problem: no proper error for unsupported opcode
This commit is contained in:
parent
0183c7ad82
commit
9b7188f259
3 changed files with 30 additions and 18 deletions
|
|
@ -37,6 +37,7 @@ var (
|
|||
ErrGasUintOverflow = errors.New("gas uint64 overflow")
|
||||
ErrInvalidCode = errors.New("invalid code: must not begin with 0xef")
|
||||
ErrNonceUintOverflow = errors.New("nonce uint64 overflow")
|
||||
ErrUnsupportedRandom = errors.New("unsupported random")
|
||||
|
||||
// errStopToken is an internal token indicating interpreter loop termination,
|
||||
// never returned to outside callers.
|
||||
|
|
|
|||
|
|
@ -476,6 +476,9 @@ func opDifficulty(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
|
|||
}
|
||||
|
||||
func opRandom(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
if interpreter.evm.Context.Random == nil {
|
||||
return nil, ErrUnsupportedRandom
|
||||
}
|
||||
v := new(uint256.Int).SetBytes(interpreter.evm.Context.Random.Bytes())
|
||||
scope.Stack.push(v)
|
||||
return nil, nil
|
||||
|
|
|
|||
|
|
@ -719,22 +719,29 @@ func TestCreate2Addreses(t *testing.T) {
|
|||
func TestRandom(t *testing.T) {
|
||||
type testcase struct {
|
||||
name string
|
||||
random common.Hash
|
||||
random *common.Hash
|
||||
err error
|
||||
}
|
||||
|
||||
keccak256Hash := crypto.Keccak256Hash([]byte{0x01, 0x02, 0x03})
|
||||
for _, tt := range []testcase{
|
||||
{name: "empty hash", random: common.Hash{}},
|
||||
{name: "1", random: common.Hash{0}},
|
||||
{name: "emptyCodeHash", random: types.EmptyCodeHash},
|
||||
{name: "hash(0x010203)", random: crypto.Keccak256Hash([]byte{0x01, 0x02, 0x03})},
|
||||
{name: "nil random", random: nil, err: ErrUnsupportedRandom},
|
||||
{name: "empty hash", random: &common.Hash{}},
|
||||
{name: "1", random: &common.Hash{0}},
|
||||
{name: "emptyCodeHash", random: &types.EmptyCodeHash},
|
||||
{name: "hash(0x010203)", random: &keccak256Hash},
|
||||
} {
|
||||
var (
|
||||
env = NewEVM(BlockContext{Random: &tt.random}, TxContext{}, nil, params.TestChainConfig, Config{})
|
||||
env = NewEVM(BlockContext{Random: tt.random}, TxContext{}, nil, params.TestChainConfig, Config{})
|
||||
stack = newstack()
|
||||
pc = uint64(0)
|
||||
evmInterpreter = env.interpreter
|
||||
)
|
||||
opRandom(&pc, evmInterpreter, &ScopeContext{nil, stack, nil})
|
||||
_, err := opRandom(&pc, evmInterpreter, &ScopeContext{nil, stack, nil})
|
||||
if tt.err != nil {
|
||||
if err != tt.err {
|
||||
t.Errorf("Testcase %v: expected %v, got %v", tt.name, tt.err, err)
|
||||
}
|
||||
} else {
|
||||
if len(stack.data) != 1 {
|
||||
t.Errorf("Expected one item on stack after %v, got %d: ", tt.name, len(stack.data))
|
||||
}
|
||||
|
|
@ -748,6 +755,7 @@ func TestRandom(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlobHash(t *testing.T) {
|
||||
type testcase struct {
|
||||
|
|
|
|||
Loading…
Reference in a new issue