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

Commit 3a6a8ac

Browse files
committed
Fixed modexp reading huge numbers
1 parent 607a1c6 commit 3a6a8ac

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

ethcore/src/builtin.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,18 @@ impl Impl for ModexpImpl {
367367
let exp_len = read_len(&mut reader);
368368
let mod_len = read_len(&mut reader);
369369

370-
// read the numbers themselves.
371-
let mut buf = vec![0; max(mod_len, max(base_len, exp_len))];
372-
let mut read_num = |len| {
373-
reader.read_exact(&mut buf[..len]).expect("reading from zero-extended memory cannot fail; qed");
374-
BigUint::from_bytes_be(&buf[..len])
375-
};
376-
377-
let base = read_num(base_len);
378370
// Gas formula allows arbitrary large exp_len when base and modulus are empty, so we need to handle empty base first.
379371
let r = if base_len == 0 && mod_len == 0 {
380372
BigUint::zero()
381373
} else {
374+
// read the numbers themselves.
375+
let mut buf = vec![0; max(mod_len, max(base_len, exp_len))];
376+
let mut read_num = |len| {
377+
reader.read_exact(&mut buf[..len]).expect("reading from zero-extended memory cannot fail; qed");
378+
BigUint::from_bytes_be(&buf[..len])
379+
};
380+
381+
let base = read_num(base_len);
382382
let exp = read_num(exp_len);
383383
let modulus = read_num(mod_len);
384384
modexp(base, exp, modulus)

0 commit comments

Comments
 (0)