Correct the shortcut for ommershash verification post Shanghai (#1756)
* Correct the shortcut for ommershash verification post Shanghai There was a faulty length check being done in the assumption that the uncles field was already the list. However it is still the RLP encoded data at that point, hence we check directly for the RLP encoded value for empty list. * Fix copy-paste error in withdrawal root verification And print out the hashes in txs root and withdrawal root verification
This commit is contained in:
parent
a65b1c9062
commit
18b3ff3390
|
@ -230,7 +230,8 @@ proc validateBlockBody(
|
||||||
|
|
||||||
let calculatedTxsRoot = calcTxsRoot(body.transactions)
|
let calculatedTxsRoot = calcTxsRoot(body.transactions)
|
||||||
if calculatedTxsRoot != header.txRoot:
|
if calculatedTxsRoot != header.txRoot:
|
||||||
return err("Invalid transactions root")
|
return err("Invalid transactions root: expected " &
|
||||||
|
$header.txRoot & " - got " & $calculatedTxsRoot)
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
|
@ -239,23 +240,26 @@ proc validateBlockBody(
|
||||||
Result[void, string] =
|
Result[void, string] =
|
||||||
## Validate the block body against the txRoot, ommersHash and withdrawalsRoot
|
## Validate the block body against the txRoot, ommersHash and withdrawalsRoot
|
||||||
## from the header.
|
## from the header.
|
||||||
# Shortcutting the ommersHash calculation as uncles needs to be empty
|
# Shortcut the ommersHash calculation as uncles must be an RLP encoded
|
||||||
# TODO: This is since post-merge, however, we would need an additional object
|
# empty list
|
||||||
# type for that period to do this.
|
if body.uncles.asSeq() != @[byte 0xc0]:
|
||||||
if body.uncles.len > 0:
|
return err("Invalid ommers hash, uncles list is not empty")
|
||||||
return err("Invalid ommers hash")
|
|
||||||
|
|
||||||
let calculatedTxsRoot = calcTxsRoot(body.transactions)
|
let calculatedTxsRoot = calcTxsRoot(body.transactions)
|
||||||
if calculatedTxsRoot != header.txRoot:
|
if calculatedTxsRoot != header.txRoot:
|
||||||
return err("Invalid transactions root")
|
return err("Invalid transactions root: expected " &
|
||||||
|
$header.txRoot & " - got " & $calculatedTxsRoot)
|
||||||
|
|
||||||
# TODO: This check is done higher up but perhaps this can become cleaner with
|
# TODO: This check is done higher up but perhaps this can become cleaner with
|
||||||
# some refactor.
|
# some refactor.
|
||||||
doAssert(header.withdrawalsRoot.isSome())
|
doAssert(header.withdrawalsRoot.isSome())
|
||||||
|
|
||||||
let calculatedWithdrawalsRoot = calcWithdrawalsRoot(body.withdrawals)
|
let
|
||||||
if calculatedWithdrawalsRoot != header.txRoot:
|
calculatedWithdrawalsRoot = calcWithdrawalsRoot(body.withdrawals)
|
||||||
return err("Invalid transactions root")
|
headerWithdrawalsRoot = header.withdrawalsRoot.get()
|
||||||
|
if calculatedWithdrawalsRoot != headerWithdrawalsRoot:
|
||||||
|
return err("Invalid withdrawals root: expected " &
|
||||||
|
$headerWithdrawalsRoot & " - got " & $calculatedWithdrawalsRoot)
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue