1"""
2Python pseudocode implementation of Solana proof-of-history.
3"""
4
5import hashlib
6
7
8class Poh:
9 def __init__(self, seed=bytes(32)):
10 self.state = bytes(seed)
11
12 def append(self):
13 msg = hashlib.sha256()
14 msg.update(self.state)
15 self.state = msg.digest()
16
17 def mixin(self, mixin):
18 assert len(mixin) == 32
19 msg = hashlib.sha256()
20 msg.update(self.state)
21 msg.update(mixin)
22 self.state = msg.digest()
23
24
25def test():
26 poh = Poh()
27 for _ in range(42):
28 poh.append()
29 poh.mixin(b"WAO.............................")
30 assert (
31 poh.state.hex()
32 == "18a244914fc9d21673ed92fc9edfbc4b00a9d630af352e0d8a4cac5846a344ce"
33 )
34
35
36if __name__ == "__main__":
37 test()
38
Table of Contents