Skip to content

Commit

Permalink
Merge pull request #615 from CosmWasm/mergify/bp/release/2.0/pr-612
Browse files Browse the repository at this point in the history
Fix unchecked flag (backport #612)
  • Loading branch information
chipshort authored Jan 22, 2025
2 parents 47eea90 + c6985ed commit 2d8c291
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/api/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func StoreCodeUnchecked(cache Cache, wasm []byte) ([]byte, error) {
w := makeView(wasm)
defer runtime.KeepAlive(wasm)
errmsg := uninitializedUnmanagedVector()
checksum, err := C.store_code(cache.ptr, w, cbool(true), cbool(true), &errmsg)
checksum, err := C.store_code(cache.ptr, w, cbool(false), cbool(true), &errmsg)
if err != nil {
return nil, errorWithMessage(err, errmsg)
}
Expand Down
23 changes: 23 additions & 0 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"bytes"
"crypto/sha256"
"encoding/hex"
"encoding/json"
Expand Down Expand Up @@ -185,6 +186,28 @@ func TestStoreCodeUnchecked(t *testing.T) {
require.Equal(t, wasm, code)
}

func TestStoreCodeUncheckedWorksWithInvalidWasm(t *testing.T) {
cache, cleanup := withCache(t)
defer cleanup()

wasm, err := os.ReadFile("../../testdata/hackatom.wasm")
require.NoError(t, err)

// Look for "interface_version_8" in the wasm file and replace it with "interface_version_9".
// This makes the wasm file invalid.
wasm = bytes.Replace(wasm, []byte("interface_version_8"), []byte("interface_version_9"), 1)

// StoreCode should fail
_, err = StoreCode(cache, wasm, true)
require.ErrorContains(t, err, "Wasm contract has unknown interface_version_* marker export")

// StoreCodeUnchecked should not fail
checksum, err := StoreCodeUnchecked(cache, wasm)
require.NoError(t, err)
expectedChecksum := sha256.Sum256(wasm)
assert.Equal(t, expectedChecksum[:], checksum)
}

func TestPin(t *testing.T) {
cache, cleanup := withCache(t)
defer cleanup()
Expand Down

0 comments on commit 2d8c291

Please # to comment.