Skip to content

Commit 62210fb

Browse files
NikVolfgavofyork
authored andcommitted
WASM contracts MVP (#5679)
* lifetime issues * refactor to new 'native env' * descriptors and such * wasm mvp continued * finalized env/ext bindings * descriptor -> call_args * inject gas counter * result processing and engine activation * tabify some source files * needs return new * wasm tests initial * erradicate warnings * origin in the descriptor * update test repo * payload verification tests * identity return payload test * some test description * dispersion test * check length here * suicidal contract * engine params * fix typo * review fixes * submodule update * update - purge reserved space * doc effort * more review fixes * fix error message * fix dependency url * reorg error handling * update submodule * update utils * update to latest parity-wasm * tabify * fix wasm magic header * update dependencies * external create and tests * update to latest tests * extra trace info * Update parity-wasm * update wasm-utils also * few traces and result handle change * alter trace content * fix issues with optimizer, update to latest parity with validator, etc * static initialization * license preamble * update wasm crates and gas costs * fix grumbles * bring back lifetime * fix compilation
1 parent b49c039 commit 62210fb

21 files changed

+1241
-17
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
path = ethcore/res/ethereum/tests
33
url = https://github.com/ethereum/tests.git
44
branch = develop
5+
[submodule "ethcore/res/wasm-tests"]
6+
path = ethcore/res/wasm-tests
7+
url = https://github.com/paritytech/wasm-tests

Cargo.lock

+82
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ethcore/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ semver = "0.6"
5252
stats = { path = "../util/stats" }
5353
time = "0.1"
5454
transient-hashmap = "0.4"
55+
parity-wasm = { git = "https://github.com/nikvolf/parity-wasm" }
56+
wasm-utils = { git = "https://github.com/paritytech/wasm-utils" }
5557

5658
[dev-dependencies]
5759
native-contracts = { path = "native_contracts", features = ["test_contracts"] }

ethcore/res/wasm-tests

Submodule wasm-tests added at 9ed6304

ethcore/src/action_params.rs

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ impl ActionValue {
3939
ActionValue::Transfer(x) | ActionValue::Apparent(x) => x
4040
}
4141
}
42+
43+
/// Returns the transfer action value of the U256-convertable raw value
44+
pub fn transfer<T: Into<U256>>(transfer_value: T) -> ActionValue {
45+
ActionValue::Transfer(transfer_value.into())
46+
}
47+
48+
/// Returns the apparent action value of the U256-convertable raw value
49+
pub fn apparent<T: Into<U256>>(apparent_value: T) -> ActionValue {
50+
ActionValue::Apparent(apparent_value.into())
51+
}
4252
}
4353

4454
// TODO: should be a trait, possible to avoid cloning everything from a Transaction(/View).

ethcore/src/engines/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ pub trait Engine : Sync + Send {
376376
self.snapshot_components().is_some()
377377
}
378378

379+
/// If this engine supports wasm contracts.
380+
fn supports_wasm(&self) -> bool {
381+
self.params().wasm
382+
}
383+
379384
/// Returns new contract address generation scheme at given block number.
380385
fn create_address_scheme(&self, number: BlockNumber) -> CreateContractAddress {
381386
if number >= self.params().eip86_transition {

ethcore/src/evm/evm.rs

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use util::{U128, U256, U512, trie};
2121
use action_params::ActionParams;
2222
use evm::Ext;
2323
use builtin;
24+
use super::wasm;
2425

2526
/// Evm errors.
2627
#[derive(Debug, Clone, PartialEq)]
@@ -66,6 +67,8 @@ pub enum Error {
6667
MutableCallInStaticContext,
6768
/// Likely to cause consensus issues.
6869
Internal(String),
70+
/// Wasm runtime error
71+
Wasm(String),
6972
}
7073

7174
impl From<Box<trie::TrieError>> for Error {
@@ -80,6 +83,12 @@ impl From<builtin::Error> for Error {
8083
}
8184
}
8285

86+
impl From<wasm::RuntimeError> for Error {
87+
fn from(err: wasm::RuntimeError) -> Self {
88+
Error::Wasm(format!("Runtime error: {:?}", err))
89+
}
90+
}
91+
8392
impl fmt::Display for Error {
8493
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8594
use self::Error::*;
@@ -92,6 +101,7 @@ impl fmt::Display for Error {
92101
BuiltIn(name) => write!(f, "Built-in failed: {}", name),
93102
Internal(ref msg) => write!(f, "Internal error: {}", msg),
94103
MutableCallInStaticContext => write!(f, "Mutable call in static context"),
104+
Wasm(ref msg) => write!(f, "Internal error: {}", msg),
95105
}
96106
}
97107
}

ethcore/src/evm/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub mod interpreter;
2222
#[macro_use]
2323
pub mod factory;
2424
pub mod schedule;
25+
pub mod wasm;
2526

2627
mod vmtype;
2728
mod instructions;

ethcore/src/evm/tests.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,31 @@ pub enum FakeCallType {
3939

4040
#[derive(PartialEq, Eq, Hash, Debug)]
4141
pub struct FakeCall {
42-
call_type: FakeCallType,
43-
gas: U256,
44-
sender_address: Option<Address>,
45-
receive_address: Option<Address>,
46-
value: Option<U256>,
47-
data: Bytes,
48-
code_address: Option<Address>,
42+
pub call_type: FakeCallType,
43+
pub gas: U256,
44+
pub sender_address: Option<Address>,
45+
pub receive_address: Option<Address>,
46+
pub value: Option<U256>,
47+
pub data: Bytes,
48+
pub code_address: Option<Address>,
4949
}
5050

5151
/// Fake externalities test structure.
5252
///
5353
/// Can't do recursive calls.
5454
#[derive(Default)]
5555
pub struct FakeExt {
56+
pub store: HashMap<H256, H256>,
57+
pub suicides: HashSet<Address>,
58+
pub calls: HashSet<FakeCall>,
5659
sstore_clears: usize,
5760
depth: usize,
58-
store: HashMap<H256, H256>,
5961
blockhashes: HashMap<U256, H256>,
6062
codes: HashMap<Address, Arc<Bytes>>,
6163
logs: Vec<FakeLogEntry>,
62-
_suicides: HashSet<Address>,
6364
info: EnvInfo,
6465
schedule: Schedule,
6566
balances: HashMap<Address, U256>,
66-
calls: HashSet<FakeCall>,
6767
}
6868

6969
// similar to the normal `finalize` function, but ignoring NeedsReturn.
@@ -173,8 +173,9 @@ impl Ext for FakeExt {
173173
unimplemented!();
174174
}
175175

176-
fn suicide(&mut self, _refund_address: &Address) -> evm::Result<()> {
177-
unimplemented!();
176+
fn suicide(&mut self, refund_address: &Address) -> evm::Result<()> {
177+
self.suicides.insert(refund_address.clone());
178+
Ok(())
178179
}
179180

180181
fn schedule(&self) -> &Schedule {

0 commit comments

Comments
 (0)