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

Commit

Permalink
Kovan WASM fork code (#7849)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
NikVolf authored and andresilva committed Feb 19, 2018
1 parent c73a38c commit 1019879
Show file tree
Hide file tree
Showing 28 changed files with 338 additions and 162 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions ethcore/evm/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Factory {
/// Create fresh instance of VM
/// Might choose implementation depending on supplied gas.
#[cfg(feature = "jit")]
pub fn create(&self, gas: U256) -> Box<Vm> {
pub fn create(&self, gas: &U256) -> Box<Vm> {
match self.evm {
VMType::Jit => {
Box::new(super::jit::JitEvm::default())
Expand All @@ -49,7 +49,7 @@ impl Factory {
/// Create fresh instance of VM
/// Might choose implementation depending on supplied gas.
#[cfg(not(feature = "jit"))]
pub fn create(&self, gas: U256) -> Box<Vm> {
pub fn create(&self, gas: &U256) -> Box<Vm> {
match self.evm {
VMType::Interpreter => if Self::can_fit_in_usize(gas) {
Box::new(super::interpreter::Interpreter::<usize>::new(self.evm_cache.clone()))
Expand All @@ -68,8 +68,8 @@ impl Factory {
}
}

fn can_fit_in_usize(gas: U256) -> bool {
gas == U256::from(gas.low_u64() as usize)
fn can_fit_in_usize(gas: &U256) -> bool {
gas == &U256::from(gas.low_u64() as usize)
}
}

Expand All @@ -95,7 +95,7 @@ impl Default for Factory {

#[test]
fn test_create_vm() {
let _vm = Factory::default().create(U256::zero());
let _vm = Factory::default().create(&U256::zero());
}

/// Create tests by injecting different VM factories
Expand Down
11 changes: 8 additions & 3 deletions ethcore/evm/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,13 @@ mod tests {
use rustc_hex::FromHex;
use vmtype::VMType;
use factory::Factory;
use vm::{ActionParams, ActionValue};
use vm::{Vm, ActionParams, ActionValue};
use vm::tests::{FakeExt, test_finalize};
use bigint::prelude::U256;

fn interpreter(gas: &U256) -> Box<Vm> {
Factory::new(VMType::Interpreter, 1).create(gas)
}

#[test]
fn should_not_fail_on_tracing_mem() {
Expand All @@ -932,7 +937,7 @@ mod tests {
ext.tracing = true;

let gas_left = {
let mut vm = Factory::new(VMType::Interpreter, 1).create(params.gas);
let mut vm = interpreter(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -954,7 +959,7 @@ mod tests {
ext.tracing = true;

let err = {
let mut vm = Factory::new(VMType::Interpreter, 1).create(params.gas);
let mut vm = interpreter(&params.gas);
test_finalize(vm.exec(params, &mut ext)).err().unwrap()
};

Expand Down
70 changes: 35 additions & 35 deletions ethcore/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn test_add(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -60,7 +60,7 @@ fn test_sha3(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -80,7 +80,7 @@ fn test_address(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -102,7 +102,7 @@ fn test_origin(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -124,7 +124,7 @@ fn test_sender(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand Down Expand Up @@ -159,7 +159,7 @@ fn test_extcodecopy(factory: super::Factory) {
ext.codes.insert(sender, Arc::new(sender_code));

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -179,7 +179,7 @@ fn test_log_empty(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand Down Expand Up @@ -211,7 +211,7 @@ fn test_log_sender(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -236,7 +236,7 @@ fn test_blockhash(factory: super::Factory) {
ext.blockhashes.insert(U256::zero(), blockhash.clone());

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -258,7 +258,7 @@ fn test_calldataload(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -279,7 +279,7 @@ fn test_author(factory: super::Factory) {
ext.info.author = author;

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -299,7 +299,7 @@ fn test_timestamp(factory: super::Factory) {
ext.info.timestamp = timestamp;

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -319,7 +319,7 @@ fn test_number(factory: super::Factory) {
ext.info.number = number;

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -339,7 +339,7 @@ fn test_difficulty(factory: super::Factory) {
ext.info.difficulty = difficulty;

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -359,7 +359,7 @@ fn test_gas_limit(factory: super::Factory) {
ext.info.gas_limit = gas_limit;

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -377,7 +377,7 @@ fn test_mul(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -395,7 +395,7 @@ fn test_sub(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -413,7 +413,7 @@ fn test_div(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -431,7 +431,7 @@ fn test_div_zero(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -449,7 +449,7 @@ fn test_mod(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -468,7 +468,7 @@ fn test_smod(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -487,7 +487,7 @@ fn test_sdiv(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -506,7 +506,7 @@ fn test_exp(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -526,7 +526,7 @@ fn test_comparison(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -547,7 +547,7 @@ fn test_signed_comparison(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -568,7 +568,7 @@ fn test_bitops(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -591,7 +591,7 @@ fn test_addmod_mulmod(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -612,7 +612,7 @@ fn test_byte(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -631,7 +631,7 @@ fn test_signextend(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -651,7 +651,7 @@ fn test_badinstruction_int() {
let mut ext = FakeExt::new();

let err = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap_err()
};

Expand All @@ -671,7 +671,7 @@ fn test_pop(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -691,7 +691,7 @@ fn test_extops(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand All @@ -714,7 +714,7 @@ fn test_jumps(factory: super::Factory) {
let mut ext = FakeExt::new();

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand Down Expand Up @@ -742,7 +742,7 @@ fn test_calls(factory: super::Factory) {
};

let gas_left = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap()
};

Expand Down Expand Up @@ -781,7 +781,7 @@ fn test_create_in_staticcall(factory: super::Factory) {
ext.is_static = true;

let err = {
let mut vm = factory.create(params.gas);
let mut vm = factory.create(&params.gas);
test_finalize(vm.exec(params, &mut ext)).unwrap_err()
};

Expand Down

0 comments on commit 1019879

Please sign in to comment.