Skip to content

Commit 5450924

Browse files
committed
patch 005
1 parent ec0a580 commit 5450924

File tree

11 files changed

+67
-24
lines changed

11 files changed

+67
-24
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ require (
154154
replace (
155155
// Use the cosmos-flavored keyring library
156156
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
157-
github.com/CosmWasm/wasmvm => github.com/sei-protocol/sei-wasmvm v1.5.4-sei.0.0.2
157+
github.com/CosmWasm/wasmvm => github.com/sei-protocol/sei-wasmvm v1.5.4-sei.0.0.3.0.20250819144601-14afbfe2bf78
158158
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
159159
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.3.56
160160
github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.1.9

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,8 @@ github.com/sei-protocol/sei-tendermint v0.5.9 h1:GLAuHGuCd1eDLfoU4uFMbqQo7z47XSV
782782
github.com/sei-protocol/sei-tendermint v0.5.9/go.mod h1:ip8M5kkQf8JC05np1xd4KR33ttJoseJi28Ea28ui85E=
783783
github.com/sei-protocol/sei-tm-db v0.0.5 h1:3WONKdSXEqdZZeLuWYfK5hP37TJpfaUa13vAyAlvaQY=
784784
github.com/sei-protocol/sei-tm-db v0.0.5/go.mod h1:Cpa6rGyczgthq7/0pI31jys2Fw0Nfrc+/jKdP1prVqY=
785-
github.com/sei-protocol/sei-wasmvm v1.5.4-sei.0.0.2 h1:bhfjHJFhYe/Ffq83UsSJrCcZPkAx5TSEJl1z5lBd6ow=
786-
github.com/sei-protocol/sei-wasmvm v1.5.4-sei.0.0.2/go.mod h1:Q0bSEtlktzh7W2hhEaifrFp1Erx11ckQZmjq8FLCyys=
785+
github.com/sei-protocol/sei-wasmvm v1.5.4-sei.0.0.3.0.20250819144601-14afbfe2bf78 h1:jVFJVae967/K3lydMGQ+CtGowE3nLaZ7kxbxPDZ9fCE=
786+
github.com/sei-protocol/sei-wasmvm v1.5.4-sei.0.0.3.0.20250819144601-14afbfe2bf78/go.mod h1:Q0bSEtlktzh7W2hhEaifrFp1Erx11ckQZmjq8FLCyys=
787787
github.com/sei-protocol/tm-db v0.0.4 h1:7Y4EU62Xzzg6wKAHEotm7SXQR0aPLcGhKHkh3qd0tnk=
788788
github.com/sei-protocol/tm-db v0.0.4/go.mod h1:PWsIWOTwdwC7Ow/GUvx8HgUJTO691pBuorIQD8JvwAs=
789789
github.com/shirou/gopsutil v2.20.5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=

x/wasm/artifacts/v152/lib.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func (vm *VM) IBCChannelOpen(
355355
gasMeter GasMeter,
356356
gasLimit uint64,
357357
deserCost types.UFraction,
358-
) (*types.IBC3ChannelOpenResponse, uint64, error) {
358+
) (*types.IBCChannelOpenResult, uint64, error) {
359359
envBin, err := json.Marshal(env)
360360
if err != nil {
361361
return nil, 0, err
@@ -377,7 +377,7 @@ func (vm *VM) IBCChannelOpen(
377377
if resp.Err != "" {
378378
return nil, gasReport.UsedInternally, fmt.Errorf("%s", resp.Err)
379379
}
380-
return resp.Ok, gasReport.UsedInternally, nil
380+
return &resp, gasReport.UsedInternally, nil
381381
}
382382

383383
// IBCChannelConnect is available on IBC-enabled contracts and is a hook to call into

x/wasm/artifacts/v155/lib.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func (vm *VM) IBCChannelOpen(
355355
gasMeter GasMeter,
356356
gasLimit uint64,
357357
deserCost types.UFraction,
358-
) (*types.IBC3ChannelOpenResponse, uint64, error) {
358+
) (*types.IBCChannelOpenResult, uint64, error) {
359359
envBin, err := json.Marshal(env)
360360
if err != nil {
361361
return nil, 0, err
@@ -377,7 +377,7 @@ func (vm *VM) IBCChannelOpen(
377377
if resp.Err != "" {
378378
return nil, gasReport.UsedInternally, fmt.Errorf("%s", resp.Err)
379379
}
380-
return resp.Ok, gasReport.UsedInternally, nil
380+
return &resp, gasReport.UsedInternally, nil
381381
}
382382

383383
// IBCChannelConnect is available on IBC-enabled contracts and is a hook to call into

x/wasm/keeper/relay.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ func (k Keeper) OnOpenChannel(
2424
msg wasmvmtypes.IBCChannelOpenMsg,
2525
) (string, error) {
2626
defer telemetry.MeasureSince(time.Now(), "wasm", "contract", "ibc-open-channel")
27-
version := ""
28-
2927
_, codeInfo, prefixStore, err := k.contractInstance(ctx, contractAddr)
3028
if err != nil {
3129
return "", err
@@ -37,15 +35,26 @@ func (k Keeper) OnOpenChannel(
3735
gas := k.runtimeGasForContract(ctx)
3836
res, gasUsed, execErr := k.getWasmer(ctx).IBCChannelOpen(codeInfo.CodeHash, env, msg, prefixStore, cosmwasmAPI, querier, ctx.GasMeter(), gas, costJSONDeserialization)
3937
k.consumeRuntimeGas(ctx, gasUsed)
38+
// check if contract panicked / VM failed
4039
if execErr != nil {
4140
return "", sdkerrors.Wrap(types.ErrExecuteFailed, execErr.Error())
4241
}
4342

44-
if res != nil {
45-
version = res.Version
43+
if res == nil {
44+
// If this gets executed, that's a bug in wasmvm
45+
return "", sdkerrors.Wrap(types.ErrVMError, "internal wasmvm error")
46+
}
47+
// check contract result
48+
if res.Err != "" {
49+
return "", types.MarkErrorDeterministic(sdkerrors.Wrap(types.ErrExecuteFailed, res.Err))
50+
}
51+
if res.Ok == nil {
52+
// a nil "ok" value is a valid response and means the contract accepts the incoming channel version
53+
// see https://docs.rs/cosmwasm-std/2.2.2/cosmwasm_std/type.IbcChannelOpenResponse.html
54+
return "", nil
4655
}
4756

48-
return version, nil
57+
return res.Ok.Version, nil
4958
}
5059

5160
// OnConnectChannel calls the contract to let it know the IBC channel was established.

x/wasm/keeper/relay_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ func TestOnOpenChannel(t *testing.T) {
5656
t.Run(name, func(t *testing.T) {
5757
myChannel := wasmvmtypes.IBCChannel{Version: "my test channel"}
5858
myMsg := wasmvmtypes.IBCChannelOpenMsg{OpenTry: &wasmvmtypes.IBCOpenTry{Channel: myChannel, CounterpartyVersion: "foo"}}
59-
m.IBCChannelOpenFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBC3ChannelOpenResponse, uint64, error) {
59+
m.IBCChannelOpenFn = func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCChannelOpenResult, uint64, error) {
6060
assert.Equal(t, myMsg, msg)
61-
return &wasmvmtypes.IBC3ChannelOpenResponse{}, spec.contractGas * DefaultGasMultiplier, spec.contractErr
61+
return &wasmvmtypes.IBCChannelOpenResult{}, spec.contractGas * DefaultGasMultiplier, spec.contractErr
6262
}
6363

6464
ctx, _ := parentCtx.CacheContext()

x/wasm/keeper/wasmtesting/mock_engine.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type MockWasmer struct {
2727
ReplyFn func(codeID wasmvm.Checksum, env wasmvmtypes.Env, reply wasmvmtypes.Reply, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error)
2828
GetCodeFn func(codeID wasmvm.Checksum) (wasmvm.WasmCode, error)
2929
CleanupFn func()
30-
IBCChannelOpenFn func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBC3ChannelOpenResponse, uint64, error)
30+
IBCChannelOpenFn func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCChannelOpenResult, uint64, error)
3131
IBCChannelConnectFn func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelConnectMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error)
3232
IBCChannelCloseFn func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelCloseMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error)
3333
IBCPacketReceiveFn func(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCPacketReceiveMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCReceiveResult, uint64, error)
@@ -38,7 +38,7 @@ type MockWasmer struct {
3838
GetMetricsFn func() (*wasmvmtypes.Metrics, error)
3939
}
4040

41-
func (m *MockWasmer) IBCChannelOpen(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBC3ChannelOpenResponse, uint64, error) {
41+
func (m *MockWasmer) IBCChannelOpen(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCChannelOpenResult, uint64, error) {
4242
if m.IBCChannelOpenFn == nil {
4343
panic("not supposed to be called!")
4444
}
@@ -210,7 +210,7 @@ type IBCContractCallbacks interface {
210210
gasMeter wasmvm.GasMeter,
211211
gasLimit uint64,
212212
deserCost wasmvmtypes.UFraction,
213-
) (*wasmvmtypes.IBC3ChannelOpenResponse, uint64, error)
213+
) (*wasmvmtypes.IBCChannelOpenResult, uint64, error)
214214

215215
IBCChannelConnect(
216216
codeID wasmvm.Checksum,

x/wasm/relay_pingpong_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ func (p *player) Execute(code wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmt
179179
}
180180

181181
// OnIBCChannelOpen ensures to accept only configured version
182-
func (p player) IBCChannelOpen(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBC3ChannelOpenResponse, uint64, error) {
182+
func (p player) IBCChannelOpen(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCChannelOpenResult, uint64, error) {
183183
if msg.GetChannel().Version != p.actor {
184-
return &wasmvmtypes.IBC3ChannelOpenResponse{}, 0, nil
184+
return &wasmvmtypes.IBCChannelOpenResult{}, 0, nil
185185
}
186-
return &wasmvmtypes.IBC3ChannelOpenResponse{}, 0, nil
186+
return &wasmvmtypes.IBCChannelOpenResult{}, 0, nil
187187
}
188188

189189
// OnIBCChannelConnect persists connection endpoints

x/wasm/relay_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,8 @@ func (c *errorReceiverContract) IBCPacketReceive(codeID wasmvm.Checksum, env was
604604
// simple helper struct that implements connection setup methods.
605605
type contractStub struct{}
606606

607-
func (s *contractStub) IBCChannelOpen(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBC3ChannelOpenResponse, uint64, error) {
608-
return &wasmvmtypes.IBC3ChannelOpenResponse{}, 0, nil
607+
func (s *contractStub) IBCChannelOpen(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCChannelOpenResult, uint64, error) {
608+
return &wasmvmtypes.IBCChannelOpenResult{}, 0, nil
609609
}
610610

611611
func (s *contractStub) IBCChannelConnect(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelConnectMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCBasicResponse, uint64, error) {

x/wasm/types/errors.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ var (
8888
// ErrExceedMaxQueryStackSize error if max query stack size is exceeded
8989
ErrExceedMaxQueryStackSize = sdkErrors.Register(DefaultCodespace, 27, "max query stack size exceeded")
9090

91-
// unused 28..29
91+
// unused 28
92+
93+
// ErrVMError means an error occurred in wasmvm (not in the contract itself, but in the host environment)
94+
ErrVMError = sdkErrors.Register(DefaultCodespace, 29, "wasmvm error")
9295

9396
// ErrExceedMaxCallDepth error if max query stack size is exceeded
9497
ErrExceedMaxCallDepth = sdkErrors.Register(DefaultCodespace, 30, "max call depth exceeded")
@@ -109,3 +112,34 @@ func (m *ErrNoSuchContract) ABCICode() uint32 {
109112
func (m *ErrNoSuchContract) Codespace() string {
110113
return DefaultCodespace
111114
}
115+
116+
// DeterministicError is a wrapper type around an error that the creator guarantees to have
117+
// a deterministic error message.
118+
// This means that the `Error()` function must always return the same string on all nodes.
119+
// The DeterministicError has the same error message as the wrapped error.
120+
// DeterministicErrors are not redacted when returned to a contract,
121+
// so not upholding this guarantee can lead to consensus failures.
122+
type DeterministicError struct {
123+
error
124+
}
125+
126+
var _ error = DeterministicError{}
127+
128+
// MarkErrorDeterministic marks an error as deterministic.
129+
// Make sure to only do that if the error message is deterministic between systems.
130+
// See [DeterministicError] for more details.
131+
func MarkErrorDeterministic(e error) DeterministicError {
132+
return DeterministicError{error: e}
133+
}
134+
135+
// Unwrap implements the built-in errors.Unwrap
136+
func (e DeterministicError) Unwrap() error {
137+
return e.error
138+
}
139+
140+
// Cause is the same as unwrap but used by ABCIInfo
141+
// By returning the wrapped error here, we ensure that the DeterministicError inherits
142+
// the ABCIInfo of the wrapped error.
143+
func (e DeterministicError) Cause() error {
144+
return e.Unwrap()
145+
}

0 commit comments

Comments
 (0)