diff --git a/.travis.yml b/.travis.yml index 8275c6f..0f8ca59 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,12 @@ rust: sudo: required services: - docker + +before_install: + # Install wasm toolchain and put it in the PATH + - WATERFALL_BUILD=31834 ./wasm-install.sh + - export PATH=$PATH:./wasm-install/bin script: - rustup target add wasm32-unknown-unknown - cargo install pwasm-utils --version 0.1 - - ./build.sh + - ./build-all.sh diff --git a/build-all.sh b/build-all.sh new file mode 100755 index 0000000..3b5aa04 --- /dev/null +++ b/build-all.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +./build-rust-test.sh alloc +./build-rust-test.sh call +./build-rust-test.sh call_code +./build-rust-test.sh call_static +./build-rust-test.sh creator +./build-rust-test.sh dispersion +./build-rust-test.sh empty +./build-rust-test.sh externs +./build-rust-test.sh events +./build-rust-test.sh identity +./build-rust-test.sh logger +./build-rust-test.sh realloc +./build-rust-test.sh rterr +./build-rust-test.sh keccak +./build-rust-test.sh suicidal +./build-rust-test.sh storage_read +./build-rust-test.sh math +./build-rust-test.sh setter +./build-wat.sh recursive diff --git a/build-rust-test.sh b/build-rust-test.sh new file mode 100755 index 0000000..86f7297 --- /dev/null +++ b/build-rust-test.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +TEST_NAME=$1 + +cargo run --manifest-path ./gen/Cargo.toml -- $TEST_NAME +RUSTFLAGS="-C link-arg=-z -C link-arg=stack-size=65536" CARGO_TARGET_DIR=./target cargo build --manifest-path=./target/tests/$TEST_NAME/Cargo.toml --release --target=wasm32-unknown-unknown +wasm-build ./target $TEST_NAME --target wasm32-unknown-unknown +cp ./target/$TEST_NAME.wasm ./compiled diff --git a/build-test.sh b/build-test.sh deleted file mode 100755 index 0ae4fd3..0000000 --- a/build-test.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -TEST_NAME=$1 - -cargo run --manifest-path ./gen/Cargo.toml -- $TEST_NAME && -CARGO_TARGET_DIR=./target cargo build --manifest-path=./target/tests/$TEST_NAME/Cargo.toml --release --target=wasm32-unknown-unknown && -wasm-build ./target $TEST_NAME --target wasm32-unknown-unknown && -cp ./target/$TEST_NAME.wasm ./compiled diff --git a/build-wat.sh b/build-wat.sh new file mode 100755 index 0000000..0921bfc --- /dev/null +++ b/build-wat.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +TEST_NAME=$1 + +mkdir -p ./target/wasm32-unknown-unknown/release/ +wat2wasm src/$TEST_NAME.wat -o ./target/wasm32-unknown-unknown/release/$TEST_NAME.wasm + +wasm-build ./target $TEST_NAME --target wasm32-unknown-unknown +cp ./target/$TEST_NAME.wasm ./compiled diff --git a/build.sh b/build.sh deleted file mode 100755 index debe586..0000000 --- a/build.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -./build-test.sh alloc && -./build-test.sh call && -./build-test.sh call_code && -./build-test.sh call_static && -./build-test.sh creator && -./build-test.sh dispersion && -./build-test.sh empty && -./build-test.sh externs && -./build-test.sh events && -./build-test.sh identity && -./build-test.sh logger && -./build-test.sh realloc && -./build-test.sh rterr && -./build-test.sh keccak && -./build-test.sh suicidal && -./build-test.sh storage_read && -./build-test.sh math && -./build-test.sh setter diff --git a/compiled/alloc.wasm b/compiled/alloc.wasm index 7d51a3d..f1a9ef4 100644 Binary files a/compiled/alloc.wasm and b/compiled/alloc.wasm differ diff --git a/compiled/call.wasm b/compiled/call.wasm index 86c9c91..7a40eab 100644 Binary files a/compiled/call.wasm and b/compiled/call.wasm differ diff --git a/compiled/call_code.wasm b/compiled/call_code.wasm index 1ed2fa8..9c21333 100644 Binary files a/compiled/call_code.wasm and b/compiled/call_code.wasm differ diff --git a/compiled/call_static.wasm b/compiled/call_static.wasm index 356eb24..3b676f9 100644 Binary files a/compiled/call_static.wasm and b/compiled/call_static.wasm differ diff --git a/compiled/creator.wasm b/compiled/creator.wasm index 1997777..2c7d178 100644 Binary files a/compiled/creator.wasm and b/compiled/creator.wasm differ diff --git a/compiled/dispersion.wasm b/compiled/dispersion.wasm index 4fdf5d5..f7a2fe4 100644 Binary files a/compiled/dispersion.wasm and b/compiled/dispersion.wasm differ diff --git a/compiled/empty.wasm b/compiled/empty.wasm index 7125e40..98669bd 100644 Binary files a/compiled/empty.wasm and b/compiled/empty.wasm differ diff --git a/compiled/events.wasm b/compiled/events.wasm index 850642c..cf8d375 100644 Binary files a/compiled/events.wasm and b/compiled/events.wasm differ diff --git a/compiled/externs.wasm b/compiled/externs.wasm index 991b6ed..85782e3 100644 Binary files a/compiled/externs.wasm and b/compiled/externs.wasm differ diff --git a/compiled/identity.wasm b/compiled/identity.wasm index 13dc99b..0844beb 100644 Binary files a/compiled/identity.wasm and b/compiled/identity.wasm differ diff --git a/compiled/keccak.wasm b/compiled/keccak.wasm index 1702179..bde4bd0 100644 Binary files a/compiled/keccak.wasm and b/compiled/keccak.wasm differ diff --git a/compiled/logger.wasm b/compiled/logger.wasm index 475816e..ec099f1 100644 Binary files a/compiled/logger.wasm and b/compiled/logger.wasm differ diff --git a/compiled/math.wasm b/compiled/math.wasm index b58af04..ac072dc 100644 Binary files a/compiled/math.wasm and b/compiled/math.wasm differ diff --git a/compiled/realloc.wasm b/compiled/realloc.wasm index 98187b0..7504164 100644 Binary files a/compiled/realloc.wasm and b/compiled/realloc.wasm differ diff --git a/compiled/recursive.wasm b/compiled/recursive.wasm new file mode 100644 index 0000000..69ff639 Binary files /dev/null and b/compiled/recursive.wasm differ diff --git a/compiled/rterr.wasm b/compiled/rterr.wasm index 67d4927..8fccf87 100644 Binary files a/compiled/rterr.wasm and b/compiled/rterr.wasm differ diff --git a/compiled/setter.wasm b/compiled/setter.wasm index c8c9774..d0656ef 100644 Binary files a/compiled/setter.wasm and b/compiled/setter.wasm differ diff --git a/compiled/storage_read.wasm b/compiled/storage_read.wasm index c0b1928..08e8095 100644 Binary files a/compiled/storage_read.wasm and b/compiled/storage_read.wasm differ diff --git a/compiled/suicidal.wasm b/compiled/suicidal.wasm index ef0ab0c..f4ccd14 100644 Binary files a/compiled/suicidal.wasm and b/compiled/suicidal.wasm differ diff --git a/gen/main.rs b/gen/main.rs index f5dd918..42799f8 100644 --- a/gen/main.rs +++ b/gen/main.rs @@ -17,14 +17,19 @@ version = "0.1.0" authors = ["NikVolf "] [dependencies] -pwasm-std = "0.5.0" -pwasm-ethereum = "0.1.0" +pwasm-std = "0.9.0" +pwasm-ethereum = "0.5.0" bigint = { version = "4", default-features = false } [lib] name = "$file_name" path = "main.rs" crate-type = ["cdylib"] + +[profile.release] +panic = "abort" +lto = true +opt-level = "z" "#; let target_toml = toml.replace("$file_name", file_name); diff --git a/rust-toolchain b/rust-toolchain index 8635e01..b66c3c9 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2018-02-05 +nightly-2018-06-28 diff --git a/src/alloc.rs b/src/alloc.rs index c19dcf8..367f574 100644 --- a/src/alloc.rs +++ b/src/alloc.rs @@ -8,8 +8,8 @@ use pwasm_std::Vec; #[no_mangle] pub fn call() { ext::ret(&{ - let mut data = Vec::with_capacity(450 * 1024); - data.extend_from_slice(&[5u8; 450*1024][..]); + let mut data = Vec::with_capacity(400 * 1024); + data.extend_from_slice(&[5u8; 400*1024][..]); data }); } \ No newline at end of file diff --git a/src/recursive.wat b/src/recursive.wat new file mode 100644 index 0000000..9915a89 --- /dev/null +++ b/src/recursive.wat @@ -0,0 +1,51 @@ +(module + (import "env" "fetch_input" (func $fetch_input (param i32))) + (import "env" "input_length" (func $input_length (result i32))) + + + (func (export "call") + ;; Assert that input_length is exactly 4 bytes long. + (if + (i32.ne + (call $input_length) + (i32.const 4) + ) + (unreachable) + ) + + ;; Load input data at the address 0. + ;; + ;; It contains only 1 word that represents an iteration count. + (call $fetch_input + (i32.const 0) + ) + + ;; Load the iteration count from the address 0 and then + ;; call $recursive with this number. + ;; Drop the result (since it's always zero). + (drop + (call $recursive + (i32.load + (i32.const 0) + ) + ) + ) + ) + + (func $recursive (param i32) (result i32) + block $out (result i32) + get_local 0 + get_local 0 + i32.eqz + br_if $out + + i32.const 1 + i32.sub + call $recursive + end + ) + + (table 0 anyfunc) + (memory 1) + (export "memory" (memory 0)) +) diff --git a/wasm-install.sh b/wasm-install.sh new file mode 100755 index 0000000..f54e5d3 --- /dev/null +++ b/wasm-install.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# this script is intended to be used from .travis.yml. +# Takes an environment variable WATERFALL_BUILD to download a +# specific version of a waterfall build. + +set -e + +if [ -z ${WATERFALL_BUILD+x} ]; then + echo "the WATERFALL_BUILD environment variable is unset"; + exit 1; +fi + +curl -sL https://storage.googleapis.com/wasm-llvm/builds/linux/$WATERFALL_BUILD/wasm-binaries.tbz2 | tar xvkj