fix(security): prevent timelock bypass via u64-to-i64 silent truncation#22
Merged
fix(security): prevent timelock bypass via u64-to-i64 silent truncation#22
Conversation
Replace the silent `as i64` cast in TimelockData::validate() with `i64::try_from()`, returning ArithmeticOverflow for any lock_duration > i64::MAX instead of wrapping to a negative value. Add a defense-in-depth guard in AddTimelockData::try_from() that rejects lock_duration > i64::MAX at instruction parse time with InvalidInstructionData, so a malicious value never reaches storage. Fixes GHSA-qgq6-7hc8-rqx6
amilz
previously approved these changes
Feb 24, 2026
Replace u64::MAX with i64::MAX as the upper success case and add test_add_timelock_rejects_lock_duration_exceeding_i64_max to cover i64::MAX+1 and u64::MAX, both of which must now return InvalidInstructionData.
amilz
approved these changes
Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes GHSA-qgq6-7hc8-rqx6 — High severity.
TimelockData::validate()usedself.lock_duration as i64to cast au64field. Anylock_duration > i64::MAXsilently wraps to a negative number, makingunlock_timeearlier thandeposited_atand bypassing the timelock check entirely. Unlike arithmetic operators,ascasts are exempt fromoverflow-checks = trueinCargo.toml.Changes
program/src/state/extensions/timelock.rs— replaceas i64withi64::try_from(), returningArithmeticOverflowfor out-of-range values.program/src/instructions/extensions/add_timelock/data.rs— add defense-in-depth guard inAddTimelockData::try_from()that rejectslock_duration > i64::MAXwithInvalidInstructionDataat instruction parse time, before the value ever reaches storage.Testing
cargo test -p escrow-program)just integration-test)just fmtandjust checkclean