diff --git a/.circleci/config.yml b/.circleci/config.yml index 9f972920d..f30230fd0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ jobs: # All checks on the codebase that can run in parallel to build_shared_library libwasmvm_sanity: docker: - - image: cimg/rust:1.67.0 + - image: cimg/rust:1.70.0 steps: - checkout - run: @@ -18,8 +18,8 @@ jobs: command: rustup component add rustfmt - restore_cache: keys: - - cargocache-v3-libwasmvm_sanity-rust:1.67.0-{{ checksum "libwasmvm/Cargo.lock" }} - - cargocache-v3-libwasmvm_sanity-rust:1.67.0- + - cargocache-v3-libwasmvm_sanity-rust:1.70.0-{{ checksum "libwasmvm/Cargo.lock" }} + - cargocache-v3-libwasmvm_sanity-rust:1.70.0- - run: name: Ensure libwasmvm/bindings.h is up-to-date working_directory: libwasmvm @@ -62,7 +62,7 @@ jobs: - libwasmvm/target/release/.fingerprint - libwasmvm/target/release/build - libwasmvm/target/release/deps - key: cargocache-v3-libwasmvm_sanity-rust:1.67.0-{{ checksum "libwasmvm/Cargo.lock" }} + key: cargocache-v3-libwasmvm_sanity-rust:1.70.0-{{ checksum "libwasmvm/Cargo.lock" }} libwasmvm_clippy: parameters: @@ -113,15 +113,15 @@ jobs: command: | set -o errexit curl -sS --output rustup-init.exe https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe - ./rustup-init.exe --no-modify-path --profile minimal --default-toolchain 1.67.0 -y + ./rustup-init.exe --no-modify-path --profile minimal --default-toolchain 1.70.0 -y echo 'export PATH="$PATH;$USERPROFILE/.cargo/bin"' >> "$BASH_ENV" - run: name: Show Rust version information command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cachev4-libwasmvm_sanity_windows-rust:1.67.0-{{ checksum "libwasmvm/Cargo.lock" }} - - cachev4-libwasmvm_sanity_windows-rust:1.67.0- + - cachev4-libwasmvm_sanity_windows-rust:1.70.0-{{ checksum "libwasmvm/Cargo.lock" }} + - cachev4-libwasmvm_sanity_windows-rust:1.70.0- - run: name: Run unit tests working_directory: libwasmvm @@ -133,13 +133,13 @@ jobs: - libwasmvm/target/debug/.fingerprint - libwasmvm/target/debug/build - libwasmvm/target/debug/deps - key: cachev4-libwasmvm_sanity_windows-rust:1.67.0-{{ checksum "libwasmvm/Cargo.lock" }} + key: cachev4-libwasmvm_sanity_windows-rust:1.70.0-{{ checksum "libwasmvm/Cargo.lock" }} libwasmvm_audit: docker: # The audit tool might use a more modern Rust version than the build jobs. See # "Tooling Rust compiler" in docs/COMPILER_VERSIONS.md - - image: cimg/rust:1.69.0 + - image: cimg/rust:1.70.0 steps: - checkout - run: @@ -152,8 +152,8 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-v3-libwasmvm_audit-rust:1.69.0-{{ checksum "libwasmvm/Cargo.lock" }} - - cargocache-v3-libwasmvm_audit-rust:1.69.0- + - cargocache-v3-libwasmvm_audit-rust:1.70.0-{{ checksum "libwasmvm/Cargo.lock" }} + - cargocache-v3-libwasmvm_audit-rust:1.70.0- - run: name: Install cargo-audit command: cargo install --debug cargo-audit --version 0.17.6 @@ -164,7 +164,7 @@ jobs: - save_cache: paths: - ~/.cargo/registry - key: cargocache-v3-libwasmvm_audit-rust:1.69.0-{{ checksum "libwasmvm/Cargo.lock" }} + key: cargocache-v3-libwasmvm_audit-rust:1.70.0-{{ checksum "libwasmvm/Cargo.lock" }} format-go: docker: @@ -248,7 +248,7 @@ jobs: build_shared_library: docker: - - image: cimg/rust:1.67.0 + - image: cimg/rust:1.70.0 steps: - checkout - run: @@ -256,8 +256,8 @@ jobs: command: rustc --version; cargo --version; rustup --version - restore_cache: keys: - - cargocache-v3-build_shared_library-rust:1.67.0-{{ checksum "libwasmvm/Cargo.lock" }} - - cargocache-v3-build_shared_library-rust:1.67.0- + - cargocache-v3-build_shared_library-rust:1.70.0-{{ checksum "libwasmvm/Cargo.lock" }} + - cargocache-v3-build_shared_library-rust:1.70.0- - run: name: Create release build of libwasmvm command: make build-rust @@ -274,7 +274,7 @@ jobs: - libwasmvm/target/release/.fingerprint - libwasmvm/target/release/build - libwasmvm/target/release/deps - key: cargocache-v3-build_shared_library-rust:1.67.0-{{ checksum "libwasmvm/Cargo.lock" }} + key: cargocache-v3-build_shared_library-rust:1.70.0-{{ checksum "libwasmvm/Cargo.lock" }} # Test the Go project wasmvm_test: @@ -420,7 +420,7 @@ workflows: matrix: parameters: # Run with MSRV and some modern stable Rust - rust-version: ["1.67.0", "1.73.0"] + rust-version: ["1.70.0", "1.73.0"] - libwasmvm_audit - format-go - wasmvm_no_cgo diff --git a/Makefile b/Makefile index e198dc999..b6b64700c 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ .PHONY: all build build-rust build-go test # Builds the Rust library libwasmvm -BUILDERS_PREFIX := cosmwasm/go-ext-builder:0016 +BUILDERS_PREFIX := cosmwasm/go-ext-builder:0017 # Contains a full Go dev environment in order to run Go tests on the built library -ALPINE_TESTER := cosmwasm/go-ext-builder:0016-alpine +ALPINE_TESTER := cosmwasm/go-ext-builder:0017-alpine USER_ID := $(shell id -u) USER_GROUP = $(shell id -g) diff --git a/docs/COMPILER_VERSIONS.md b/docs/COMPILER_VERSIONS.md index 333cd8869..d20d6b196 100644 --- a/docs/COMPILER_VERSIONS.md +++ b/docs/COMPILER_VERSIONS.md @@ -64,5 +64,5 @@ We currently use the following version: | Type | Rust version | Note | | ------------------------ | ------------ | --------------------------------- | | Production Rust compiler | 1.73.0 | Builders version 0017 | -| Min Rust compiler | 1.67.0 | Supports builder versions >= 0015 | -| Tooling Rust compiler | 1.69.0 | | +| Min Rust compiler | 1.70.0 | Supports builder versions >= 0017 | +| Tooling Rust compiler | 1.70.0 | | diff --git a/internal/api/lib_test.go b/internal/api/lib_test.go index e967ce48e..9ab03c13a 100644 --- a/internal/api/lib_test.go +++ b/internal/api/lib_test.go @@ -2,11 +2,13 @@ package api import ( "crypto/sha256" + "encoding/hex" "encoding/json" "fmt" "io/ioutil" "os" "path/filepath" + "strings" "testing" "time" @@ -907,6 +909,10 @@ func createReflectContract(t *testing.T, cache Cache) []byte { return createContract(t, cache, "../../testdata/reflect.wasm") } +func createFloaty2(t *testing.T, cache Cache) []byte { + return createContract(t, cache, "../../testdata/floaty_2.0.wasm") +} + func createContract(t *testing.T, cache Cache, wasmFile string) []byte { wasm, err := ioutil.ReadFile(wasmFile) require.NoError(t, err) @@ -1055,3 +1061,100 @@ func TestCustomReflectQuerier(t *testing.T) { require.NoError(t, err) require.Equal(t, "SMALL FRYS :)", response.Text) } + +// TestFloats is a port of the float_instrs_are_deterministic test in cosmwasm-vm +func TestFloats(t *testing.T) { + type Value struct { + U32 *uint32 `json:"u32,omitempty"` + U64 *uint64 `json:"u64,omitempty"` + F32 *uint32 `json:"f32,omitempty"` + F64 *uint64 `json:"f64,omitempty"` + } + + // helper to print the value in the same format as Rust's Debug trait + debugStr := func(value Value) string { + if value.U32 != nil { + return fmt.Sprintf("U32(%d)", *value.U32) + } else if value.U64 != nil { + return fmt.Sprintf("U64(%d)", *value.U64) + } else if value.F32 != nil { + return fmt.Sprintf("F32(%d)", *value.F32) + } else if value.F64 != nil { + return fmt.Sprintf("F64(%d)", *value.F64) + } else { + t.FailNow() + return "" + } + } + + cache, cleanup := withCache(t) + defer cleanup() + checksum := createFloaty2(t, cache) + + gasMeter := NewMockGasMeter(TESTING_GAS_LIMIT) + igasMeter := types.GasMeter(gasMeter) + // instantiate it with this store + store := NewLookup(gasMeter) + api := NewMockAPI() + querier := DefaultQuerier(MOCK_CONTRACT_ADDR, nil) + env := MockEnvBin(t) + + // query instructions + query := []byte(`{"instructions":{}}`) + data, _, err := Query(cache, checksum, env, query, &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG) + require.NoError(t, err) + var qres types.QueryResponse + err = json.Unmarshal(data, &qres) + require.NoError(t, err) + require.Equal(t, "", qres.Err) + var instructions []string + err = json.Unmarshal(qres.Ok, &instructions) + require.NoError(t, err) + // little sanity check + require.Equal(t, 70, len(instructions)) + + hasher := sha256.New() + const RUNS_PER_INSTRUCTION = 150 + for _, instr := range instructions { + for seed := 0; seed < RUNS_PER_INSTRUCTION; seed++ { + // query some input values for the instruction + msg := fmt.Sprintf(`{"random_args_for":{"instruction":"%s","seed":%d}}`, instr, seed) + data, _, err = Query(cache, checksum, env, []byte(msg), &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG) + require.NoError(t, err) + err = json.Unmarshal(data, &qres) + require.NoError(t, err) + require.Equal(t, "", qres.Err) + var args []Value + err = json.Unmarshal(qres.Ok, &args) + require.NoError(t, err) + + // build the run message + argStr, err := json.Marshal(args) + require.NoError(t, err) + msg = fmt.Sprintf(`{"run":{"instruction":"%s","args":%s}}`, instr, argStr) + + // run the instruction + // this might throw a runtime error (e.g. if the instruction traps) + data, _, err = Query(cache, checksum, env, []byte(msg), &igasMeter, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG) + var result string + if err != nil { + assert.ErrorContains(t, err, "Error calling the VM: Error executing Wasm: ") + // remove the prefix to make the error message the same as in the cosmwasm-vm test + result = strings.Replace(err.Error(), "Error calling the VM: Error executing Wasm: ", "", 1) + } else { + err = json.Unmarshal(data, &qres) + require.NoError(t, err) + require.Equal(t, "", qres.Err) + var response Value + err = json.Unmarshal(qres.Ok, &response) + require.NoError(t, err) + result = debugStr(response) + } + // add the result to the hash + hasher.Write([]byte(fmt.Sprintf("%s%d%s", instr, seed, result))) + } + } + + hash := hasher.Sum(nil) + require.Equal(t, "95f70fa6451176ab04a9594417a047a1e4d8e2ff809609b8f81099496bee2393", hex.EncodeToString(hash)) +} diff --git a/libwasmvm/Cargo.lock b/libwasmvm/Cargo.lock index 585c9b234..80c96d4f2 100644 --- a/libwasmvm/Cargo.lock +++ b/libwasmvm/Cargo.lock @@ -84,6 +84,12 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + [[package]] name = "bitflags" version = "1.3.2" @@ -223,9 +229,9 @@ dependencies = [ [[package]] name = "clru" -version = "0.4.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "591ff76ca0691bd91c1b0b5b987e5cf93b21ec810ad96665c5a569c60846dd93" +checksum = "b8191fa7302e03607ff0e237d4246cc043ff5b3cb9409d995172ba3bea16b807" [[package]] name = "const-oid" @@ -248,10 +254,11 @@ dependencies = [ [[package]] name = "cosmwasm-crypto" -version = "1.4.1" -source = "git+https://github.com/CosmWasm/cosmwasm.git?rev=v1.4.1#9410fa2f76e576d3eaa2a0a53036d4a97e2705fe" +version = "1.5.0-rc.0" +source = "git+https://github.com/CosmWasm/cosmwasm.git?rev=v1.5.0-rc.0#d41afdda656eda81695fb80ff47e73ed13017965" dependencies = [ "digest 0.10.7", + "ecdsa", "ed25519-zebra", "k256", "rand_core 0.6.4", @@ -260,18 +267,19 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.4.1" -source = "git+https://github.com/CosmWasm/cosmwasm.git?rev=v1.4.1#9410fa2f76e576d3eaa2a0a53036d4a97e2705fe" +version = "1.5.0-rc.0" +source = "git+https://github.com/CosmWasm/cosmwasm.git?rev=v1.5.0-rc.0#d41afdda656eda81695fb80ff47e73ed13017965" dependencies = [ "syn 1.0.109", ] [[package]] name = "cosmwasm-std" -version = "1.4.1" -source = "git+https://github.com/CosmWasm/cosmwasm.git?rev=v1.4.1#9410fa2f76e576d3eaa2a0a53036d4a97e2705fe" +version = "1.5.0-rc.0" +source = "git+https://github.com/CosmWasm/cosmwasm.git?rev=v1.5.0-rc.0#d41afdda656eda81695fb80ff47e73ed13017965" dependencies = [ "base64", + "bech32", "bnum", "cosmwasm-crypto", "cosmwasm-derive", @@ -282,13 +290,14 @@ dependencies = [ "serde", "serde-json-wasm", "sha2 0.10.7", + "static_assertions", "thiserror", ] [[package]] name = "cosmwasm-vm" -version = "1.4.1" -source = "git+https://github.com/CosmWasm/cosmwasm.git?rev=v1.4.1#9410fa2f76e576d3eaa2a0a53036d4a97e2705fe" +version = "1.5.0-rc.0" +source = "git+https://github.com/CosmWasm/cosmwasm.git?rev=v1.5.0-rc.0#d41afdda656eda81695fb80ff47e73ed13017965" dependencies = [ "bitflags", "bytecheck", @@ -444,6 +453,16 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "crossbeam-queue" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.16" @@ -612,7 +631,7 @@ checksum = "64fba5a42bd76a17cad4bfa00de168ee1cbfa06a5e8ce992ae880218c05641a9" dependencies = [ "byteorder", "dynasm", - "memmap2", + "memmap2 0.5.10", ] [[package]] @@ -1052,6 +1071,15 @@ dependencies = [ "libc", ] +[[package]] +name = "memmap2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d28bba84adfe6646737845bc5ebbfa2c08424eb1c37e94a1fd2a82adb56a872" +dependencies = [ + "libc", +] + [[package]] name = "memoffset" version = "0.8.0" @@ -1419,6 +1447,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "self_cell" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c309e515543e67811222dbc9e3dd7e1056279b782e1dacffe4242b718734fb6" + [[package]] name = "serde" version = "1.0.188" @@ -1505,6 +1539,16 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "shared-buffer" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cf61602ee61e2f83dd016b3e6387245291cf728ea071c378b35088125b4d995" +dependencies = [ + "bytes", + "memmap2 0.6.2", +] + [[package]] name = "signature" version = "2.1.0" @@ -1549,6 +1593,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strsim" version = "0.10.0" @@ -1863,9 +1913,9 @@ checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "wasmer" -version = "4.1.2" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7142dbb91ede83cc0aef2301fa75fcc7e0c9e5a7d5358e3c4f3a7249fe9ce8" +checksum = "0e626f958755a90a6552b9528f59b58a62ae288e6c17fcf40e99495bc33c60f0" dependencies = [ "bytes", "cfg-if", @@ -1876,6 +1926,7 @@ dependencies = [ "rustc-demangle", "serde", "serde-wasm-bindgen", + "shared-buffer", "target-lexicon", "thiserror", "wasm-bindgen", @@ -1891,19 +1942,23 @@ dependencies = [ [[package]] name = "wasmer-compiler" -version = "4.1.2" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5b99c70711ec7631b602a9fc95577c40df21e8f3916159c9d80c3fb4f77abdc" +checksum = "848e1922694cf97f4df680a0534c9d72c836378b5eb2313c1708fe1a75b40044" dependencies = [ "backtrace", + "bytes", "cfg-if", "enum-iterator", "enumset", "lazy_static", "leb128", - "memmap2", + "memmap2 0.5.10", "more-asserts", "region", + "rkyv", + "self_cell", + "shared-buffer", "smallvec", "thiserror", "wasmer-types", @@ -1914,9 +1969,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-cranelift" -version = "4.1.2" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52aef2ef35513a04fed54de9a7dc9c469d4742a5c2e378a5f7e2a79b1327e3bd" +checksum = "3d96bce6fad15a954edcfc2749b59e47ea7de524b6ef3df392035636491a40b4" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -1933,9 +1988,9 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" -version = "4.1.2" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebfd019aa98b19fea0fb1d8db9b539145c9416d183ce4cda4e8e024b2c890aac" +checksum = "ebaa865b40ffb3351b03dab9fe9930a5248c25daebd55b464b79b862d9b55ccd" dependencies = [ "byteorder", "dynasm", @@ -1952,9 +2007,9 @@ dependencies = [ [[package]] name = "wasmer-derive" -version = "4.1.2" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25bb1425c9e4dc3e2d3aacd6e82e22e27a3127379e0d09bcbdf25ff376229162" +checksum = "7f08f80d166a9279671b7af7a09409c28ede2e0b4e3acabbf0e3cb22c8038ba7" dependencies = [ "proc-macro-error", "proc-macro2", @@ -1964,9 +2019,9 @@ dependencies = [ [[package]] name = "wasmer-middlewares" -version = "4.1.2" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acfc08fb8e2e1511f1d69302d7406ace6c0ec0c90e103f8c0a5aa81ecb9fe81f" +checksum = "eeb4b87c0ea9f8636c81a8ab8f52bad01c8623c9fcbb3db5f367d5f157fada30" dependencies = [ "wasmer", "wasmer-types", @@ -1975,9 +2030,9 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "4.1.2" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7e32ed799fa8c0d96ca9615d9ea8006857a0f0c18e7c2ed8082bd5c63a9ea70" +checksum = "ae2c892882f0b416783fb4310e5697f5c30587f6f9555f9d4f2be85ab39d5d3d" dependencies = [ "bytecheck", "enum-iterator", @@ -1991,14 +2046,15 @@ dependencies = [ [[package]] name = "wasmer-vm" -version = "4.1.2" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0847513cb176b5d62a6f65d6ae474594935e726a10e9e3387177d9cbf8b8cda0" +checksum = "7c0a9a57b627fb39e5a491058d4365f099bc9b140031c000fded24a3306d9480" dependencies = [ "backtrace", "cc", "cfg-if", "corosensei", + "crossbeam-queue", "dashmap", "derivative", "enum-iterator", @@ -2028,7 +2084,7 @@ dependencies = [ [[package]] name = "wasmvm" -version = "1.4.1" +version = "1.5.0-rc.0" dependencies = [ "cbindgen", "cosmwasm-std", diff --git a/libwasmvm/Cargo.toml b/libwasmvm/Cargo.toml index 64160541e..e74d7c1e7 100644 --- a/libwasmvm/Cargo.toml +++ b/libwasmvm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmvm" -version = "1.4.1" +version = "1.5.0-rc.0" publish = false authors = ["Ethan Frey "] edition = "2021" @@ -26,8 +26,8 @@ default = [] backtraces = [] [dependencies] -cosmwasm-std = { git = "https://github.com/CosmWasm/cosmwasm.git", rev = "v1.4.1", features = ["staking", "stargate", "iterator"] } -cosmwasm-vm = { git = "https://github.com/CosmWasm/cosmwasm.git", rev = "v1.4.1", features = ["staking", "stargate", "iterator"] } +cosmwasm-std = { git = "https://github.com/CosmWasm/cosmwasm.git", rev = "v1.5.0-rc.0", features = ["staking", "stargate", "iterator"] } +cosmwasm-vm = { git = "https://github.com/CosmWasm/cosmwasm.git", rev = "v1.5.0-rc.0", features = ["staking", "stargate", "iterator"] } errno = "0.2" serde_json = "1.0.91" thiserror = "1.0.38" diff --git a/testdata/floaty_2.0.wasm b/testdata/floaty_2.0.wasm new file mode 100755 index 000000000..3dd07a913 Binary files /dev/null and b/testdata/floaty_2.0.wasm differ