Question:: BitHelper - sha3 vs keccak
dkataskin opened this issue · 5 comments
Hello sirs, I looked into implementation of BitHelper
and I see that keccakf1600
is used. While the algorithm is the same keccakf1600
package contains NIST SHA3
implementation and it's different from original Keccak and Ethereum is using original Keccak.
Shouldn't BitHelper
be utilizing keccak hash instead of sha3? SHA3 can be reversed to to Keccak by changing padding and there is a fork that does that for keccakf1600
.
To be honest, I haven't verified our usage of SHA3 with the official Ethereum tests yet. If you would suggest a change to the algorithm that you believe we should make, I'd be happy to discuss and/or look over a PR.
Here's a good example of an official Eth test case that covers the expected result of a SHA3: https://github.com/ethereum/tests/blob/e8ba92a9e20a252d215cbc95d314eba22b1d79c5/src/GeneralStateTestsFiller/stSolidityTest/TestCryptographicFunctionsFiller.json#L43
You're right that the current implementation does not look to match those tests as is, e.g.:
iex> BitHelper.kec("teststring") |> :binary.decode_unsigned |> inspect(base: :hex)
0xA52EF463EDB03558BE0598FB9A3AE67E0FC41C44BD0B1D4392B354D1E817FEA8
I suggest doing the following:
- fork
erlang-keccakf1600
under exthereum - apply this change jur0/erlang-keccakf1600@a87d31d
- modify
mix.exs
to pull keccak package from exthereum
or if you just fork erlang-keccakf1600
under exthereum I can prepare pull requests with required changes and tests
FYI, right now we're using https://hex.pm/packages/keccakf1600_orig to solve this issue.