design icon indicating copy to clipboard operation
design copied to clipboard

Provide kecccak256 host function

Open seanyoung opened this issue 5 years ago • 3 comments

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 avatar Sep 02 '20 11:09 seanyoung

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

seanyoung avatar Sep 02 '20 11:09 seanyoung

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

axic avatar Sep 02 '20 11:09 axic

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.

seanyoung avatar Sep 02 '20 12:09 seanyoung