diff --git a/EIPS/eip-1057.md b/EIPS/eip-1057.md index 82807941..e85d218e 100644 --- a/EIPS/eip-1057.md +++ b/EIPS/eip-1057.md @@ -251,8 +251,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; } } ``` @@ -329,8 +330,11 @@ void progPowLoop( if (i < PROGPOW_CNT_MATH) { // Random Math - int src1 = kiss99(prog_rnd) % PROGPOW_REGS; - int src2 = kiss99(prog_rnd) % 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 src int sel1 = kiss99(prog_rnd); int dst = mix_seq_dst[(mix_seq_dst_cnt++)%PROGPOW_REGS]; int sel2 = kiss99(prog_rnd);