diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 42af498ec5..09097b79b9 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -440,10 +440,10 @@ func opBlockhash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ( } var upper, lower uint64 upper = interpreter.evm.Context.BlockNumber.Uint64() - if upper < 257 { + if upper < 2 { lower = 0 } else { - lower = upper - 256 + lower = upper - 1 } if num64 >= lower && num64 < upper { num.SetBytes(interpreter.evm.Context.GetHash(num64).Bytes()) diff --git a/core/vm/runtime/runtime_test.go b/core/vm/runtime/runtime_test.go index abbb632ef5..6892e65d92 100644 --- a/core/vm/runtime/runtime_test.go +++ b/core/vm/runtime/runtime_test.go @@ -337,10 +337,10 @@ func TestBlockhash(t *testing.T) { if first.Uint64() != 999 { t.Fatalf("second block should be 999, got %d (%x)", first, ret[32:64]) } - if last.Uint64() != 744 { - t.Fatalf("last block should be 744, got %d (%x)", last, ret[64:96]) + if last.Uint64() != 0 { + t.Fatalf("last block should be 0, got %d (%x)", last, ret[64:96]) } - if exp, got := 255, chain.counter; exp != got { + if exp, got := 0, chain.counter; exp != got { t.Errorf("suboptimal; too much chain iteration, expected %d, got %d", exp, got) } }