fix: handle overflow in BTC final TLC expiry delta calculation#1145
Merged
quake merged 2 commits intonervosnetwork:developfrom Mar 1, 2026
Merged
fix: handle overflow in BTC final TLC expiry delta calculation#1145quake merged 2 commits intonervosnetwork:developfrom
quake merged 2 commits intonervosnetwork:developfrom
Conversation
…d error for invalid configuration
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an overflow vulnerability in the CCH (Cross-Chain Hub) module that occurs when btc_final_tlc_expiry_delta_blocks is configured with a very large value. The overflow happened during the conversion from BTC blocks to milliseconds when multiplying by 600,000 (10 minutes per block * 1000 milliseconds per second).
Changes:
- Added
ConfigErrorvariant toCchErrorenum for configuration-related errors - Replaced unsafe multiplication with
checked_multo detect overflow conditions - Returns descriptive error message when overflow is detected in
receive_btcfunction
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/fiber-lib/src/cch/error.rs | Added ConfigError(String) variant to handle configuration errors including overflow |
| crates/fiber-lib/src/cch/actor.rs | Replaced direct multiplication with checked_mul and overflow detection in BTC block to millisecond conversion |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace the magic number `600 * 1000` with a documented named constant `BTC_BLOCK_TIME_MILLIS` (600,000 ms = 10 minutes per Bitcoin block) for improved readability and maintainability.
quake
approved these changes
Mar 1, 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.
Problem
When
btc_final_tlc_expiry_delta_blocksis set to a very large value, multiplying it by600 * 1000to convert to milliseconds can overflow, causing unexpected behavior.Related issue: #977
Solution
checked_mulinstead of plain multiplication to detect overflow.CchError::ConfigErrorwhen overflow is detected, with a descriptive message indicating the problematic configuration value.ConfigErrorvariant toCchErrorenum.Changes
crates/fiber-lib/src/cch/actor.rs: Replace*withchecked_muland propagate an error on overflow.crates/fiber-lib/src/cch/error.rs: AddConfigError(String)variant toCchError.