Last active
November 19, 2019 15:40
-
-
Save mratsim/0f152a5d671d6374a1d0035be81c7b62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyutils.ssz.ssz_typing import uint64, List, Bitlist, Bytes32, Bytes96, Container | |
from pyutils.ssz.ssz_impl import hash_tree_root | |
# Minimal | |
# MAX_VALIDATORS_PER_COMMITTEE = 2048 | |
# Mainnet | |
MAX_VALIDATORS_PER_COMMITTEE = 4096 | |
class Checkpoint(Container): | |
epoch: uint64 | |
root: Bytes32 | |
def __init__(self, epoch, root): | |
self.epoch = epoch | |
self.root = root | |
class AttestationData(Container): | |
slot: uint64 | |
index: uint64 | |
# LMD GHOST vote | |
beacon_block_root: Bytes32 | |
# FFG vote | |
source: Checkpoint | |
target: Checkpoint | |
def __init__(self, slot, index, beacon_block_root, source, target): | |
self.slot = slot | |
self.index = index | |
self.beacon_block_root = beacon_block_root | |
self.source = source | |
self.target = target | |
class Attestation(Container): | |
aggregation_bits: Bitlist[MAX_VALIDATORS_PER_COMMITTEE] | |
data: AttestationData | |
signature: Bytes96 | |
def __init__(self, aggregation_bits, data, signature): | |
self.aggregation_bits = aggregation_bits | |
self.data = data | |
self.signature = signature | |
x = Bitlist[MAX_VALIDATORS_PER_COMMITTEE]( | |
0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, | |
1, 1, 0, 1, 0, 0, 1, 0, | |
0, 0, 0, 0, 0, 0, 1, 1 | |
) | |
# '0xd203' | |
# x = Bitlist[MAX_VALIDATORS_PER_COMMITTEE]( | |
# 0, 0, 0, 0, 0, 0, 0, 0, | |
# 0, 0, 0, 0, 0, 0, 0, 1 | |
# ) | |
# # 0x01 | |
agg_bits = Bitlist[MAX_VALIDATORS_PER_COMMITTEE](x) | |
data = AttestationData( | |
16190417324762968195, # slot | |
11925472494053767852, # index | |
Bytes32(bytes.fromhex('6fdd48270188c7abda9c27cca8e670b7fbf2b2bbd3ad44c6ae07243d64b01bae')), | |
Checkpoint(11830679453202619032, Bytes32(bytes.fromhex('314da949cc563740f2316a5ab49867d4f8766cee4608ea29e3a4ab99ff0d9250'))), | |
Checkpoint(8155824741468644389, Bytes32(bytes.fromhex('ecf4804a437264413f838299b81b2d9dc7b92e71e7743eda04389641224f8c98'))), | |
) | |
sig = Bytes96(bytes.fromhex('63f34097da24274a0afeeab5415d301abfe395d9a38aab73e0e1a57510bdfa694a7205c6b181079b3a45618b1cd78622e4ff059b3c3b4793e2dec50f52c0099d02c71d0c58b29173c9eff94fd558edc2bceafa48b395abaacaca18663c7d3308')) | |
Att = Attestation(agg_bits, data, sig) | |
print(f'{"Attestation tree root":<30}{hash_tree_root(Att).hex()}') | |
print(f'{"agg_bits value":<30}{agg_bits}') | |
print(f'{"agg_bits tree root":<30}{hash_tree_root(agg_bits).hex()}') | |
# print(f'{"Att data":<30}{data}') | |
print(f'{"Att data tree root":<30}{hash_tree_root(data).hex()}') | |
print(f'{"signature":<30}{sig.hex()}') | |
print(f'{"signature tree root":<30}{hash_tree_root(sig).hex()}') | |
# Attestation tree root d2df8f75d37f5d3e9cc36a471044475abd7801ba0232987aa5f46b5f1845350f | |
# agg_bits value Bitlist[boolean, 4096](0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1) | |
# agg_bits tree root cd2d671816a3507266406926d437145adca85bab52317496f56ab9ee2bf6505e | |
# Att data tree root e839150d928f85d5ebf98769bcd138ad6ff307f1cb1c7f0c2eae882b98ce413c | |
# signature 63f34097da24274a0afeeab5415d301abfe395d9a38aab73e0e1a57510bdfa694a7205c6b181079b3a45618b1cd78622e4ff059b3c3b4793e2dec50f52c0099d02c71d0c58b29173c9eff94fd558edc2bceafa48b395abaacaca18663c7d3308 | |
# signature tree root 0d39c97cdd152abb298629e7c79afeab43f78ba911180cd84e67e0164464fe4f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment