Fix quality overflow (#75)

This commit is contained in:
Chenxing Li 2024-05-30 21:49:47 +08:00 committed by GitHub
parent 0852b2355c
commit c0f9d5cc31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -102,8 +102,15 @@ impl<'a> Miner<'a> {
let quality = self.pora(idx, &sealed_data, pad_seed);
let quality_scale = self.range.shard_mask.count_zeros();
if quality << quality_scale <= *self.target_quality {
debug!("Find a PoRA valid answer, quality: {}", quality);
if quality <= U256::MAX >> quality_scale
&& quality << quality_scale <= *self.target_quality
{
debug!(
"Find a PoRA valid answer, quality: {}, target_quality {}, scale {}",
U256::MAX / quality,
U256::MAX / self.target_quality,
quality_scale
);
// Undo mix data when find a valid solition
for (x, y) in sealed_data.iter_mut().zip(scratch_pad.iter()) {
*x ^= y;