diff --git a/libdevcore/FixedHash.h b/libdevcore/FixedHash.h index 6aeb0a660..02d199f62 100644 --- a/libdevcore/FixedHash.h +++ b/libdevcore/FixedHash.h @@ -158,21 +158,25 @@ public: return ret; } - template inline FixedHash& shiftBloom(FixedHash const& _h) { return (*this |= _h.template nbloom()); } + template inline FixedHash& shiftBloom(FixedHash const& _h) + { + return (*this |= _h.template nbloom()); + } template inline FixedHash nbloom() const { - static const unsigned c_bloomBytes = (M + 7) / 8; - unsigned mask = (1 << c_bloomBytes) - 1; + static const unsigned c_bloomBits = M * 8; + unsigned mask = c_bloomBits - 1; + unsigned bloomBytes = (dev::toLog2(c_bloomBits) + 7) / 8; FixedHash ret; byte const* p = data(); for (unsigned i = 0; i < P; ++i) { unsigned index = 0; - for (unsigned j = 0; j < c_bloomBytes; ++j, ++p) + for (unsigned j = 0; j < bloomBytes; ++j, ++p) index = (index << 8) | *p; index &= mask; - ret[N - 1 - index / 8] |= (1 << (index % 8)); + ret[M - 1 - index / 8] |= (1 << (index % 8)); } return ret; }