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

WASM contracts MVP #5679

Merged
merged 70 commits into from
Jul 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
d8cc649
lifetime issues
NikVolf May 17, 2017
36f51d6
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf May 17, 2017
1632387
refactor to new 'native env'
NikVolf May 19, 2017
d3c0e85
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf May 19, 2017
af5a4b4
descriptors and such
NikVolf May 21, 2017
9a8c3c3
wasm mvp continued
NikVolf May 21, 2017
7dced88
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf May 21, 2017
ee07e77
finalized env/ext bindings
NikVolf May 21, 2017
fcbd5bc
descriptor -> call_args
NikVolf May 22, 2017
d9c026c
inject gas counter
NikVolf May 22, 2017
a952b56
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf May 22, 2017
b073836
result processing and engine activation
NikVolf May 22, 2017
7c7c5b1
tabify some source files
NikVolf May 22, 2017
5b2aac6
Merge branch 'master' into wasm-mvp
NikVolf May 23, 2017
0546281
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf May 23, 2017
fe18e14
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf May 23, 2017
340b2fa
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf May 24, 2017
b39552d
needs return new
NikVolf May 24, 2017
0b8d0b4
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf May 25, 2017
34ad213
wasm tests initial
NikVolf May 26, 2017
290347e
erradicate warnings
NikVolf May 26, 2017
f7a8959
origin in the descriptor
NikVolf May 26, 2017
74cbc2f
Merge branch 'master' of github.com:paritytech/parity into wasm-mvp
NikVolf May 26, 2017
5f9056d
update test repo
NikVolf May 26, 2017
e80a75b
payload verification tests
NikVolf May 26, 2017
5edcaf3
identity return payload test
NikVolf May 26, 2017
a7c3e21
some test description
NikVolf May 26, 2017
e86ee04
dispersion test
NikVolf May 26, 2017
b3f3c76
check length here
NikVolf May 26, 2017
4596611
suicidal contract
NikVolf May 29, 2017
6ba30e1
engine params
NikVolf May 29, 2017
f0d5221
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf May 29, 2017
b871211
fix typo
NikVolf May 29, 2017
0842aa8
review fixes
NikVolf May 29, 2017
1258adc
submodule update
NikVolf May 29, 2017
29ef219
update - purge reserved space
NikVolf May 29, 2017
00dd894
doc effort
NikVolf May 29, 2017
223833b
more review fixes
NikVolf May 29, 2017
e3bb056
fix error message
NikVolf May 29, 2017
f3cd650
fix dependency url
NikVolf May 29, 2017
e12f7cb
reorg error handling
NikVolf May 29, 2017
c921e6e
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf May 30, 2017
7b261e3
update submodule
NikVolf May 30, 2017
e90a0d3
update utils
NikVolf May 30, 2017
15befc5
update to latest parity-wasm
NikVolf May 30, 2017
16c4916
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf May 31, 2017
ff871a9
tabify
NikVolf May 31, 2017
6c0b165
fix wasm magic header
NikVolf May 31, 2017
eaedb48
update dependencies
NikVolf Jun 2, 2017
615691c
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf Jun 2, 2017
07696d2
external create and tests
NikVolf Jun 2, 2017
165ffc0
update to latest tests
NikVolf Jun 2, 2017
efbc251
extra trace info
NikVolf Jun 5, 2017
af6b62f
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf Jun 6, 2017
2f0cd97
Update parity-wasm
NikVolf Jun 6, 2017
e6a1fd7
update wasm-utils also
NikVolf Jun 6, 2017
201a115
merge and update
NikVolf Jun 8, 2017
9222708
few traces and result handle change
NikVolf Jun 9, 2017
f514444
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf Jun 14, 2017
d873433
alter trace content
NikVolf Jun 14, 2017
6ca80c4
fix issues with optimizer, update to latest parity with validator, etc
NikVolf Jun 14, 2017
b45c451
static initialization
NikVolf Jun 14, 2017
7811663
license preamble
NikVolf Jun 14, 2017
540bd6a
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf Jun 19, 2017
ce97dcf
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf Jun 26, 2017
3b96f08
update wasm crates and gas costs
NikVolf Jun 26, 2017
59c5da4
Merge remote-tracking branch 'origin/master' into wasm-mvp
NikVolf Jul 3, 2017
397fb7b
fix grumbles
NikVolf Jul 10, 2017
1731787
bring back lifetime
NikVolf Jul 10, 2017
7dadc9f
fix compilation
NikVolf Jul 10, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
path = ethcore/res/ethereum/tests
url = https://github.com/ethereum/tests.git
branch = develop
[submodule "ethcore/res/wasm-tests"]
path = ethcore/res/wasm-tests
url = https://github.com/paritytech/wasm-tests
82 changes: 82 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions ethcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ semver = "0.6"
stats = { path = "../util/stats" }
time = "0.1"
transient-hashmap = "0.4"
parity-wasm = { git = "https://github.com/nikvolf/parity-wasm" }
wasm-utils = { git = "https://github.com/paritytech/wasm-utils" }

