feat: make BLOCKHASH return only last blockhash (#196)

* make BLOCKHASH return only last blockhash

* fix

* small fix
This commit is contained in:
Nazarii Denha 2023-02-10 06:06:42 +01:00 committed by GitHub
parent 98eb664f23
commit 7c3657b61b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -440,10 +440,10 @@ func opBlockhash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) (
} }
var upper, lower uint64 var upper, lower uint64
upper = interpreter.evm.Context.BlockNumber.Uint64() upper = interpreter.evm.Context.BlockNumber.Uint64()
if upper < 257 { if upper < 2 {
lower = 0 lower = 0
} else { } else {
lower = upper - 256 lower = upper - 1
} }
if num64 >= lower && num64 < upper { if num64 >= lower && num64 < upper {
num.SetBytes(interpreter.evm.Context.GetHash(num64).Bytes()) num.SetBytes(interpreter.evm.Context.GetHash(num64).Bytes())

View file

@ -337,10 +337,10 @@ func TestBlockhash(t *testing.T) {
if first.Uint64() != 999 { if first.Uint64() != 999 {
t.Fatalf("second block should be 999, got %d (%x)", first, ret[32:64]) t.Fatalf("second block should be 999, got %d (%x)", first, ret[32:64])
} }
if last.Uint64() != 744 { if last.Uint64() != 0 {
t.Fatalf("last block should be 744, got %d (%x)", last, ret[64:96]) 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) t.Errorf("suboptimal; too much chain iteration, expected %d, got %d", exp, got)
} }
} }