Additional check before conversion

This commit is contained in:
Tomusdrw 2016-01-17 14:08:31 +01:00
parent aca68dcfe7
commit c8d94c981b
1 changed files with 6 additions and 2 deletions

View File

@ -491,8 +491,12 @@ impl Interpreter {
// s * memory_gas + s * s / quad_coeff_div
let a = overflowing!(s.overflowing_mul(U256::from(schedule.memory_gas)));
// We need to go to U512 to calculate s*s/quad_coeff_div
let b = U256::from(U512::from(s) * U512::from(s) / U512::from(schedule.quad_coeff_div));
Ok(overflowing!(a.overflowing_add(b)))
let b = U512::from(s) * U512::from(s) / U512::from(schedule.quad_coeff_div);
if b > U512::from(!U256::zero()) {
Err(evm::Error::OutOfGas)
} else {
Ok(overflowing!(a.overflowing_add(U256::from(b))))
}
};
let current_mem_size = U256::from(current_mem_size);
let req_mem_size_rounded = (overflowing!(mem_size.overflowing_add(U256::from(31))) >> 5) << 5;