nimbus-eth1/stateless/witness_types.nim

56 lines
1.3 KiB
Nim
Raw Normal View History

import nimcrypto/hash, stew/bitops2
type
TrieNodeType* = enum
BranchNodeType
ExtensionNodeType
AccountNodeType
HashNodeType
AccountType* = enum
SimpleAccountType
ExtendedAccountType
2020-05-14 04:09:01 +00:00
BytecodeType* = enum
CodeTouched
CodeUntouched
2020-04-29 05:46:50 +00:00
WitnessFlag* = enum
wfNoFlag
wfEIP170 # fork >= Spurious Dragon
MetadataType* = enum
MetadataNothing
MetadataSomething
2020-04-29 05:46:50 +00:00
WitnessFlags* = set[WitnessFlag]
ContractCodeError* = object of ValueError
ParsingError* = object of ValueError
StorageSlot* = array[32, byte]
2020-04-29 05:46:50 +00:00
const
StorageLeafNodeType* = AccountNodeType
2020-04-29 04:12:15 +00:00
BlockWitnessVersion* = 0x01
proc setBranchMaskBit*(x: var uint, i: int) {.inline.} =
assert(i >= 0 and i < 17)
x = x or (1 shl i).uint
func branchMaskBitIsSet*(x: uint, i: int): bool {.inline.} =
assert(i >= 0 and i < 17)
result = ((x shr i.uint) and 1'u) == 1'u
func constructBranchMask*(b1, b2: byte): uint {.inline.} =
result = uint(b1) shl 8 or uint(b2)
if countOnes(result) < 2 or ((result and (not 0x1FFFF'u)) != 0):
raise newException(ParsingError, "Invalid branch mask pattern " & $result)
2020-05-07 15:03:00 +00:00
iterator nonEmpty*(branchMask: uint): int =
for i in 0..<16:
if not branchMask.branchMaskBitIsSet(i):
# we skip an empty elem
continue
yield i