diff --git a/stateless/tree_from_witness.nim b/stateless/tree_from_witness.nim index d83677cef..54af337da 100644 --- a/stateless/tree_from_witness.nim +++ b/stateless/tree_from_witness.nim @@ -65,9 +65,8 @@ template read(t: var TreeBuilder, len: int): auto = toOpenArray(t.data, pos, pos + len - 1) ]# -proc readU32(t: var TreeBuilder): int = - # TODO: what if the value overflow int32.high? - result = fromBytesLE(uint32, t.read(4)).int +proc readU32(t: var TreeBuilder): uint32 = + result = fromBytesBE(uint32, t.read(4)) proc toAddress(r: var EthAddress, x: openArray[byte]) {.inline.} = r[0..19] = x[0..19] @@ -210,7 +209,7 @@ proc extensionNode(t: var TreeBuilder, depth: int): NodeKey = proc accountNode(t: var TreeBuilder, depth: int): NodeKey = assert(depth < 65) - let len = t.readU32() + let len = t.readU32().int result = toNodeKey(t.read(len)) when defined(debugDepth): diff --git a/stateless/witness_from_tree.nim b/stateless/witness_from_tree.nim index 672498d97..f117c3f3d 100644 --- a/stateless/witness_from_tree.nim +++ b/stateless/witness_from_tree.nim @@ -39,6 +39,9 @@ proc rlpListToBitmask(r: var Rlp): uint = inc i r.position = 0 +proc writeU32(wb: var WitnessBuilder, x: uint32) = + wb.output.append(toBytesBE(x)) + proc writeNibbles(wb: var WitnessBuilder; n: NibblesSeq) = let nibblesLen = n.len let numBytes = nibblesLen div 2 + nibblesLen mod 2 @@ -87,7 +90,7 @@ proc writeBranchNode(wb: var WitnessBuilder, mask: uint, depth: int, node: openA proc writeAccountNode(wb: var WitnessBuilder, node: openArray[byte], depth: int) = # write type wb.output.append(AccountNodeType.byte) - wb.output.append(toBytesLe(node.len.uint32)) + wb.writeU32(node.len.uint32) wb.output.append(node) when defined(debugDepth):