This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
tests.py
executable file
·54 lines (47 loc) · 11.1 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
from pyzceqsolver import Solver
import binascii
from hashlib import sha256
def main():
vectors = (
{
'height': 100, # testnet rc4
'hash': b'004a4bcb42c9fe51332ea01c9bf9eeff7f9bd6957711862c5471041fd94ef95b',
'block': '04000000ad6c8c34c3d72887c5eab6276564c349d60df2863495ff22f4079488813bf0018e20f8505a31f69381c0fbeabe3f24b99b6109e0e66eaea14cf9bb1ac2e3f88c0000000000000000000000000000000000000000000000000000000000000000bb341258a81802200600dfe244233d83bec8985f6c5b5e5e248d9b19204451df5dc2f4b7f87c0000fd400500b31c3ae78b552cfbd1a6df3ef175e610c63980aa3fdeee24be6727b5d40645c91570118e5faf1c0a0611572ee7f0c8246398bc62efce1ff899c14efc93dd57804abd80da0ac2e71617b00bfb29fee324fda66805ffbe283b8e6ef3b4fd43ba66309a95cb01d2e572135406763cc4d573738741859975bf756b739340120d15d8cbaed4b6790e2e01b5d3e8cd09e1d8f77bb73d1be7ab4021fec317ea26ce9b570f61d7749fc9e208cebfba2ced40e3762d927b412f6612733adf35bc347cf619dc20ab5df05497f85bc3ecaba113be5b9a292b74d9938c3e08a972b353f6eba4c950d959a0024b846d8642d466e7045049b0b95d7d1b77745fd90f0c6a664ecc8c202bf7b590e2c0cacc4d1a307d652f314617fc4e954bfd32fb54f891f0fee5e38af8e1b4238112016e5bf3f5ba21b4567dfc431146686ed13d26400adf810a34f6eaeea3b196ae45354f408bac700113fd95f6cb0b81ea6d128023d968a987129ed11a18442d4aa20955f7cb8ae2bba777a7f57049789cbf262ddc0d539a3da7ecb46575e765ada657a85eb94744b202c0d52cd335a19f845c1f4c08e54d50f52502061edfcac89d5df7c43383783aa903c24f94ba400726d03250d3d8ffc52986b2df3d5a5ba4ff3e7ce0510a9d7bc6384f101f3f072238fcae7b00b45dbf31250b91e0de30d6ab7367a0c8a56ef9909251145cdd1f01418921b2913080a14f909292f6d3d59be5717d7209b853ffbb48c0cd233db173ef770ace1f64f5422c033495709d54f3335d22b0872813261d4d40970b981a40bdb93b3525abb4f3224fcfe994121d041e39d6021564b9fc111fbe9def83311ea56c28d13d4a48ca1509bbe745e750b58fc0f25832dd091d29598d3e59123f357df04c20813414618b5eeaef9d004dcd6f9a1f238f8fe9651a3ba21ad6a723d9c9b5c6186f4ad80105ae08495f391b196c219e0194eff2a6bbf83a3a2123434e499b8f4d6230735634d5410544dd70e3f80571df6fb199d5637640d6dc637c4b91fd929abe5a229ee47fc0d7e493baef99280e68656aee6ff9cb64097f6b313885b5f7cfcfad4e8afeec1fa7355df5b60b26da0b2f4b464ba9c616ae3f3ccf9208a7178ae01c0d0c985ba6313f77dc448963a6d6c2f7e57fb4f125e389d66699467564468aebe4fcd0f2d0b0fedd2a013dbec635892ca584f612b404aac832408d388c55051928bd38211009a1b9b2ed6b3fbc3da21ed515411710b8f5d0537c8f5d70a3265f685c16a1ac36485924a16bded44b7a948e20026c77cb1c6e0bad9739da0424b2c49b958da3f2ef357c2e403c4d9ed496f1dc1fb785394c4e9493881f5281b9e798a2e73d7dff4504994b8e3e8a331f0c55d1ca0e955a2cb933da91d3435d7ff68d255f957b08663abf7dc27a2380d8ee5f024e8ccb8d1952d8f13a71e063a128ae743cb5f7180e700e9e25615a2fc293f2b148c7cb419f21fe203311db1de3cddbf3fbbc04a2286073a8ce36199409c4355aee2ed4e8e9096991b6fc2dfd302e706194477620be22f410d2c7d5c09786e034da708f00e8fe12c1335521ea9f21b13ffcc3e41c3f370de9aff0ba2f94248843d7f662fe776b984607b5b626ca05c8de5bd7258b8befc31b406b1b6293cdbdd663ce0fdbdd33a80d2307eb30231ad58a4c4364082b6ef65573bbc2f232bba1d24b16d9c96fc143610927f3e1457b99edf10ee592ed028456fff761016f18411ffb65af9c5e7d1ae88e84c8bd614df64c6275ddc46f19c4c3fac8d515b4b9e114237f15cbebf22be62e0ef91c976b021317004a29c3e6210dbb37d1842153840dafb777dd93285d09a8f38e6b5de0b06294ba19c6f94ba3f9335431f73dc3cd9126d1f417f597663d05bdc9f93034ae0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0401640103ffffffff02404b4c0000000000232103bc707cd02a0bcc498afceb1748822482ef8e179d79d8dd672913f61c16484069acd01213000000000017a914ef775f1f997f122a062fff1a2d7443abd1f9c6428700000000',
'sol_id': 0
},
{
'height': 1000, # testnet rc4
'hash': b'00000012d0323e496c5c2ded0fc47c555894d29a1e092fb3af2df72e121078d9',
'block': '04000000708fcb43f55789d24439addb18cc94413e649e672e2099202514e58558000000150b1446c8ff33834e45152d7bbeb493f1f99c6d22e36968a6013e9d14e0d6c3000000000000000000000000000000000000000000000000000000000000000024101358ed7d011e5103000000000000010000000000000000000000000000000000000000000000fd4005001f028d4d071ba70f8229286178d9cfaee47f35654a259eb59464db29993977cff84bcdbe25de324c1213f7725beec79ba33588828f34ce5de8ada96fcf4668043b86c822783f960e98abbe66747e652735517a04b4e48058c4a887e8f0e090f6b6e434ef4bced9c42d28b9ebf4d6fef1179d130c283c8d29508aea939e0f6c4ae530e684ef5a4926787e5025eeed15d80d1a286eb4cca08bdc126c398610d65f7ab596f31b175f029f1c75a0da30e90f81d29ca1bf8d2b49751f41db1468bd4413f21c4b9b3df24f04ea72ad0a7ff8dc710768865127061d4c5d2b023d7d45dbf223913a66d8142554f49d2b5197c161528899f100c2d42bf99850059d28afecd2070df65606a64e75f979e2a3fe49d40935f57526d727a5a327c1048762892e26057d93372b4d7e0a8b34120beab0b4b0383be61e0bb31c0a504306567188b45785d17f96ce9d47ea42b2a63ef520004e4b8cbe049d3aa08de85206ce4eeef733199eec36b97dfa3c9723d8ba39b37e1c63e5a1bbeb2ed36f0d507b5307a7f54fdf61c2c812fc2440b25d735acd0e92cc98867a1455d56e711b5e9f95d8fbe9518a940265fd68b24a83fdcac041b0e52afb89912aee621b278464c7039b7ad5e4b12a93fb6a67b731161eea7707e3ab80c105fd82e23453a09a4fc5e64ff4fb568635c72c550c60b7732b1e751a19d2449d4e24192abb036057dd6940ef4b8e1e368458fcd6c9f82ed2c13116b13dd509990e57173d72625b5ddae0a4f3f7c4cf09bc4934de8cb165ccd68429ebe6e161ab13b6523432fc666857ef516583c393a81cb88dd268d33d8df505deb3ec0944174cb2c072e8a22c5dad61205d16ad13cac8c71d506a77e10fb264162c69870f9a1b9f8f0b763af0c24770eeca5412503c22b9b27db2f7d72b4b68345d4bd9a077becd76f2244ca63e69f39dc3ec00d12dc10554b5558fbdf03e0f385a49ea16162f857ee24e142c2485273177c83f13c952838aa55e0a4803c8a03e3d727e1d9e1e508dceaeaa52041b72e43a0595ea3e7b5b374f966fa2bc781df1671cf87d6c810b67d504b08dd2a2da977117277297c7163f9fc50e1cbf627c3f6ebf31f0be0203ede6e390cc3f5da85826ae0cbdd70f706eeedbe402b524ea766df3dd17d5525a1c4542ec3733915dd55964b3bd1a2c1b9bae8f01e8833ccac22fdb300533b569acd63eb59356e5f02669bb962419940334cde96f5cea833f3a105ee7790270f31522c61c99e6af43435d49225cf510bd1021104a1161b4cb539f7923c2ec7828909d9a528d3d890ba4b39c6fce151e773652e5381f81e116e377c4c72246a478a05551b3f1f5e24bf0bc49a4f55873808310acf716048a00f51e3e5348d8f8875db5ca6e50832a405bf5ee0e50870810d78c9f6055e331c77cdcad01c0cd7e3721a865caf1d5e16f7eab9dfa2ebfbb254bc32ff760762331c8219612a7b907ee752b975a890576f26cd7100e994a89f0968551f4e9bcd8f89d560f7b8ba9c3255d9738fe53f283ed8bc2f3e01991bb057ea7e8aad6351d38798512414a8f6dc9539f92050de436ab08087b2735c9819c917e8894955bccaf640dfe5f5bbd0ef60b1226a45c41f6070199479c3a09529f1360b23243d195e3565488fdd8a2eae8df0fda0479a1bab0203dedc1c31455857915c6723a55fa0c056270495a022f3479d8b31f4873119e5f75b6201c055d64ccb63bc021fa9f732384c7013e88921a847f0c2c6fa6986fc64dbae0955fe87be9a19282da6faa16d4ff39b60939b133d0f2d6e3dcad08bf24488e71599786a11656cc496643666e0f54b1675a30befc0817778a92964901428155b982e5d24402ef175f22343309dd4c1d9cd5c53da42aa3f67fc88f26191f598a0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0602e80302d700ffffffff0280f0fa0200000000232103ad63e41526f301370b3eac4f243efce6e1cc9f5907189360666f82312fe6d8f0ac20bcbe000000000017a914ef775f1f997f122a062fff1a2d7443abd1f9c6428700000000',
'sol_id': 2
},
{
'height': 70, # mainnet
'hash': b'0000c3e45b6183f5d1938d7293c0517ccbacbd53abd79eb8b8b5c9a06e50a66a',
'block': '04000000d88b45abc52c84d1345b6344b04a53abf92f05577b08c88d709fc110bb480200deb767c7c9cfdec27967faf5d0c09026da0b835b58a3acef9e39d7552db5e2a800000000000000000000000000000000000000000000000000000000000000001f7c135822b5021f1bb2b37300000000000000000000000000000000000000000000000000000002fd400500673cdd059b980150fe526e7fb7750e3e25b515f933ffaacb765a893f7652445bc073ad054b186fe718057ce0c584969247b2ca23609a5e87711b3c54d5fc2e021edb07b43e1df03fa2e557c47e55b9b139a445099751e11d48df60804cc57159fe23fd7bc6b932b0295719cf859aa6333054b98fda77e5f296f7fdb9161561ad757dc8489377d2f53c0c2e73de2c3234a7e7880014c7f42e87c9873daa964c7c92a2d2ab56afa004c3f58abfdfbbd524bcf17f6b76e5f6310b5e80bd0b7811ffc997d767eaa5c230225d35b5c612b1cd0d09a6bda04d82dff59bf8d1f99fa64acd735a94ac1a4cb63d3ff9e71feb3b1575e186ff461996b21c14190fe73d9f3c1d42b9fbf69cc179ed42b739257e17291c7c4f0afa0e922ff0d45766a26edb1e461c5b1b7212d913438462470d924b27ec23ed592b64acdd9d90137aedd39ebd3425f047d55597d72042af1e1fd330031bff47e6c30cbcef6cb034d9e5094e657fd8d9210901e7f697f0f251a9dfe3b64c7ac56a082c7176aa04eb47fbbc55a535aac61314f57ad5f1d3f77c1b7f42a2bc31b7e24f49184215a7a5757fe369f8db9cd203dfc8f714c2313dfd2c249d01f369ba3f507ce8dc0d1b35796b2d8bb7ae5314838c671819b45e30995a06727c7bdfe4fe65d2fb1135afe882e8e04b580701419cb6a09a516a8f6c8b14a67df037d55e4b70758605c1e46338939eb69d71132ab12ce489bae6b1f509283aae0a3f69590da10c02adb4e5d48d8735ec804c06eb76971f838485e222e1fd06a287114511da40210a2620e6505ca8ab0b2037c4526b793a897e7887aa0bac48e44261ce49cbebc3d69d55ad23210199619f45ecc6a8bda0365316ab99cfa77945632ff1ba645e23f56d3bacb17317c340e4b886f2036d476593c16c4cecc56d87d37bc73984e609805b12bdedd3722e1f0091e0d120ca9db30062d3c444dea97aaa8f5bc4981d2ea15785d0946ad7162270e7747e7195087416ff0641c164a457c57ef316653530c6e8eb22feb986611d554c7bbbee6c19c01069964556741efd8c5cbc8701ca23f86198cd6ccc1c923f6363fcd95aff5e395407d0c2630795e63986c17de72e7c72cf7bf95e755923789e18f1685059eeb57355dea7dd12cee439471c3637733bbe9e99b71d7e64e962e71c4e41beb5f2810175dd7f8feff25fc8da638e8b31f7717048929cd84bdadb13ee5b28f3f610b4cdafc9fbdd71e87858da07cb84dd7cdf3cb9e6d63767bdeffb3a795fffe17d18fe85e010cf741d3e2787369055040669c6d5befc061a5a337d09b78f556510aeecf2b821b4af35a8105ab79d0486732f25fef1b7035366f9ca8fd599ae3e065d3f42ec869321391b723bc51d701d7a7333cca5334813429f9d19c5dbae635fedcfaf093840d6bd2f0188e74cf68e4a52c96913039faa2b3df946fee04e0805987f089647058668c82e92442c5bbb8b3f9f050d5fda8b64e40e23899425f4cfed659de5055e6c023b389a37151962f5dc7473b61e29649dcc03b079240253e1660c41bcc5ca884210b829671596c438ce101049dfc6189fe97d01aa69084ffc47c6fb50ddf0a11f6406ab34e02dc17b2033955ef207e7aaee5dbb31490d2d0ef1ad184dce13980559ed5b3b5d573cf03309772cd3cd642363985860df34674ff0479575d24f1056df7a4a53c1339d0481c8e918a394ff0a1c8cd80a051746678f0e6ad1e5c18a5ba55e793c5e5ffae9231d6b5bf75429ad928a25296cd93b3e7455555ba60b1f6e50118aa6ba9433929d564e067e14f7bcad730d274a677f11a3e8f23172e9aea102829ea678f2560e9cd2d91c5da62bdf5ef138ffba584db72b2f0d04232f8df8c3115813e786052deb55f26dce457e9ff70101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03014600ffffffff02e0673500000000002321027a46eb513588b01b37ea24303f4b628afd12cc20df789fede0921e43cad3e875acf8590d000000000017a9147d46a730d31f97b1930d3368a967c309bd4d136a8700000000',
'sol_id': 1,
}
)
s = Solver()
for v in vectors:
print("Testing block %s" % v['hash'])
header = binascii.unhexlify(v['block'])[:140]
solution = binascii.unhexlify(v['block'])[143:143+1344]
sol_cnt = s.find_solutions(header)
for i in range(sol_cnt):
sol = s.get_solution(i)
if i == v['sol_id']:
if sol == solution:
print("Computed solution PASSED")
else:
raise Exception("Solutions are different!")
elif sol == solution:
raise Exception("Something is seriously broken")
# Recalculate block hash of given block
tohash = binascii.unhexlify(v['block'])[:143+1344]
print(binascii.hexlify(tohash))
hash = sha256(sha256(tohash).digest()).digest()
print("Block data fits block hash:", binascii.hexlify(hash[::-1]) == v['hash'])
if __name__ == '__main__':
main()