From 7fa91961017651b8fe4ba0966d683fe5de995e41 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Fri, 9 Sep 2022 09:52:39 -0400 Subject: [PATCH] chore(wasmer): add helpers.go file with helper functions (#2749) - Split out (CGO related) helper functions from `imports.go` to `lib/runtime/wasmer/helpers.go` - Move pointer size helper functions to `lib/runtime/wasmer/helpers.go` - Change `toWasmMemorySized` to NOT take a size argument (unneeded) - Clarify all comments for helper functions - Update all error wrappings - Review variable names - Use `ptr` instead of `out` for 32 bit pointers - Use `pointerSize` instead of `span` for 64 bit pointers size - Name return values - Other minor renamings such as `res` to `result`, `enc` to `encodedResult` - Optimizations: - `storageAppend`: use slice capacity allocation, `copy` and remove unneeded `append`s - `toKillStorageResultEnum`: use `copy` instead of `append` - `toWasmMemoryOptional`: remove unneeded variable copy --- lib/runtime/common.go | 14 -- lib/runtime/wasmer/helpers.go | 216 ++++++++++++++++++++++++++++ lib/runtime/wasmer/helpers_test.go | 49 +++++++ lib/runtime/wasmer/imports.go | 209 ++------------------------- lib/runtime/wasmer/imports_test.go | 2 +- lib/runtime/wasmer/instance.go | 2 +- lib/runtime/wasmer/instance_test.go | 9 -- 7 files changed, 281 insertions(+), 220 deletions(-) delete mode 100644 lib/runtime/common.go create mode 100644 lib/runtime/wasmer/helpers.go create mode 100644 lib/runtime/wasmer/helpers_test.go diff --git a/lib/runtime/common.go b/lib/runtime/common.go deleted file mode 100644 index 41133b65f9..0000000000 --- a/lib/runtime/common.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2021 ChainSafe Systems (ON) -// SPDX-License-Identifier: LGPL-3.0-only - -package runtime - -// Int64ToPointerAndSize converts an int64 into a int32 pointer and a int32 length -func Int64ToPointerAndSize(in int64) (ptr, length int32) { - return int32(in), int32(in >> 32) -} - -// PointerAndSizeToInt64 converts int32 pointer and size to a int64 -func PointerAndSizeToInt64(ptr, size int32) int64 { - return int64(ptr) | (int64(size) << 32) -} diff --git a/lib/runtime/wasmer/helpers.go b/lib/runtime/wasmer/helpers.go new file mode 100644 index 0000000000..6065f2d83c --- /dev/null +++ b/lib/runtime/wasmer/helpers.go @@ -0,0 +1,216 @@ +// Copyright 2022 ChainSafe Systems (ON) +// SPDX-License-Identifier: LGPL-3.0-only + +package wasmer + +// #include +import "C" //skipcq: SCC-compile + +import ( + "fmt" + "math/big" + + "github.com/ChainSafe/gossamer/lib/common/types" + "github.com/ChainSafe/gossamer/lib/runtime" + "github.com/ChainSafe/gossamer/pkg/scale" + "github.com/wasmerio/go-ext-wasm/wasmer" +) + +// toPointerSize converts an uint32 pointer and uint32 size +// to an int64 pointer size. +func toPointerSize(ptr, size uint32) (pointerSize int64) { + return int64(ptr) | (int64(size) << 32) +} + +// splitPointerSize converts an int64 pointer size to an +// uint32 pointer and an uint32 size. +func splitPointerSize(pointerSize int64) (ptr, size uint32) { + return uint32(pointerSize), uint32(pointerSize >> 32) +} + +// asMemorySlice converts a 64 bit pointer size to a Go byte slice. +func asMemorySlice(context wasmer.InstanceContext, pointerSize C.int64_t) (data []byte) { + memory := context.Memory().Data() + ptr, size := splitPointerSize(int64(pointerSize)) + return memory[ptr : ptr+size] +} + +// toWasmMemory copies a Go byte slice to wasm memory and returns the corresponding +// 64 bit pointer size. +func toWasmMemory(context wasmer.InstanceContext, data []byte) ( + pointerSize int64, err error) { + allocator := context.Data().(*runtime.Context).Allocator + size := uint32(len(data)) + + ptr, err := allocator.Allocate(size) + if err != nil { + return 0, fmt.Errorf("allocating: %w", err) + } + + memory := context.Memory().Data() + + if uint32(len(memory)) < ptr+size { + panic(fmt.Sprintf("length of memory is less than expected, want %d have %d", ptr+size, len(memory))) + } + + copy(memory[ptr:ptr+size], data) + pointerSize = toPointerSize(ptr, size) + return pointerSize, nil +} + +// toWasmMemorySized copies a Go byte slice to wasm memory and returns the corresponding +// 32 bit pointer. Note the data must have a well known fixed length in the runtime. +func toWasmMemorySized(context wasmer.InstanceContext, data []byte) ( + pointer uint32, err error) { + allocator := context.Data().(*runtime.Context).Allocator + + size := uint32(len(data)) + pointer, err = allocator.Allocate(size) + if err != nil { + return 0, fmt.Errorf("allocating: %w", err) + } + + memory := context.Memory().Data() + copy(memory[pointer:pointer+size], data) + + return pointer, nil +} + +// toWasmMemoryOptional scale encodes the byte slice `data`, writes it to wasm memory +// and returns the corresponding 64 bit pointer size. +func toWasmMemoryOptional(context wasmer.InstanceContext, data []byte) ( + pointerSize int64, err error) { + var optionalSlice *[]byte + if data != nil { + optionalSlice = &data + } + + encoded, err := scale.Marshal(optionalSlice) + if err != nil { + return 0, err + } + + return toWasmMemory(context, encoded) +} + +// toWasmMemoryResult wraps the data byte slice in a Result type, scale encodes it, +// copies it to wasm memory and returns the corresponding 64 bit pointer size. +func toWasmMemoryResult(context wasmer.InstanceContext, data []byte) ( + pointerSize int64, err error) { + var result *types.Result + if len(data) == 0 { + result = types.NewResult(byte(1), nil) + } else { + result = types.NewResult(byte(0), data) + } + + encodedResult, err := result.Encode() + if err != nil { + return 0, fmt.Errorf("encoding result: %w", err) + } + + return toWasmMemory(context, encodedResult) +} + +// toWasmMemoryOptional scale encodes the uint32 pointer `data`, writes it to wasm memory +// and returns the corresponding 64 bit pointer size. +func toWasmMemoryOptionalUint32(context wasmer.InstanceContext, data *uint32) ( + pointerSize int64, err error) { + enc, err := scale.Marshal(data) + if err != nil { + return 0, fmt.Errorf("scale encoding: %w", err) + } + return toWasmMemory(context, enc) +} + +// toKillStorageResultEnum encodes the `allRemoved` flag and +// the `numRemoved` uint32 to a byte slice and returns it. +// The format used is: +// Byte 0: 1 if allRemoved is false, 0 otherwise +// Byte 1-5: scale encoding of numRemoved (up to 4 bytes) +func toKillStorageResultEnum(allRemoved bool, numRemoved uint32) ( + encodedEnumValue []byte, err error) { + encodedNumRemoved, err := scale.Marshal(numRemoved) + if err != nil { + return nil, fmt.Errorf("scale encoding: %w", err) + } + + encodedEnumValue = make([]byte, len(encodedNumRemoved)+1) + if !allRemoved { + // At least one key resides in the child trie due to the supplied limit. + encodedEnumValue[0] = 1 + } + copy(encodedEnumValue[1:], encodedNumRemoved) + + return encodedEnumValue, nil +} + +// toWasmMemoryFixedSizeOptional copies the `data` byte slice to a 64B array, +// scale encodes the pointer to the resulting array, writes it to wasm memory +// and returns the corresponding 64 bit pointer size. +func toWasmMemoryFixedSizeOptional(context wasmer.InstanceContext, data []byte) ( + pointerSize int64, err error) { + var optionalFixedSize [64]byte + copy(optionalFixedSize[:], data) + encodedOptionalFixedSize, err := scale.Marshal(&optionalFixedSize) + if err != nil { + return 0, fmt.Errorf("scale encoding: %w", err) + } + return toWasmMemory(context, encodedOptionalFixedSize) +} + +func storageAppend(storage runtime.Storage, key, valueToAppend []byte) error { + // this function assumes the item in storage is a SCALE encoded array of items + // the valueToAppend is a new item, so it appends the item and increases the length prefix by 1 + currentValue := storage.Get(key) + + var value []byte + if len(currentValue) == 0 { + nextLength := big.NewInt(1) + encodedLength, err := scale.Marshal(nextLength) + if err != nil { + return fmt.Errorf("scale encoding: %w", err) + } + value = make([]byte, len(encodedLength)+len(valueToAppend)) + // append new length prefix to start of items array + copy(value, encodedLength) + copy(value[len(encodedLength):], valueToAppend) + } else { + var currentLength *big.Int + err := scale.Unmarshal(currentValue, ¤tLength) + if err != nil { + logger.Tracef( + "item in storage is not SCALE encoded, overwriting at key 0x%x", key) + value = make([]byte, 1+len(valueToAppend)) + value[0] = 4 + copy(value[1:], valueToAppend) + } else { + lengthBytes, err := scale.Marshal(currentLength) + if err != nil { + return fmt.Errorf("scale encoding: %w", err) + } + + // increase length by 1 + nextLength := big.NewInt(0).Add(currentLength, big.NewInt(1)) + nextLengthBytes, err := scale.Marshal(nextLength) + if err != nil { + return fmt.Errorf("scale encoding next length bytes: %w", err) + } + + // append new item, pop off number of bytes required for length encoding, + // since we're not using old scale.Decoder + value = make([]byte, len(nextLengthBytes)+len(currentValue)-len(lengthBytes)+len(valueToAppend)) + // append new length prefix to start of items array + i := 0 + copy(value[i:], nextLengthBytes) + i += len(nextLengthBytes) + copy(value[i:], currentValue[len(lengthBytes):]) + i += len(currentValue) - len(lengthBytes) + copy(value[i:], valueToAppend) + } + } + + logger.Debugf("resulting value: 0x%x", value) + storage.Set(key, value) + return nil +} diff --git a/lib/runtime/wasmer/helpers_test.go b/lib/runtime/wasmer/helpers_test.go new file mode 100644 index 0000000000..c6bda5f811 --- /dev/null +++ b/lib/runtime/wasmer/helpers_test.go @@ -0,0 +1,49 @@ +// Copyright 2022 ChainSafe Systems (ON) +// SPDX-License-Identifier: LGPL-3.0-only + +package wasmer + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func Test_pointerSize(t *testing.T) { + t.Parallel() + + testCases := map[string]struct { + ptr uint32 + size uint32 + pointerSize int64 + }{ + "0": {}, + "ptr 8 size 32": { + ptr: 8, + size: 32, + pointerSize: int64(8) | (int64(32) << 32), + }, + "ptr max uint32 and size max uint32": { + ptr: ^uint32(0), + size: ^uint32(0), + pointerSize: ^int64(0), + }, + } + + for name, testCase := range testCases { + testCase := testCase + t.Run(name, func(t *testing.T) { + t.Parallel() + + pointerSize := toPointerSize(testCase.ptr, testCase.size) + + require.Equal(t, testCase.pointerSize, pointerSize) + + ptr, size := splitPointerSize(pointerSize) + + assert.Equal(t, testCase.ptr, ptr) + assert.Equal(t, testCase.size, size) + }) + } +} diff --git a/lib/runtime/wasmer/imports.go b/lib/runtime/wasmer/imports.go index cd503780f1..daad753bab 100644 --- a/lib/runtime/wasmer/imports.go +++ b/lib/runtime/wasmer/imports.go @@ -102,7 +102,6 @@ import "C" //skipcq: SCC-compile import ( "encoding/binary" - "errors" "fmt" "math/big" "math/rand" @@ -111,7 +110,6 @@ import ( "unsafe" "github.com/ChainSafe/gossamer/lib/common" - rtype "github.com/ChainSafe/gossamer/lib/common/types" "github.com/ChainSafe/gossamer/lib/crypto" "github.com/ChainSafe/gossamer/lib/crypto/ed25519" "github.com/ChainSafe/gossamer/lib/crypto/secp256k1" @@ -261,7 +259,7 @@ func ext_crypto_ed25519_generate_version_1(context unsafe.Pointer, keyTypeID C.i return 0 } - ret, err := toWasmMemorySized(instanceContext, kp.Public().Encode(), 32) + ret, err := toWasmMemorySized(instanceContext, kp.Public().Encode()) if err != nil { logger.Warnf("failed to allocate memory: %s", err) return 0 @@ -585,7 +583,7 @@ func ext_crypto_sr25519_generate_version_1(context unsafe.Pointer, keyTypeID C.i return 0 } - ret, err := toWasmMemorySized(instanceContext, kp.Public().Encode(), 32) + ret, err := toWasmMemorySized(instanceContext, kp.Public().Encode()) if err != nil { logger.Errorf("failed to allocate memory: %s", err) return 0 @@ -1009,7 +1007,7 @@ func ext_default_child_storage_read_version_1(context unsafe.Pointer, return 0 } - valueBuf, valueLen := runtime.Int64ToPointerAndSize(int64(valueOut)) + valueBuf, valueLen := splitPointerSize(int64(valueOut)) copy(memory[valueBuf:valueBuf+valueLen], value[offset:]) size := uint32(len(value[offset:])) @@ -1333,7 +1331,7 @@ func ext_hashing_blake2_128_version_1(context unsafe.Pointer, dataSpan C.int64_t "data 0x%x has hash 0x%x", data, hash) - out, err := toWasmMemorySized(instanceContext, hash, 16) + out, err := toWasmMemorySized(instanceContext, hash) if err != nil { logger.Errorf("failed to allocate: %s", err) return 0 @@ -1357,7 +1355,7 @@ func ext_hashing_blake2_256_version_1(context unsafe.Pointer, dataSpan C.int64_t logger.Debugf("data 0x%x has hash %s", data, hash) - out, err := toWasmMemorySized(instanceContext, hash[:], 32) + out, err := toWasmMemorySized(instanceContext, hash[:]) if err != nil { logger.Errorf("failed to allocate: %s", err) return 0 @@ -1381,7 +1379,7 @@ func ext_hashing_keccak_256_version_1(context unsafe.Pointer, dataSpan C.int64_t logger.Debugf("data 0x%x has hash %s", data, hash) - out, err := toWasmMemorySized(instanceContext, hash[:], 32) + out, err := toWasmMemorySized(instanceContext, hash[:]) if err != nil { logger.Errorf("failed to allocate: %s", err) return 0 @@ -1400,7 +1398,7 @@ func ext_hashing_sha2_256_version_1(context unsafe.Pointer, dataSpan C.int64_t) logger.Debugf("data 0x%x has hash %s", data, hash) - out, err := toWasmMemorySized(instanceContext, hash[:], 32) + out, err := toWasmMemorySized(instanceContext, hash[:]) if err != nil { logger.Errorf("failed to allocate: %s", err) return 0 @@ -1424,7 +1422,7 @@ func ext_hashing_twox_256_version_1(context unsafe.Pointer, dataSpan C.int64_t) logger.Debugf("data 0x%x has hash %s", data, hash) - out, err := toWasmMemorySized(instanceContext, hash[:], 32) + out, err := toWasmMemorySized(instanceContext, hash[:]) if err != nil { logger.Errorf("failed to allocate: %s", err) return 0 @@ -1449,7 +1447,7 @@ func ext_hashing_twox_128_version_1(context unsafe.Pointer, dataSpan C.int64_t) "data 0x%x hash hash 0x%x", data, hash) - out, err := toWasmMemorySized(instanceContext, hash, 16) + out, err := toWasmMemorySized(instanceContext, hash) if err != nil { logger.Errorf("failed to allocate: %s", err) return 0 @@ -1475,7 +1473,7 @@ func ext_hashing_twox_64_version_1(context unsafe.Pointer, dataSpan C.int64_t) C "data 0x%x has hash 0x%x", data, hash) - out, err := toWasmMemorySized(instanceContext, hash, 8) + out, err := toWasmMemorySized(instanceContext, hash) if err != nil { logger.Errorf("failed to allocate: %s", err) return 0 @@ -1647,13 +1645,8 @@ func ext_offchain_network_state_version_1(context unsafe.Pointer) C.int64_t { return 0 } - // copy network state length to memory writtenOut location - nsEncLen := uint32(len(nsEnc)) - buf := make([]byte, 4) - binary.LittleEndian.PutUint32(buf, nsEncLen) - // allocate memory for value and copy value to memory - ptr, err := toWasmMemorySized(instanceContext, nsEnc, nsEncLen) + ptr, err := toWasmMemorySized(instanceContext, nsEnc) if err != nil { logger.Errorf("failed to allocate memory: %s", err) return 0 @@ -1672,7 +1665,7 @@ func ext_offchain_random_seed_version_1(context unsafe.Pointer) C.int32_t { if err != nil { logger.Errorf("failed to generate random seed: %s", err) } - ptr, err := toWasmMemorySized(instanceContext, seed, 32) + ptr, err := toWasmMemorySized(instanceContext, seed) if err != nil { logger.Errorf("failed to allocate memory: %s", err) } @@ -1809,51 +1802,6 @@ func ext_offchain_http_request_add_header_version_1(context unsafe.Pointer, return C.int64_t(ptr) } -func storageAppend(storage runtime.Storage, key, valueToAppend []byte) error { - nextLength := big.NewInt(1) - var valueRes []byte - - // this function assumes the item in storage is a SCALE encoded array of items - // the valueToAppend is a new item, so it appends the item and increases the length prefix by 1 - valueCurr := storage.Get(key) - - if len(valueCurr) == 0 { - valueRes = valueToAppend - } else { - var currLength *big.Int - err := scale.Unmarshal(valueCurr, &currLength) - if err != nil { - logger.Tracef( - "item in storage is not SCALE encoded, overwriting at key 0x%x", key) - storage.Set(key, append([]byte{4}, valueToAppend...)) - return nil //nolint:nilerr - } - - lengthBytes, err := scale.Marshal(currLength) - if err != nil { - return err - } - // append new item, pop off number of bytes required for length encoding, - // since we're not using old scale.Decoder - valueRes = append(valueCurr[len(lengthBytes):], valueToAppend...) - - // increase length by 1 - nextLength = big.NewInt(0).Add(currLength, big.NewInt(1)) - } - - lengthEnc, err := scale.Marshal(nextLength) - if err != nil { - logger.Tracef("failed to encode new length: %s", err) - return err - } - - // append new length prefix to start of items array - lengthEnc = append(lengthEnc, valueRes...) - logger.Debugf("resulting value: 0x%x", lengthEnc) - storage.Set(key, lengthEnc) - return nil -} - //export ext_storage_append_version_1 func ext_storage_append_version_1(context unsafe.Pointer, keySpan, valueSpan C.int64_t) { logger.Trace("executing...") @@ -2046,12 +1994,9 @@ func ext_storage_read_version_1(context unsafe.Pointer, keySpan, valueOut C.int6 } var size uint32 - - if int(offset) > len(value) { - size = uint32(0) - } else { + if uint32(offset) <= uint32(len(value)) { size = uint32(len(value[offset:])) - valueBuf, valueLen := runtime.Int64ToPointerAndSize(int64(valueOut)) + valueBuf, valueLen := splitPointerSize(int64(valueOut)) copy(memory[valueBuf:valueBuf+valueLen], value[offset:]) } @@ -2135,132 +2080,6 @@ func ext_storage_commit_transaction_version_1(context unsafe.Pointer) { instanceContext.Data().(*runtime.Context).Storage.CommitStorageTransaction() } -// Convert 64bit wasm span descriptor to Go memory slice -func asMemorySlice(context wasm.InstanceContext, span C.int64_t) []byte { - memory := context.Memory().Data() - ptr, size := runtime.Int64ToPointerAndSize(int64(span)) - return memory[ptr : ptr+size] -} - -// Copy a byte slice to wasm memory and return the resulting 64bit span descriptor -func toWasmMemory(context wasm.InstanceContext, data []byte) (int64, error) { - allocator := context.Data().(*runtime.Context).Allocator - size := uint32(len(data)) - - out, err := allocator.Allocate(size) - if err != nil { - return 0, err - } - - memory := context.Memory().Data() - - if uint32(len(memory)) < out+size { - panic(fmt.Sprintf("length of memory is less than expected, want %d have %d", out+size, len(memory))) - } - - copy(memory[out:out+size], data) - return runtime.PointerAndSizeToInt64(int32(out), int32(size)), nil -} - -// Copy a byte slice of a fixed size to wasm memory and return resulting pointer -func toWasmMemorySized(context wasm.InstanceContext, data []byte, size uint32) (uint32, error) { - if int(size) != len(data) { - return 0, errors.New("internal byte array size missmatch") - } - - allocator := context.Data().(*runtime.Context).Allocator - - out, err := allocator.Allocate(size) - if err != nil { - return 0, err - } - - memory := context.Memory().Data() - copy(memory[out:out+size], data) - - return out, nil -} - -// Wraps slice in optional.Bytes and copies result to wasm memory. Returns resulting 64bit span descriptor -func toWasmMemoryOptional(context wasm.InstanceContext, data []byte) (int64, error) { - var opt *[]byte - if data != nil { - temp := data - opt = &temp - } - - enc, err := scale.Marshal(opt) - if err != nil { - return 0, err - } - - return toWasmMemory(context, enc) -} - -// Wraps slice in Result type and copies result to wasm memory. Returns resulting 64bit span descriptor -func toWasmMemoryResult(context wasm.InstanceContext, data []byte) (int64, error) { - var res *rtype.Result - if len(data) == 0 { - res = rtype.NewResult(byte(1), nil) - } else { - res = rtype.NewResult(byte(0), data) - } - - enc, err := res.Encode() - if err != nil { - return 0, err - } - - return toWasmMemory(context, enc) -} - -// Wraps slice in optional and copies result to wasm memory. Returns resulting 64bit span descriptor -func toWasmMemoryOptionalUint32(context wasm.InstanceContext, data *uint32) (int64, error) { - var opt *uint32 - if data != nil { - temp := *data - opt = &temp - } - - enc, err := scale.Marshal(opt) - if err != nil { - return int64(0), err - } - return toWasmMemory(context, enc) -} - -// toKillStorageResult returns enum encoded value -func toKillStorageResultEnum(allRemoved bool, numRemoved uint32) ([]byte, error) { - var b, sbytes []byte - sbytes, err := scale.Marshal(numRemoved) - if err != nil { - return nil, err - } - - if allRemoved { - // No key remains in the child trie. - b = append(b, byte(0)) - } else { - // At least one key still resides in the child trie due to the supplied limit. - b = append(b, byte(1)) - } - - b = append(b, sbytes...) - - return b, err -} - -// Wraps slice in optional.FixedSizeBytes and copies result to wasm memory. Returns resulting 64bit span descriptor -func toWasmMemoryFixedSizeOptional(context wasm.InstanceContext, data []byte) (int64, error) { - var opt [64]byte - copy(opt[:], data) - enc, err := scale.Marshal(&opt) - if err != nil { - return 0, err - } - return toWasmMemory(context, enc) -} - // importsNodeRuntime returns the WASM imports for the node runtime. func importsNodeRuntime() (imports *wasm.Imports, err error) { imports = wasm.NewImports() diff --git a/lib/runtime/wasmer/imports_test.go b/lib/runtime/wasmer/imports_test.go index 5ba1db2b98..7061110a77 100644 --- a/lib/runtime/wasmer/imports_test.go +++ b/lib/runtime/wasmer/imports_test.go @@ -41,7 +41,7 @@ func Test_ext_offchain_timestamp_version_1(t *testing.T) { res, err := runtimeFunc(0, 0) require.NoError(t, err) - outputPtr, outputLength := runtime.Int64ToPointerAndSize(res.ToI64()) + outputPtr, outputLength := splitPointerSize(res.ToI64()) memory := inst.vm.Memory.Data() data := memory[outputPtr : outputPtr+outputLength] var timestamp int64 diff --git a/lib/runtime/wasmer/instance.go b/lib/runtime/wasmer/instance.go index 0bcf13c3d0..3e2bc6efea 100644 --- a/lib/runtime/wasmer/instance.go +++ b/lib/runtime/wasmer/instance.go @@ -321,7 +321,7 @@ func (in *Instance) Exec(function string, data []byte) (result []byte, err error return nil, fmt.Errorf("running runtime function: %w", err) } - outputPtr, outputLength := runtime.Int64ToPointerAndSize(wasmValue.ToI64()) + outputPtr, outputLength := splitPointerSize(wasmValue.ToI64()) memory = in.vm.Memory.Data() // call Data() again to get larger slice return memory[outputPtr : outputPtr+outputLength], nil } diff --git a/lib/runtime/wasmer/instance_test.go b/lib/runtime/wasmer/instance_test.go index b67baa0dac..dd1e22686b 100644 --- a/lib/runtime/wasmer/instance_test.go +++ b/lib/runtime/wasmer/instance_test.go @@ -27,15 +27,6 @@ func TestConcurrentRuntimeCalls(t *testing.T) { }() } -func TestPointerSize(t *testing.T) { - in := int64(8) + int64(32)<<32 - ptr, length := runtime.Int64ToPointerAndSize(in) - require.Equal(t, int32(8), ptr) - require.Equal(t, int32(32), length) - res := runtime.PointerAndSizeToInt64(ptr, length) - require.Equal(t, in, res) -} - func Test_GetRuntimeVersion(t *testing.T) { polkadotRuntimeFilepath, err := runtime.GetRuntime( context.Background(), runtime.POLKADOT_RUNTIME)