use-ink / contracts-ui

Web application for deploying wasm smart contracts on Substrate chains that include the FRAME contracts pallet
https://contracts-ui.substrate.io/
GNU General Public License v3.0
61 stars 44 forks source link

Instantiate dry-run doesn't catch the reversion #494

Closed statictype closed 10 months ago

statictype commented 1 year ago

Trying to upload a contract with the wrong metadata should result in a failed dry-run, however the dry run is successful and the instantiation fails

CONTRACTS.ContractReverted: The contract ran to completion but decided to revert its storage changes.,Please note that this error is only returned from extrinsics. When called directly,or via RPC an `Ok` will be returned. In this case the caller needs to inspect the flags,to determine whether a reversion has taken place.

Similarly to the call dry-run, the results should be decoded and shown to the user.

https://github.com/paritytech/contracts-ui/blob/master/src/helpers/output.ts

gaboesquivel commented 11 months ago

I run several tests and found out that source, spec.constructors, types, version are the only values required and verified before calling contract api instantiate to get dry run results. No other metadata is being checked or validated, In my case I don't get a ContractReverted error, the deployment is successful but ui is not able to detect how to interact with the contract. dryRun call doesn't throw any error either.

Do we want to add further metadata validation at the ui level? it seems that api endpoints wont complain about malformatted metadata in some cases.

statictype commented 11 months ago

@gaboesquivel the issue description is a bit confusing, sorry about that. the problem doesn't happen on contract upload, but on re-instantiation when you update the metadata. in order to reproduce, one must follow these steps.

  1. Have an already deployed contract
  2. Click on "reinstantiate" on the contract interaction page. Alternatively, you can use the "instantiate from code hash" page and select an existing code hash.
  3. On the next step, scroll to the bottom and upload the metadata of another contract (the json file generated from compilation)
  4. See the successful instantiation dry-run on the next step
  5. When attempting to deploy the contract, you can see an error occured and inspect it in the console.

This happens because contract reversion is not returned as a dry-run error. We must inspect the flags and decode the dry-run result. On the interact page (where we perform contract calls on deployed contracts) we have a way to do that, but it's not implemented for instantiation yet. Would be nice if we could reuse the UI and logic for contract call dry run in the instantiation flow. Hope that makes more sense!