Skip to content

Commit

Permalink
update input format, add instructions to readme #46
Browse files Browse the repository at this point in the history
  • Loading branch information
SK0M0R0H authored and NickVolynkin committed Aug 11, 2023
1 parent 4e4081e commit f8ddc34
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 9 additions & 0 deletions storage-proof-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@ Historical data for blocks produced before Capella update is located in 'histori
The newer data is located in `historical_summaries`.
More information about Beacon State structure can be found [here](https://eth2book.info/capella/part3/containers/state/).

# How to use it?

**To generate test data about account on Consensus Layer**

Run
```
python3 mock_data.py --output <output file name>
```

14 changes: 11 additions & 3 deletions storage-proof-app/mock_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@
import json
import sys
import random
import argparse

def slice_into_low_high(digest):
low = int.from_bytes(digest[:16], 'big')
high = int.from_bytes(digest[16:], 'big')
low = str(int.from_bytes(digest[:16], 'big'))
high = str(int.from_bytes(digest[16:], 'big'))

return [low, high]

if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog='Dummy data generator for Consensus Layer Storage Proof',
description='Provides a Merkle path for an account into a state root from Consensus Layer.')
parser.add_argument('--output', help="Output file path", default="output.json")

args = parser.parse_args()

index = random.randint(1, 16)
state, tree = get_random_state()
merkle_path = tree.prove_inclusion(index)
leaf = tree.get_leaf(index)
root = state.state_root[0]
print(f"Preparing Merkle path for index {index - 1} and state root {root.hex()}")
input = [{"array" : [slice_into_low_high(node) for node in merkle_path.path]}, {"vector": slice_into_low_high(leaf)}, {"vector" : slice_into_low_high(root)}]
with open("path.inp", 'w') as f:
with open(args.output, 'w') as f:
sys.stdout = f
print(json.dumps(input, indent=4))

0 comments on commit f8ddc34

Please sign in to comment.