diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bc147af7..c92240086 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ set(LIBRARY ethash) if (CPPETHEREUM) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") -#else () endif () set(CMAKE_BUILD_TYPE Release) @@ -13,6 +12,7 @@ endif() set(FILES util.c util.h + io.c internal.c ethash.h endian.h @@ -20,6 +20,12 @@ set(FILES util.c fnv.h data_sizes.h) +if (MSVC) + list(APPEND FILES io_win32.c) +else() + list(APPEND FILES io_posix.c) +endif() + if (NOT CRYPTOPP_FOUND) find_package(CryptoPP 5.6.2) endif() diff --git a/data_sizes.h b/data_sizes.h index a10d4c42c..cf52ae4f8 100644 --- a/data_sizes.h +++ b/data_sizes.h @@ -20,8 +20,6 @@ * @date 2015 */ -// TODO: Update this after ~3.5 years - #pragma once #include @@ -33,23 +31,24 @@ extern "C" { #include -// 2048 Epochs worth of tabulated DAG sizes +// 2048 Epochs (~20 years) worth of tabulated DAG sizes // Generated with the following Mathematica Code: -// GetDataSizes[n_] := Module[{ -// DataSetSizeBytesInit = 2^30, -// MixBytes = 128, -// DataSetGrowth = 2^23, +// GetCacheSizes[n_] := Module[{ +// CacheSizeBytesInit = 2^24, +// CacheGrowth = 2^17, +// HashBytes = 64, // j = 0}, -// Reap[ -// While[j < n, -// Module[{i = -// Floor[(DataSetSizeBytesInit + DataSetGrowth * j) / MixBytes]}, -// While[! PrimeQ[i], i--]; -// Sow[i*MixBytes]; j++]]]][[2]][[1]] +// Reap[ +// While[j < n, +// Module[{i = +// Floor[(CacheSizeBytesInit + CacheGrowth * j) / HashBytes]}, +// While[! PrimeQ[i], i--]; +// Sow[i*HashBytes]; j++]]]][[2]][[1]] + -static const size_t dag_sizes[] = { +static const uint64_t dag_sizes[2048] = { 1073739904U, 1082130304U, 1090514816U, 1098906752U, 1107293056U, 1115684224U, 1124070016U, 1132461952U, 1140849536U, 1149232768U, 1157627776U, 1166013824U, 1174404736U, 1182786944U, 1191180416U, @@ -478,300 +477,334 @@ static const size_t dag_sizes[] = { // While[! PrimeQ[i], i--]; // Sow[i*HashBytes]; j++]]]][[2]][[1]] -const size_t cache_sizes[] = { - 1048384U, 1055552U, 1064512U, 1072832U, 1080896U, 1089344U, 1096768U, - 1104448U, 1113664U, 1121216U, 1130176U, 1138624U, 1146304U, 1155008U, - 1162816U, 1171264U, 1179328U, 1187392U, 1195456U, 1203392U, 1210816U, - 1220416U, 1227712U, 1236416U, 1244608U, 1253312U, 1261376U, 1268416U, - 1277632U, 1285696U, 1294016U, 1302208U, 1310656U, 1318336U, 1326784U, - 1334848U, 1342912U, 1350848U, 1359808U, 1366208U, 1376192U, 1383488U, - 1392448U, 1400384U, 1408832U, 1416512U, 1425344U, 1433408U, 1440704U, - 1449664U, 1458112U, 1466048U, 1474496U, 1482688U, 1490752U, 1498688U, - 1507136U, 1515328U, 1523264U, 1531456U, 1539904U, 1547584U, 1556288U, - 1564352U, 1572544U, 1580608U, 1588544U, 1596992U, 1605568U, 1612096U, - 1621952U, 1630144U, 1637696U, 1645888U, 1654336U, 1662784U, 1671104U, - 1679168U, 1686848U, 1695296U, 1702208U, 1711168U, 1720256U, 1727552U, - 1736128U, 1744576U, 1751488U, 1760576U, 1769408U, 1777472U, 1785664U, - 1793984U, 1801664U, 1810112U, 1818304U, 1826624U, 1834816U, 1842752U, - 1851328U, 1858112U, 1867456U, 1875904U, 1883968U, 1892288U, 1899712U, - 1908416U, 1916608U, 1924544U, 1932992U, 1940672U, 1948736U, 1956928U, - 1965632U, 1973824U, 1982144U, 1989824U, 1998784U, 2006848U, 2014784U, - 2022848U, 2031424U, 2038976U, 2047424U, 2055616U, 2064064U, 2072384U, - 2080448U, 2088512U, 2095936U, 2104768U, 2113472U, 2121664U, 2127808U, - 2137792U, 2146112U, 2153408U, 2162624U, 2170304U, 2178496U, 2186944U, - 2195392U, 2203456U, 2211136U, 2219968U, 2227648U, 2236096U, 2244416U, - 2250944U, 2260928U, 2268736U, 2276672U, 2283328U, 2293696U, 2301632U, - 2309312U, 2317888U, 2325952U, 2334656U, 2342848U, 2350144U, 2358848U, - 2366656U, 2375488U, 2383552U, 2391616U, 2400064U, 2407616U, 2415808U, - 2424256U, 2432704U, 2439616U, 2448704U, 2457152U, 2464064U, 2473792U, - 2482112U, 2489792U, 2497472U, 2506432U, 2514752U, 2522816U, 2531264U, - 2539456U, 2547136U, 2555456U, 2564032U, 2572096U, 2578496U, 2587712U, - 2595776U, 2604736U, 2613056U, 2620736U, 2629184U, 2637632U, 2645824U, - 2653888U, 2662208U, 2670016U, 2678464U, 2686912U, 2694464U, 2703296U, - 2710976U, 2719424U, 2727104U, 2736064U, 2743232U, 2752192U, 2760512U, - 2768704U, 2777024U, 2785088U, 2792512U, 2800576U, 2809024U, 2817856U, - 2826176U, 2833984U, 2840896U, 2850752U, 2858048U, 2867008U, 2875328U, - 2883392U, 2891584U, 2899648U, 2908096U, 2915648U, 2924224U, 2932672U, - 2940736U, 2948672U, 2956736U, 2964928U, 2973248U, 2981824U, 2988992U, - 2997184U, 3005248U, 3013952U, 3022144U, 3030592U, 3037376U, 3046976U, - 3055552U, 3063616U, 3070784U, 3079744U, 3087808U, 3096512U, 3103808U, - 3111872U, 3121088U, 3128896U, 3137216U, 3144896U, 3153856U, 3161152U, - 3169984U, 3178432U, 3186496U, 3194816U, 3203008U, 3210176U, 3218624U, - 3227072U, 3235264U, 3243712U, 3250496U, 3259456U, 3268544U, 3276736U, - 3283648U, 3292736U, 3301184U, 3308224U, 3317696U, 3324736U, 3333184U, - 3342272U, 3348544U, 3357248U, 3365312U, 3374912U, 3383104U, 3390784U, - 3399488U, 3407296U, 3414976U, 3424192U, 3432256U, 3440576U, 3448768U, - 3456832U, 3464896U, 3473216U, 3480128U, 3489344U, 3497408U, 3505856U, - 3514048U, 3521344U, 3530432U, 3538624U, 3546304U, 3555008U, 3563072U, - 3571648U, 3579712U, 3587392U, 3595456U, 3603904U, 3612352U, 3620416U, - 3628864U, 3636928U, 3645248U, 3652928U, 3660992U, 3669184U, 3677888U, - 3685952U, 3694528U, 3702592U, 3710528U, 3719104U, 3727168U, 3735488U, - 3742784U, 3751232U, 3759424U, 3765184U, 3775808U, 3783872U, 3792832U, - 3800768U, 3808832U, 3816256U, 3825344U, 3832768U, 3841856U, 3849536U, - 3857344U, 3866432U, 3874496U, 3882304U, 3890752U, 3899072U, 3907264U, - 3914816U, 3923008U, 3930688U, 3939904U, 3947968U, 3956416U, 3964736U, - 3972544U, 3981248U, 3988928U, 3997376U, 4005824U, 4012864U, 4020928U, - 4030144U, 4038592U, 4045504U, 4054592U, 4063168U, 4071104U, 4079552U, - 4087232U, 4095808U, 4103872U, 4111168U, 4120384U, 4127936U, 4136512U, - 4144832U, 4153024U, 4160704U, 4169408U, 4177216U, 4186048U, 4193344U, - 4202048U, 4210496U, 4217536U, 4227008U, 4235072U, 4243264U, 4251584U, - 4259392U, 4267712U, 4275776U, 4284352U, 4291904U, 4300096U, 4307648U, - 4316992U, 4325056U, 4333376U, 4341056U, 4349888U, 4357568U, 4366016U, - 4374464U, 4382528U, 4390208U, 4398656U, 4407232U, 4413632U, 4423616U, - 4431808U, 4439744U, 4447936U, 4455872U, 4463296U, 4472128U, 4480576U, - 4489024U, 4497344U, 4505152U, 4512448U, 4520896U, 4530112U, 4537664U, - 4546496U, 4554688U, 4562752U, 4570816U, 4579264U, 4586944U, 4595648U, - 4603712U, 4611392U, 4619072U, 4628032U, 4635584U, 4643776U, 4652864U, - 4660672U, 4669376U, 4677056U, 4684096U, 4693184U, 4702144U, 4710208U, - 4718528U, 4726336U, 4734272U, 4742464U, 4750784U, 4759232U, 4767296U, - 4775872U, 4783808U, 4791872U, 4797376U, 4808512U, 4816192U, 4825024U, - 4832704U, 4841024U, 4849472U, 4856512U, 4865984U, 4874176U, 4882112U, - 4889792U, 4898752U, 4906688U, 4913984U, 4922816U, 4931008U, 4938944U, - 4946624U, 4955584U, 4964032U, 4972096U, 4980032U, 4988864U, 4997056U, - 5004992U, 5012288U, 5020096U, 5029312U, 5037632U, 5045696U, 5052224U, - 5062592U, 5070784U, 5078848U, 5086784U, 5095232U, 5100736U, 5111488U, - 5119936U, 5127104U, 5136064U, 5143616U, 5151424U, 5160256U, 5168704U, - 5175232U, 5185472U, 5192384U, 5199296U, 5209664U, 5218112U, 5225536U, - 5233472U, 5242816U, 5250496U, 5258944U, 5267264U, 5274944U, 5283776U, - 5290048U, 5300032U, 5308096U, 5316544U, 5323328U, 5331904U, 5340736U, - 5349056U, 5356864U, 5365312U, 5372096U, 5381696U, 5390272U, 5398336U, - 5405888U, 5413696U, 5422784U, 5430976U, 5439424U, 5446976U, 5455808U, - 5463616U, 5471168U, 5480128U, 5488064U, 5494592U, 5504704U, 5513152U, - 5521216U, 5529536U, 5536576U, 5544256U, 5554112U, 5559616U, 5570368U, - 5577664U, 5586752U, 5594944U, 5603008U, 5611456U, 5619392U, 5627584U, - 5634368U, 5643328U, 5651264U, 5659328U, 5667008U, 5675584U, 5684416U, - 5692864U, 5701568U, 5709632U, 5717056U, 5725376U, 5734336U, 5740096U, - 5750336U, 5758912U, 5766848U, 5775296U, 5782976U, 5790784U, 5799616U, - 5807936U, 5815232U, 5823808U, 5832256U, 5840192U, 5848768U, 5856832U, - 5864896U, 5873344U, 5879872U, 5888576U, 5897792U, 5905216U, 5914432U, - 5920448U, 5930944U, 5938624U, 5947328U, 5955392U, 5963456U, 5971648U, - 5979328U, 5988032U, 5995712U, 6003904U, 6012736U, 6021056U, 6029248U, - 6037184U, 6045632U, 6053312U, 6061376U, 6070208U, 6077504U, 6086464U, - 6094784U, 6101696U, 6110912U, 6118592U, 6127168U, 6135616U, 6143296U, - 6150208U, 6158912U, 6168128U, 6175808U, 6182464U, 6192832U, 6201152U, - 6209344U, 6217664U, 6224576U, 6233408U, 6241472U, 6249664U, 6258496U, - 6266816U, 6275008U, 6281152U, 6291136U, 6299456U, 6306752U, 6314816U, - 6323776U, 6332096U, 6339392U, 6348224U, 6356288U, 6364096U, 6373184U, - 6381376U, 6389696U, 6397504U, 6404416U, 6413632U, 6421952U, 6430016U, - 6437824U, 6446912U, 6454592U, 6463168U, 6471616U, 6478144U, 6487232U, - 6496192U, 6504128U, 6511936U, 6520256U, 6528832U, 6536896U, 6544576U, - 6553408U, 6561472U, 6569792U, 6577216U, 6586304U, 6592448U, 6601024U, - 6610624U, 6619072U, 6627136U, 6634816U, 6643264U, 6650816U, 6659776U, - 6667712U, 6675904U, 6682688U, 6691904U, 6700864U, 6709184U, 6717376U, - 6724544U, 6733504U, 6741824U, 6749888U, 6756032U, 6766528U, 6773056U, - 6782912U, 6790976U, 6798016U, 6807488U, 6815168U, 6823744U, 6832064U, - 6840128U, 6847552U, 6855872U, 6864064U, 6872128U, 6880576U, 6889408U, - 6897472U, 6905792U, 6913472U, 6920896U, 6930368U, 6938432U, 6946624U, - 6953536U, 6963136U, 6971072U, 6979136U, 6986944U, 6995392U, 7003712U, - 7012288U, 7019072U, 7028416U, 7036352U, 7044416U, 7051712U, 7060672U, - 7069376U, 7077568U, 7085504U, 7092544U, 7102016U, 7110592U, 7118656U, - 7126208U, 7135168U, 7143104U, 7150912U, 7159744U, 7167808U, 7175744U, - 7184192U, 7191232U, 7200448U, 7207744U, 7216576U, 7224128U, 7233472U, - 7241536U, 7249856U, 7256512U, 7264832U, 7274048U, 7282112U, 7290176U, - 7298752U, 7306688U, 7315136U, 7322816U, 7331392U, 7339456U, 7347776U, - 7356224U, 7364288U, 7371712U, 7380928U, 7387456U, 7396544U, 7404352U, - 7413568U, 7421632U, 7429696U, 7436864U, 7446464U, 7454144U, 7461952U, - 7470784U, 7478336U, 7487296U, 7495616U, 7503424U, 7511872U, 7520192U, - 7527616U, 7536448U, 7544512U, 7551424U, 7560128U, 7568576U, 7577536U, - 7583552U, 7592512U, 7600448U, 7610048U, 7618496U, 7626176U, 7634752U, - 7642816U, 7651264U, 7659328U, 7667008U, 7675456U, 7683136U, 7691584U, - 7700416U, 7707584U, 7716416U, 7724224U, 7733056U, 7740608U, 7749184U, - 7756096U, 7765952U, 7774016U, 7781824U, 7790528U, 7798592U, 7805888U, - 7814336U, 7822784U, 7831232U, 7839296U, 7847104U, 7855552U, 7863616U, - 7872448U, 7880128U, 7888576U, 7896256U, 7905088U, 7912768U, 7920448U, - 7928768U, 7937344U, 7945792U, 7953728U, 7959488U, 7970752U, 7978816U, - 7987136U, 7994816U, 8003392U, 8011712U, 8019904U, 8027456U, 8035264U, - 8044352U, 8052544U, 8060224U, 8069056U, 8076736U, 8084672U, 8093504U, - 8101312U, 8110016U, 8117696U, 8125888U, 8134592U, 8142016U, 8149952U, - 8159168U, 8166976U, 8175296U, 8183488U, 8191808U, 8199616U, 8207296U, - 8216128U, 8224576U, 8232256U, 8241088U, 8248256U, 8257472U, 8264128U, - 8273728U, 8281792U, 8290112U, 8297152U, 8305216U, 8314816U, 8322752U, - 8330944U, 8339392U, 8347072U, 8355392U, 8363968U, 8371904U, 8379328U, - 8388544U, 8394944U, 8404544U, 8412736U, 8421184U, 8429504U, 8437696U, - 8445376U, 8452544U, 8460736U, 8470208U, 8478016U, 8486848U, 8494144U, - 8503232U, 8511296U, 8519488U, 8527424U, 8534464U, 8543936U, 8552384U, - 8558912U, 8568128U, 8575936U, 8584256U, 8593216U, 8601536U, 8608832U, - 8616896U, 8625728U, 8634176U, 8641856U, 8649664U, 8658112U, 8666176U, - 8674112U, 8682944U, 8691136U, 8699456U, 8707648U, 8716096U, 8724416U, - 8732608U, 8740672U, 8748352U, 8756032U, 8764864U, 8773568U, 8781376U, - 8789824U, 8796992U, 8806208U, 8814272U, 8822336U, 8830912U, 8838848U, - 8847296U, 8854336U, 8863552U, 8871488U, 8879296U, 8887616U, 8894528U, - 8904512U, 8911424U, 8920768U, 8928704U, 8936128U, 8944576U, 8953664U, - 8960576U, 8970176U, 8977984U, 8986304U, 8994112U, 9002432U, 9011008U, - 9018176U, 9026624U, 9035584U, 9043904U, 9052096U, 9059264U, 9068096U, - 9075904U, 9084224U, 9092288U, 9100352U, 9108928U, 9116992U, 9125824U, - 9133504U, 9141824U, 9150272U, 9157952U, 9164608U, 9174848U, 9182912U, - 9190976U, 9199552U, 9205312U, 9215936U, 9222592U, 9232192U, 9240512U, - 9248704U, 9256256U, 9264832U, 9272896U, 9281344U, 9288896U, 9297088U, - 9305536U, 9313984U, 9322304U, 9329728U, 9337792U, 9346112U, 9355072U, - 9363136U, 9371072U, 9378752U, 9387712U, 9395648U, 9404224U, 9411008U, - 9420608U, 9428416U, 9436864U, 9445312U, 9453376U, 9460928U, 9468736U, - 9477824U, 9485248U, 9493696U, 9502144U, 9509056U, 9518528U, 9527104U, - 9535424U, 9543616U, 9551296U, 9559744U, 9568192U, 9576256U, 9584576U, - 9591872U, 9600704U, 9608384U, 9615808U, 9624512U, 9633472U, 9641536U, - 9649856U, 9658048U, 9665728U, 9674432U, 9682496U, 9691072U, 9699136U, - 9707072U, 9715136U, 9722176U, 9732032U, 9740096U, 9747904U, 9756352U, - 9764288U, 9771584U, 9780544U, 9789376U, 9796928U, 9804224U, 9813952U, - 9822016U, 9829696U, 9838016U, 9845824U, 9852992U, 9863104U, 9870656U, - 9878464U, 9887552U, 9895744U, 9903808U, 9912128U, 9920192U, 9927616U, - 9936064U, 9944768U, 9952576U, 9960128U, 9969472U, 9977152U, 9985216U, - 9994048U, 10001216U, 10007744U, 10018496U, 10026944U, 10035136U, 10042432U, - 10051264U, 10059584U, 10067648U, 10075712U, 10083904U, 10091456U, 10100672U, - 10108864U, 10116928U, 10124864U, 10133056U, 10140736U, 10149824U, 10156736U, - 10165952U, 10173376U, 10182208U, 10190528U, 10198336U, 10206272U, 10213696U, - 10223296U, 10231744U, 10238656U, 10247488U, 10256192U, 10263872U, 10272448U, - 10280896U, 10288448U, 10296512U, 10305088U, 10313536U, 10321088U, 10330048U, - 10337984U, 10346176U, 10354112U, 10362304U, 10369088U, 10377152U, 10386752U, - 10394816U, 10403648U, 10411712U, 10418624U, 10427968U, 10436032U, 10444736U, - 10452928U, 10459712U, 10468672U, 10476608U, 10484416U, 10491328U, 10501952U, - 10509376U, 10517824U, 10526528U, 10534336U, 10542656U, 10549696U, 10559168U, - 10566592U, 10575808U, 10583488U, 10590656U, 10599488U, 10607936U, 10616768U, - 10624832U, 10630336U, 10640576U, 10649536U, 10655168U, 10665152U, 10674112U, - 10682176U, 10690496U, 10698176U, 10705216U, 10715072U, 10722752U, 10731328U, - 10739264U, 10746688U, 10754752U, 10761664U, 10770752U, 10779712U, 10787776U, - 10796608U, 10803392U, 10812352U, 10821056U, 10828736U, 10837952U, 10846144U, - 10853824U, 10861376U, 10869952U, 10877248U, 10887104U, 10895296U, 10903232U, - 10910912U, 10918976U, 10927936U, 10935872U, 10944448U, 10952384U, 10960832U, - 10968512U, 10977088U, 10985024U, 10992832U, 11000896U, 11009984U, 11018048U, - 11026112U, 11034304U, 11042624U, 11050432U, 11058368U, 11064512U, 11075392U, - 11083712U, 11091776U, 11099584U, 11107904U, 11115968U, 11124416U, 11131712U, - 11141056U, 11148608U, 11157184U, 11165248U, 11173312U, 11180992U, 11189056U, - 11197376U, 11206592U, 11214656U, 11222336U, 11230784U, 11238464U, 11246528U, - 11254976U, 11263552U, 11271872U, 11279552U, 11288512U, 11296576U, 11304256U, - 11312192U, 11320768U, 11329216U, 11336384U, 11345216U, 11352512U, 11362112U, - 11369408U, 11378624U, 11386688U, 11394496U, 11402816U, 11411264U, 11418688U, - 11427776U, 11435584U, 11444032U, 11452096U, 11459648U, 11467072U, 11476928U, - 11484992U, 11493184U, 11500352U, 11509312U, 11517248U, 11524928U, 11534144U, - 11542208U, 11550272U, 11556416U, 11566784U, 11574208U, 11581376U, 11589568U, - 11599552U, 11607104U, 11616064U, 11623616U, 11632576U, 11639872U, 11648704U, - 11657024U, 11664704U, 11672896U, 11681216U, 11689792U, 11697856U, 11705536U, - 11714368U, 11722688U, 11730496U, 11737408U, 11745728U, 11754304U, 11763008U, - 11770816U, 11779648U, 11788096U, 11795776U, 11804608U, 11812544U, 11820992U, - 11829184U, 11837248U, 11844928U, 11852096U, 11860928U, 11869888U, 11878336U, - 11886272U, 11894336U, 11902144U, 11910848U, 11919296U, 11925952U, 11934784U, - 11943616U, 11951552U, 11960128U, 11968192U, 11976512U, 11983168U, 11992768U, - 12000832U, 12008896U, 12016832U, 12025408U, 12033856U, 12042176U, 12049984U, - 12058048U, 12066112U, 12073792U, 12082624U, 12091328U, 12098752U, 12106816U, - 12115904U, 12124096U, 12131776U, 12140224U, 12148672U, 12156736U, 12164032U, - 12173248U, 12181184U, 12186176U, 12197824U, 12205888U, 12213952U, 12218944U, - 12230336U, 12238784U, 12246592U, 12254272U, 12262336U, 12269888U, 12279104U, - 12287936U, 12295744U, 12304064U, 12312512U, 12319936U, 12328768U, 12337088U, - 12344896U, 12352832U, 12361408U, 12368704U, 12377152U, 12384832U, 12394432U, - 12402496U, 12409024U, 12417728U, 12426688U, 12433216U, 12443584U, 12450752U, - 12459968U, 12468032U, 12475712U, 12484544U, 12492608U, 12500416U, 12508352U, - 12517184U, 12525376U, 12532288U, 12541888U, 12549568U, 12556864U, 12565568U, - 12574528U, 12582208U, 12590528U, 12598592U, 12607424U, 12615488U, 12623552U, - 12631744U, 12638656U, 12647744U, 12656576U, 12664768U, 12672832U, 12680896U, - 12688576U, 12697408U, 12704192U, 12713408U, 12721216U, 12729664U, 12738496U, - 12745792U, 12754496U, 12762688U, 12769472U, 12779456U, 12787648U, 12795712U, - 12804032U, 12812224U, 12819008U, 12828352U, 12836672U, 12844736U, 12851648U, - 12859456U, 12868672U, 12877504U, 12885568U, 12892864U, 12902336U, 12909376U, - 12918208U, 12926656U, 12934976U, 12942784U, 12951104U, 12959552U, 12967744U, - 12976064U, 12984256U, 12991936U, 12999488U, 13007936U, 13016768U, 13021504U, - 13033024U, 13041472U, 13049408U, 13057472U, 13065664U, 13072064U, 13081408U, - 13089344U, 13098688U, 13107008U, 13115072U, 13122752U, 13130944U, 13139648U, - 13147712U, 13155776U, 13162432U, 13172672U, 13180864U, 13188928U, 13196992U, - 13203392U, 13213504U, 13219264U, 13228736U, 13236928U, 13244992U, 13253056U, - 13262528U, 13269952U, 13278784U, 13285952U, 13295552U, 13303616U, 13311808U, - 13319744U, 13328192U, 13336256U, 13344704U, 13352384U, 13360576U, 13369024U, - 13377344U, 13385408U, 13393216U, 13401664U, 13410112U, 13418176U, 13426496U, - 13434688U, 13442368U, 13451072U, 13459136U, 13466944U, 13475648U, 13482944U, - 13491904U, 13500352U, 13508288U, 13516736U, 13524416U, 13532224U, 13541312U, - 13549504U, 13556288U, 13564736U, 13573184U, 13581376U, 13587008U, 13598656U, - 13605952U, 13612864U, 13622464U, 13631168U, 13639616U, 13647808U, 13655104U, - 13663424U, 13671872U, 13680064U, 13688768U, 13696576U, 13705024U, 13712576U, - 13721536U, 13729216U, 13737664U, 13746112U, 13753024U, 13759552U, 13770304U, - 13777856U, 13786688U, 13793984U, 13802176U, 13811264U, 13819328U, 13827904U, - 13835456U, 13844416U, 13851584U, 13860544U, 13868992U, 13877056U, 13884608U, - 13893184U, 13901248U, 13909696U, 13917632U, 13925056U, 13934528U, 13942336U, - 13950784U, 13959104U, 13966912U, 13975232U, 13982656U, 13991872U, 13999936U, - 14007872U, 14016064U, 14024512U, 14032064U, 14040896U, 14049088U, 14057408U, - 14065088U, 14072896U, 14081344U, 14089664U, 14097856U, 14106304U, 14114752U, - 14122688U, 14130752U, 14138816U, 14147008U, 14155072U, 14163904U, 14170432U, - 14180288U, 14187328U, 14196032U, 14204864U, 14212672U, 14220736U, 14229056U, - 14237504U, 14245568U, 14253632U, 14261824U, 14269888U, 14278592U, 14286656U, - 14293696U, 14302784U, 14309696U, 14317504U, 14326336U, 14335936U, 14343232U, - 14352064U, 14359232U, 14368064U, 14376512U, 14384576U, 14393024U, 14401472U, - 14409536U, 14416832U, 14424512U, 14433856U, 14440768U, 14449984U, 14458816U, - 14465728U, 14474816U, 14482112U, 14491328U, 14499392U, 14506816U, 14516032U, - 14524352U, 14531392U, 14540224U, 14547392U, 14556992U, 14565184U, 14573248U, - 14580928U, 14588864U, 14596928U, 14606272U, 14613824U, 14622656U, 14630464U, - 14638912U, 14646976U, 14655296U, 14661952U, 14671808U, 14679872U, 14687936U, - 14696384U, 14704576U, 14710336U, 14720192U, 14729152U, 14736448U, 14745152U, - 14752448U, 14761792U, 14769856U, 14777024U, 14785984U, 14792384U, 14802752U, - 14810816U, 14819264U, 14827328U, 14835136U, 14843072U, 14851264U, 14860096U, - 14867648U, 14876096U, 14884544U, 14892736U, 14900672U, 14907968U, 14917312U, - 14924864U, 14933824U, 14939968U, 14950336U, 14957632U, 14966464U, 14974912U, - 14982592U, 14991296U, 14999104U, 15006272U, 15015232U, 15023936U, 15031616U, - 15040448U, 15047488U, 15055552U, 15063616U, 15073216U, 15079744U, 15088064U, - 15097664U, 15105344U, 15113792U, 15122368U, 15130048U, 15137728U, 15146176U, - 15154112U, 15162688U, 15171392U, 15179456U, 15187264U, 15194176U, 15204032U, - 15212224U, 15220544U, 15227456U, 15237056U, 15245248U, 15253184U, 15261632U, - 15269824U, 15277376U, 15285824U, 15293888U, 15301568U, 15310784U, 15318848U, - 15325504U, 15335104U, 15343168U, 15350848U, 15359936U, 15367232U, 15373376U, - 15384256U, 15392576U, 15400384U, 15408832U, 15417152U, 15424832U, 15433024U, - 15441344U, 15449152U, 15457088U, 15466432U, 15474112U, 15482816U, 15488576U, - 15499072U, 15505856U, 15514816U, 15523264U, 15531584U, 15540032U, 15547328U, - 15553984U, 15564608U, 15571904U, 15579968U, 15589312U, 15597376U, 15605696U, - 15612992U, 15621824U, 15630016U, 15638464U, 15646144U, 15654592U, 15662912U, - 15671104U, 15677248U, 15686848U, 15693376U, 15701696U, 15712064U, 15720256U, - 15728576U, 15736384U, 15744704U, 15752512U, 15761344U, 15769024U, 15777728U, - 15785152U, 15793984U, 15802048U, 15809984U, 15817024U, 15825856U, 15834944U, - 15843008U, 15849664U, 15859136U, 15866432U, 15876032U, 15884096U, 15892288U, - 15900608U, 15908416U, 15916864U, 15924928U, 15930176U, 15941056U, 15949504U, - 15957824U, 15965632U, 15973952U, 15982528U, 15990592U, 15998272U, 16006976U, - 16012736U, 16023104U, 16031296U, 16039616U, 16048064U, 16055744U, 16064192U, - 16071488U, 16080832U, 16088768U, 16097216U, 16104896U, 16112704U, 16121792U, - 16129856U, 16138048U, 16146112U, 16154176U, 16162624U, 16170688U, 16177856U, - 16186816U, 16195136U, 16202176U, 16211648U, 16220096U, 16228288U, 16235584U, - 16244672U, 16252864U, 16260544U, 16269248U, 16277056U, 16285504U, 16291648U, - 16301632U, 16309312U, 16318144U, 16326208U, 16333888U, 16342336U, 16351168U, - 16359232U, 16367552U, 16375616U, 16383296U, 16391744U, 16398016U, 16407616U, - 16415936U, 16424896U, 16432448U, 16440896U, 16449088U, 16457024U, 16465472U, - 16474048U, 16481216U, 16490048U, 16498624U, 16505792U, 16513984U, 16523072U, - 16531136U, 16538944U, 16547264U, 16555328U, 16563776U, 16570816U, 16578112U, - 16587712U, 16596544U, 16604992U, 16613312U, 16620608U, 16629568U, 16637888U, - 16645696U, 16653632U, 16661696U, 16669888U, 16677568U, 16686272U, 16695232U, - 16703168U, 16710464U, 16719424U, 16726592U, 16733888U, 16744384U, 16752448U, - 16760768U, 16768448U, 16776896U, 16785344U, 16793536U, 16801216U, 16809664U, - 16818112U, 16826176U, 16833472U, 16842688U, 16850752U, 16859072U, 16866368U, - 16875328U, 16883392U, 16891712U, 16899776U, 16907456U, 16915264U, 16924352U, - 16931776U, 16940608U, 16949056U, 16957376U, 16965056U, 16973248U, 16981696U, - 16990144U, 16997056U, 17005888U, 17014208U, 17021504U, 17031104U, 17039296U, - 17046976U, 17055424U, 17062592U, 17070016U, 17079488U, 17087936U, 17096512U, - 17104576U, 17113024U, 17121088U, 17129408U, 17136832U, 17145664U, 17152832U, - 17161792U, 17170112U, 17177792U, 17186368U, 17194304U, 17202496U, 17211328U, - 17218624U, 17227712U, 17233984U, 17243584U, 17251904U, 17259712U, 17266624U, - 17276608U, 17284672U, 17292224U, 17301056U, 17309632U, 17317568U, 17326016U, - 17333824U, 17342272U, 17350208U, 17358784U, 17366848U, 17374912U, 17382592U, - 17390656U, 17399488U, 17406784U, 17413952U, 17423936U, 17432512U, 17440448U, - 17447744U, 17456704U, 17464768U, 17472064U, 17481536U, 17489344U, 17495488U, - 17505728U, 17513792U, 17522368U, 17530816U, 17538112U, 17546944U, 17555264U, - 17563072U, 17569856U, 17579456U, 17587904U, 17596352U, 17603776U, 17611712U, - 17620672U, 17628992U, 17637184U, 17645504U, 17653568U, 17661632U, 17669824U, - 17677376U, 17686208U, 17693888U, 17702336U, 17710144U, 17718208U, 17726528U, - 17734336U, 17743808U, 17751872U, 17759936U, 17766592U, 17776448U, 17784512U, - 17791936U, 17801152U, 17809216U, 17817152U +const uint64_t cache_sizes[2048] = { + 16776896U, 16907456U, 17039296U, 17170112U, 17301056U, 17432512U, 17563072U, + 17693888U, 17824192U, 17955904U, 18087488U, 18218176U, 18349504U, 18481088U, + 18611392U, 18742336U, 18874304U, 19004224U, 19135936U, 19267264U, 19398208U, + 19529408U, 19660096U, 19791424U, 19922752U, 20053952U, 20184896U, 20315968U, + 20446912U, 20576576U, 20709184U, 20840384U, 20971072U, 21102272U, 21233216U, + 21364544U, 21494848U, 21626816U, 21757376U, 21887552U, 22019392U, 22151104U, + 22281536U, 22412224U, 22543936U, 22675264U, 22806464U, 22935872U, 23068096U, + 23198272U, 23330752U, 23459008U, 23592512U, 23723968U, 23854912U, 23986112U, + 24116672U, 24247616U, 24378688U, 24509504U, 24640832U, 24772544U, 24903488U, + 25034432U, 25165376U, 25296704U, 25427392U, 25558592U, 25690048U, 25820096U, + 25951936U, 26081728U, 26214208U, 26345024U, 26476096U, 26606656U, 26737472U, + 26869184U, 26998208U, 27131584U, 27262528U, 27393728U, 27523904U, 27655744U, + 27786688U, 27917888U, 28049344U, 28179904U, 28311488U, 28441792U, 28573504U, + 28700864U, 28835648U, 28966208U, 29096768U, 29228608U, 29359808U, 29490752U, + 29621824U, 29752256U, 29882816U, 30014912U, 30144448U, 30273728U, 30406976U, + 30538432U, 30670784U, 30799936U, 30932672U, 31063744U, 31195072U, 31325248U, + 31456192U, 31588288U, 31719232U, 31850432U, 31981504U, 32110784U, 32243392U, + 32372672U, 32505664U, 32636608U, 32767808U, 32897344U, 33029824U, 33160768U, + 33289664U, 33423296U, 33554368U, 33683648U, 33816512U, 33947456U, 34076992U, + 34208704U, 34340032U, 34471744U, 34600256U, 34734016U, 34864576U, 34993984U, + 35127104U, 35258176U, 35386688U, 35518528U, 35650624U, 35782336U, 35910976U, + 36044608U, 36175808U, 36305728U, 36436672U, 36568384U, 36699968U, 36830656U, + 36961984U, 37093312U, 37223488U, 37355072U, 37486528U, 37617472U, 37747904U, + 37879232U, 38009792U, 38141888U, 38272448U, 38403392U, 38535104U, 38660672U, + 38795584U, 38925632U, 39059264U, 39190336U, 39320768U, 39452096U, 39581632U, + 39713984U, 39844928U, 39974848U, 40107968U, 40238144U, 40367168U, 40500032U, + 40631744U, 40762816U, 40894144U, 41023552U, 41155904U, 41286208U, 41418304U, + 41547712U, 41680448U, 41811904U, 41942848U, 42073792U, 42204992U, 42334912U, + 42467008U, 42597824U, 42729152U, 42860096U, 42991552U, 43122368U, 43253696U, + 43382848U, 43515712U, 43646912U, 43777088U, 43907648U, 44039104U, 44170432U, + 44302144U, 44433344U, 44564288U, 44694976U, 44825152U, 44956864U, 45088448U, + 45219008U, 45350464U, 45481024U, 45612608U, 45744064U, 45874496U, 46006208U, + 46136768U, 46267712U, 46399424U, 46529344U, 46660672U, 46791488U, 46923328U, + 47053504U, 47185856U, 47316928U, 47447872U, 47579072U, 47710144U, 47839936U, + 47971648U, 48103232U, 48234176U, 48365248U, 48496192U, 48627136U, 48757312U, + 48889664U, 49020736U, 49149248U, 49283008U, 49413824U, 49545152U, 49675712U, + 49807168U, 49938368U, 50069056U, 50200256U, 50331584U, 50462656U, 50593472U, + 50724032U, 50853952U, 50986048U, 51117632U, 51248576U, 51379904U, 51510848U, + 51641792U, 51773248U, 51903296U, 52035136U, 52164032U, 52297664U, 52427968U, + 52557376U, 52690112U, 52821952U, 52952896U, 53081536U, 53213504U, 53344576U, + 53475776U, 53608384U, 53738816U, 53870528U, 54000832U, 54131776U, 54263744U, + 54394688U, 54525248U, 54655936U, 54787904U, 54918592U, 55049152U, 55181248U, + 55312064U, 55442752U, 55574336U, 55705024U, 55836224U, 55967168U, 56097856U, + 56228672U, 56358592U, 56490176U, 56621888U, 56753728U, 56884928U, 57015488U, + 57146816U, 57278272U, 57409216U, 57540416U, 57671104U, 57802432U, 57933632U, + 58064576U, 58195264U, 58326976U, 58457408U, 58588864U, 58720192U, 58849984U, + 58981696U, 59113024U, 59243456U, 59375552U, 59506624U, 59637568U, 59768512U, + 59897792U, 60030016U, 60161984U, 60293056U, 60423872U, 60554432U, 60683968U, + 60817216U, 60948032U, 61079488U, 61209664U, 61341376U, 61471936U, 61602752U, + 61733696U, 61865792U, 61996736U, 62127808U, 62259136U, 62389568U, 62520512U, + 62651584U, 62781632U, 62910784U, 63045056U, 63176128U, 63307072U, 63438656U, + 63569216U, 63700928U, 63831616U, 63960896U, 64093888U, 64225088U, 64355392U, + 64486976U, 64617664U, 64748608U, 64879424U, 65009216U, 65142464U, 65273792U, + 65402816U, 65535424U, 65666752U, 65797696U, 65927744U, 66060224U, 66191296U, + 66321344U, 66453056U, 66584384U, 66715328U, 66846656U, 66977728U, 67108672U, + 67239104U, 67370432U, 67501888U, 67631296U, 67763776U, 67895104U, 68026304U, + 68157248U, 68287936U, 68419264U, 68548288U, 68681408U, 68811968U, 68942912U, + 69074624U, 69205568U, 69337024U, 69467584U, 69599168U, 69729472U, 69861184U, + 69989824U, 70122944U, 70253888U, 70385344U, 70515904U, 70647232U, 70778816U, + 70907968U, 71040832U, 71171648U, 71303104U, 71432512U, 71564992U, 71695168U, + 71826368U, 71958464U, 72089536U, 72219712U, 72350144U, 72482624U, 72613568U, + 72744512U, 72875584U, 73006144U, 73138112U, 73268672U, 73400128U, 73530944U, + 73662272U, 73793344U, 73924544U, 74055104U, 74185792U, 74316992U, 74448832U, + 74579392U, 74710976U, 74841664U, 74972864U, 75102784U, 75233344U, 75364544U, + 75497024U, 75627584U, 75759296U, 75890624U, 76021696U, 76152256U, 76283072U, + 76414144U, 76545856U, 76676672U, 76806976U, 76937792U, 77070016U, 77200832U, + 77331392U, 77462464U, 77593664U, 77725376U, 77856448U, 77987776U, 78118336U, + 78249664U, 78380992U, 78511424U, 78642496U, 78773056U, 78905152U, 79033664U, + 79166656U, 79297472U, 79429568U, 79560512U, 79690816U, 79822784U, 79953472U, + 80084672U, 80214208U, 80346944U, 80477632U, 80608576U, 80740288U, 80870848U, + 81002048U, 81133504U, 81264448U, 81395648U, 81525952U, 81657536U, 81786304U, + 81919808U, 82050112U, 82181312U, 82311616U, 82443968U, 82573376U, 82705984U, + 82835776U, 82967744U, 83096768U, 83230528U, 83359552U, 83491264U, 83622464U, + 83753536U, 83886016U, 84015296U, 84147776U, 84277184U, 84409792U, 84540608U, + 84672064U, 84803008U, 84934336U, 85065152U, 85193792U, 85326784U, 85458496U, + 85589312U, 85721024U, 85851968U, 85982656U, 86112448U, 86244416U, 86370112U, + 86506688U, 86637632U, 86769344U, 86900672U, 87031744U, 87162304U, 87293632U, + 87424576U, 87555392U, 87687104U, 87816896U, 87947968U, 88079168U, 88211264U, + 88341824U, 88473152U, 88603712U, 88735424U, 88862912U, 88996672U, 89128384U, + 89259712U, 89390272U, 89521984U, 89652544U, 89783872U, 89914816U, 90045376U, + 90177088U, 90307904U, 90438848U, 90569152U, 90700096U, 90832832U, 90963776U, + 91093696U, 91223744U, 91356992U, 91486784U, 91618496U, 91749824U, 91880384U, + 92012224U, 92143552U, 92273344U, 92405696U, 92536768U, 92666432U, 92798912U, + 92926016U, 93060544U, 93192128U, 93322816U, 93453632U, 93583936U, 93715136U, + 93845056U, 93977792U, 94109504U, 94240448U, 94371776U, 94501184U, 94632896U, + 94764224U, 94895552U, 95023424U, 95158208U, 95287744U, 95420224U, 95550016U, + 95681216U, 95811904U, 95943872U, 96075328U, 96203584U, 96337856U, 96468544U, + 96599744U, 96731072U, 96860992U, 96992576U, 97124288U, 97254848U, 97385536U, + 97517248U, 97647808U, 97779392U, 97910464U, 98041408U, 98172608U, 98303168U, + 98434496U, 98565568U, 98696768U, 98827328U, 98958784U, 99089728U, 99220928U, + 99352384U, 99482816U, 99614272U, 99745472U, 99876416U, 100007104U, + 100138048U, 100267072U, 100401088U, 100529984U, 100662592U, 100791872U, + 100925248U, 101056064U, 101187392U, 101317952U, 101449408U, 101580608U, + 101711296U, 101841728U, 101973824U, 102104896U, 102235712U, 102366016U, + 102498112U, 102628672U, 102760384U, 102890432U, 103021888U, 103153472U, + 103284032U, 103415744U, 103545152U, 103677248U, 103808576U, 103939648U, + 104070976U, 104201792U, 104332736U, 104462528U, 104594752U, 104725952U, + 104854592U, 104988608U, 105118912U, 105247808U, 105381184U, 105511232U, + 105643072U, 105774784U, 105903296U, 106037056U, 106167872U, 106298944U, + 106429504U, 106561472U, 106691392U, 106822592U, 106954304U, 107085376U, + 107216576U, 107346368U, 107478464U, 107609792U, 107739712U, 107872192U, + 108003136U, 108131392U, 108265408U, 108396224U, 108527168U, 108657344U, + 108789568U, 108920384U, 109049792U, 109182272U, 109312576U, 109444928U, + 109572928U, 109706944U, 109837888U, 109969088U, 110099648U, 110230976U, + 110362432U, 110492992U, 110624704U, 110755264U, 110886208U, 111017408U, + 111148864U, 111279296U, 111410752U, 111541952U, 111673024U, 111803456U, + 111933632U, 112066496U, 112196416U, 112328512U, 112457792U, 112590784U, + 112715968U, 112852672U, 112983616U, 113114944U, 113244224U, 113376448U, + 113505472U, 113639104U, 113770304U, 113901376U, 114031552U, 114163264U, + 114294592U, 114425536U, 114556864U, 114687424U, 114818624U, 114948544U, + 115080512U, 115212224U, 115343296U, 115473472U, 115605184U, 115736128U, + 115867072U, 115997248U, 116128576U, 116260288U, 116391488U, 116522944U, + 116652992U, 116784704U, 116915648U, 117046208U, 117178304U, 117308608U, + 117440192U, 117569728U, 117701824U, 117833024U, 117964096U, 118094656U, + 118225984U, 118357312U, 118489024U, 118617536U, 118749632U, 118882112U, + 119012416U, 119144384U, 119275328U, 119406016U, 119537344U, 119668672U, + 119798464U, 119928896U, 120061376U, 120192832U, 120321728U, 120454336U, + 120584512U, 120716608U, 120848192U, 120979136U, 121109056U, 121241408U, + 121372352U, 121502912U, 121634752U, 121764416U, 121895744U, 122027072U, + 122157632U, 122289088U, 122421184U, 122550592U, 122682944U, 122813888U, + 122945344U, 123075776U, 123207488U, 123338048U, 123468736U, 123600704U, + 123731264U, 123861952U, 123993664U, 124124608U, 124256192U, 124386368U, + 124518208U, 124649024U, 124778048U, 124911296U, 125041088U, 125173696U, + 125303744U, 125432896U, 125566912U, 125696576U, 125829056U, 125958592U, + 126090304U, 126221248U, 126352832U, 126483776U, 126615232U, 126746432U, + 126876608U, 127008704U, 127139392U, 127270336U, 127401152U, 127532224U, + 127663552U, 127794752U, 127925696U, 128055232U, 128188096U, 128319424U, + 128449856U, 128581312U, 128712256U, 128843584U, 128973632U, 129103808U, + 129236288U, 129365696U, 129498944U, 129629888U, 129760832U, 129892288U, + 130023104U, 130154048U, 130283968U, 130416448U, 130547008U, 130678336U, + 130807616U, 130939456U, 131071552U, 131202112U, 131331776U, 131464384U, + 131594048U, 131727296U, 131858368U, 131987392U, 132120256U, 132250816U, + 132382528U, 132513728U, 132644672U, 132774976U, 132905792U, 133038016U, + 133168832U, 133299392U, 133429312U, 133562048U, 133692992U, 133823296U, + 133954624U, 134086336U, 134217152U, 134348608U, 134479808U, 134607296U, + 134741056U, 134872384U, 135002944U, 135134144U, 135265472U, 135396544U, + 135527872U, 135659072U, 135787712U, 135921472U, 136052416U, 136182848U, + 136313792U, 136444864U, 136576448U, 136707904U, 136837952U, 136970048U, + 137099584U, 137232064U, 137363392U, 137494208U, 137625536U, 137755712U, + 137887424U, 138018368U, 138149824U, 138280256U, 138411584U, 138539584U, + 138672832U, 138804928U, 138936128U, 139066688U, 139196864U, 139328704U, + 139460032U, 139590208U, 139721024U, 139852864U, 139984576U, 140115776U, + 140245696U, 140376512U, 140508352U, 140640064U, 140769856U, 140902336U, + 141032768U, 141162688U, 141294016U, 141426496U, 141556544U, 141687488U, + 141819584U, 141949888U, 142080448U, 142212544U, 142342336U, 142474432U, + 142606144U, 142736192U, 142868288U, 142997824U, 143129408U, 143258944U, + 143392448U, 143523136U, 143653696U, 143785024U, 143916992U, 144045632U, + 144177856U, 144309184U, 144440768U, 144570688U, 144701888U, 144832448U, + 144965056U, 145096384U, 145227584U, 145358656U, 145489856U, 145620928U, + 145751488U, 145883072U, 146011456U, 146144704U, 146275264U, 146407232U, + 146538176U, 146668736U, 146800448U, 146931392U, 147062336U, 147193664U, + 147324224U, 147455936U, 147586624U, 147717056U, 147848768U, 147979456U, + 148110784U, 148242368U, 148373312U, 148503232U, 148635584U, 148766144U, + 148897088U, 149028416U, 149159488U, 149290688U, 149420224U, 149551552U, + 149683136U, 149814976U, 149943616U, 150076352U, 150208064U, 150338624U, + 150470464U, 150600256U, 150732224U, 150862784U, 150993088U, 151125952U, + 151254976U, 151388096U, 151519168U, 151649728U, 151778752U, 151911104U, + 152042944U, 152174144U, 152304704U, 152435648U, 152567488U, 152698816U, + 152828992U, 152960576U, 153091648U, 153222976U, 153353792U, 153484096U, + 153616192U, 153747008U, 153878336U, 154008256U, 154139968U, 154270912U, + 154402624U, 154533824U, 154663616U, 154795712U, 154926272U, 155057984U, + 155188928U, 155319872U, 155450816U, 155580608U, 155712064U, 155843392U, + 155971136U, 156106688U, 156237376U, 156367424U, 156499264U, 156630976U, + 156761536U, 156892352U, 157024064U, 157155008U, 157284416U, 157415872U, + 157545536U, 157677248U, 157810496U, 157938112U, 158071744U, 158203328U, + 158334656U, 158464832U, 158596288U, 158727616U, 158858048U, 158988992U, + 159121216U, 159252416U, 159381568U, 159513152U, 159645632U, 159776192U, + 159906496U, 160038464U, 160169536U, 160300352U, 160430656U, 160563008U, + 160693952U, 160822208U, 160956352U, 161086784U, 161217344U, 161349184U, + 161480512U, 161611456U, 161742272U, 161873216U, 162002752U, 162135872U, + 162266432U, 162397888U, 162529216U, 162660032U, 162790976U, 162922048U, + 163052096U, 163184576U, 163314752U, 163446592U, 163577408U, 163707968U, + 163839296U, 163969984U, 164100928U, 164233024U, 164364224U, 164494912U, + 164625856U, 164756672U, 164887616U, 165019072U, 165150016U, 165280064U, + 165412672U, 165543104U, 165674944U, 165805888U, 165936832U, 166067648U, + 166198336U, 166330048U, 166461248U, 166591552U, 166722496U, 166854208U, + 166985408U, 167116736U, 167246656U, 167378368U, 167508416U, 167641024U, + 167771584U, 167903168U, 168034112U, 168164032U, 168295744U, 168427456U, + 168557632U, 168688448U, 168819136U, 168951616U, 169082176U, 169213504U, + 169344832U, 169475648U, 169605952U, 169738048U, 169866304U, 169999552U, + 170131264U, 170262464U, 170393536U, 170524352U, 170655424U, 170782016U, + 170917696U, 171048896U, 171179072U, 171310784U, 171439936U, 171573184U, + 171702976U, 171835072U, 171966272U, 172097216U, 172228288U, 172359232U, + 172489664U, 172621376U, 172747712U, 172883264U, 173014208U, 173144512U, + 173275072U, 173407424U, 173539136U, 173669696U, 173800768U, 173931712U, + 174063424U, 174193472U, 174325696U, 174455744U, 174586816U, 174718912U, + 174849728U, 174977728U, 175109696U, 175242688U, 175374272U, 175504832U, + 175636288U, 175765696U, 175898432U, 176028992U, 176159936U, 176291264U, + 176422592U, 176552512U, 176684864U, 176815424U, 176946496U, 177076544U, + 177209152U, 177340096U, 177470528U, 177600704U, 177731648U, 177864256U, + 177994816U, 178126528U, 178257472U, 178387648U, 178518464U, 178650176U, + 178781888U, 178912064U, 179044288U, 179174848U, 179305024U, 179436736U, + 179568448U, 179698496U, 179830208U, 179960512U, 180092608U, 180223808U, + 180354752U, 180485696U, 180617152U, 180748096U, 180877504U, 181009984U, + 181139264U, 181272512U, 181402688U, 181532608U, 181663168U, 181795136U, + 181926592U, 182057536U, 182190016U, 182320192U, 182451904U, 182582336U, + 182713792U, 182843072U, 182976064U, 183107264U, 183237056U, 183368384U, + 183494848U, 183631424U, 183762752U, 183893824U, 184024768U, 184154816U, + 184286656U, 184417984U, 184548928U, 184680128U, 184810816U, 184941248U, + 185072704U, 185203904U, 185335616U, 185465408U, 185596352U, 185727296U, + 185859904U, 185989696U, 186121664U, 186252992U, 186383552U, 186514112U, + 186645952U, 186777152U, 186907328U, 187037504U, 187170112U, 187301824U, + 187429184U, 187562048U, 187693504U, 187825472U, 187957184U, 188087104U, + 188218304U, 188349376U, 188481344U, 188609728U, 188743616U, 188874304U, + 189005248U, 189136448U, 189265088U, 189396544U, 189528128U, 189660992U, + 189791936U, 189923264U, 190054208U, 190182848U, 190315072U, 190447424U, + 190577984U, 190709312U, 190840768U, 190971328U, 191102656U, 191233472U, + 191364032U, 191495872U, 191626816U, 191758016U, 191888192U, 192020288U, + 192148928U, 192282176U, 192413504U, 192542528U, 192674752U, 192805952U, + 192937792U, 193068608U, 193198912U, 193330496U, 193462208U, 193592384U, + 193723456U, 193854272U, 193985984U, 194116672U, 194247232U, 194379712U, + 194508352U, 194641856U, 194772544U, 194900672U, 195035072U, 195166016U, + 195296704U, 195428032U, 195558592U, 195690304U, 195818176U, 195952576U, + 196083392U, 196214336U, 196345792U, 196476736U, 196607552U, 196739008U, + 196869952U, 197000768U, 197130688U, 197262784U, 197394368U, 197523904U, + 197656384U, 197787584U, 197916608U, 198049472U, 198180544U, 198310208U, + 198442432U, 198573632U, 198705088U, 198834368U, 198967232U, 199097792U, + 199228352U, 199360192U, 199491392U, 199621696U, 199751744U, 199883968U, + 200014016U, 200146624U, 200276672U, 200408128U, 200540096U, 200671168U, + 200801984U, 200933312U, 201062464U, 201194944U, 201326144U, 201457472U, + 201588544U, 201719744U, 201850816U, 201981632U, 202111552U, 202244032U, + 202374464U, 202505152U, 202636352U, 202767808U, 202898368U, 203030336U, + 203159872U, 203292608U, 203423296U, 203553472U, 203685824U, 203816896U, + 203947712U, 204078272U, 204208192U, 204341056U, 204472256U, 204603328U, + 204733888U, 204864448U, 204996544U, 205125568U, 205258304U, 205388864U, + 205517632U, 205650112U, 205782208U, 205913536U, 206044736U, 206176192U, + 206307008U, 206434496U, 206569024U, 206700224U, 206831168U, 206961856U, + 207093056U, 207223616U, 207355328U, 207486784U, 207616832U, 207749056U, + 207879104U, 208010048U, 208141888U, 208273216U, 208404032U, 208534336U, + 208666048U, 208796864U, 208927424U, 209059264U, 209189824U, 209321792U, + 209451584U, 209582656U, 209715136U, 209845568U, 209976896U, 210106432U, + 210239296U, 210370112U, 210501568U, 210630976U, 210763712U, 210894272U, + 211024832U, 211156672U, 211287616U, 211418176U, 211549376U, 211679296U, + 211812032U, 211942592U, 212074432U, 212204864U, 212334016U, 212467648U, + 212597824U, 212727616U, 212860352U, 212991424U, 213120832U, 213253952U, + 213385024U, 213515584U, 213645632U, 213777728U, 213909184U, 214040128U, + 214170688U, 214302656U, 214433728U, 214564544U, 214695232U, 214826048U, + 214956992U, 215089088U, 215219776U, 215350592U, 215482304U, 215613248U, + 215743552U, 215874752U, 216005312U, 216137024U, 216267328U, 216399296U, + 216530752U, 216661696U, 216790592U, 216923968U, 217054528U, 217183168U, + 217316672U, 217448128U, 217579072U, 217709504U, 217838912U, 217972672U, + 218102848U, 218233024U, 218364736U, 218496832U, 218627776U, 218759104U, + 218888896U, 219021248U, 219151936U, 219281728U, 219413056U, 219545024U, + 219675968U, 219807296U, 219938624U, 220069312U, 220200128U, 220331456U, + 220461632U, 220592704U, 220725184U, 220855744U, 220987072U, 221117888U, + 221249216U, 221378368U, 221510336U, 221642048U, 221772736U, 221904832U, + 222031808U, 222166976U, 222297536U, 222428992U, 222559936U, 222690368U, + 222820672U, 222953152U, 223083968U, 223213376U, 223345984U, 223476928U, + 223608512U, 223738688U, 223869376U, 224001472U, 224132672U, 224262848U, + 224394944U, 224524864U, 224657344U, 224788288U, 224919488U, 225050432U, + 225181504U, 225312704U, 225443776U, 225574592U, 225704768U, 225834176U, + 225966784U, 226097216U, 226229824U, 226360384U, 226491712U, 226623424U, + 226754368U, 226885312U, 227015104U, 227147456U, 227278528U, 227409472U, + 227539904U, 227669696U, 227802944U, 227932352U, 228065216U, 228196288U, + 228326464U, 228457792U, 228588736U, 228720064U, 228850112U, 228981056U, + 229113152U, 229243328U, 229375936U, 229505344U, 229636928U, 229769152U, + 229894976U, 230030272U, 230162368U, 230292416U, 230424512U, 230553152U, + 230684864U, 230816704U, 230948416U, 231079616U, 231210944U, 231342016U, + 231472448U, 231603776U, 231733952U, 231866176U, 231996736U, 232127296U, + 232259392U, 232388672U, 232521664U, 232652608U, 232782272U, 232914496U, + 233043904U, 233175616U, 233306816U, 233438528U, 233569984U, 233699776U, + 233830592U, 233962688U, 234092224U, 234221888U, 234353984U, 234485312U, + 234618304U, 234749888U, 234880832U, 235011776U, 235142464U, 235274048U, + 235403456U, 235535936U, 235667392U, 235797568U, 235928768U, 236057152U, + 236190272U, 236322752U, 236453312U, 236583616U, 236715712U, 236846528U, + 236976448U, 237108544U, 237239104U, 237371072U, 237501632U, 237630784U, + 237764416U, 237895232U, 238026688U, 238157632U, 238286912U, 238419392U, + 238548032U, 238681024U, 238812608U, 238941632U, 239075008U, 239206336U, + 239335232U, 239466944U, 239599168U, 239730496U, 239861312U, 239992384U, + 240122816U, 240254656U, 240385856U, 240516928U, 240647872U, 240779072U, + 240909632U, 241040704U, 241171904U, 241302848U, 241433408U, 241565248U, + 241696192U, 241825984U, 241958848U, 242088256U, 242220224U, 242352064U, + 242481856U, 242611648U, 242744896U, 242876224U, 243005632U, 243138496U, + 243268672U, 243400384U, 243531712U, 243662656U, 243793856U, 243924544U, + 244054592U, 244187072U, 244316608U, 244448704U, 244580032U, 244710976U, + 244841536U, 244972864U, 245104448U, 245233984U, 245365312U, 245497792U, + 245628736U, 245759936U, 245889856U, 246021056U, 246152512U, 246284224U, + 246415168U, 246545344U, 246675904U, 246808384U, 246939584U, 247070144U, + 247199552U, 247331648U, 247463872U, 247593536U, 247726016U, 247857088U, + 247987648U, 248116928U, 248249536U, 248380736U, 248512064U, 248643008U, + 248773312U, 248901056U, 249036608U, 249167552U, 249298624U, 249429184U, + 249560512U, 249692096U, 249822784U, 249954112U, 250085312U, 250215488U, + 250345792U, 250478528U, 250608704U, 250739264U, 250870976U, 251002816U, + 251133632U, 251263552U, 251395136U, 251523904U, 251657792U, 251789248U, + 251919424U, 252051392U, 252182464U, 252313408U, 252444224U, 252575552U, + 252706624U, 252836032U, 252968512U, 253099712U, 253227584U, 253361728U, + 253493056U, 253623488U, 253754432U, 253885504U, 254017216U, 254148032U, + 254279488U, 254410432U, 254541376U, 254672576U, 254803264U, 254933824U, + 255065792U, 255196736U, 255326528U, 255458752U, 255589952U, 255721408U, + 255851072U, 255983296U, 256114624U, 256244416U, 256374208U, 256507712U, + 256636096U, 256768832U, 256900544U, 257031616U, 257162176U, 257294272U, + 257424448U, 257555776U, 257686976U, 257818432U, 257949632U, 258079552U, + 258211136U, 258342464U, 258473408U, 258603712U, 258734656U, 258867008U, + 258996544U, 259127744U, 259260224U, 259391296U, 259522112U, 259651904U, + 259784384U, 259915328U, 260045888U, 260175424U, 260308544U, 260438336U, + 260570944U, 260700992U, 260832448U, 260963776U, 261092672U, 261226304U, + 261356864U, 261487936U, 261619648U, 261750592U, 261879872U, 262011968U, + 262143424U, 262274752U, 262404416U, 262537024U, 262667968U, 262799296U, + 262928704U, 263061184U, 263191744U, 263322944U, 263454656U, 263585216U, + 263716672U, 263847872U, 263978944U, 264108608U, 264241088U, 264371648U, + 264501184U, 264632768U, 264764096U, 264895936U, 265024576U, 265158464U, + 265287488U, 265418432U, 265550528U, 265681216U, 265813312U, 265943488U, + 266075968U, 266206144U, 266337728U, 266468032U, 266600384U, 266731072U, + 266862272U, 266993344U, 267124288U, 267255616U, 267386432U, 267516992U, + 267648704U, 267777728U, 267910592U, 268040512U, 268172096U, 268302784U, + 268435264U, 268566208U, 268696256U, 268828096U, 268959296U, 269090368U, + 269221312U, 269352256U, 269482688U, 269614784U, 269745856U, 269876416U, + 270007616U, 270139328U, 270270272U, 270401216U, 270531904U, 270663616U, + 270791744U, 270924736U, 271056832U, 271186112U, 271317184U, 271449536U, + 271580992U, 271711936U, 271843136U, 271973056U, 272105408U, 272236352U, + 272367296U, 272498368U, 272629568U, 272759488U, 272891456U, 273022784U, + 273153856U, 273284672U, 273415616U, 273547072U, 273677632U, 273808448U, + 273937088U, 274071488U, 274200896U, 274332992U, 274463296U, 274595392U, + 274726208U, 274857536U, 274988992U, 275118656U, 275250496U, 275382208U, + 275513024U, 275643968U, 275775296U, 275906368U, 276037184U, 276167872U, + 276297664U, 276429376U, 276560576U, 276692672U, 276822976U, 276955072U, + 277085632U, 277216832U, 277347008U, 277478848U, 277609664U, 277740992U, + 277868608U, 278002624U, 278134336U, 278265536U, 278395328U, 278526784U, + 278657728U, 278789824U, 278921152U, 279052096U, 279182912U, 279313088U, + 279443776U, 279576256U, 279706048U, 279838528U, 279969728U, 280099648U, + 280230976U, 280361408U, 280493632U, 280622528U, 280755392U, 280887104U, + 281018176U, 281147968U, 281278912U, 281411392U, 281542592U, 281673152U, + 281803712U, 281935552U, 282066496U, 282197312U, 282329024U, 282458816U, + 282590272U, 282720832U, 282853184U, 282983744U, 283115072U, 283246144U, + 283377344U, 283508416U, 283639744U, 283770304U, 283901504U, 284032576U, + 284163136U, 284294848U, 284426176U, 284556992U, 284687296U, 284819264U, + 284950208U, 285081536U }; #ifdef __cplusplus diff --git a/ethash.h b/ethash.h index 3dd75288c..eb3097307 100644 --- a/ethash.h +++ b/ethash.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of ethash. - cpp-ethereum is free software: you can redistribute it and/or modify + ethash is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + ethash is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with ethash. If not, see . */ /** @file ethash.h @@ -26,13 +26,15 @@ #include #include "compiler.h" -#define REVISION 20 -#define DAGSIZE_BYTES_INIT 1073741824U // 2**30 -#define DAG_GROWTH 8388608U // 2**23 -#define CACHE_MULTIPLIER 1024 +#define REVISION 23 +#define DATASET_BYTES_INIT 1073741824U // 2**30 +#define DATASET_BYTES_GROWTH 8388608U // 2**23 +#define CACHE_BYTES_INIT 1073741824U // 2**24 +#define CACHE_BYTES_GROWTH 131072U // 2**17 #define EPOCH_LENGTH 30000U #define MIX_BYTES 128 -#define DAG_PARENTS 256 +#define HASH_BYTES 64 +#define DATASET_PARENTS 256 #define CACHE_ROUNDS 3 #define ACCESSES 64 @@ -41,22 +43,22 @@ extern "C" { #endif typedef struct ethash_params { - size_t full_size; // Size of full data set (in bytes, multiple of mix size (128)). - size_t cache_size; // Size of compute cache (in bytes, multiple of node size (64)). + uint64_t full_size; // Size of full data set (in bytes, multiple of mix size (128)). + uint64_t cache_size; // Size of compute cache (in bytes, multiple of node size (64)). } ethash_params; typedef struct ethash_return_value { - uint8_t result[32]; - uint8_t mix_hash[32]; + uint8_t result[32]; + uint8_t mix_hash[32]; } ethash_return_value; -size_t ethash_get_datasize(const uint32_t block_number); -size_t ethash_get_cachesize(const uint32_t block_number); +uint64_t ethash_get_datasize(const uint32_t block_number); +uint64_t ethash_get_cachesize(const uint32_t block_number); // initialize the parameters static inline void ethash_params_init(ethash_params *params, const uint32_t block_number) { - params->full_size = ethash_get_datasize(block_number); - params->cache_size = ethash_get_cachesize(block_number); + params->full_size = ethash_get_datasize(block_number); + params->cache_size = ethash_get_cachesize(block_number); } typedef struct ethash_cache { @@ -67,28 +69,54 @@ void ethash_mkcache(ethash_cache *cache, ethash_params const *params, const uint void ethash_compute_full_data(void *mem, ethash_params const *params, ethash_cache const *cache); void ethash_full(ethash_return_value *ret, void const *full_mem, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce); void ethash_light(ethash_return_value *ret, ethash_cache const *cache, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce); +void ethash_get_seedhash(uint8_t seedhash[32], const uint32_t block_number); -static inline void ethash_prep_light(void *cache, ethash_params const *params, const uint8_t seed[32]) { ethash_cache c; c.mem = cache; ethash_mkcache(&c, params, seed); } -static inline void ethash_compute_light(ethash_return_value *ret, void const *cache, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce) { ethash_cache c; c.mem = (void*)cache; ethash_light(ret, &c, params, header_hash, nonce); } -static inline void ethash_prep_full(void *full, ethash_params const *params, void const *cache) { ethash_cache c; c.mem = (void*)cache; ethash_compute_full_data(full, params, &c); } -static inline void ethash_compute_full(ethash_return_value *ret, void const *full, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce) { ethash_full(ret, full, params, header_hash, nonce); } - -static inline int ethash_check_difficulty( - const uint8_t hash[32], - const uint8_t difficulty[32]) { - // Difficulty is big endian - for (int i = 0; i < 32; i++) { - if (hash[i] == difficulty[i]) continue; - return hash[i] < difficulty[i]; - } +static inline void ethash_prep_light(void *cache, ethash_params const *params, const uint8_t seed[32]) { + ethash_cache c; + c.mem = cache; + ethash_mkcache(&c, params, seed); +} + +static inline void ethash_compute_light(ethash_return_value *ret, void const *cache, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce) { + ethash_cache c; + c.mem = (void *) cache; + ethash_light(ret, &c, params, header_hash, nonce); +} + +static inline void ethash_prep_full(void *full, ethash_params const *params, void const *cache) { + ethash_cache c; + c.mem = (void *) cache; + ethash_compute_full_data(full, params, &c); +} + +static inline void ethash_compute_full(ethash_return_value *ret, void const *full, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce) { + ethash_full(ret, full, params, header_hash, nonce); +} + +/// @brief Compare two s256-bit big-endian values. +/// @returns 1 if @a a is less than or equal to @a b, 0 otherwise. +/// Both parameters are 256-bit big-endian values. +static inline int ethash_leq_be256(const uint8_t a[32], const uint8_t b[32]) { + // Boundary is big endian + for (int i = 0; i < 32; i++) { + if (a[i] == b[i]) + continue; + return a[i] < b[i]; + } return 1; } -int ethash_quick_check_difficulty( - const uint8_t header_hash[32], - const uint64_t nonce, - const uint8_t mix_hash[32], - const uint8_t difficulty[32]); +/// Perofrms a cursory check on the validity of the nonce. +/// @returns 1 if the nonce may possibly be valid for the given header_hash & boundary. +/// @p boundary equivalent to 2 ^ 256 / block_difficulty, represented as a 256-bit big-endian. +int ethash_preliminary_check_boundary( + const uint8_t header_hash[32], + const uint64_t nonce, + const uint8_t mix_hash[32], + const uint8_t boundary[32]); + +#define ethash_quick_check_difficulty ethash_preliminary_check_boundary +#define ethash_check_difficulty ethash_leq_be256 #ifdef __cplusplus } diff --git a/internal.c b/internal.c index a2b82d375..ae9b95065 100644 --- a/internal.c +++ b/internal.c @@ -1,12 +1,12 @@ /* - This file is part of cpp-ethereum. + This file is part of ethash. - cpp-ethereum is free software: you can redistribute it and/or modify + ethash is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + ethash is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ -/** @file dash.cpp +/** @file internal.c * @author Tim Hughes * @author Matthew Wampler-Doty * @date 2015 @@ -37,13 +37,13 @@ #include "sha3.h" #endif // WITH_CRYPTOPP -size_t ethash_get_datasize(const uint32_t block_number) { - assert(block_number / EPOCH_LENGTH < 500); +uint64_t ethash_get_datasize(const uint32_t block_number) { + assert(block_number / EPOCH_LENGTH < 2048); return dag_sizes[block_number / EPOCH_LENGTH]; } -size_t ethash_get_cachesize(const uint32_t block_number) { - assert(block_number / EPOCH_LENGTH < 500); +uint64_t ethash_get_cachesize(const uint32_t block_number) { + assert(block_number / EPOCH_LENGTH < 2048); return cache_sizes[block_number / EPOCH_LENGTH]; } @@ -55,7 +55,7 @@ void static ethash_compute_cache_nodes( ethash_params const *params, const uint8_t seed[32]) { assert((params->cache_size % sizeof(node)) == 0); - uint32_t const num_nodes = (uint32_t)(params->cache_size / sizeof(node)); + uint32_t const num_nodes = (uint32_t) (params->cache_size / sizeof(node)); SHA3_512(nodes[0].bytes, seed, 32); @@ -68,10 +68,9 @@ void static ethash_compute_cache_nodes( uint32_t const idx = nodes[i].words[0] % num_nodes; node data; data = nodes[(num_nodes - 1 + i) % num_nodes]; - for (unsigned w = 0; w != NODE_WORDS; ++w) - { - data.words[w] ^= nodes[idx].words[w]; - } + for (unsigned w = 0; w != NODE_WORDS; ++w) { + data.words[w] ^= nodes[idx].words[w]; + } SHA3_512(nodes[i].bytes, data.bytes, sizeof(data)); } } @@ -86,7 +85,7 @@ void static ethash_compute_cache_nodes( } void ethash_mkcache( - ethash_cache *cache, + ethash_cache *cache, ethash_params const *params, const uint8_t seed[32]) { node *nodes = (node *) cache->mem; @@ -99,13 +98,13 @@ void ethash_calculate_dag_item( const struct ethash_params *params, const struct ethash_cache *cache) { - uint32_t num_parent_nodes = (uint32_t)(params->cache_size / sizeof(node)); + uint32_t num_parent_nodes = (uint32_t) (params->cache_size / sizeof(node)); node const *cache_nodes = (node const *) cache->mem; node const *init = &cache_nodes[node_index % num_parent_nodes]; - memcpy(ret, init, sizeof(node)); - ret->words[0] ^= node_index; - SHA3_512(ret->bytes, ret->bytes, sizeof(node)); + memcpy(ret, init, sizeof(node)); + ret->words[0] ^= node_index; + SHA3_512(ret->bytes, ret->bytes, sizeof(node)); #if defined(_M_X64) && ENABLE_SSE __m128i const fnv_prime = _mm_set1_epi32(FNV_PRIME); @@ -115,12 +114,11 @@ void ethash_calculate_dag_item( __m128i xmm3 = ret->xmm[3]; #endif - for (unsigned i = 0; i != DAG_PARENTS; ++i) - { - uint32_t parent_index = ((node_index ^ i)*FNV_PRIME ^ ret->words[i % NODE_WORDS]) % num_parent_nodes; + for (unsigned i = 0; i != DATASET_PARENTS; ++i) { + uint32_t parent_index = ((node_index ^ i) * FNV_PRIME ^ ret->words[i % NODE_WORDS]) % num_parent_nodes; node const *parent = &cache_nodes[parent_index]; - #if defined(_M_X64) && ENABLE_SSE +#if defined(_M_X64) && ENABLE_SSE { xmm0 = _mm_mullo_epi32(xmm0, fnv_prime); xmm1 = _mm_mullo_epi32(xmm1, fnv_prime); @@ -143,10 +141,10 @@ void ethash_calculate_dag_item( ret->words[w] = fnv_hash(ret->words[w], parent->words[w]); } } - #endif +#endif } - SHA3_512(ret->bytes, ret->bytes, sizeof(node)); + SHA3_512(ret->bytes, ret->bytes, sizeof(node)); } void ethash_compute_full_data( @@ -164,7 +162,7 @@ void ethash_compute_full_data( } static void ethash_hash( - ethash_return_value * ret, + ethash_return_value *ret, node const *full_nodes, ethash_cache const *cache, ethash_params const *params, @@ -174,7 +172,7 @@ static void ethash_hash( assert((params->full_size % MIX_WORDS) == 0); // pack hash and nonce together into first 40 bytes of s_mix - assert(sizeof(node)*8 == 512); + assert(sizeof(node) * 8 == 512); node s_mix[MIX_NODES + 1]; memcpy(s_mix[0].bytes, header_hash, 32); @@ -193,23 +191,21 @@ static void ethash_hash( } #endif - node* const mix = s_mix + 1; + node *const mix = s_mix + 1; for (unsigned w = 0; w != MIX_WORDS; ++w) { mix->words[w] = s_mix[0].words[w % NODE_WORDS]; } unsigned const page_size = sizeof(uint32_t) * MIX_WORDS, - num_full_pages = (unsigned)(params->full_size / page_size); + num_full_pages = (unsigned) (params->full_size / page_size); - for (unsigned i = 0; i != ACCESSES; ++i) - { - uint32_t const index = ((s_mix->words[0] ^ i)*FNV_PRIME ^ mix->words[i % MIX_WORDS]) % num_full_pages; + for (unsigned i = 0; i != ACCESSES; ++i) { + uint32_t const index = ((s_mix->words[0] ^ i) * FNV_PRIME ^ mix->words[i % MIX_WORDS]) % num_full_pages; - for (unsigned n = 0; n != MIX_NODES; ++n) - { - const node * dag_node = &full_nodes[MIX_NODES * index + n]; + for (unsigned n = 0; n != MIX_NODES; ++n) { + const node *dag_node = &full_nodes[MIX_NODES * index + n]; if (!full_nodes) { node tmp_node; @@ -217,7 +213,7 @@ static void ethash_hash( dag_node = &tmp_node; } - #if defined(_M_X64) && ENABLE_SSE +#if defined(_M_X64) && ENABLE_SSE { __m128i fnv_prime = _mm_set1_epi32(FNV_PRIME); __m128i xmm0 = _mm_mullo_epi32(fnv_prime, mix[n].xmm[0]); @@ -235,20 +231,19 @@ static void ethash_hash( mix[n].words[w] = fnv_hash(mix[n].words[w], dag_node->words[w]); } } - #endif +#endif } } - // compress mix - for (unsigned w = 0; w != MIX_WORDS; w += 4) - { - uint32_t reduction = mix->words[w+0]; - reduction = reduction*FNV_PRIME ^ mix->words[w+1]; - reduction = reduction*FNV_PRIME ^ mix->words[w+2]; - reduction = reduction*FNV_PRIME ^ mix->words[w+3]; - mix->words[w/4] = reduction; - } + // compress mix + for (unsigned w = 0; w != MIX_WORDS; w += 4) { + uint32_t reduction = mix->words[w + 0]; + reduction = reduction * FNV_PRIME ^ mix->words[w + 1]; + reduction = reduction * FNV_PRIME ^ mix->words[w + 2]; + reduction = reduction * FNV_PRIME ^ mix->words[w + 3]; + mix->words[w / 4] = reduction; + } #if BYTE_ORDER != LITTLE_ENDIAN for (unsigned w = 0; w != MIX_WORDS/4; ++w) { @@ -258,7 +253,7 @@ static void ethash_hash( memcpy(ret->mix_hash, mix->bytes, 32); // final Keccak hash - SHA3_256(ret->result, s_mix->bytes, 64+32); // Keccak-256(s + compressed_mix) + SHA3_256(ret->result, s_mix->bytes, 64 + 32); // Keccak-256(s + compressed_mix) } void ethash_quick_hash( @@ -267,7 +262,7 @@ void ethash_quick_hash( const uint64_t nonce, const uint8_t mix_hash[32]) { - uint8_t buf[64+32]; + uint8_t buf[64 + 32]; memcpy(buf, header_hash, 32); #if BYTE_ORDER != LITTLE_ENDIAN nonce = fix_endian64(nonce); @@ -275,24 +270,31 @@ void ethash_quick_hash( memcpy(&(buf[32]), &nonce, 8); SHA3_512(buf, buf, 40); memcpy(&(buf[64]), mix_hash, 32); - SHA3_256(return_hash, buf, 64+32); + SHA3_256(return_hash, buf, 64 + 32); +} + +void ethash_get_seedhash(uint8_t seedhash[32], const uint32_t block_number) { + memset(seedhash, 0, 32); + const uint32_t epochs = block_number / EPOCH_LENGTH; + for (uint32_t i = 0; i < epochs; ++i) + SHA3_256(seedhash, seedhash, 32); } -int ethash_quick_check_difficulty( +int ethash_preliminary_check_boundary( const uint8_t header_hash[32], const uint64_t nonce, const uint8_t mix_hash[32], - const uint8_t difficulty[32]) { + const uint8_t difficulty[32]) { - uint8_t return_hash[32]; + uint8_t return_hash[32]; ethash_quick_hash(return_hash, header_hash, nonce, mix_hash); - return ethash_check_difficulty(return_hash, difficulty); + return ethash_leq_be256(return_hash, difficulty); } -void ethash_full(ethash_return_value * ret, void const *full_mem, ethash_params const *params, const uint8_t previous_hash[32], const uint64_t nonce) { +void ethash_full(ethash_return_value *ret, void const *full_mem, ethash_params const *params, const uint8_t previous_hash[32], const uint64_t nonce) { ethash_hash(ret, (node const *) full_mem, NULL, params, previous_hash, nonce); } -void ethash_light(ethash_return_value * ret, ethash_cache const *cache, ethash_params const *params, const uint8_t previous_hash[32], const uint64_t nonce) { +void ethash_light(ethash_return_value *ret, ethash_cache const *cache, ethash_params const *params, const uint8_t previous_hash[32], const uint64_t nonce) { ethash_hash(ret, NULL, cache, params, previous_hash, nonce); } diff --git a/internal.h b/internal.h index bcbacdaa4..ddd06e8f4 100644 --- a/internal.h +++ b/internal.h @@ -3,7 +3,7 @@ #include "endian.h" #include "ethash.h" -#define ENABLE_SSE 1 +#define ENABLE_SSE 0 #if defined(_M_X64) && ENABLE_SSE #include diff --git a/io.c b/io.c new file mode 100644 index 000000000..dd4f1f9e8 --- /dev/null +++ b/io.c @@ -0,0 +1,89 @@ +/* + This file is part of ethash. + + ethash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ethash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ethash. If not, see . +*/ +/** @file io.c + * @author Lefteris Karapetsas + * @date 2015 + */ +#include "io.h" +#include +#include + +// silly macro to save some typing +#define PASS_ARR(c_) (c_), sizeof(c_) + +static bool ethash_io_write_file(char const *dirname, + char const* filename, + size_t filename_length, + void const* data, + size_t data_size) +{ + bool ret = false; + char *fullname = ethash_io_create_filename(dirname, filename, filename_length); + if (!fullname) { + return false; + } + FILE *f = fopen(fullname, "wb"); + if (!f) { + goto free_name; + } + if (data_size != fwrite(data, 1, data_size, f)) { + goto close; + } + + ret = true; +close: + fclose(f); +free_name: + free(fullname); + return ret; +} + +bool ethash_io_write(char const *dirname, + ethash_params const* params, + ethash_blockhash_t seedhash, + void const* cache, + uint8_t **data, + size_t *data_size) +{ + char info_buffer[DAG_MEMO_BYTESIZE]; + // allocate the bytes + uint8_t *temp_data_ptr = malloc(params->full_size); + if (!temp_data_ptr) { + goto end; + } + ethash_compute_full_data(temp_data_ptr, params, cache); + + if (!ethash_io_write_file(dirname, PASS_ARR(DAG_FILE_NAME), temp_data_ptr, params->full_size)) { + goto fail_free; + } + + ethash_io_serialize_info(REVISION, seedhash, info_buffer); + if (!ethash_io_write_file(dirname, PASS_ARR(DAG_MEMO_NAME), info_buffer, DAG_MEMO_BYTESIZE)) { + goto fail_free; + } + + *data = temp_data_ptr; + *data_size = params->full_size; + return true; + +fail_free: + free(temp_data_ptr); +end: + return false; +} + +#undef PASS_ARR diff --git a/io.h b/io.h new file mode 100644 index 000000000..0fa292362 --- /dev/null +++ b/io.h @@ -0,0 +1,116 @@ +/* + This file is part of ethash. + + ethash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ethash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ethash. If not, see . +*/ +/** @file io.h + * @author Lefteris Karapetsas + * @date 2015 + */ +#pragma once +#include +#include +#include +#include "ethash.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ethash_blockhash { uint8_t b[32]; } ethash_blockhash_t; + +static const char DAG_FILE_NAME[] = "full"; +static const char DAG_MEMO_NAME[] = "full.info"; +// MSVC thinks that "static const unsigned int" is not a compile time variable. Sorry for the #define :( +#define DAG_MEMO_BYTESIZE 36 + +/// Possible return values of @see ethash_io_prepare +enum ethash_io_rc { + ETHASH_IO_FAIL = 0, ///< There has been an IO failure + ETHASH_IO_MEMO_MISMATCH, ///< Memo file either did not exist or there was content mismatch + ETHASH_IO_MEMO_MATCH, ///< Memo file existed and contents matched. No need to do anything +}; + +/** + * Prepares io for ethash + * + * Create the DAG directory if it does not exist, and check if the memo file matches. + * If it does not match then it's deleted to pave the way for @ref ethash_io_write() + * + * @param dirname A null terminated c-string of the path of the ethash + * data directory. If it does not exist it's created. + * @param seedhash The seedhash of the current block number + * @return For possible return values @see enum ethash_io_rc + */ +enum ethash_io_rc ethash_io_prepare(char const *dirname, ethash_blockhash_t seedhash); +/** + * Fully computes data and writes it to the file on disk. + * + * This function should be called after @see ethash_io_prepare() and only if + * its return value is @c ETHASH_IO_MEMO_MISMATCH. Will write both the full data + * and the memo file. + * + * @param[in] dirname A null terminated c-string of the path of the ethash + * data directory. Has to exist. + * @param[in] params An ethash_params object containing the full size + * and the cache size + * @param[in] seedhash The seedhash of the current block number + * @param[in] cache The cache data. Would have usually been calulated by + * @see ethash_prep_light(). + * @param[out] data Pass a pointer to uint8_t by reference here. If the + * function is succesfull then this point to the allocated + * data calculated by @see ethash_prep_full(). Memory + * ownership is transfered to the callee. Remember that + * you eventually need to free this with a call to free(). + * @param[out] data_size Pass a size_t by value. If the function is succesfull + * then this will contain the number of bytes allocated + * for @a data. + * @return True for success and false in case of failure. + */ +bool ethash_io_write(char const *dirname, + ethash_params const* params, + ethash_blockhash_t seedhash, + void const* cache, + uint8_t **data, + size_t *data_size); + +static inline void ethash_io_serialize_info(uint32_t revision, + ethash_blockhash_t seed_hash, + char *output) +{ + // if .info is only consumed locally we don't really care about endianess + memcpy(output, &revision, 4); + memcpy(output + 4, &seed_hash, 32); +} + +static inline char *ethash_io_create_filename(char const *dirname, + char const* filename, + size_t filename_length) +{ + // in C the cast is not needed, but a C++ compiler will complain for invalid conversion + char *name = (char*)malloc(strlen(dirname) + filename_length); + if (!name) { + return NULL; + } + + name[0] = '\0'; + strcat(name, dirname); + strcat(name, filename); + return name; +} + + +#ifdef __cplusplus +} +#endif diff --git a/io_posix.c b/io_posix.c new file mode 100644 index 000000000..693bdf750 --- /dev/null +++ b/io_posix.c @@ -0,0 +1,76 @@ +/* + This file is part of ethash. + + ethash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ethash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ethash. If not, see . +*/ +/** @file io_posix.c + * @author Lefteris Karapetsas + * @date 2015 + */ + +#include "io.h" +#include +#include +#include +#include +#include +#include + +enum ethash_io_rc ethash_io_prepare(char const *dirname, ethash_blockhash_t seedhash) +{ + char read_buffer[DAG_MEMO_BYTESIZE]; + char expect_buffer[DAG_MEMO_BYTESIZE]; + enum ethash_io_rc ret = ETHASH_IO_FAIL; + + // assert directory exists, full owner permissions and read/search for others + int rc = mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + if (rc == -1 && errno != EEXIST) { + goto end; + } + + char *memofile = ethash_io_create_filename(dirname, DAG_MEMO_NAME, sizeof(DAG_MEMO_NAME)); + if (!memofile) { + goto end; + } + + // try to open memo file + FILE *f = fopen(memofile, "rb"); + if (!f) { + // file does not exist, so no checking happens. All is fine. + ret = ETHASH_IO_MEMO_MISMATCH; + goto free_memo; + } + + if (fread(read_buffer, 1, DAG_MEMO_BYTESIZE, f) != DAG_MEMO_BYTESIZE) { + goto close; + } + + ethash_io_serialize_info(REVISION, seedhash, expect_buffer); + if (memcmp(read_buffer, expect_buffer, DAG_MEMO_BYTESIZE) != 0) { + // we have different memo contents so delete the memo file + if (unlink(memofile) != 0) { + goto close; + } + ret = ETHASH_IO_MEMO_MISMATCH; + } + + ret = ETHASH_IO_MEMO_MATCH; + +close: + fclose(f); +free_memo: + free(memofile); +end: + return ret; +} diff --git a/io_win32.c b/io_win32.c new file mode 100644 index 000000000..2cabc939a --- /dev/null +++ b/io_win32.c @@ -0,0 +1,73 @@ +/* + This file is part of ethash. + + ethash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ethash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ethash. If not, see . +*/ +/** @file io_win32.c + * @author Lefteris Karapetsas + * @date 2015 + */ + +#include "io.h" +#include +#include +#include + +enum ethash_io_rc ethash_io_prepare(char const *dirname, ethash_blockhash_t seedhash) +{ + char read_buffer[DAG_MEMO_BYTESIZE]; + char expect_buffer[DAG_MEMO_BYTESIZE]; + enum ethash_io_rc ret = ETHASH_IO_FAIL; + + // assert directory exists + int rc = _mkdir(dirname); + if (rc == -1 && errno != EEXIST) { + goto end; + } + + char *memofile = ethash_io_create_filename(dirname, DAG_MEMO_NAME, sizeof(DAG_MEMO_NAME)); + if (!memofile) { + goto end; + } + + // try to open memo file + FILE *f = fopen(memofile, "rb"); + if (!f) { + // file does not exist, so no checking happens. All is fine. + ret = ETHASH_IO_MEMO_MISMATCH; + goto free_memo; + } + + if (fread(read_buffer, 1, DAG_MEMO_BYTESIZE, f) != DAG_MEMO_BYTESIZE) { + goto close; + } + + ethash_io_serialize_info(REVISION, seedhash, expect_buffer); + if (memcmp(read_buffer, expect_buffer, DAG_MEMO_BYTESIZE) != 0) { + // we have different memo contents so delete the memo file + if (_unlink(memofile) != 0) { + goto close; + } + ret = ETHASH_IO_MEMO_MISMATCH; + } + + ret = ETHASH_IO_MEMO_MATCH; + +close: + fclose(f); +free_memo: + free(memofile); +end: + return ret; +} diff --git a/sha3_cryptopp.cpp b/sha3_cryptopp.cpp index 9454ce04a..6cbbcad8f 100644 --- a/sha3_cryptopp.cpp +++ b/sha3_cryptopp.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of ethash. - cpp-ethereum is free software: you can redistribute it and/or modify + ethash is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + ethash is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with ethash. If not, see . */ /** @file sha3.cpp diff --git a/util.h b/util.h index 2f59076f6..ba8957815 100644 --- a/util.h +++ b/util.h @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of ethash. - cpp-ethereum is free software: you can redistribute it and/or modify + ethash is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, + ethash is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + along with ethash. If not, see . */ /** @file util.h * @author Tim Hughes