-
Notifications
You must be signed in to change notification settings - Fork 42
Description
Hi !
I was going through the staking & attestation contracts, and I believe I might have found a potential bug.
In the function calculate_next_epoch_starting_block here in the statement:
let blocks_passed = current_block - *self.starting_block;I believe if the update method for EpochInfo is called twice in the same epoch, starting_block will be equal to the starting block of the next epoch (after the 1st call) and will therefore be greater than current_block (in the 2nd call). Therefore, I believe this statement would panic.
If I'm correct, then a fix could be something like this:
let mut blocks_passed = current_block - *self.last_starting_block_before_update;
if *self.starting_block < current_block {
blocks_passed = current_block - *self.starting_block;
}And this would necessitate setting last_starting_block_before_update to starting_block in the new method. Actually, the if statement might not even be needed because the modulo operation % on length is used after anyway, so I believe always setting blocks_passed to last_starting_block_before_update would be fine!
(If i may, I would almost also add a check in new method to make sure that method parameter starting_block <= get_block_number() to be an additional safety)