Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unchecked flag (backport #612) #616

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 22 additions & 0 deletions internal/api/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,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
Loading