ewasm-precompiles
ewasm-precompiles copied to clipboard
Adapt blake2 precompile to match the EIP
See https://github.com/ethereum/EIPs/issues/152
Could you explain a bit further what has to be done?
Here is what I understand so far:
Current blake2 implementation just reads an input data and calculates the blake2b hash using the blake2
crate. In order to change it to match the EIP the following has to be done:
- Read input data
h
(current state) - Read input data
t
(data length) - Read input data
m
(message/data) with lengtht
- Read input data
f
(finalization flag) - Read input data
r
(rounds)
Based on data length t
we can calculate if we need to call Blake2b
or Blake2s
. Then set h
(using new_keyed
fn, and request the output, but currently the result
fn sets 0
as finalization flag.
@hugo-dc sorry for the delay. Yes, that is correct, it needs to follow what specification of the EIP. I'm not sure if we can use the current crate - likely not -, because we need direct access to all parameters of blake2.
The current version of the Blake2 precompile is here: https://github.com/ethereum/EIPs/pull/2024
Our code is pretty close to that and would be easy to update.
It seems the now-current proposal is at https://github.com/ethereum/EIPs/pull/2129, which brings us back to a specification similar to https://github.com/ewasm/ewasm-precompiles/issues/36#issuecomment-458416477
The final EIP, which went live 2 days ago with Istanbul, is quite different: https://eips.ethereum.org/EIPS/eip-152