Skip to content

Commit f59201f

Browse files
authored
Merge branch 'main' into faddat/errcheck
2 parents 7bd5e19 + 98ce9d0 commit f59201f

File tree

10 files changed

+93
-22
lines changed

10 files changed

+93
-22
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ jobs:
156156
- v3-libwasmvm_audit-rust:1.81.0-
157157
- run:
158158
name: Install cargo-audit
159-
command: cargo install --debug cargo-audit --version 0.17.6
159+
command: cargo install --debug cargo-audit --version 0.21.0 --locked
160160
- run:
161161
name: Run cargo-audit
162162
working_directory: libwasmvm

.github/workflows/lint-go.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ jobs:
1717
name: lint
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/checkout@v3
21-
- uses: actions/setup-go@v4
20+
- uses: actions/checkout@v4
21+
- uses: actions/setup-go@v5
2222
with:
23-
go-version: "1.21.4"
23+
go-version: "1.23.4"
2424
cache: false
2525
- name: golangci-lint
26-
uses: golangci/golangci-lint-action@v3.6.0
26+
uses: golangci/golangci-lint-action@v6
2727
with:
2828
# Require: The version of golangci-lint to use.
2929
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ library that can be used via FFI. It is compiled like this:
2828
# Run unit tests
2929
(cd libwasmvm && cargo test)
3030

31-
# Create release build for your current system. Uses whatever default Rust
31+
# Create a release build for your current system. Uses whatever default Rust
3232
# version you have installed.
3333
make build-libwasmvm
3434

@@ -107,11 +107,11 @@ go build -tags "nolink_libwasmvm"
107107
See [COMPILER_VERSIONS.md](docs/COMPILER_VERSIONS.md) for information on Go and
108108
Rust compiler support.
109109

110-
The Rust implementation of the VM is compiled to a library called libwasmvm.
110+
The Rust implementation of the VM is compiled into a library called libwasmvm.
111111
This is then linked to the Go code when the final binary is built. For that
112112
reason not all systems supported by Go are supported by this project.
113113

