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

Commit

Permalink
Fixed potential exp len overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Oct 10, 2017
1 parent 4e8853c commit ab63044
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ethcore/res/wasm-tests
23 changes: 22 additions & 1 deletion ethcore/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,15 @@ impl Pricer for ModexpPricer {
}

let base_len = base_len.low_u64();
let exp_len = exp_len.low_u64();
let mod_len = mod_len.low_u64();
let m = max(mod_len, base_len);
if m == 0 {
return U256::zero();
}
if exp_len > max_len {
return U256::max_value();
}
let exp_len = exp_len.low_u64();
// read fist 32-byte word of the exponent.
let exp_low = if base_len + 96 >= input.len() as u64 { U256::zero() } else {
let mut buf = [0; 32];
Expand Down Expand Up @@ -707,6 +710,24 @@ mod tests {
native: ethereum_builtin("modexp"),
activate_at: 0,
};

// test for potential exp len overflow
{
let input = FromHex::from_hex("\
00000000000000000000000000000000000000000000000000000000000000ff\
2a1e530000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000"
).unwrap();

let mut output = vec![0u8; 32];
let expected = FromHex::from_hex("0000000000000000000000000000000000000000000000000000000000000000").unwrap();
let expected_cost = U256::max_value();

f.execute(&input[..], &mut BytesRef::Fixed(&mut output[..])).expect("Builtin should fail");
assert_eq!(output, expected);
assert_eq!(f.cost(&input[..]), expected_cost.into());
}

// fermat's little theorem example.
{
let input = FromHex::from_hex("\
Expand Down

0 comments on commit ab63044

Please sign in to comment.