From 25163424bb8da1875656bc7dee49374315c20ce8 Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Sat, 7 Apr 2018 13:13:18 +0700 Subject: [PATCH] Add fix for retrieving valid block hash --- mythril/leveldb/client.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mythril/leveldb/client.py b/mythril/leveldb/client.py index e5458b40..d62895a6 100644 --- a/mythril/leveldb/client.py +++ b/mythril/leveldb/client.py @@ -15,7 +15,7 @@ bodyPrefix = b'b' # bodyPrefix + num (uint64 big endian) + hash -> block b numSuffix = b'n' # headerPrefix + num (uint64 big endian) + numSuffix -> hash blockHashPrefix = b'H' # blockHashPrefix + hash -> num (uint64 big endian) # known geth keys -headHeaderKey = b'LastHeader' # head (latest) header hash +headHeaderKey = b'LastBlock' # head (latest) header hash def _formatBlockNumber(number): ''' @@ -162,6 +162,12 @@ class EthLevelDB(object): hash = self.db.get(headHeaderKey) num = self._get_block_number(hash) self.headBlockHeader = self._get_block_header(hash, num) + # find header with valid state + while not self.db.get(self.headBlockHeader.state_root) and self.headBlockHeader.prevhash is not None: + hash = self.headBlockHeader.prevhash + num = self._get_block_number(hash) + self.headBlockHeader = self._get_block_header(hash, num) + return self.headBlockHeader def _get_block_number(self, hash):