Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Depicted code hash is not the contract code hash #94

Open
cmichi opened this issue Apr 15, 2021 · 2 comments
Open

Depicted code hash is not the contract code hash #94

cmichi opened this issue Apr 15, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@cmichi
Copy link

cmichi commented Apr 15, 2021

The value which is shown as Code Hash is not actually the code hash, but instead the contract's Wasm bytecode.

This is what the UI shows:
ui

This is how the contract bundle looks:

$ cat target/ink/delegator.contract | jq .                                     
{                                                                                                                                                              
  "metadataVersion": "0.1.0",                                                                                                                                  
  "source": {                                                                                                                                                  
    "hash": "0xfa28de816b7ca333f5258a60b5ee37404174609eb629265cfcf770f0d5c0688a",                                                                              
    "language": "ink! 3.0.0-rc3",                                                                                                                              
    "compiler": "rustc 1.53.0-nightly",                                                                                                                        
    "wasm": "0x0061736d…",
  },
  …
}

So using source.hash instead of source.wasm would be the fix.

(Note: In an ideal world the Canvas UI would compute the hash source.wasm by itself and assert hash(source.wasm) == source.hash.)

@cmichi cmichi added the bug Something isn't working label Apr 15, 2021
@statictype statictype self-assigned this Apr 15, 2021
@statictype
Copy link

statictype commented Apr 20, 2021

@cmichi @kwingram25
this happens in polkadot.js/api-contract and apparently has been always the case. should we change it for Canvas or in general?

@cmichi
Copy link
Author

cmichi commented Apr 21, 2021

Could be that this field was not always available, but now it is, so yeah we should in general change it to always display the actual contract hash and not an excerpt of the contracts Wasm bytecode.

It would be even better to not use the source.hash field from the .contract file, but rather compute hash(source.wasm) and display the result of that. This way a user could be sure that the displayed hash always corresponds to what is to be submitted to the chain.

But I'm not sure if it is possible to do that, since AFAIU the type of hash which is used by the chain is generic and could be an arbitrary hashing algorithm. But maybe there is already some polkadot-js function for computing the hash?

But anyway, the easy fix would be to just use source.hash from the contract file.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants