Skip to content

Commit

Permalink
feat: make BLOCKHASH return only last blockhash (ethereum#196)
Browse files Browse the repository at this point in the history
* make BLOCKHASH return only last blockhash

* fix

* small fix
  • Loading branch information
NazariiDenha authored Feb 10, 2023
1 parent 98eb664 commit 7c3657b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions core/vm/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 7c3657b

Please sign in to comment.