Skip to content

Commit

Permalink
Merge pull request #1500 from scrtlabs/support-rust-1.70-wasm
Browse files Browse the repository at this point in the history
Support compiling contracts with Rust v1.70+
  • Loading branch information
assafmo authored Aug 9, 2023
2 parents 30a5ef2 + eadac6e commit 4f21d57
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
make clean-enclave
Build-Contracts:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Download sccache
Expand Down
4 changes: 2 additions & 2 deletions cosmwasm/Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ contract_with_floats.wasm: $(Rust_Crate_Source)
rm -f ./contract_with_floats.wasm
mv -f ./target/wasm32-unknown-unknown/release/test_contract.wasm ./contract_with_floats.wasm

# Older versions of wabt had the --enable-sign-extension flag, while on newer
# versions it's turned on by default and the flag is replaced with --disable-sign-extension
WASM2WAT_OPTS := $(shell wasm2wat --help | grep -Po '\-\-enable-sign-extension')
WAT2WAT_OPTS := $(shell wat2wasm --help | grep -Po '\-\-enable-sign-extension')

# Create a wasm with more than 192 memory pages (fails in init, handle & query, this is our limit)
# https://github.com/scrtlabs/SecretNetwork/blob/9eef8591b2c04c586ceee12f424b92062598123e/cosmwasm/packages/wasmi-runtime/src/wasm/memory.rs#L39
too-high-initial-memory.wasm: contract.wasm
wasm2wat ./contract.wasm | perl -pe 's/\(memory \(;0;\) \d+\)/(memory (;0;) 193)/' > /tmp/too-high-initial-memory.wat
wat2wasm /tmp/too-high-initial-memory.wat -o ./too-high-initial-memory.wasm
wasm2wat $(WASM2WAT_OPTS) ./contract.wasm | perl -pe 's/\(memory \(;0;\) \d+\)/(memory (;0;) 193)/' > /tmp/too-high-initial-memory.wat
wat2wasm $(WAT2WAT_OPTS) /tmp/too-high-initial-memory.wat -o ./too-high-initial-memory.wasm

# Create a wasm with more than 512 memory pages (fails in store, this is cosmwasm's limit)
# https://github.com/scrtlabs/SecretNetwork/blob/9eef8591b2c04c586ceee12f424b92062598123e/cosmwasm/packages/sgx-vm/src/compatability.rs#L36
static-too-high-initial-memory.wasm: contract.wasm
wasm2wat ./contract.wasm | perl -pe 's/\(memory \(;0;\) \d+\)/(memory (;0;) 513)/' > /tmp/static-too-high-initial-memory.wat
wat2wasm /tmp/static-too-high-initial-memory.wat -o ./static-too-high-initial-memory.wasm
wasm2wat $(WASM2WAT_OPTS) ./contract.wasm | perl -pe 's/\(memory \(;0;\) \d+\)/(memory (;0;) 513)/' > /tmp/static-too-high-initial-memory.wat
wat2wasm $(WAT2WAT_OPTS) /tmp/static-too-high-initial-memory.wat -o ./static-too-high-initial-memory.wasm

setup:
apt-get install wabt
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.69
1.71
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.69
1.71
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.69
1.71
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.69
1.71
16 changes: 11 additions & 5 deletions cosmwasm/enclaves/Cargo.lock

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

4 changes: 3 additions & 1 deletion cosmwasm/enclaves/execute/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ serde_json = { git = "https://github.com/mesalock-linux/serde-json-sgx" }
ctor = "0.1.13"
derive_more = "0.99"
pwasm-utils = { version = "0.12.0", default-features = false }
parity-wasm = { version = "0.41.0", default-features = false }
parity-wasm = { version = "0.45.0", default-features = false, features = [
"sign_ext"
] }
base64 = { rev = "dc7389e10817b078f289386b3b6a852ab6c4c021", git = "https://github.com/mesalock-linux/rust-base64-sgx" }
# for attestation
chrono = { git = "https://github.com/mesalock-linux/chrono-sgx" }
Expand Down
4 changes: 3 additions & 1 deletion cosmwasm/enclaves/shared/contract-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ derive_more = "0.99"
sha2 = "0.8.1"
bech32 = "0.7.2"
pwasm-utils = { version = "0.12.0", default-features = false, optional = true }
parity-wasm = { version = "0.41.0", default-features = false, optional = true }
parity-wasm = { version = "0.45.0", default-features = false, optional = true, features = [
"sign_ext"
] }
wasm3 = { git = "https://github.com/scrtlabs/wasm3-rs", rev = "ad1c868" }
walrus = { version = "0.19.0", git = "https://github.com/scrtlabs/walrus", rev = "c5777d4" }
lru = { version = "0.7", default-features = false }
Expand Down
12 changes: 6 additions & 6 deletions cosmwasm/enclaves/test/Cargo.lock

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

2 changes: 1 addition & 1 deletion cosmwasm/packages/sgx-vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ snafu = { version = "0.6.3" }
sha2 = "0.10.7"
hex = "0.4"
memmap = "0.7"
parity-wasm = "0.41"
parity-wasm = { version = "0.45", features = ["sign_ext"] }
# requirements specific to Secret Network
lazy_static = "1.4"
enclave-ffi-types = { path = "../../enclaves/ffi-types", features = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.69.0-slim-bullseye
FROM rust:1.71.0-slim-bullseye

RUN rustup target add wasm32-unknown-unknown
RUN apt update && apt install -y binaryen clang && rm -rf /var/lib/apt/lists/*
Expand Down
12 changes: 6 additions & 6 deletions go-cosmwasm/Cargo.lock

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

30 changes: 4 additions & 26 deletions scripts/install-wasm-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,12 @@ cargo install pwasm-utils-cli --bin wasm-prune --force
if [[ "$OSTYPE" == "linux-gnu" ]]; then
set -e

BUILD_NUM=`curl -s https://storage.googleapis.com/wasm-llvm/builds/linux/lkgr.json | jq -r '.build'`
if [ -z ${BUILD_NUM+x} ]; then
echo "Could not fetch the latest build number.";
exit 1;
fi

tmp=`mktemp -d`
pushd $tmp > /dev/null
echo "Downloading wasm-binaries.tbz2";
curl -L -o wasm-binaries.tbz2 https://storage.googleapis.com/wasm-llvm/builds/linux/$BUILD_NUM/wasm-binaries.tbz2

declare -a binaries=("wasm2wat" "wat2wasm") # Default binaries
if [ "$#" -ne 0 ]; then
echo "Installing selected binaries.";
binaries=("$@");
else
echo "Installing default binaries.";
fi

for bin in "${binaries[@]}"
do
echo "Installing $bin into ~/.cargo/bin"
tar -xvjf wasm-binaries.tbz2 wasm-install/bin/$bin > /dev/null
cp -f wasm-install/bin/$bin ~/.cargo/bin/
done
popd > /dev/null
sudo apt-get install -y wabt
fi

echo ""
echo "Run source ~/.cargo/env now to update environment."
echo ""

source ~/.cargo/env
wasm2wat --version
Binary file modified x/compute/internal/keeper/testdata/contract.wasm
Binary file not shown.
Binary file modified x/compute/internal/keeper/testdata/contract_with_floats.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified x/compute/internal/keeper/testdata/v1-contract-v2.wasm
Binary file not shown.
Binary file modified x/compute/internal/keeper/testdata/v1-contract.wasm
Binary file not shown.
Binary file modified x/compute/internal/keeper/testdata/v1_random_test.wasm
Binary file not shown.

0 comments on commit 4f21d57

Please sign in to comment.