No internet connection
  1. Home
  2. Smart Contracts

crypto opcodes like SHA3

By Orkun Külçe @orkunkl
    2020-07-27 09:18:43.048Z

    Hi guys, maybe this is a silly question, but how do you deal with crypto opcodes like SHA3 in CosmWasm? I suppose it is a function call to a Rust implementation of it? If so, where in the code may I find that? I am writing a compiler from a custom contract language to WebAssembly, already supports a large portion of eWasm and currently wanting to target CosmWasm, so it would be great if I can receive some hints on the CosmWasm impl

    Solved in post #2, click to view
    • 2 replies
    1. Orkun Külçe @orkunkl
        2020-07-27 09:19:34.981Z

        The only opcodes available are the ones from Wasm. I assume sha3 is an Ethereum opcode, not one from Wasm, right? Then you need to inline a Wasm implementation of sha3.

        ReplySolution
        1. E
          In reply toorkunkl:
          Ethan Frey @ethanfrey
            2020-07-27 09:25:07.554Z

            As Orkun says, you can just import a crate that provides the functionality and do the hashing in the contract

            You can see a sample where we import and use the sha256 crate in a contract: https://github.com/CosmWasm/cosmwasm/blob/74781c56aae6fa328b394474c69f9c341e9a1589/contracts/hackatom/src/contract.rs#L266

            Just one line in Cargo.toml to enable it: https://github.com/CosmWasm/cosmwasm/blob/74781c56aae6fa328b394474c69f9c341e9a1589/contracts/hackatom/Cargo.toml#L35