Skip to content

Commit

Permalink
Merge pull request #3 from LayerZero-Labs/fix/refill-method-overflow
Browse files Browse the repository at this point in the history
Fix potential overflow in `refill` method
  • Loading branch information
ziming-zung authored Nov 21, 2024
2 parents fc94939 + 61ef269 commit 985de7f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/solana/contracts/programs/oft/src/state/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ impl RateLimiter {
let current_time: u64 = Clock::get()?.unix_timestamp.try_into().unwrap();
if current_time > self.last_refill_time {
let time_elapsed_in_seconds = current_time - self.last_refill_time;
new_tokens += time_elapsed_in_seconds * self.refill_per_second;
new_tokens = new_tokens
.saturating_add(time_elapsed_in_seconds.saturating_mul(self.refill_per_second));
}
self.tokens = std::cmp::min(self.capacity, self.tokens.saturating_add(new_tokens));

Expand All @@ -49,7 +50,7 @@ impl RateLimiter {
Some(new_tokens) => {
self.tokens = new_tokens;
Ok(())
},
}
None => Err(error!(OftError::RateLimitExceeded)),
}
}
Expand Down

0 comments on commit 985de7f

Please sign in to comment.