114-
Linux (tested on Ubuntu, Debian, Alpine) and macOS is supported. We are working
114+
Linux (tested on Ubuntu, Debian, Alpine) and macOS are supported. We are working
115115
on Windows support with very low priority (#288).
116116

117117
[#288]: https://github.com/CosmWasm/wasmvm/pull/288

docs/COMPILER_VERSIONS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The Go version here has the following goals:
1515
versions reasonably wide to avoid unnecessary friction for users. I.e. just
1616
because Cosmos SDK now uses Go 1.19 does not mean we make 1.19 the minimal
1717
supported version here. However, the project should work with the latest
18-
stable Go version. When the majority of our users is between 1.18 and 1.19, we
18+
stable Go version. When the majority of our users are between 1.18 and 1.19, we
1919
can slowly remove 1.17 support by bumping the min version to 1.18.
2020
- Be stable enough to test Go code. We always pin the patch version to ensure CI
2121
runs are reproducible. Those versions will contain security issues from time
@@ -31,10 +31,10 @@ Go version locations:
3131
## Rust
3232

3333
In contrast to Go, the Rust compiler used here produces actual artifacts used
34-
directly by consumer projects. This are the shared .dylib, .so, .dll libraries
34+
directly by consumer projects. These are the shared .dylib, .so, .dll libraries
3535
as well as the static .a libraries. Those libwasmvm builds contain all the Rust
3636
code executing contracts, especially cosmwasm-vm. New Rust versions usually add
37-
features which are not necessarily used or needed. But we should move with the
37+
features that are not necessarily used or needed. But we should move with the
3838
ecosystem to keep the dependency tree compiling. Also new Rust versions tend to
3939
increase runtime speed through optimizer improvements, which never hurts.
4040

docs/MIGRATING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
- `QueryRequest.Grpc` was added. It is similar to `QueryRequest.Stargate` but
2828
unlike that, it should always return protobuf encoded responses on all chains.
2929
- `VM.StoreCode` now returns a `uint64` containing the gas cost in CosmWasm gas
30-
and takes a gas limit as argument. This was previously calculated in wasmd.
30+
and takes a gas limit as an argument. This was previously calculated in wasmd.
3131
The change brings consistency with the other functions that cause gas usage.
3232
- `GoAPI` now requires an additional `ValidateAddress` function that validates
3333
whether the given string is a valid address. This was previously done

internal/api/lib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func StoreCodeUnchecked(cache Cache, wasm []byte) ([]byte, error) {
101101
w := makeView(wasm)
102102
defer runtime.KeepAlive(wasm)
103103
errmsg := uninitializedUnmanagedVector()
104-
checksum, err := C.store_code(cache.ptr, w, cbool(true), cbool(true), &errmsg)
104+
checksum, err := C.store_code(cache.ptr, w, cbool(false), cbool(true), &errmsg)
105105
if err != nil {
106106
return nil, errorWithMessage(err, errmsg)
107107
}

internal/api/lib_test.go

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ const (
2626
TESTING_CACHE_SIZE = 100 // MiB
2727
)
2828

29-
// Add mutex for thread safety
30-
var testMutex sync.Mutex
31-
3229
var TESTING_CAPABILITIES = []string{"staking", "stargate", "iterator", "cosmwasm_1_1", "cosmwasm_1_2", "cosmwasm_1_3"}
3330

3431
func TestInitAndReleaseCache(t *testing.T) {
@@ -278,6 +275,28 @@ func TestStoreCodeUnchecked(t *testing.T) {
278275
require.Equal(t, wasm, code)
279276
}
280277

278+
func TestStoreCodeUncheckedWorksWithInvalidWasm(t *testing.T) {
279+
cache, cleanup := withCache(t)
280+
defer cleanup()
281+
282+
wasm, err := os.ReadFile("../../testdata/hackatom.wasm")
283+
require.NoError(t, err)
284+
285+
// Look for "interface_version_8" in the wasm file and replace it with "interface_version_9".
286+
// This makes the wasm file invalid.
287+
wasm = bytes.Replace(wasm, []byte("interface_version_8"), []byte("interface_version_9"), 1)
288+
289+
// StoreCode should fail
290+
_, err = StoreCode(cache, wasm, true)
291+
require.ErrorContains(t, err, "Wasm contract has unknown interface_version_* marker export")
292+
293+
// StoreCodeUnchecked should not fail
294+
checksum, err := StoreCodeUnchecked(cache, wasm)
295+
require.NoError(t, err)
296+
expectedChecksum := sha256.Sum256(wasm)
297+
assert.Equal(t, expectedChecksum[:], checksum)
298+
}
299+
281300
func TestPin(t *testing.T) {
282301
cache, cleanup := withCache(t)
283302
defer cleanup()
@@ -810,9 +829,7 @@ func BenchmarkContractCall(b *testing.B) {
810829
gasMeter2 := NewMockGasMeter(TESTING_GAS_LIMIT)
811830
igasMeter2 := types.GasMeter(gasMeter2)
812831
store.SetGasMeter(gasMeter2)
813-
testMutex.Lock()
814832
info = MockInfoBin(b, "fred")
815-
testMutex.Unlock()
816833
msg := []byte(`{"allocate_large_memory":{"pages":0}}`) // replace with noop once we have it
817834
res, _, err = Execute(cache, checksum, env, info, msg, &igasMeter2, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
818835
require.NoError(b, err)
@@ -841,6 +858,8 @@ func Benchmark100ConcurrentContractCalls(b *testing.B) {
841858
require.NoError(b, err)
842859
requireOkResponse(b, res, 0)
843860

861+
info = MockInfoBin(b, "fred")
862+
844863
const callCount = 100 // Calls per benchmark iteration
845864

846865
b.ResetTimer()
@@ -849,7 +868,11 @@ func Benchmark100ConcurrentContractCalls(b *testing.B) {
849868
errChan := make(chan error, callCount)
850869
resChan := make(chan []byte, callCount)
851870
wg.Add(callCount)
871+
852872
info = mockInfoBinNoAssert("fred")
873+
874+
875+
853876
for i := 0; i < callCount; i++ {
854877
go func() {
855878
defer wg.Done()
@@ -1332,6 +1355,10 @@ func TestCustomReflectQuerier(t *testing.T) {
13321355
// https://github.com/CosmWasm/cosmwasm/blob/v0.11.0-alpha3/contracts/reflect/src/msg.rs#L18-L28
13331356
}
13341357

1358+
type CapitalizedResponse struct {
1359+
Text string `json:"text"`
1360+
}
1361+
13351362
cache, cleanup := withCache(t)
13361363
defer cleanup()
13371364
checksum := createReflectContract(t, cache)
@@ -1370,10 +1397,6 @@ func TestCustomReflectQuerier(t *testing.T) {
13701397
require.Equal(t, "SMALL FRYS :)", response.Text)
13711398
}
13721399

1373-
type CapitalizedResponse struct {
1374-
Text string `json:"text"`
1375-
}
1376-
13771400
// TestFloats is a port of the float_instrs_are_deterministic test in cosmwasm-vm
13781401
func TestFloats(t *testing.T) {
13791402
type Value struct {

types/eureka.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package types
2+
3+
// EurekaPayload defines a single packet sent in the EurekaSendPacketMsg.
4+
//
5+
// Payload value should be encoded using the method specified in the Encoding field,
6+
// and the module on the other side should know how to parse this.
7+
type EurekaPayload struct {
8+
// The port id on the chain where the packet is sent to (external chain).
9+
DestinationPort string `json:"destination_port"`
10+
// Version of the receiving contract.
11+
Version string `json:"version"`
12+
// Encoding used to serialize the Value.
13+
Encoding string `json:"encoding"`
14+
// Encoded payload data
15+
Value []byte `json:"value"`
16+
}

types/msg.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type CosmosMsg struct {
6060
Staking *StakingMsg `json:"staking,omitempty"`
6161
Any *AnyMsg `json:"any,omitempty"`
6262
Wasm *WasmMsg `json:"wasm,omitempty"`
63+
Eureka *EurekaMsg `json:"eureka,omitempty"`
6364
}
6465

6566
func (m *CosmosMsg) UnmarshalJSON(data []byte) error {
@@ -74,6 +75,7 @@ func (m *CosmosMsg) UnmarshalJSON(data []byte) error {
7475
Any *AnyMsg `json:"any,omitempty"`
7576
Wasm *WasmMsg `json:"wasm,omitempty"`
7677
Stargate *AnyMsg `json:"stargate,omitempty"`
78+
Eureka *EurekaMsg `json:"eureka,omitempty"`
7779
}
7880
var tmp InternalCosmosMsg
7981
err := json.Unmarshal(data, &tmp)
@@ -97,6 +99,7 @@ func (m *CosmosMsg) UnmarshalJSON(data []byte) error {
9799
Staking: tmp.Staking,
98100
Any: tmp.Any,
99101
Wasm: tmp.Wasm,
102+
Eureka: tmp.Eureka,
100103
}
101104
return nil
102105
}
@@ -350,6 +353,18 @@ type WasmMsg struct {
350353
ClearAdmin *ClearAdminMsg `json:"clear_admin,omitempty"`
351354
}
352355

356+
// These are messages in the IBC lifecycle using the new Eureka approach. Only usable by IBC-enabled contracts
357+
type EurekaMsg struct {
358+
SendPacket *EurekaSendPacketMsg `json:"send_packet,omitempty"`
359+
}
360+
361+
// Sends an IBC packet with given payloads over the existing channel.
362+
type EurekaSendPacketMsg struct {
363+
ChannelID string `json:"channel_id"`
364+
Payloads []EurekaPayload `json:"payloads"`
365+
Timeout uint64 `json:"timeout,string,omitempty"`
366+
}
367+
353368
// ExecuteMsg is used to call another defined contract on this chain.
354369
// The calling contract requires the callee to be defined beforehand,
355370
// and the address should have been defined in initialization.

types/msg_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,20 @@ func TestMsgFundCommunityPoolSerialization(t *testing.T) {
161161

162162
require.Equal(t, Array[Coin]{{"adenom", "300"}, {"bdenom", "400"}}, msg.FundCommunityPool.Amount)
163163
}
164+
165+
func TestMsgEurekaSendPacketSerialization(t *testing.T) {
166+
document := []byte(`{"send_packet":{"channel_id":"channel-432", "payloads": [{"destination_port": "wasm.123", "version": "random_version", "encoding": "json", "value": ""}], "timeout": "0"}}`)
167+
168+
var msg EurekaMsg
169+
err := json.Unmarshal(document, &msg)
170+
require.NoError(t, err)
171+
172+
require.Equal(t, "channel-432", msg.SendPacket.ChannelID)
173+
require.Equal(t, []EurekaPayload{{
174+
DestinationPort: "wasm.123",
175+
Version: "random_version",
176+
Encoding: "json",
177+
Value: []byte(""),
178+
}}, msg.SendPacket.Payloads)
179+
require.Equal(t, uint64(0), msg.SendPacket.Timeout)
180+
}

0 commit comments

Comments
 (0)