[dev-dependencies]
native-contracts = { path = "native_contracts", features = ["test_contracts"] }
Expand Down
1 change: 1 addition & 0 deletions ethcore/res/wasm-tests
Submodule wasm-tests added at 9ed630
10 changes: 10 additions & 0 deletions ethcore/src/action_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ impl ActionValue {
ActionValue::Transfer(x) | ActionValue::Apparent(x) => x
}
}

/// Returns the transfer action value of the U256-convertable raw value
pub fn transfer<T: Into<U256>>(transfer_value: T) -> ActionValue {
ActionValue::Transfer(transfer_value.into())
}

/// Returns the apparent action value of the U256-convertable raw value
pub fn apparent<T: Into<U256>>(apparent_value: T) -> ActionValue {
ActionValue::Apparent(apparent_value.into())
}
}

// TODO: should be a trait, possible to avoid cloning everything from a Transaction(/View).
Expand Down
5 changes: 5 additions & 0 deletions ethcore/src/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ pub trait Engine : Sync + Send {
self.snapshot_components().is_some()
}

/// If this engine supports wasm contracts.
fn supports_wasm(&self) -> bool {
self.params().wasm
}

/// Returns new contract address generation scheme at given block number.
fn create_address_scheme(&self, number: BlockNumber) -> CreateContractAddress {
if number >= self.params().eip86_transition {
Expand Down
10 changes: 10 additions & 0 deletions ethcore/src/evm/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use util::{U128, U256, U512, trie};
use action_params::ActionParams;
use evm::Ext;
use builtin;
use super::wasm;

/// Evm errors.
#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -66,6 +67,8 @@ pub enum Error {
MutableCallInStaticContext,
/// Likely to cause consensus issues.
Internal(String),
/// Wasm runtime error
Wasm(String),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something better we can give here than String? Maybe a WasmError enum with some number of "proper" error variants and one Unknown(String) variant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid to wrap parity_wasm::interpreter::Error, because it cannot be later meaningfully encoded as trace error and put in trace db, that's why it's encoded as string

Also I cannot imagine any code that would rely on handling specific wasm interpreter errors

Copy link
Contributor

@eira-fransham eira-fransham Jul 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as it's strictly for human-readable messages then that's fine. If we ever finding ourself matching on it we can refactor to make it an enum.

}

impl From<Box<trie::TrieError>> for Error {
Expand All @@ -80,6 +83,12 @@ impl From<builtin::Error> for Error {
}
}

impl From<wasm::RuntimeError> for Error {
fn from(err: wasm::RuntimeError) -> Self {
Error::Wasm(format!("Runtime error: {:?}", err))
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Error::*;
Expand All @@ -92,6 +101,7 @@ impl fmt::Display for Error {
BuiltIn(name) => write!(f, "Built-in failed: {}", name),
Internal(ref msg) => write!(f, "Internal error: {}", msg),
MutableCallInStaticContext => write!(f, "Mutable call in static context"),
Wasm(ref msg) => write!(f, "Internal error: {}", msg),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ethcore/src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod interpreter;
#[macro_use]
pub mod factory;
pub mod schedule;
pub mod wasm;

mod vmtype;
mod instructions;
Expand Down
25 changes: 13 additions & 12 deletions ethcore/src/evm/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ pub enum FakeCallType {

#[derive(PartialEq, Eq, Hash, Debug)]
pub struct FakeCall {
call_type: FakeCallType,
gas: U256,
sender_address: Option<Address>,
receive_address: Option<Address>,
value: Option<U256>,
data: Bytes,
code_address: Option<Address>,
pub call_type: FakeCallType,
pub gas: U256,
pub sender_address: Option<Address>,
pub receive_address: Option<Address>,
pub value: Option<U256>,
pub data: Bytes,
pub code_address: Option<Address>,
}

/// Fake externalities test structure.
///
/// Can't do recursive calls.
#[derive(Default)]
pub struct FakeExt {
pub store: HashMap<H256, H256>,
pub suicides: HashSet<Address>,
pub calls: HashSet<FakeCall>,
sstore_clears: usize,
depth: usize,
store: HashMap<H256, H256>,
blockhashes: HashMap<U256, H256>,
codes: HashMap<Address, Arc<Bytes>>,
logs: Vec<FakeLogEntry>,
_suicides: HashSet<Address>,
info: EnvInfo,
schedule: Schedule,
balances: HashMap<Address, U256>,
calls: HashSet<FakeCall>,
}

// similar to the normal `finalize` function, but ignoring NeedsReturn.
Expand Down Expand Up @@ -172,8 +172,9 @@ impl Ext for FakeExt {
unimplemented!();
}

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

fn schedule(&self) -> &Schedule {
Expand Down
Loading