Address all math issues reported by soteria

None of these should have been a real issue.
This commit is contained in:
Christian Kamm 2022-01-21 08:21:00 +01:00
parent 40708e80ef
commit 22b4923ef2
4 changed files with 20 additions and 4 deletions

View File

@ -54,7 +54,12 @@ pub fn log_voter_info(ctx: Context<LogVoterInfo>, deposit_entry_begin: u8) -> Re
end_timestamp: (lockup.kind != LockupKind::Constant).then(|| end_ts),
vesting: lockup.kind.is_vesting().then(|| VestingInfo {
rate: deposit.amount_initially_locked_native / periods_total,
next_timestamp: end_ts - (periods_left - 1) * lockup.kind.period_secs(),
next_timestamp: end_ts.saturating_sub(
periods_left
.saturating_sub(1)
.checked_mul(lockup.kind.period_secs())
.unwrap(),
),
}),
});

View File

@ -342,7 +342,10 @@ impl DepositEntry {
vested_amount <= self.amount_initially_locked_native,
InternalProgramError
);
self.amount_initially_locked_native -= vested_amount;
self.amount_initially_locked_native = self
.amount_initially_locked_native
.checked_sub(vested_amount)
.unwrap();
self.lockup.remove_past_periods(curr_ts)?;
require!(self.vested(curr_ts)? == 0, InternalProgramError);
Ok(())

View File

@ -113,7 +113,11 @@ impl Lockup {
if curr_ts < self.start_ts {
return self.periods_total();
}
Ok((self.seconds_left(curr_ts) + period_secs - 1) / period_secs)
Ok(self
.seconds_left(curr_ts)
.checked_add(period_secs.saturating_sub(1))
.unwrap()
/ period_secs)
}
/// Returns the current period in the vesting schedule.

View File

@ -26,7 +26,11 @@ const_assert!(std::mem::size_of::<Registrar>() == 5 * 32 + 4 * 120 + 8 + 1 + 31)
impl Registrar {
pub fn clock_unix_timestamp(&self) -> i64 {
Clock::get().unwrap().unix_timestamp + self.time_offset
Clock::get()
.unwrap()
.unix_timestamp
.checked_add(self.time_offset)
.unwrap()
}
pub fn voting_mint_config_index(&self, mint: Pubkey) -> Result<usize> {