From 7492033536970b454b75dce6bd0efa17b4942a6e Mon Sep 17 00:00:00 2001 From: ia Date: Wed, 9 May 2018 08:49:37 +0900 Subject: [PATCH 1/3] problem: panic at SVM RequireBlockhash (nil pointer block ref) solution: ensure loaded block reference is not nil and accurate Fixes #585 --- core/multivm_processor.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/multivm_processor.go b/core/multivm_processor.go index cb119b221..526452d52 100644 --- a/core/multivm_processor.go +++ b/core/multivm_processor.go @@ -119,8 +119,9 @@ Loop: vm.CommitNonexist(address) case sputnikvm.RequireBlockhash: number := ret.BlockNumber() - hash := bc.GetBlockByNumber(number.Uint64()).Hash() - vm.CommitBlockhash(number, hash) + if block := bc.GetBlockByNumber(number.Uint64()); block != nil && block.Number().Cmp(number) == 0 { + vm.CommitBlockhash(number, block.Hash()) + } } } From 6c0ed1968291eb0ca43ba88c04b3aba4cd91bfcf Mon Sep 17 00:00:00 2001 From: ia Date: Wed, 9 May 2018 08:58:06 +0900 Subject: [PATCH 2/3] problem: name shadowy variable 'key' solution: rename, adding tiny prefix for legibility --- core/multivm_processor.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/multivm_processor.go b/core/multivm_processor.go index 526452d52..bf04a01ed 100644 --- a/core/multivm_processor.go +++ b/core/multivm_processor.go @@ -112,8 +112,8 @@ Loop: key := common.BigToHash(ret.StorageKey()) if statedb.Exist(address) { value := statedb.GetState(address, key).Big() - key := ret.StorageKey() - vm.CommitAccountStorage(address, key, value) + sKey := ret.StorageKey() + vm.CommitAccountStorage(address, sKey, value) break } vm.CommitNonexist(address) From d04d8c19a2873381d93216a985b14d2d0bc961dc Mon Sep 17 00:00:00 2001 From: ia Date: Thu, 10 May 2018 16:03:24 +0900 Subject: [PATCH 3/3] problem: RequireBlockchash MUST commit a hash solution: commit empty hash if no required block exists in db --- core/multivm_processor.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/multivm_processor.go b/core/multivm_processor.go index bf04a01ed..2ac2a960e 100644 --- a/core/multivm_processor.go +++ b/core/multivm_processor.go @@ -119,9 +119,11 @@ Loop: vm.CommitNonexist(address) case sputnikvm.RequireBlockhash: number := ret.BlockNumber() + hash := common.Hash{} if block := bc.GetBlockByNumber(number.Uint64()); block != nil && block.Number().Cmp(number) == 0 { - vm.CommitBlockhash(number, block.Hash()) + hash = block.Hash() } + vm.CommitBlockhash(number, hash) } }