Add nil checks

This commit is contained in:
Christoph Otter
2024-03-06 10:27:26 +01:00
parent ad93ad3dda
commit 62eaa6eedf
2 changed files with 40 additions and 0 deletions

View File

@@ -323,6 +323,10 @@ func (k Keeper) instantiate(
if err != nil {
return nil, nil, errorsmod.Wrap(types.ErrVMError, err.Error())
}
if res == nil {
// If this gets executed, that's a bug in wasmvm
return nil, nil, errorsmod.Wrap(types.ErrVMError, "internal wasmvm error")
}
if res.Err != "" {
return nil, nil, types.MarkErrorDeterministic(errorsmod.Wrap(types.ErrInstantiateFailed, res.Err))
}
@@ -407,6 +411,10 @@ func (k Keeper) execute(ctx context.Context, contractAddress, caller sdk.AccAddr
if execErr != nil {
return nil, errorsmod.Wrap(types.ErrVMError, execErr.Error())
}
if res == nil {
// If this gets executed, that's a bug in wasmvm
return nil, errorsmod.Wrap(types.ErrVMError, "internal wasmvm error")
}
if res.Err != "" {
return nil, types.MarkErrorDeterministic(errorsmod.Wrap(types.ErrExecuteFailed, res.Err))
}
@@ -484,6 +492,10 @@ func (k Keeper) migrate(
if err != nil {
return nil, errorsmod.Wrap(types.ErrVMError, err.Error())
}
if res == nil {
// If this gets executed, that's a bug in wasmvm
return nil, errorsmod.Wrap(types.ErrVMError, "internal wasmvm error")
}
if res.Err != "" {
return nil, types.MarkErrorDeterministic(errorsmod.Wrap(types.ErrMigrationFailed, res.Err))
}
@@ -549,6 +561,10 @@ func (k Keeper) Sudo(ctx context.Context, contractAddress sdk.AccAddress, msg []
if execErr != nil {
return nil, errorsmod.Wrap(types.ErrVMError, execErr.Error())
}
if res == nil {
// If this gets executed, that's a bug in wasmvm
return nil, errorsmod.Wrap(types.ErrVMError, "internal wasmvm error")
}
if res.Err != "" {
return nil, types.MarkErrorDeterministic(errorsmod.Wrap(types.ErrExecuteFailed, res.Err))
}
@@ -589,6 +605,10 @@ func (k Keeper) reply(ctx sdk.Context, contractAddress sdk.AccAddress, reply was
if execErr != nil {
return nil, errorsmod.Wrap(types.ErrVMError, execErr.Error())
}
if res == nil {
// If this gets executed, that's a bug in wasmvm
return nil, errorsmod.Wrap(types.ErrVMError, "internal wasmvm error")
}
if res.Err != "" {
return nil, types.MarkErrorDeterministic(errorsmod.Wrap(types.ErrExecuteFailed, res.Err))
}

View File

@@ -75,6 +75,10 @@ func (k Keeper) OnConnectChannel(
if execErr != nil {
return errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error())
}
if res == nil {
// If this gets executed, that's a bug in wasmvm
return errorsmod.Wrap(types.ErrVMError, "internal wasmvm error")
}
if res.Err != "" {
return types.MarkErrorDeterministic(errorsmod.Wrap(types.ErrExecuteFailed, res.Err))
}
@@ -109,6 +113,10 @@ func (k Keeper) OnCloseChannel(
if execErr != nil {
return errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error())
}
if res == nil {
// If this gets executed, that's a bug in wasmvm
return errorsmod.Wrap(types.ErrVMError, "internal wasmvm error")
}
if res.Err != "" {
return types.MarkErrorDeterministic(errorsmod.Wrap(types.ErrExecuteFailed, res.Err))
}
@@ -145,6 +153,10 @@ func (k Keeper) OnRecvPacket(
// all state downstream and not persist any data in ibc-go.
// This can be triggered by throwing a panic in the contract
}
if res == nil {
// If this gets executed, that's a bug in wasmvm
return nil, errorsmod.Wrap(types.ErrVMError, "internal wasmvm error")
}
if res.Err != "" {
// return error ACK with non-redacted contract message, state will be reverted
return channeltypes.Acknowledgement{
@@ -200,6 +212,10 @@ func (k Keeper) OnAckPacket(
if execErr != nil {
return errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error())
}
if res == nil {
// If this gets executed, that's a bug in wasmvm
return errorsmod.Wrap(types.ErrVMError, "internal wasmvm error")
}
if res.Err != "" {
return types.MarkErrorDeterministic(errorsmod.Wrap(types.ErrExecuteFailed, res.Err))
}
@@ -231,6 +247,10 @@ func (k Keeper) OnTimeoutPacket(
if execErr != nil {
return errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error())
}
if res == nil {
// If this gets executed, that's a bug in wasmvm
return errorsmod.Wrap(types.ErrVMError, "internal wasmvm error")
}
if res.Err != "" {
return types.MarkErrorDeterministic(errorsmod.Wrap(types.ErrExecuteFailed, res.Err))
}