-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Protect against passing i128::MIN to abs() which causes overflow
#2241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
eaa2616
5c0f1fd
056ba1e
3047c7e
af9263d
7359bd7
6188112
faeefca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| use std::num::NonZeroU64; | ||
|
|
||
| use crate::v1::{ | ||
| tests::UpdaterBuilder, | ||
| AlgorithmUpdaterV1, | ||
| AlgorithmV1, | ||
| ClampedPercentage, | ||
| }; | ||
| use proptest::prelude::*; | ||
|
|
||
|
|
@@ -143,3 +147,30 @@ fn worst_case__same_block_gives_the_same_value_as_calculate() { | |
| let expected = algorithm.calculate(); | ||
| assert_eq!(expected, actual); | ||
| } | ||
|
|
||
| #[test] | ||
| fn da_change_should_not_panic() { | ||
| let updater = AlgorithmUpdaterV1 { | ||
| new_scaled_exec_price: 0, | ||
| min_exec_gas_price: 0, | ||
| exec_gas_price_change_percent: 0, | ||
| l2_block_height: 0, | ||
| l2_block_fullness_threshold_percent: ClampedPercentage::new(0), | ||
| new_scaled_da_gas_price: 0, | ||
| gas_price_factor: NonZeroU64::new(1).unwrap(), | ||
| min_da_gas_price: 0, | ||
| max_da_gas_price_change_percent: 0, | ||
| total_da_rewards_excess: 0, | ||
| da_recorded_block_height: 0, | ||
| latest_known_total_da_cost_excess: 0, | ||
| projected_total_da_cost: 0, | ||
| da_p_component: 0, | ||
| da_d_component: 0, | ||
| last_profit: 0, | ||
| second_to_last_profit: 0, | ||
| latest_da_cost_per_byte: 0, | ||
| unrecorded_blocks: vec![], | ||
| }; | ||
|
|
||
| updater.da_change(i128::MIN / 2, i128::MIN / 2); | ||
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. Nice find.