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

Public method to build checksum for wasm code #359

Closed
alpe opened this issue Nov 9, 2022 · 4 comments · Fixed by #410
Closed

Public method to build checksum for wasm code #359

alpe opened this issue Nov 9, 2022 · 4 comments · Fixed by #410
Milestone

Comments

@alpe
Copy link
Contributor

alpe commented Nov 9, 2022

I have the assumption that the checksum is a sha256 hash on the unzipped wasm code. It would be better to not have this assumption but call into the wasmvm library to let it do the checksum calculation.

Also helpful in this context: IsChecksum([]byte) bool

@webmaster128
Copy link
Member

webmaster128 commented Nov 23, 2022

Could be done. However, I think it's safe to say sha256 is the checksum and that's not going to change any time soon. I took sha256 from the wasmd codebase long time ago if I recall correctly, so it was introduced there first. Also we have such docs: "Checksum is the sha256 hash of the stored code".

Sholdn't we start by deduplicating all the sha256.Sum256 calls in the wasmd codebase into a Wasm checksum function? We can also move it here if you want but I'd like to avoid a call into cosmwasm-vm (Rust) for that.

Also helpful in this context: IsChecksum([]byte) bool

What's that method doing? It cannot tell of something is a checksum or not.

@alpe
Copy link
Contributor Author

alpe commented Jan 3, 2023

The wasmvm lib owns the checksum generation so it would be the cleanest to have it in this project. I trust the Go version of sha256 to work the same way as the Rust one. No need to call into Rust.
The deduplication in wasmd would be an intermediate step only that is removed.

Sorry, IsChecksum(s []byte) bool should return true when len(s) == 32. A simple sanity check only.

@nicolaslara
Copy link

There's a bug related to this that I've fixed on our fork: osmosis-labs/wasmd#15

Basically: the checksum is being checked wrong in the CLI (it's checking the zipped instead of unzipped source)

I can upstream this next week if no one gets to it before me

@webmaster128
Copy link
Member

webmaster128 commented Mar 27, 2023

I can upstream this next week if no one gets to it before me

Could you please report this in wasmd? Thank you! This issue is for creating a hasher, not hashing the right data so the bug is out of scope for wasmvm.

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

Successfully merging a pull request may close this issue.

3 participants