diff --git a/README.md b/README.md index 337d45b..83ac301 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ Growing collection of varios WASM compilable contract examples, both source and ### Rust - Rust with `wasm32-unknown-unknown` target -- wasm-build util, run `cargo install pwasm-utils` to install -- bash to run `./build.sh` +- wasm-build util, run `cargo install pwasm-utils-cli` to install +- bash to run `./build-all.sh` ### C/C++ - to be updated diff --git a/build-all.sh b/build-all.sh index 3b5aa04..2900c2d 100755 --- a/build-all.sh +++ b/build-all.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e @@ -6,7 +6,7 @@ set -e ./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 creator kip4 ./build-rust-test.sh dispersion ./build-rust-test.sh empty ./build-rust-test.sh externs diff --git a/build-rust-test.sh b/build-rust-test.sh index 86f7297..615fbe3 100755 --- a/build-rust-test.sh +++ b/build-rust-test.sh @@ -1,10 +1,11 @@ -#!/bin/bash +#!/usr/bin/env bash set -e TEST_NAME=$1 +ADDITIONAL_FEATURES=$2 -cargo run --manifest-path ./gen/Cargo.toml -- $TEST_NAME +cargo run --manifest-path ./gen/Cargo.toml -- $TEST_NAME $ADDITIONAL_FEATURES 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 +wasm-build ./target $TEST_NAME --save-raw ./target/$TEST_NAME.raw.wasm --target wasm32-unknown-unknown +cp ./target/$TEST_NAME.raw.wasm ./compiled/$TEST_NAME.wasm diff --git a/build-wat.sh b/build-wat.sh index 0921bfc..a63011e 100755 --- a/build-wat.sh +++ b/build-wat.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e diff --git a/compiled/alloc.wasm b/compiled/alloc.wasm index f1a9ef4..c50b034 100644 Binary files a/compiled/alloc.wasm and b/compiled/alloc.wasm differ diff --git a/compiled/call.wasm b/compiled/call.wasm index 7a40eab..17c01fd 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 9c21333..9969222 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 3b676f9..cd6a144 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 2c7d178..9c09f37 100644 Binary files a/compiled/creator.wasm and b/compiled/creator.wasm differ diff --git a/compiled/dispersion.wasm b/compiled/dispersion.wasm index f7a2fe4..811b922 100644 Binary files a/compiled/dispersion.wasm and b/compiled/dispersion.wasm differ diff --git a/compiled/empty.wasm b/compiled/empty.wasm index 98669bd..920dc23 100644 Binary files a/compiled/empty.wasm and b/compiled/empty.wasm differ diff --git a/compiled/events.wasm b/compiled/events.wasm index cf8d375..5307ea0 100644 Binary files a/compiled/events.wasm and b/compiled/events.wasm differ diff --git a/compiled/externs.wasm b/compiled/externs.wasm index 85782e3..4f716c1 100644 Binary files a/compiled/externs.wasm and b/compiled/externs.wasm differ diff --git a/compiled/identity.wasm b/compiled/identity.wasm index 0844beb..45af38d 100644 Binary files a/compiled/identity.wasm and b/compiled/identity.wasm differ diff --git a/compiled/keccak.wasm b/compiled/keccak.wasm index bde4bd0..ea9a67c 100644 Binary files a/compiled/keccak.wasm and b/compiled/keccak.wasm differ diff --git a/compiled/logger.wasm b/compiled/logger.wasm index ec099f1..894b6a2 100644 Binary files a/compiled/logger.wasm and b/compiled/logger.wasm differ diff --git a/compiled/math.wasm b/compiled/math.wasm index ac072dc..4cc50c5 100644 Binary files a/compiled/math.wasm and b/compiled/math.wasm differ diff --git a/compiled/realloc.wasm b/compiled/realloc.wasm index 7504164..2a7d05b 100644 Binary files a/compiled/realloc.wasm and b/compiled/realloc.wasm differ diff --git a/compiled/rterr.wasm b/compiled/rterr.wasm index 8fccf87..43c77ee 100644 Binary files a/compiled/rterr.wasm and b/compiled/rterr.wasm differ diff --git a/compiled/setter.wasm b/compiled/setter.wasm index d0656ef..17a79eb 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 08e8095..cc6dcb4 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 f4ccd14..d857d42 100644 Binary files a/compiled/suicidal.wasm and b/compiled/suicidal.wasm differ diff --git a/gen/main.rs b/gen/main.rs index 42799f8..f15a232 100644 --- a/gen/main.rs +++ b/gen/main.rs @@ -3,23 +3,26 @@ use std::path::PathBuf; fn main() { let args = env::args().collect::>(); - if args.len() != 2 { - println!("Usage: {} gen ", args[0]); - return; - } - - let file_name = &args[1]; - - let toml = r#" + let (file_name, pwasm_ethereum_version) = match args.len() { + 2 => (&args[1], r#""0.6.1""#.to_string()), + 3 => (&args[1], format!(r#"{{ git = "https://github.com/paritytech/pwasm-ethereum", features = [{}] }}"#, args[2].split(",").map(|s| format!(r#""{}""#, s)).collect::>().join(", "))), + _ => { + println!("Usage: {} gen ", args[0]); + return; + }, + }; + + let toml = format!(r#" [package] name = "wasm-tests" version = "0.1.0" authors = ["NikVolf "] [dependencies] -pwasm-std = "0.9.0" -pwasm-ethereum = "0.5.0" -bigint = { version = "4", default-features = false } +pwasm-std = "0.10.0" +pwasm-ethereum = {} +bigint = {{ version = "4", default-features = false }} +parity-hash = {{ version = "1", default-features = false }} [lib] name = "$file_name" @@ -30,7 +33,7 @@ crate-type = ["cdylib"] panic = "abort" lto = true opt-level = "z" -"#; +"#, pwasm_ethereum_version); let target_toml = toml.replace("$file_name", file_name); diff --git a/rust-toolchain b/rust-toolchain index b66c3c9..e4c7292 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2018-06-28 +nightly-2018-07-24 diff --git a/src/alloc.rs b/src/alloc.rs index 367f574..a7efa21 100644 --- a/src/alloc.rs +++ b/src/alloc.rs @@ -12,4 +12,4 @@ pub fn call() { data.extend_from_slice(&[5u8; 400*1024][..]); data }); -} \ No newline at end of file +} diff --git a/src/creator.rs b/src/creator.rs index aad6733..1e7c9cc 100644 --- a/src/creator.rs +++ b/src/creator.rs @@ -2,16 +2,30 @@ extern crate pwasm_std; extern crate pwasm_ethereum; +extern crate bigint; +extern crate parity_hash as hash; use pwasm_std::logger; -use pwasm_ethereum::{input, ret, create, value}; +use pwasm_ethereum::{input, ret, create, create2, value}; +use bigint::U256; +use hash::H256; #[no_mangle] pub fn call() { - if let Ok(addr) = create(value(), &input()) { - logger::debug("Created contractwith code"); - ret(&addr[..]); + let mut r = [0u8; 40]; + if let Ok(addr) = create(value() / U256::from(2), &input()) { + logger::debug("Created contract with code"); + (&mut r[0..20]).copy_from_slice(&addr[..]); } else { logger::debug("Error creating contract"); } + + if let Ok(addr) = create2(value() / U256::from(2), H256::from([5u8].as_ref()), &input()) { + logger::debug("Created contract with code and salt"); + (&mut r[0..20]).copy_from_slice(&addr[..]); + } else { + logger::debug("Error creating contract"); + } + + ret(&r[..]); } diff --git a/src/dispersion.rs b/src/dispersion.rs index 7085098..ef56e8b 100644 --- a/src/dispersion.rs +++ b/src/dispersion.rs @@ -23,4 +23,4 @@ pub fn call() { } ret(&dispersed[..]) -} \ No newline at end of file +} diff --git a/src/empty.rs b/src/empty.rs index 7d71169..e9092fb 100644 --- a/src/empty.rs +++ b/src/empty.rs @@ -7,4 +7,4 @@ use pwasm_std::logger; #[no_mangle] pub fn call() { logger::debug("Empty contract"); -} \ No newline at end of file +} diff --git a/src/events.rs b/src/events.rs index 04e2494..d21b17c 100644 --- a/src/events.rs +++ b/src/events.rs @@ -20,4 +20,4 @@ pub fn call() { ext::log(&[hash, H256::from(&reverse_hash[..])], &reverse_input); ext::ret(&reverse_input); -} \ No newline at end of file +} diff --git a/src/identity.rs b/src/identity.rs index e79b317..499edeb 100644 --- a/src/identity.rs +++ b/src/identity.rs @@ -5,4 +5,4 @@ extern crate pwasm_ethereum as ext; #[no_mangle] pub fn call() { ext::ret(&ext::sender()[..]); -} \ No newline at end of file +} diff --git a/src/math.rs b/src/math.rs index 6207a37..ebe3329 100644 --- a/src/math.rs +++ b/src/math.rs @@ -27,4 +27,4 @@ pub fn call() { result_bytes }) -} \ No newline at end of file +} diff --git a/src/realloc.rs b/src/realloc.rs index 8f9c88f..3f871fe 100644 --- a/src/realloc.rs +++ b/src/realloc.rs @@ -15,4 +15,4 @@ pub fn call() { } data }); -} \ No newline at end of file +} diff --git a/src/rterr.rs b/src/rterr.rs index e9bdbdd..ba12f93 100644 --- a/src/rterr.rs +++ b/src/rterr.rs @@ -8,4 +8,4 @@ use pwasm_std::logger; pub fn call() { logger::debug("Exception will occur here:"); unreachable!(); -} \ No newline at end of file +} diff --git a/src/setter.rs b/src/setter.rs index 1a4cc24..d43011a 100644 --- a/src/setter.rs +++ b/src/setter.rs @@ -15,4 +15,4 @@ pub fn call() { val.copy_from_slice(&ext::input()[32+i*64..64+i*64]); ext::write(&key, &val); } -} \ No newline at end of file +} diff --git a/src/suicidal.rs b/src/suicidal.rs index 23fd932..5eb04fd 100644 --- a/src/suicidal.rs +++ b/src/suicidal.rs @@ -17,4 +17,4 @@ pub fn call() { } else { ret(&input); } -} \ No newline at end of file +} diff --git a/wasm-install.sh b/wasm-install.sh index f54e5d3..267f7d4 100755 --- a/wasm-install.sh +++ b/wasm-install.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # this script is intended to be used from .travis.yml. # Takes an environment variable WATERFALL_BUILD to download a