From c00571ca020e13e39bf59e4d18d5ce630427a69c Mon Sep 17 00:00:00 2001 From: hackyminer Date: Mon, 10 Dec 2018 23:23:10 +0900 Subject: [PATCH] ProgPoW spec v0.9.2 * unique sources for random math by ifdefelse - https://github.com/ifdefelse/ProgPOW/commit/824cd791634204c4cc7e31f84bb76c0c84895bd3 * test cases from : https://github.com/chfast/ethash/pull/116 by chfast --- src/libethash/progpow-internal.c | 16 ++++--- test/c/test_progpow.cpp | 74 ++++++++++++++++---------------- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/src/libethash/progpow-internal.c b/src/libethash/progpow-internal.c index 92dd2800..e9981877 100644 --- a/src/libethash/progpow-internal.c +++ b/src/libethash/progpow-internal.c @@ -278,8 +278,9 @@ void merge(uint32_t *a, uint32_t b, uint32_t r) { case 0: *a = (*a * 33) + b; break; case 1: *a = (*a ^ b) * 33; break; - case 2: *a = ROTL32(*a, ((r >> 16) % 32)) ^ b; break; - case 3: *a = ROTR32(*a, ((r >> 16) % 32)) ^ b; break; + // prevent rotate by 0 which is a NOP + case 2: *a = ROTL32(*a, ((r >> 16) % 31)+1) ^ b; break; + case 3: *a = ROTR32(*a, ((r >> 16) % 31)+1) ^ b; break; } } @@ -370,10 +371,13 @@ void progPowLoop( if (i < PROGPOW_CNT_MATH) { // Random Math - uint32_t src1 = kiss99(&prog_rnd) % PROGPOW_REGS; - uint32_t src2 = kiss99(&prog_rnd) % PROGPOW_REGS; - uint32_t sel1 = kiss99(&prog_rnd); - uint32_t dst = mix_seq_dst[(mix_seq_dst_cnt++)%PROGPOW_REGS]; + // Generate 2 unique sources + int src_rnd = kiss99(&prog_rnd) % (PROGPOW_REGS * (PROGPOW_REGS-1)); + int src1 = src_rnd % PROGPOW_REGS; // 0 <= src1 < PROGPOW_REGS + int src2 = src_rnd / PROGPOW_REGS; // 0 <= src2 < PROGPOW_REGS - 1 + if (src2 >= src1) ++src2; // src2 is now any reg other than src1 + int sel1 = kiss99(&prog_rnd); + int dst = mix_seq_dst[(mix_seq_dst_cnt++)%PROGPOW_REGS]; int sel2 = kiss99(&prog_rnd); for (int l = 0; l < PROGPOW_LANES; l++) { diff --git a/test/c/test_progpow.cpp b/test/c/test_progpow.cpp index 307ad34e..9742598b 100644 --- a/test/c/test_progpow.cpp +++ b/test/c/test_progpow.cpp @@ -292,8 +292,8 @@ BOOST_AUTO_TEST_CASE(test_progpow_light_client_checks) { { uint64_t nonce = 0x0; const std::string - exphead = "7ea12cfc33f64616ab7dbbddf3362ee7dd3e1e20d60d860a85c51d6559c912c4", - expmix = "a09ffaa0f2b5d47a98c2d4fbc0e90936710dd2b2a220fce04e8d55a6c6a093d6"; + exphead = "63155f732f2bf556967f906155b510c917e48e99685ead76ea83f4eca03ab12b", + expmix = "faeb1be51075b03a4ff44b335067951ead07a3b078539ace76fd56fc410557a3"; const std::string hash_string = blockhashToHexString(&hash); light_out = progpow_light_compute_internal(light, full_size, hash, nonce, 0); @@ -324,41 +324,41 @@ struct progpow_hash_test_case progpow_hash_test_case progpow_hash_test_cases[] = { {0, "0000000000000000000000000000000000000000000000000000000000000000", "0000000000000000", - "a09ffaa0f2b5d47a98c2d4fbc0e90936710dd2b2a220fce04e8d55a6c6a093d6", - "7ea12cfc33f64616ab7dbbddf3362ee7dd3e1e20d60d860a85c51d6559c912c4"}, - {49, "7ea12cfc33f64616ab7dbbddf3362ee7dd3e1e20d60d860a85c51d6559c912c4", "0000000006ff2c47", - "4e453d59426905122ef3d176a6fe660f29b53fdf2f82b5af2753dbaaebebf609", - "f0167e445f8510504ce024856ec614a1a4461610bf58caa32df731ee4c315641"}, - {50, "f0167e445f8510504ce024856ec614a1a4461610bf58caa32df731ee4c315641", "00000000076e482e", - "4e5291ae6132f64bff00dd05861721b0da701f789e7e65d096b9affa24bffd7e", - "fdc3bce3e0d0b1a5af43f84acc7d5421d423ec5d3b7e41698178b24c459a6cbe"}, - {99, "fdc3bce3e0d0b1a5af43f84acc7d5421d423ec5d3b7e41698178b24c459a6cbe", "000000003917afab", - "d35c7e4012204d1db243dc7cf0bf2075f897e362e6ad2b36c02e325cfc6f8dbb", - "5b014c2c706476b56cf3b9c37ed999d30b20c0fb038d27cc94c991dacef62033"}, - {29950, "5b014c2c706476b56cf3b9c37ed999d30b20c0fb038d27cc94c991dacef62033", "005d409dbc23a62a", - "0c64704dedb0677149b47fabc6726e9ff0585233692c8562e485a330ce90c0e9", - "a01b432e82cacaae095ef402b575f1764c45247ba9cf17e99d5432cf00829ee2"}, - {29999, "a01b432e82cacaae095ef402b575f1764c45247ba9cf17e99d5432cf00829ee2", "005db5fa4c2a3d03", - "3d95cad9cf4513bb31a4766d3a2f488bbff1baa57da8b2252e246ac91594c769", - "0fc3e6e1392033619f614ec3236d8fbfcefe94d9fdc341a4d7daeffa0b8ad35d"}, - {30000, "0fc3e6e1392033619f614ec3236d8fbfcefe94d9fdc341a4d7daeffa0b8ad35d", "005db8607994ff30", - "7ee9d0c571ed35073404454eebe9a73a6d677a32446cf6c427ee63a63bd512da", - "b94de4495555dc2ab4ad8725cabd395178813c8c434134b2f25062b5f72dafb9"}, - {30049, "b94de4495555dc2ab4ad8725cabd395178813c8c434134b2f25062b5f72dafb9", "005e2e215a8ca2e7", - "7a16d37208288152237afdc13724d26fe7aadf3cd354a42c587a4192761ef18e", - "e152d3770855cea35a94ee53ab321f93ee3a426513c6ab1ec5e8d81ea9a661d7"}, - {30050, "e152d3770855cea35a94ee53ab321f93ee3a426513c6ab1ec5e8d81ea9a661d7", "005e30899481055e", - "005df2434f2a5265c2ed0d13dd12308795620202d2784a40967461c383f859a3", - "55d013e85571e46e914a7529909fbfc686965a92c7baaef2e89e5b5f533a6dc9"}, - {30099, "55d013e85571e46e914a7529909fbfc686965a92c7baaef2e89e5b5f533a6dc9", "005ea6aef136f88b", - "d8b1046cc2c8273a06e6f7ce19b7b4aefb7fb43b141721663252e2872b654548", - "8ba5629b6affa0514c2f4951c3a63761465ef0e5be7cbb8f9ce230a5564faccb"}, - {59950, "8ba5629b6affa0514c2f4951c3a63761465ef0e5be7cbb8f9ce230a5564faccb", "02ebe0503bd7b1da", - "b3131de1a747449e5328f50742447d5c6da637a5d141a117caf9a986bd524de9", - "10af438404304f4a7de0b07e7d08bfc80b521860237e3e2d47f77630eef5f742"}, - {59999, "10af438404304f4a7de0b07e7d08bfc80b521860237e3e2d47f77630eef5f742", "02edb6275bd221e3", - "87f7d6c73fb86a5ed00d2ad7fff7b2a8a9796c3138b31f2473b89065946cb0ed", - "3863e5c767a6b0d28f5cf1d261e35c52fe03f7fd690d50c10596ec73d7595887"}, + "faeb1be51075b03a4ff44b335067951ead07a3b078539ace76fd56fc410557a3", + "63155f732f2bf556967f906155b510c917e48e99685ead76ea83f4eca03ab12b"}, + {49, "63155f732f2bf556967f906155b510c917e48e99685ead76ea83f4eca03ab12b", "0000000006ff2c47", + "c789c1180f890ec555ff42042913465481e8e6bc512cb981e1c1108dc3f2227d", + "9e7248f20914913a73d80a70174c331b1d34f260535ac3631d770e656b5dd922"}, + {50, "9e7248f20914913a73d80a70174c331b1d34f260535ac3631d770e656b5dd922", "00000000076e482e", + "c7340542c2a06b3a7dc7222635f7cd402abf8b528ae971ddac6bbe2b0c7cb518", + "de37e1824c86d35d154cf65a88de6d9286aec4f7f10c3fc9f0fa1bcc2687188d"}, + {99, "de37e1824c86d35d154cf65a88de6d9286aec4f7f10c3fc9f0fa1bcc2687188d", "000000003917afab", + "f5e60b2c5bfddd136167a30cbc3c8dbdbd15a512257dee7964e0bc6daa9f8ba7", + "ac7b55e801511b77e11d52e9599206101550144525b5679f2dab19386f23dcce"}, + {29950, "ac7b55e801511b77e11d52e9599206101550144525b5679f2dab19386f23dcce", "005d409dbc23a62a", + "07393d15805eb08ee6fc6cb3ad4ad1010533bd0ff92d6006850246829f18fd6e", + "e43d7e0bdc8a4a3f6e291a5ed790b9fa1a0948a2b9e33c844888690847de19f5"}, + {29999, "e43d7e0bdc8a4a3f6e291a5ed790b9fa1a0948a2b9e33c844888690847de19f5", "005db5fa4c2a3d03", + "7551bddf977491da2f6cfc1679299544b23483e8f8ee0931c4c16a796558a0b8", + "d34519f72c97cae8892c277776259db3320820cb5279a299d0ef1e155e5c6454"}, + {30000, "d34519f72c97cae8892c277776259db3320820cb5279a299d0ef1e155e5c6454", "005db8607994ff30", + "f1c2c7c32266af9635462e6ce1c98ebe4e7e3ecab7a38aaabfbf2e731e0fbff4", + "8b6ce5da0b06d18db7bd8492d9e5717f8b53e7e098d9fef7886d58a6e913ef64"}, + {30049, "8b6ce5da0b06d18db7bd8492d9e5717f8b53e7e098d9fef7886d58a6e913ef64", "005e2e215a8ca2e7", + "57fe6a9fbf920b4e91deeb66cb0efa971e08229d1a160330e08da54af0689add", + "c2c46173481b9ced61123d2e293b42ede5a1b323210eb2a684df0874ffe09047"}, + {30050, "c2c46173481b9ced61123d2e293b42ede5a1b323210eb2a684df0874ffe09047", "005e30899481055e", + "ba30c61cc5a2c74a5ecaf505965140a08f24a296d687e78720f0b48baf712f2d", + "ea42197eb2ba79c63cb5e655b8b1f612c5f08aae1a49ff236795a3516d87bc71"}, + {30099, "ea42197eb2ba79c63cb5e655b8b1f612c5f08aae1a49ff236795a3516d87bc71", "005ea6aef136f88b", + "cfd5e46048cd133d40f261fe8704e51d3f497fc14203ac6a9ef6a0841780b1cd", + "49e15ba4bf501ce8fe8876101c808e24c69a859be15de554bf85dbc095491bd6"}, + {59950, "49e15ba4bf501ce8fe8876101c808e24c69a859be15de554bf85dbc095491bd6", "02ebe0503bd7b1da", + "21511fbaa31fb9f5fc4998a754e97b3083a866f4de86fa7500a633346f56d773", + "f5c50ba5c0d6210ddb16250ec3efda178de857b2b1703d8d5403bd0f848e19cf"}, + {59999, "f5c50ba5c0d6210ddb16250ec3efda178de857b2b1703d8d5403bd0f848e19cf", "02edb6275bd221e3", + "653eda37d337e39d311d22be9bbd3458d3abee4e643bee4a7280a6d08106ef98", + "341562d10d4afb706ec2c8d5537cb0c810de02b4ebb0a0eea5ae335af6fb2e88"}, }; BOOST_AUTO_TEST_CASE(test_progpow_test_cases) {