ewasm / design

Ewasm Design Overview and Specification
Apache License 2.0
1.02k stars 125 forks source link

Provide kecccak256 host function #203

Open seanyoung opened 4 years ago

seanyoung commented 4 years ago

EVM has an keccak instruction, webassembly does not. Because of this, https://github.com/hyperledger-labs/solang has to include a keccak implementation in any contract which does keccak hashing. Keccak hashing is used for mappings and storage arrays.

It would be much better if the EEI provided a keccak host function.

Note that Substrate wasm interface does provide this and another hashing functions too: https://github.com/paritytech/substrate/blob/master/frame/contracts/src/wasm/runtime.rs#L1199

seanyoung commented 4 years ago

This file is compiled to wasm by clang and linked into every ewasm contract: https://github.com/hyperledger-labs/solang/blob/master/stdlib/sha3.c

axic commented 4 years ago

Please note there is a proposed precompile instead of a host function: https://github.com/ewasm/design/blob/master/system_contracts.md#keccak256

seanyoung commented 4 years ago

Ah I had missed that, thanks.

A host function is much better, this has much lower gas cost (no call overhead). This would help make ewasm competitive with evm.