[Beta] Backports (#7945)

* ECIP 1041 - Remove Difficulty Bomb (#7905)

Enable difficulty bomb defusion at block:
 - 5900000 on Ethereum Classic mainnet,
 - 2300000 on morden testnet.

Reference:
https://github.com/ethereumproject/ECIPs/blob/master/ECIPs/ECIP-1041.md

* spec: Validate required divisor fields are not 0 (#7933)

* Add validate_non_zero function

It's used to validate that a Spec's uint field used as a divisor is not zero.

* Add deserialize_with to gas_limit_bound_divisor

Prevents panics due to divide-by-zero on the gas_limit_bound_divisor
field.

* Add deserialize_with to difficulty_bound_divisor

Prevents panics due to divide-by-zero on the difficulty_bound_divisor
field.

* Add validate_optional_non_zero function

Used to validate Option<Uint> divisor fields.

* Use deserialize_with on optional divisor fields.

* Add #[serde(default)] attribute to divisor fields

When using `#[serde(deserialize_with)]`, `#[serde(default)]` must be specified so that missing
fields can be deserialized with the deserializer for `None`.

* Kovan WASM fork code (#7849)

* kovan fork code

* introduce ethcore level vm_factory and let it fail

* fix json tests

* wasmcosts as option

* review changes

* wasm costs in parser

* fix evm tests

* review fixes

* fix test

* remove redundant json field
This commit is contained in:
André Silva
2018-02-19 15:05:21 +00:00
committed by Rando
parent 3bfb2fa1aa
commit 804ddfe31e
32 changed files with 402 additions and 169 deletions

View File

@@ -186,7 +186,7 @@ impl<'a> Runtime<'a> {
pub fn adjusted_charge<F>(&mut self, f: F) -> Result<()>
where F: FnOnce(&vm::Schedule) -> u64
{
self.charge(|schedule| f(schedule) * schedule.wasm.opcodes_div as u64 / schedule.wasm.opcodes_mul as u64)
self.charge(|schedule| f(schedule) * schedule.wasm().opcodes_div as u64 / schedule.wasm().opcodes_mul as u64)
}
/// Charge gas provided by the closure, and closure also can return overflowing
@@ -212,8 +212,8 @@ impl<'a> Runtime<'a> {
{
self.overflow_charge(|schedule|
f(schedule)
.and_then(|x| x.checked_mul(schedule.wasm.opcodes_div as u64))
.map(|x| x / schedule.wasm.opcodes_mul as u64)
.and_then(|x| x.checked_mul(schedule.wasm().opcodes_div as u64))
.map(|x| x / schedule.wasm().opcodes_mul as u64)
)
}
@@ -385,8 +385,8 @@ impl<'a> Runtime<'a> {
// todo: optimize to use memory views once it's in
let payload = self.memory.get(input_ptr, input_len as usize)?;
let adjusted_gas = match gas.checked_mul(self.ext.schedule().wasm.opcodes_div as u64)
.map(|x| x / self.ext.schedule().wasm.opcodes_mul as u64)
let adjusted_gas = match gas.checked_mul(self.ext.schedule().wasm().opcodes_div as u64)
.map(|x| x / self.ext.schedule().wasm().opcodes_mul as u64)
{
Some(x) => x,
None => {
@@ -412,8 +412,8 @@ impl<'a> Runtime<'a> {
vm::MessageCallResult::Success(gas_left, _) => {
// cannot overflow, before making call gas_counter was incremented with gas, and gas_left < gas
self.gas_counter = self.gas_counter -
gas_left.low_u64() * self.ext.schedule().wasm.opcodes_div as u64
/ self.ext.schedule().wasm.opcodes_mul as u64;
gas_left.low_u64() * self.ext.schedule().wasm().opcodes_div as u64
/ self.ext.schedule().wasm().opcodes_mul as u64;
self.memory.set(result_ptr, &result)?;
Ok(0i32.into())
@@ -421,8 +421,8 @@ impl<'a> Runtime<'a> {
vm::MessageCallResult::Reverted(gas_left, _) => {
// cannot overflow, before making call gas_counter was incremented with gas, and gas_left < gas
self.gas_counter = self.gas_counter -
gas_left.low_u64() * self.ext.schedule().wasm.opcodes_div as u64
/ self.ext.schedule().wasm.opcodes_mul as u64;
gas_left.low_u64() * self.ext.schedule().wasm().opcodes_div as u64
/ self.ext.schedule().wasm().opcodes_mul as u64;
self.memory.set(result_ptr, &result)?;
Ok((-1i32).into())
@@ -450,14 +450,14 @@ impl<'a> Runtime<'a> {
fn return_address_ptr(&mut self, ptr: u32, val: Address) -> Result<()>
{
self.charge(|schedule| schedule.wasm.static_address as u64)?;
self.charge(|schedule| schedule.wasm().static_address as u64)?;
self.memory.set(ptr, &*val)?;
Ok(())
}
fn return_u256_ptr(&mut self, ptr: u32, val: U256) -> Result<()> {
let value: H256 = val.into();
self.charge(|schedule| schedule.wasm.static_u256 as u64)?;
self.charge(|schedule| schedule.wasm().static_u256 as u64)?;
self.memory.set(ptr, &*value)?;
Ok(())
}
@@ -489,8 +489,8 @@ impl<'a> Runtime<'a> {
self.adjusted_charge(|schedule| schedule.create_data_gas as u64 * code.len() as u64)?;
let gas_left: U256 = U256::from(self.gas_left()?)
* U256::from(self.ext.schedule().wasm.opcodes_mul)
/ U256::from(self.ext.schedule().wasm.opcodes_div);
* U256::from(self.ext.schedule().wasm().opcodes_mul)
/ U256::from(self.ext.schedule().wasm().opcodes_div);
match self.ext.create(&gas_left, &endowment, &code, vm::CreateContractAddress::FromSenderAndCodeHash) {
vm::ContractCreateResult::Created(address, gas_left) => {
@@ -498,8 +498,8 @@ impl<'a> Runtime<'a> {
self.gas_counter = self.gas_limit -
// this cannot overflow, since initial gas is in [0..u64::max) range,
// and gas_left cannot be bigger
gas_left.low_u64() * self.ext.schedule().wasm.opcodes_div as u64
/ self.ext.schedule().wasm.opcodes_mul as u64;
gas_left.low_u64() * self.ext.schedule().wasm().opcodes_div as u64
/ self.ext.schedule().wasm().opcodes_mul as u64;
trace!(target: "wasm", "runtime: create contract success (@{:?})", address);
Ok(0i32.into())
},
@@ -512,8 +512,8 @@ impl<'a> Runtime<'a> {
self.gas_counter = self.gas_limit -
// this cannot overflow, since initial gas is in [0..u64::max) range,
// and gas_left cannot be bigger
gas_left.low_u64() * self.ext.schedule().wasm.opcodes_div as u64
/ self.ext.schedule().wasm.opcodes_mul as u64;
gas_left.low_u64() * self.ext.schedule().wasm().opcodes_div as u64
/ self.ext.schedule().wasm().opcodes_mul as u64;
Ok((-1i32).into())
},