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

Add keccak256 host function #1697

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

zjg555543
Copy link

@zjg555543 zjg555543 commented May 29, 2023

Support keccak256 native code function.

  • keccak256 is a frequently-used function in contracts.
  • native code is more efficient than using libraries in contracts.

@zjg555543 zjg555543 changed the title add Keccak256 host function Add keccak256 host function May 29, 2023
@zjg555543 zjg555543 marked this pull request as ready for review May 29, 2023 13:25
@omniwired
Copy link

I was wondering if @webmaster128 saw this one.

@webmaster128
Copy link
Member

webmaster128 commented Aug 17, 2023

Right, so in the past when working on crypto APIs we conclude that all hash function should be executed right in Wasm instead of adding a call to the environment. The reasoning is the following:

  • Hash functions are cheap in execution cost and code size
  • There is a huge amount of hash functions needed (keccak256, SHA2, SHA3, ripemd160, various flavours of blake, ...)
  • Benchmarking and setting a gas price for those functions is a lot of work
  • Keeping the contract-host API minimal is good for maintenance

In contrast to EVM environments, Wasm allows for much faster execution in the contract.

We added a few crypto functions that are much heavier than hashing, like secp256k1 and ed25519 verification. Pairing based cryptography might join at some point. For those cases we win a lot in terms of code size and execution speed when having them in the host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants