RustFund

First Flight #36
Beginner FriendlyRust
100 EXP
View results
Submission Details
Severity: medium
Invalid

Clock::get().unwrap().unix_timestamp.try_into().unwrap() is risky

Summary

Clock::get().unwrap().unix_timestamp.try_into().unwrap() is too risky as it might fail

Vulnerability Details

  • Clock::get() returns Result<Clock, ProgramError>, and calling .unwrap() will panic if it fails. If used in an on-chain program, a panic will abort the transaction, which is not ideal

  • unix_timestamp is already an i64, so calling .try_into() (which converts between integer types) is redundant unless you're converting to another type.

  • If try_into() were converting to a different integer type (like u64), it could fail (e.g., i64u64 if the value is negative), leading to another panic.

Impact

Panic.

Tools Used

Manual Review/chatgpt

Recommendations

Replace it with:

Clock::get()?.unix_timestamp

Updates

Appeal created

bube Lead Judge 2 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

[Invalid] Incorrect error handling for timestamp

It is very unlikely `Clock::get` to fail, therefore I think it is safe to use `unwrap` here. Consider this issue as informational.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.