-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Protect against passing i128::MIN
to abs()
which causes overflow
#2241
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 commentThe reason will be displayed to describe this comment to others. Learn more. Let's not test private functions. We should be able to test this with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in 3047c7e, however, I'm not fully convinced this fits better here. Rationale: I'm open to suggestions on how we can do this better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd be okay with removing the test since there are many places in the code that "could" panic if programmed poorly. It might be worth adding some more aggressive prop testing for those cases, but that could be a separate issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this boils down to the fact that people (me, at least) do not associate an "innocent" So yes, I agree that this test is kinda redundant - I removed it in 7359bd7 What we could do is:
Wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently we have #![deny(clippy::arithmetic_side_effects)]
#![deny(clippy::cast_possible_truncation)]
#![deny(warnings)] But I'd be open to adding more for sure. |
||
} |
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.