Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Fixed modexp gas calculation overflow (#6741)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Oct 13, 2017
1 parent f71344e commit 64cd0cc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ethcore/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,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()
}
}

Expand Down Expand Up @@ -711,6 +715,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("\
Expand Down

0 comments on commit 64cd0cc

Please sign in to comment.