Skip to content

Commit 8559a49

Browse files
committed
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.
1 parent e4c3d1e commit 8559a49

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

bitcoin/src/blockdata/transaction.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,31 +1165,23 @@ mod sealed {
11651165
#[cfg(feature = "arbitrary")]
11661166
impl<'a> Arbitrary<'a> for InputWeightPrediction {
11671167
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
1168-
// limit script size to 4Mwu block size.
1169-
let max_block = Weight::MAX_BLOCK.to_wu() as usize;
1170-
let input_script_len = u.int_in_range(0..=max_block)?;
1171-
let remaining = max_block - input_script_len;
1172-
1173-
// create witness data if there is remaining space.
1174-
let mut witness_length = u.int_in_range(0..=remaining)?;
1175-
let mut witness_element_lengths = Vec::new();
1176-
1177-
// build vec of random witness element lengths.
1178-
while witness_length > 0 {
1179-
let elem = u.int_in_range(1..=witness_length)?;
1180-
witness_element_lengths.push(elem);
1181-
witness_length -= elem;
1182-
}
1183-
11841168
match u.int_in_range(0..=7)? {
11851169
0 => Ok(InputWeightPrediction::P2WPKH_MAX),
11861170
1 => Ok(InputWeightPrediction::NESTED_P2WPKH_MAX),
11871171
2 => Ok(InputWeightPrediction::P2PKH_COMPRESSED_MAX),
11881172
3 => Ok(InputWeightPrediction::P2PKH_UNCOMPRESSED_MAX),
11891173
4 => Ok(InputWeightPrediction::P2TR_KEY_DEFAULT_SIGHASH),
11901174
5 => Ok(InputWeightPrediction::P2TR_KEY_NON_DEFAULT_SIGHASH),
1191-
6 => Ok(InputWeightPrediction::new(input_script_len, witness_element_lengths)),
1192-
_ => Ok(InputWeightPrediction::from_slice(input_script_len, &witness_element_lengths)),
1175+
6 => {
1176+
let input_script_len = usize::arbitrary(u)?;
1177+
let witness_element_lengths: Vec<usize> = Vec::arbitrary(u)?;
1178+
Ok(InputWeightPrediction::new(input_script_len, witness_element_lengths))
1179+
}
1180+
_ => {
1181+
let input_script_len = usize::arbitrary(u)?;
1182+
let witness_element_lengths: Vec<usize> = Vec::arbitrary(u)?;
1183+
Ok(InputWeightPrediction::from_slice(input_script_len, &witness_element_lengths))
1184+
}
11931185
}
11941186
}
11951187
}

0 commit comments

Comments
 (0)