Skip to content

Commit 2f83b1c

Browse files
Switch to manual parsing for validation (#157)
* wasm-parser: remove parity-wasm dependency * wasm-parser: proof of basic idea * wasm-parser: import instruction mappings from parity-wasm * wasm-parser: build and link with kernel * wasm-parser: fix parsing of import entries * wasm-parser: add missing file * kernel: add test script * wasm-parser: minor cleanup * circleci: don't force rebuild of parity-ethereum * kernel: update tests to be more accurate * kernel: update nightly version for alloc crate * circleci: fix error with parity installation * circleci: fix error in previous commit * wasm-parser: reinclude alloc * wasm-parser: merge Cursor and CodeCursor * circleci: add example contract 2 * circleci: set-up environment for test * circleci: fix example_contract_2 build * wasm-parser: properly validate instructions in syscall * wasm-parser: fix import cursor progression * circleci: remove config step from parity * circleci: clear cache
1 parent f912c3d commit 2f83b1c

File tree

23 files changed

+3915
-189
lines changed

23 files changed

+3915
-189
lines changed

.circleci/config.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ jobs:
4343
steps:
4444
- restore_cache:
4545
keys:
46-
- deps6-{{ .Branch }}-{{ .Revision }}
47-
# - deps6-{{ .Branch }}-cargo-{{ checksum "kernel-ewasm/Cargo.lock" }}
48-
- deps6-{{ .Branch }}-
49-
- deps6-
46+
- deps7-{{ .Branch }}-{{ .Revision }}
47+
# - deps7-{{ .Branch }}-cargo-{{ checksum "kernel-ewasm/Cargo.lock" }}
48+
- deps7-{{ .Branch }}-
49+
- deps7-
5050
- run:
5151
name: Install native build prequisites
5252
command: |
@@ -96,9 +96,13 @@ jobs:
9696
# cargo build --verbose --release --features final
9797
# strip target/debug/parity
9898
# file target/debug/parity
99-
cargo install --bin parity -j 1 --path . --bin parity parity-ethereum --force
99+
if parity --version; then
100+
echo "Parity node installed"
101+
else
102+
cargo install --bin parity -j 1 --path . --bin parity parity-ethereum
103+
fi
100104
- save_cache:
101-
key: deps6-{{ .Branch }}-cargo #-{{ checksum "kernel-ewasm/Cargo.lock" }}
105+
key: deps7-{{ .Branch }}-cargo #-{{ checksum "kernel-ewasm/Cargo.lock" }}
102106
paths:
103107
- "~/.cargo"
104108
- "~/.rustup"
@@ -118,7 +122,7 @@ jobs:
118122
cd kernel-ewasm
119123
# we need to run parity once to set up the accounts and keys
120124
# this only needs to be active for a few seconds (hence timeout)
121-
timeout 5 parity --config dev || true
125+
# timeout 5 parity --config dev || true
122126
# We then run parity properly, now unlocking the previously setup
123127
# account
124128
parity --config dev --chain ./wasm-dev-chain.json --jsonrpc-apis=all --ws-apis=all --reseal-min-period 0 --gasprice 0
@@ -135,6 +139,7 @@ jobs:
135139
- run:
136140
name: Test Rust Component
137141
command: |
142+
. ~/.profile
138143
cd cap9
139144
cd kernel-ewasm && npm install
140145
npm run test

kernel-ewasm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ crate-type = ["cdylib"]
2626
[features]
2727
default = ["std"]
2828
std = ["pwasm-std/std", "pwasm-ethereum/std", "pwasm-test/std"]
29+
panic_with_msg = ["pwasm-std/panic_with_msg"]
2930

3031
[profile.release]
3132
panic = "abort"

kernel-ewasm/build.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cargo install --path ..\cap9-build --bin cap9-build --force
66

77
set contract_name=kernel_ewasm
88

9-
cargo build --release --target wasm32-unknown-unknown --no-default-features
9+
cargo build --release --target wasm32-unknown-unknown --no-default-features --features "panic_with_msg"
1010
cap9-build set-mem --pages 3 .\target\wasm32-unknown-unknown\release\%contract_name%.wasm .\target\wasm32-unknown-unknown\release\%contract_name%.wasm
1111
wasm-build --target=wasm32-unknown-unknown .\target kernel-ewasm
1212
REM ..\..\wasm-utils\target\debug\wasm-build.exe --target=wasm32-unknown-unknown .\target kernel-ewasm

kernel-ewasm/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ rustup target add wasm32-unknown-unknown
44
cargo install pwasm-utils-cli --bin wasm-build --version 0.6.0
55
cargo install --path ../cap9-build --bin cap9-build --force
66

7-
cargo build --release --target wasm32-unknown-unknown --no-default-features
7+
cargo build --release --target wasm32-unknown-unknown --no-default-features --features "panic_with_msg"
88
cap9-build set-mem --pages 3 ./target/wasm32-unknown-unknown/release/kernel_ewasm.wasm ./target/wasm32-unknown-unknown/release/kernel_ewasm.wasm
99
wasm-build --target=wasm32-unknown-unknown ./target kernel-ewasm
1010

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "example_contract_2"
3+
version = "0.1.0"
4+
5+
[dependencies]
6+
pwasm-std = "0.13"
7+
pwasm-ethereum = { version = "0.8", features = ["kip6"] }
8+
pwasm-abi = "0.2"
9+
pwasm-abi-derive = "0.2"
10+
tiny-keccak = "1.4.2"
11+
12+
[dev-dependencies]
13+
pwasm-test = { git = "https://github.com/paritytech/pwasm-test" }
14+
cap9-build = { path = "../../cap9-build" }
15+
pwasm-utils-cli = "0.7.0"
16+
17+
[features]
18+
default = []
19+
std = ["pwasm-std/std", "pwasm-ethereum/std"]
20+
21+
[lib]
22+
crate-type = ["cdylib"]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@echo OFF
2+
3+
mkdir .\build
4+
5+
rustup target add wasm32-unknown-unknown
6+
REM cargo install pwasm-utils-cli --bin wasm-build --force
7+
8+
set contract_name=example_contract_2
9+
10+
cargo build --release --target wasm32-unknown-unknown
11+
REM We don't need to use cap9 build here as it contains no syscalls
12+
wasm-build --target=wasm32-unknown-unknown .\target %contract_name%
13+
14+
copy .\target\*.wasm .\build
15+
copy .\target\json\* .\build
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@echo OFF
2+
3+
mkdir ./build
4+
5+
rustup target add wasm32-unknown-unknown
6+
REM cargo install pwasm-utils-cli --bin wasm-build --force
7+
cargo install --path ../../cap9-build --bin cap9-build --force
8+
9+
export contract_name=example_contract_2
10+
11+
cargo build --release --target wasm32-unknown-unknown
12+
# We don't need to use cap9 build here as it contains no syscalls
13+
wasm-build --target=wasm32-unknown-unknown ./target $contract_name
14+
15+
cp ./target/*.wasm ./build
16+
cp ./target/json/* ./build
Binary file not shown.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#![cfg_attr(not(feature="std"), no_std)]
2+
3+
#![allow(non_snake_case)]
4+
5+
extern crate tiny_keccak;
6+
extern crate pwasm_std;
7+
extern crate pwasm_ethereum;
8+
extern crate pwasm_abi;
9+
extern crate pwasm_abi_derive;
10+
11+
use tiny_keccak::Keccak;
12+
use pwasm_ethereum as eth;
13+
use pwasm_abi::types::*;
14+
use pwasm_abi_derive::eth_abi;
15+
use pwasm_ethereum::Error;
16+
17+
/// The call function is the main function of the *deployed* contract
18+
#[no_mangle]
19+
pub fn call() {
20+
let mut endpoint = contract::ExampleContract2Endpoint::new(contract::ExampleContract2{});
21+
pwasm_ethereum::ret(&endpoint.dispatch(&pwasm_ethereum::input()));
22+
}
23+
24+
// Declares the dispatch and dispatch_ctor methods
25+
use pwasm_abi::eth::EndpointInterface;
26+
27+
#[no_mangle]
28+
pub fn deploy() {
29+
let mut endpoint = contract::ExampleContract2Endpoint::new(contract::ExampleContract2{});
30+
endpoint.dispatch_ctor(&pwasm_ethereum::input());
31+
}
32+
33+
34+
pub mod contract {
35+
use super::*;
36+
use pwasm_abi_derive::eth_abi;
37+
38+
#[eth_abi(ExampleContract2Endpoint, ExampleContract2Client)]
39+
pub trait ExampleContract2Interface {
40+
/// Check if Procedure Contract is Valid
41+
fn check_contract(&mut self, _to: Address) -> bool;
42+
}
43+
44+
pub struct ExampleContract2;
45+
46+
impl ExampleContract2Interface for ExampleContract2 {
47+
fn check_contract(&mut self, _target: Address) -> bool {
48+
// unimplemented!()
49+
false
50+
}
51+
}
52+
}

kernel-ewasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"deploy": "node script/deploy.js",
8-
"test": "test.sh"
8+
"test": "sh ./test.sh"
99
},
1010
"author": "",
1111
"license": "ISC",

0 commit comments

Comments
 (0)