Do not bound Arbitrary parameters passed to InputWeightPrediction

Now that InputWeightPrediction can no longer overflow due to extreme
values, there is no longer need to bound the Arbitrary parameters
passed.
This commit is contained in:
yancy 2025-05-27 18:58:02 -05:00
parent e4c3d1e7a6
commit 8559a49e03
1 changed files with 10 additions and 18 deletions

View File

@ -1165,22 +1165,6 @@ mod sealed {
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for InputWeightPrediction {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
// limit script size to 4Mwu block size.
let max_block = Weight::MAX_BLOCK.to_wu() as usize;
let input_script_len = u.int_in_range(0..=max_block)?;
let remaining = max_block - input_script_len;
// create witness data if there is remaining space.
let mut witness_length = u.int_in_range(0..=remaining)?;
let mut witness_element_lengths = Vec::new();
// build vec of random witness element lengths.
while witness_length > 0 {
let elem = u.int_in_range(1..=witness_length)?;
witness_element_lengths.push(elem);
witness_length -= elem;
}
match u.int_in_range(0..=7)? {
0 => Ok(InputWeightPrediction::P2WPKH_MAX),
1 => Ok(InputWeightPrediction::NESTED_P2WPKH_MAX),
@ -1188,8 +1172,16 @@ impl<'a> Arbitrary<'a> for InputWeightPrediction {
3 => Ok(InputWeightPrediction::P2PKH_UNCOMPRESSED_MAX),
4 => Ok(InputWeightPrediction::P2TR_KEY_DEFAULT_SIGHASH),
5 => Ok(InputWeightPrediction::P2TR_KEY_NON_DEFAULT_SIGHASH),
6 => Ok(InputWeightPrediction::new(input_script_len, witness_element_lengths)),
_ => Ok(InputWeightPrediction::from_slice(input_script_len, &witness_element_lengths)),
6 => {
let input_script_len = usize::arbitrary(u)?;
let witness_element_lengths: Vec<usize> = Vec::arbitrary(u)?;
Ok(InputWeightPrediction::new(input_script_len, witness_element_lengths))
}
_ => {
let input_script_len = usize::arbitrary(u)?;
let witness_element_lengths: Vec<usize> = Vec::arbitrary(u)?;
Ok(InputWeightPrediction::from_slice(input_script_len, &witness_element_lengths))
}
}
}
}