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

Deterministic contract errors vs non deterministic vm errors #1707

Closed
alpe opened this issue Jun 5, 2023 · 6 comments
Closed

Deterministic contract errors vs non deterministic vm errors #1707

alpe opened this issue Jun 5, 2023 · 6 comments
Milestone

Comments

@alpe
Copy link
Contributor

alpe commented Jun 5, 2023

Currently contract devs have a hard time to find out the root cause for contract errors. This pops up on discord and wasmd issues regular.

@ethanfrey suggested on internal slack to separate out (deterministic) “contract-originating errors” as a subset of (non-deterministic) “wasmer-originating errors”.
The “contract-originating errors” would be a big step towards better dev UX already.

@ethanfrey
Copy link
Member

The only things in the SDK we can trust as fully deterministic are "state writes" (including ordering), the data returned on a message, and the error code (but not codespace !?).

Error can definitely change between any two systems or any patch version and thus can never be exposed to contracts, which might write them to state.

However, with wasm, we also guarantee the exact same code running on each machine and the result returned by any import should be considered deterministic (writes, events, errors, gas usage, submessages, etc). In only this case could we expose the event to other state machine code.

We need to be careful to distinguish wasmer/vm-errors (which are raised on panic, out of gas, etc) and a string returned directly from a wasm contract. Only in the second case can we expose this to other contracts. This likely needs some updates to wasmvm to allow such distinction to be made

@webmaster128
Copy link
Member

Requires CosmWasm/wasmvm#398

@webmaster128 webmaster128 added this to the 2.0.0 milestone Jun 13, 2023
@0xLaurenzo
Copy link

0xLaurenzo commented Jun 18, 2023

After looking through cosmwasm-vm and wasmvm, I think we might be able to return any error type of type ContractResult.Error to a calling contract in a submsg. I'm not sure what the best way is specifically to catch ContractResult Errors in, but probably it's best to catch these in redactError() similar to

if wasmvmtypes.ToSystemError(err) != nil {
		return err
	}

an example of an call to a contract in wasmvm is the execute api call

@0xLaurenzo
Copy link

After talking about this issue in discord, I heard there were some backwards compatibility issues. AFAIK, these changes would only introduce backwards incompatibility in the sense that they are state breaking. Returning submsg errors should not affect direct calls to smart contracts or successful contract behavior. Given that and the huge amount of DX increase this gives us, I think it's still worth considering or looking for a way to include this sooner

@nicolaslara
Copy link

The only things in the SDK we can trust as fully deterministic are "state writes" (including ordering), the data returned on a message, and the error code (but not codespace !?).

There's a discussion about including codespace in cometbft/cometbft#844

@webmaster128
Copy link
Member

There is nothing to be done in this repo. Please follow CosmWasm/wasmvm#398 for progress on the matter discussed here. Thanks everyone for your participation – appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants