# Nimbus # Copyright (c) 2020-2023 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) # * MIT license ([LICENSE-MIT](LICENSE-MIT) or # http://opensource.org/licenses/MIT) # at your option. This file may not be copied, modified, or distributed except # according to those terms. import randutils, random, parseopt, strutils, os, eth/[common, rlp], eth/trie/[hexary, db, trie_defs], nimcrypto/sysrand, ../stateless/[json_from_tree], ../nimbus/db/[storage_types, distinct_tries], ./witness_types, ./multi_keys type DB = TrieDatabaseRef StorageKeys = tuple[storageRoot: Hash256, keys: MultikeysRef] AccountDef = object storageKeys: MultiKeysRef account: Account codeTouched: bool proc randU256(): UInt256 = var bytes: array[32, byte] discard randomBytes(bytes[0].addr, sizeof(result)) result = UInt256.fromBytesBE(bytes) proc randStorageSlot(): StorageSlot = discard randomBytes(result[0].addr, sizeof(result)) proc randNonce(): AccountNonce = discard randomBytes(result.addr, sizeof(result)) proc randCode(db: DB): Hash256 = if rand(0..1) == 0: result = blankStringHash else: let codeLen = rand(1..150) let code = randList(byte, rng(0, 255), codeLen, unique = false) result = keccakHash(code) db.put(contractHashKey(result).toOpenArray, code) proc randStorage(db: DB, numSlots: int): StorageKeys = if rand(0..1) == 0 or numSlots == 0: result = (emptyRlpHash, MultikeysRef(nil)) else: var trie = initStorageTrie(db) var keys = newSeq[StorageSlot](numSlots) for i in 0.. 0: outputDir / filename: else: filename writeFile(filePath, witness) main()