ensure passing unsigned integer to `rlp.encode` (#6397)
RLP encoding is not defined for signed integers. Make sure to use unsigned integers when encoding RLP for EL block hash computation.
This commit is contained in:
parent
fba8cc3ee5
commit
515bd486e6
|
@ -1322,7 +1322,7 @@ proc ETHExecutionBlockHeaderCreateFromJson(
|
||||||
var tr = initHexaryTrie(newMemoryDB())
|
var tr = initHexaryTrie(newMemoryDB())
|
||||||
for i, wd in wds:
|
for i, wd in wds:
|
||||||
try:
|
try:
|
||||||
tr.put(rlp.encode(i), wd.bytes)
|
tr.put(rlp.encode(i.uint), wd.bytes)
|
||||||
except RlpError:
|
except RlpError:
|
||||||
raiseAssert "Unreachable"
|
raiseAssert "Unreachable"
|
||||||
if tr.rootHash() != data.withdrawalsRoot.get.asEth2Digest:
|
if tr.rootHash() != data.withdrawalsRoot.get.asEth2Digest:
|
||||||
|
@ -1632,7 +1632,7 @@ proc ETHTransactionsCreateFromJson(
|
||||||
var tr = initHexaryTrie(newMemoryDB())
|
var tr = initHexaryTrie(newMemoryDB())
|
||||||
for i, transaction in txs:
|
for i, transaction in txs:
|
||||||
try:
|
try:
|
||||||
tr.put(rlp.encode(i), distinctBase(transaction.bytes))
|
tr.put(rlp.encode(i.uint), distinctBase(transaction.bytes))
|
||||||
except RlpError:
|
except RlpError:
|
||||||
raiseAssert "Unreachable"
|
raiseAssert "Unreachable"
|
||||||
if tr.rootHash() != transactionsRoot[]:
|
if tr.rootHash() != transactionsRoot[]:
|
||||||
|
@ -2208,7 +2208,7 @@ proc ETHReceiptsCreateFromJson(
|
||||||
var tr = initHexaryTrie(newMemoryDB())
|
var tr = initHexaryTrie(newMemoryDB())
|
||||||
for i, rec in recs:
|
for i, rec in recs:
|
||||||
try:
|
try:
|
||||||
tr.put(rlp.encode(i), rec.bytes)
|
tr.put(rlp.encode(i.uint), rec.bytes)
|
||||||
except RlpError:
|
except RlpError:
|
||||||
raiseAssert "Unreachable"
|
raiseAssert "Unreachable"
|
||||||
if tr.rootHash() != receiptsRoot[]:
|
if tr.rootHash() != receiptsRoot[]:
|
||||||
|
|
|
@ -445,9 +445,10 @@ proc computeTransactionsTrieRoot*(
|
||||||
var tr = initHexaryTrie(newMemoryDB())
|
var tr = initHexaryTrie(newMemoryDB())
|
||||||
for i, transaction in payload.transactions:
|
for i, transaction in payload.transactions:
|
||||||
try:
|
try:
|
||||||
tr.put(rlp.encode(i), distinctBase(transaction)) # Already RLP encoded
|
# Transactions are already RLP encoded
|
||||||
|
tr.put(rlp.encode(i.uint), distinctBase(transaction))
|
||||||
except RlpError as exc:
|
except RlpError as exc:
|
||||||
doAssert false, "HexaryTrie.put failed: " & $exc.msg
|
raiseAssert "HexaryTrie.put failed: " & $exc.msg
|
||||||
tr.rootHash()
|
tr.rootHash()
|
||||||
|
|
||||||
func toExecutionWithdrawal*(
|
func toExecutionWithdrawal*(
|
||||||
|
@ -468,9 +469,9 @@ proc computeWithdrawalsTrieRoot*(
|
||||||
var tr = initHexaryTrie(newMemoryDB())
|
var tr = initHexaryTrie(newMemoryDB())
|
||||||
for i, withdrawal in payload.withdrawals:
|
for i, withdrawal in payload.withdrawals:
|
||||||
try:
|
try:
|
||||||
tr.put(rlp.encode(i), rlp.encode(toExecutionWithdrawal(withdrawal)))
|
tr.put(rlp.encode(i.uint), rlp.encode(toExecutionWithdrawal(withdrawal)))
|
||||||
except RlpError as exc:
|
except RlpError as exc:
|
||||||
doAssert false, "HexaryTrie.put failed: " & $exc.msg
|
raiseAssert "HexaryTrie.put failed: " & $exc.msg
|
||||||
tr.rootHash()
|
tr.rootHash()
|
||||||
|
|
||||||
proc blockToBlockHeader*(blck: ForkyBeaconBlock): ExecutionBlockHeader =
|
proc blockToBlockHeader*(blck: ForkyBeaconBlock): ExecutionBlockHeader =
|
||||||
|
|
Loading…
Reference in New Issue