diff --git a/stateless/multi_keys.nim b/stateless/multi_keys.nim index 263547836..8701a1e19 100644 --- a/stateless/multi_keys.nim +++ b/stateless/multi_keys.nim @@ -28,8 +28,14 @@ type mask*: uint groups*: array[16, Group] - AccountKey* = tuple[address: EthAddress, codeTouched: bool, storageKeys: MultikeysRef] - MatchGroup* = tuple[match: bool, group: Group] + AccountKey* = object + address*: EthAddress + codeTouched*: bool + storageKeys*: MultikeysRef + + MatchGroup* = object + match*: bool + group*: Group func cmpHash(a, b: KeyHash): int = var i = 0 @@ -128,12 +134,12 @@ func groups*(m: MultikeysRef, depth: int, n: NibblesSeq, parentGroup: Group): Ma if not compareNibbles(m.keys[i].hash, depth, n): g.last = i - 1 # case 1: match and no match - return (true, g) + return MatchGroup(match: true, group: g) inc i # case 2: all is a match group g.last = parentGroup.last - return (true, g) + return MatchGroup(match: true, group: g) # no match came first, skip no match # we only interested in a match group @@ -149,15 +155,15 @@ func groups*(m: MultikeysRef, depth: int, n: NibblesSeq, parentGroup: Group): Ma if not compareNibbles(m.keys[i].hash, depth, n): # case 3: no match, match, and no match g.last = i - 1 - return (true, g) + return MatchGroup(match: true, group: g) inc i # case 4: no match and match g.last = parentGroup.last - return (true, g) + return MatchGroup(match: true, group: g) # case 5: no match at all - result = (false, g) + result = MatchGroup(match: false, group: g) func isValidMatch(mg: MatchGroup): bool {.inline.} = result = mg.match and mg.group.first == mg.group.last diff --git a/stateless/test_witness_keys.nim b/stateless/test_witness_keys.nim index 16df0513b..40e9e2cb4 100644 --- a/stateless/test_witness_keys.nim +++ b/stateless/test_witness_keys.nim @@ -75,18 +75,18 @@ proc runTest(numPairs: int, testStatusIMPL: var TestStatus, for i in 0..= 32: + raise newException(ParsingError, "Failed when try to convert short rlp to NodeKey") result.usedBytes = z.len result.data[0..z.len-1] = z[0..z.len-1] @@ -230,7 +231,7 @@ proc buildForest*(t: var TreeBuilder): seq[KeccakHash] result.add KeccakHash(data: res.data) proc treeNode(t: var TreeBuilder, depth: int, storageMode = false): NodeKey = - if depth >= 64: + if depth > 64: raise newException(ParsingError, "invalid trie structure") let nodeType = safeReadEnum(t, TrieNodeType) @@ -494,13 +495,13 @@ proc hashNode(t: var TreeBuilder, depth: int, storageMode: bool): NodeKey = if storageMode and depth >= 9: let z = t.safeReadByte() if z == ShortRlpPrefix: - let y = t.safeReadByte().int - if y == 0: + let rlpLen = t.safeReadByte().int + if rlpLen == 0: safeReadBytes(t, 31): result.toKeccak(0, t.read(31)) else: - safeReadBytes(t, y): - result = toNodeKey(t.read(y)) + safeReadBytes(t, rlpLen): + result = toNodeKey(t.read(rlpLen)) else: safeReadBytes(t, 31): result.toKeccak(z, t.read(31)) diff --git a/stateless/witness_from_tree.nim b/stateless/witness_from_tree.nim index 4b381206b..9c4becf2a 100644 --- a/stateless/witness_from_tree.nim +++ b/stateless/witness_from_tree.nim @@ -148,7 +148,7 @@ proc writeHashNode(wb: var WitnessBuilder, node: openArray[byte], depth: int, st proc writeShortRlp(wb: var WitnessBuilder, node: openArray[byte], depth: int, storageMode: bool) = doAssert(node.len < 32 and depth >= 9 and storageMode) - debugEcho "SHORT RLP ", node.len + wb.writeByte(HashNodeType) wb.writeByte(ShortRlpPrefix) wb.writeByte(node.len) wb.write(node)