mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 07:26:51 +00:00
overflow check
This commit is contained in:
@@ -17,8 +17,8 @@ pub enum OreError {
|
||||
StakeTooLarge = 4,
|
||||
#[error("The clock time is invalid")]
|
||||
ClockInvalid = 5,
|
||||
#[error("The tolerance cannot be negative")]
|
||||
ToleranceNegative = 6,
|
||||
#[error("The tolerance cannot exceed i64 max value")]
|
||||
ToleranceInvalid = 6,
|
||||
}
|
||||
|
||||
impl From<OreError> for ProgramError {
|
||||
|
||||
@@ -14,7 +14,6 @@ use solana_program::{
|
||||
program_error::ProgramError, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
// TODO Admin fn for spam/liveness tolerances?
|
||||
// TODO Alternative to bincode?
|
||||
// TODO Is downgrade necessary?
|
||||
|
||||
|
||||
@@ -30,14 +30,17 @@ pub fn process_update_tolerance<'a, 'info>(
|
||||
return Err(ProgramError::MissingRequiredSignature);
|
||||
}
|
||||
|
||||
// Overflow checks
|
||||
if args.tolerance_liveness.gt(&(i64::MAX as u64)) {
|
||||
return Err(OreError::ToleranceInvalid.into());
|
||||
}
|
||||
if args.tolerance_spam.gt(&(i64::MAX as u64)) {
|
||||
return Err(OreError::ToleranceInvalid.into());
|
||||
}
|
||||
|
||||
// Update tolerances
|
||||
config.tolerance_liveness = args.tolerance_liveness as i64;
|
||||
config.tolerance_spam = args.tolerance_spam as i64;
|
||||
|
||||
// Sanity checks
|
||||
if config.tolerance_liveness.lt(&0) || config.tolerance_spam.lt(&0) {
|
||||
return Err(OreError::ToleranceNegative.into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user