interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / agora / test / pow.om

102 lines · 1652 bytes Raw Blame History
1note pow.om -- test proof-of-work solver for the Agora wire.
2note Build: { printf 'om2\n'; cat sha256.om test/pow.om; } | omc > pow
3note Usage: pow <challenge_hex32> <bits> < rest_of_body
4note Prints the smallest decimal nonce n such that SHA-256(challenge "\n" n "\n" rest) starts with
5note <bits> zero bits, where rest is the request body after the nonce line.
6
7global g_in uchar 16384
8
9fn lzb d view uchar 32 to ulong
10z = ulong 0
11for i ulong 32
12c = get d i
13if eq c 0
14z = add z 8
15continue
16end
17for b ulong 8
18if ne and c shr uchar 128 b 0
19ret z
20end
21z = add z 1
22end
23ret z
24end
25ret z
26end
27
28fn cat b edit uchar 16500 p ulong v ulong to ulong
29d = new uchar 20 0
30i = ulong 20
31x = v
32for it ulong 20
33i = sub i 1
34put d i uchar add rem x 10 48
35x = div x 10
36if eq x 0
37break
38end
39end
40q = p
41for k ulong sub 20 i
42put b q get d add i k
43q = add q 1
44end
45ret q
46end
47
48fn try b edit uchar 16500 n ulong rn ulong nonce ulong need ulong to bool
49dg = new uchar 32 0
50q = cat b 33 nonce
51put b q 10
52q = add q 1
53for i ulong rn
54put b add q i get g_in i
55end
56sha256_hash view part b 0 add q rn dg
57ret ge lzb dg need
58end
59
60fn rdin to ulong
61n = ulong 0
62for it ulong 4096
63if ge n 16384
64ret n
65end
66r = read 0 g_in n sub 16384 n
67if le r 0
68ret n
69end
70n = add n ulong r
71end
72ret n
73end
74
75fn main to int
76b = new uchar 16500 0
77ab = new uchar 64 0
78c = argread 1 b 0 32
79if ne c 32
80ret 2
81end
82put b 32 10
83k = argread 2 ab 0 8
84need = ulong 0
85for i ulong ulong k
86need = add mul need 10 ulong sub get ab i 48
87end
88rn = rdin
89nonce = ulong 0
90for hi ulong 65536
91for lo ulong 65536
92if try b 33 rn nonce need
93q = cat b 33 nonce
94put b q 10
95w = write 1 b 33 sub q 32
96ret 0
97end
98nonce = add nonce 1
99end
100end
101ret 1
102end