Fixed modexp gas calculation overflow (#6741)

This commit is contained in:
Arkadiy Paronyan 2017-10-13 16:06:53 +02:00 committed by Gav Wood
parent fcd81a7b86
commit 691e93834c
1 changed files with 13 additions and 1 deletions

View File

@ -123,7 +123,11 @@ impl Pricer for ModexpPricer {
let adjusted_exp_len = Self::adjusted_exp_len(exp_len, exp_low);
(Self::mult_complexity(m) * max(adjusted_exp_len, 1) / self.divisor as u64).into()
let (gas, overflow) = Self::mult_complexity(m).overflowing_mul(max(adjusted_exp_len, 1));
if overflow {
return U256::max_value();
}
(gas / self.divisor as u64).into()
}
}
@ -706,6 +710,14 @@ mod tests {
activate_at: 0,
};
// test for potential gas cost multiplication overflow
{
let input = FromHex::from_hex("0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000003b27bafd00000000000000000000000000000000000000000000000000000000503c8ac3").unwrap();
let expected_cost = U256::max_value();
assert_eq!(f.cost(&input[..]), expected_cost.into());
}
// test for potential exp len overflow
{
let input = FromHex::from_hex("\