From 6abfbaf9c5301ef0db8d46308c8fc7c550c02a1c Mon Sep 17 00:00:00 2001 From: Izel Nakri Date: Fri, 17 Sep 2021 05:43:26 +0200 Subject: [PATCH] update keccak library --- lib/eth.ex | 1 - lib/eth/transaction/signer.ex | 2 +- lib/eth/utils.ex | 13 ++++--------- mix.exs | 13 ++++++------- mix.lock | 28 +++++++++++++--------------- test/eth/eth_test.exs | 1 - 6 files changed, 24 insertions(+), 34 deletions(-) diff --git a/lib/eth.ex b/lib/eth.ex index 2ce3045..8a47472 100644 --- a/lib/eth.ex +++ b/lib/eth.ex @@ -97,7 +97,6 @@ defmodule ETH do defdelegate get_address(private_or_public_key), to: ETH.Utils defdelegate convert(value, denomination), to: ETH.Utils defdelegate secp256k1_signature(hash, private_key), to: ETH.Utils - defdelegate keccak256(data), to: ETH.Utils defdelegate encode16(data), to: ETH.Utils defdelegate decode16(decoded_data), to: ETH.Utils defdelegate to_buffer(data), to: ETH.Utils diff --git a/lib/eth/transaction/signer.ex b/lib/eth/transaction/signer.ex index c1ad469..a7c6cbc 100644 --- a/lib/eth/transaction/signer.ex +++ b/lib/eth/transaction/signer.ex @@ -34,7 +34,7 @@ defmodule ETH.Transaction.Signer do target_list |> ExRLP.encode() - |> keccak256 + |> ExKeccak.hash_256 end def hash_transaction( diff --git a/lib/eth/utils.ex b/lib/eth/utils.ex index e639db9..9fbbf5d 100644 --- a/lib/eth/utils.ex +++ b/lib/eth/utils.ex @@ -14,25 +14,25 @@ defmodule ETH.Utils do def get_address(<>) do <<4::size(8), key::binary-size(64)>> = private_key |> get_public_key() - <<_::binary-size(12), eth_address::binary-size(20)>> = keccak256(key) + <<_::binary-size(12), eth_address::binary-size(20)>> = ExKeccak.hash_256(key) "0x#{Base.encode16(eth_address)}" end def get_address(<>) do public_key = Base.decode16!(encoded_private_key, case: :mixed) |> get_public_key() <<4::size(8), key::binary-size(64)>> = public_key - <<_::binary-size(12), eth_address::binary-size(20)>> = keccak256(key) + <<_::binary-size(12), eth_address::binary-size(20)>> = ExKeccak.hash_256(key) "0x#{Base.encode16(eth_address)}" end def get_address(<<4::size(8), key::binary-size(64)>>) do - <<_::binary-size(12), eth_address::binary-size(20)>> = keccak256(key) + <<_::binary-size(12), eth_address::binary-size(20)>> = ExKeccak.hash_256(key) "0x#{Base.encode16(eth_address)}" end def get_address(<>) do <<4::size(8), key::binary-size(64)>> = Base.decode16!(encoded_public_key, case: :mixed) - <<_::binary-size(12), eth_address::binary-size(20)>> = keccak256(key) + <<_::binary-size(12), eth_address::binary-size(20)>> = ExKeccak.hash_256(key) "0x#{Base.encode16(eth_address)}" end @@ -64,11 +64,6 @@ defmodule ETH.Utils do [signature: signature, recovery: recovery] end - def keccak256(data) do - {:ok, result} = ExKeccak.hash_256(data) - result - end - def encode16(value), do: Base.encode16(value, case: :lower) def decode16(value), do: Base.decode16!(value, case: :mixed) diff --git a/mix.exs b/mix.exs index 31d7447..36159ba 100644 --- a/mix.exs +++ b/mix.exs @@ -20,7 +20,7 @@ defmodule Eth.Mixfile do # Run "mix help compile.app" to learn about applications. def application() do [ - extra_applications: [:logger, :telemetry, :ethereumex] + extra_applications: [:logger, :ethereumex] ] end @@ -29,14 +29,13 @@ defmodule Eth.Mixfile do [ {:ethereumex, "~> 0.7.0"}, {:ex_rlp, "~> 0.5.3"}, - {:ex_doc, ">= 0.23.0", only: :dev}, - {:dialyxir, "~> 1.0.0", only: [:dev], runtime: false}, + {:ex_doc, ">= 0.25.2", only: :dev}, + {:dialyxir, "~> 1.1.0", only: [:dev], runtime: false}, {:hexate, "~> 0.6.1"}, - {:ex_keccak, "~> 0.1.2"}, - {:mnemonic, "~> 0.2.2"}, + {:ex_keccak, "~> 0.2.0"}, + {:mnemonic, "~> 0.3.0"}, {:poison, "~> 5.0.0"}, - {:ex_secp256k1, "~> 0.1.2"}, - {:telemetry, "~> 0.4.2"} + {:ex_secp256k1, "~> 0.2.1"}, ] end diff --git a/mix.lock b/mix.lock index 671450c..3b55212 100644 --- a/mix.lock +++ b/mix.lock @@ -1,33 +1,31 @@ %{ - "certifi": {:hex, :certifi, "2.5.3", "70bdd7e7188c804f3a30ee0e7c99655bc35d8ac41c23e12325f36ab449b70651", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "ed516acb3929b101208a9d700062d520f3953da3b6b918d866106ffa980e1c10"}, - "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"}, - "earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm", "8cf8a291ebf1c7b9539e3cddb19e9cef066c2441b1640f13c34c1d3cfc825fec"}, - "earmark_parser": {:hex, :earmark_parser, "1.4.13", "0c98163e7d04a15feb62000e1a891489feb29f3d10cb57d4f845c405852bbef8", [:mix], [], "hexpm", "d602c26af3a0af43d2f2645613f65841657ad6efc9f0e361c3b6c06b578214ba"}, + "certifi": {:hex, :certifi, "2.6.1", "dbab8e5e155a0763eea978c913ca280a6b544bfa115633fa20249c3d396d9493", [:rebar3], [], "hexpm", "524c97b4991b3849dd5c17a631223896272c6b0af446778ba4675a1dff53bb7e"}, + "comeonin": {:hex, :comeonin, "5.3.2", "5c2f893d05c56ae3f5e24c1b983c2d5dfb88c6d979c9287a76a7feb1e1d8d646", [:mix], [], "hexpm", "d0993402844c49539aeadb3fe46a3c9bd190f1ecf86b6f9ebd71957534c95f04"}, + "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.15", "b29e8e729f4aa4a00436580dcc2c9c5c51890613457c193cc8525c388ccb2f06", [:mix], [], "hexpm", "044523d6438ea19c1b8ec877ec221b008661d3c27e3b848f4c879f500421ca5c"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ethereumex": {:hex, :ethereumex, "0.7.0", "6083ae91f6e4c886f935923751bfd4bcfc1d43ea969237a06a652df71fb4deb8", [:mix], [{:httpoison, "~> 1.7", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "0969d1f3ab2a8272acf6d0239edb6ee7ef8681366b7315a3d14381eae149cad2"}, - "ex_doc": {:hex, :ex_doc, "0.25.1", "4b736fa38dc76488a937e5ef2944f5474f3eff921de771b25371345a8dc810bc", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "3200b0a69ddb2028365281fbef3753ea9e728683863d8cdaa96580925c891f67"}, - "ex_keccak": {:hex, :ex_keccak, "0.1.3", "818faf6df706209782e7e0a8c16202e380a7a9b0e932e9fcb8fa3724f6e41d2e", [:mix], [{:rustler, "~> 0.21.1", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "10b3acd7c99624e52fd48dafb2d8b32063c7c5135cd98390974a41292b0601fe"}, + "ex_doc": {:hex, :ex_doc, "0.25.2", "4f1cae793c4d132e06674b282f1d9ea3bf409bcca027ddb2fe177c4eed6a253f", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5b0c172e87ac27f14dfd152d52a145238ec71a95efbf29849550278c58a393d6"}, + "ex_keccak": {:hex, :ex_keccak, "0.2.0", "ca31d7fdae818380aa07952e6941c5de6b689cb8a68189fcce1e25d7bb0c4574", [:mix], [{:rustler, "~> 0.22.0", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "4bef13ce4dda45b15e2958e0ce5ff77502279778fb7e32cfa887dccb036f3bb2"}, "ex_rlp": {:hex, :ex_rlp, "0.5.3", "9055bddade545ee3e734aaad62c4b4d08211834da3beb43ae269b75785909e5e", [:mix], [], "hexpm", "a755a5f8f9f66079f3ecbe021536b949077fac0df963d9e59a20321bab28722d"}, - "ex_secp256k1": {:hex, :ex_secp256k1, "0.1.2", "affe4e0fa1adc085ab47d7ab3cc44d594249d24bd0a37a9002f6648d112c2081", [:mix], [{:rustler, "~> 0.21.1 ", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "8ae0131380ada331b15924b563f89e7f56b4e74cc10978f3ea0836589e87730a"}, - "hackney": {:hex, :hackney, "1.17.0", "717ea195fd2f898d9fe9f1ce0afcc2621a41ecfe137fae57e7fe6e9484b9aa99", [:rebar3], [{:certifi, "~>2.5", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "64c22225f1ea8855f584720c0e5b3cd14095703af1c9fbc845ba042811dc671c"}, + "ex_secp256k1": {:hex, :ex_secp256k1, "0.2.1", "09999aa0fdf123e7a8b25e0910facc2fd9aa4ebe9661ccd14dadfdc7da98831b", [:mix], [{:rustler, "~> 0.22", [hex: :rustler, repo: "hexpm", optional: false]}], "hexpm", "8cfd43c264f20b4b06e77867dc43a38b551ce79c70b9a52fc847805fa74916fa"}, + "hackney": {:hex, :hackney, "1.17.4", "99da4674592504d3fb0cfef0db84c3ba02b4508bae2dff8c0108baa0d6e0977c", [:rebar3], [{:certifi, "~>2.6.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "de16ff4996556c8548d512f4dbe22dd58a587bf3332e7fd362430a7ef3986b16"}, "hexate": {:hex, :hexate, "0.6.1", "1cea42e462c1daa32223127d4752e71016c3d933d492b9bb7fa4709a4a0fd50d", [:mix], [], "hexpm", "667c429c0970e3097107c9fafcc645636302888388845d78a3947a739fd946b7"}, - "httpoison": {:hex, :httpoison, "1.7.0", "abba7d086233c2d8574726227b6c2c4f6e53c4deae7fe5f6de531162ce9929a0", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "975cc87c845a103d3d1ea1ccfd68a2700c211a434d8428b10c323dc95dc5b980"}, + "httpoison": {:hex, :httpoison, "1.8.0", "6b85dea15820b7804ef607ff78406ab449dd78bed923a49c7160e1886e987a3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "28089eaa98cf90c66265b6b5ad87c59a3729bea2e74e9d08f9b51eb9729b3c3a"}, "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, - "keccakf1600": {:hex, :keccakf1600_orig, "2.0.0", "0a7217ddb3ee8220d449bbf7575ec39d4e967099f220a91e3dfca4dbaef91963", [:rebar3], [], "hexpm", "bdbbb02d67bea35605f95d4e3de48203347374e414da7945c4f2f7fd13ffe632"}, - "libsecp256k1": {:hex, :libsecp256k1, "0.1.10", "d27495e2b9851c7765129b76c53b60f5e275bd6ff68292c50536bf6b8d091a4d", [:make, :mix], [{:mix_erlang_tasks, "0.1.0", [hex: :mix_erlang_tasks, repo: "hexpm", optional: false]}], "hexpm", "09ea06239938571124f7f5a27bc9ac45dfb1cfc2df40d46ee9b59c3d51366652"}, "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, "makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, - "mix_erlang_tasks": {:hex, :mix_erlang_tasks, "0.1.0", "36819fec60b80689eb1380938675af215565a89320a9e29c72c70d97512e4649", [:mix], [], "hexpm", "95d2839c422c482a70c08a8702da8242f86b773f8ab6e8602a4eb72da8da04ed"}, - "mnemonic": {:hex, :mnemonic, "0.2.2", "cb232a604ca5e8a25fb81aae15b2828eabfeaa07483314e7ed8f97c33f4daf7e", [:mix], [], "hexpm", "ca4d05bb51f9f1fa2658cdf0d1b450430380eb0f3b9964511e2abffc77f3d940"}, + "mnemonic": {:hex, :mnemonic, "0.3.0", "bcf403da54a034c442c51bc0d8f0c7cecdfcb8a997efa408dd3506ae84b5e04b", [:mix], [{:pbkdf2_elixir, ">= 1.3.0", [hex: :pbkdf2_elixir, repo: "hexpm", optional: false]}], "hexpm", "4ad2b1809e69127ef95d9f4d6d0ae567fc0bf9f45fde5c5dc69f3a56114c10a2"}, "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"}, - "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"}, + "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"}, + "pbkdf2_elixir": {:hex, :pbkdf2_elixir, "1.4.1", "a5249aa0f79bc519cb0180021bab93d5dd690d3c8eb86d7ad628d7767dfb4952", [:mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}], "hexpm", "5b229341a7087fb5ba35de909a1036170e1f86df771f69069d13a87520a6a5c1"}, "poison": {:hex, :poison, "5.0.0", "d2b54589ab4157bbb82ec2050757779bfed724463a544b6e20d79855a9e43b24", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "11dc6117c501b80c62a7594f941d043982a1bd05a1184280c0d9166eb4d8d3fc"}, "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm", "dad79704ce5440f3d5a3681c8590b9dc25d1a561e8f5a9c995281012860901e3"}, - "rustler": {:hex, :rustler, "0.21.1", "5299980be32da997c54382e945bacaa015ed97a60745e1e639beaf6a7b278c65", [:mix], [{:toml, "~> 0.5.2", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "6ee1651e10645b2b2f3bb70502bf180341aa058709177e9bc28c105934094bc6"}, + "rustler": {:hex, :rustler, "0.22.0", "e2930f9d6933e910f87526bb0a7f904e32b62a7e838a3ca4a884ee7fdfb957ed", [:mix], [{:toml, "~> 0.5.2", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "01f5989dd511ebec09be481e07d3c59773d5373c5061e09d3ebc3ef61811b49d"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, "telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"}, "toml": {:hex, :toml, "0.5.2", "e471388a8726d1ce51a6b32f864b8228a1eb8edc907a0edf2bb50eab9321b526", [:mix], [], "hexpm", "f1e3dabef71fb510d015fad18c0e05e7c57281001141504c6b69d94e99750a07"}, diff --git a/test/eth/eth_test.exs b/test/eth/eth_test.exs index 4b5faeb..db50382 100644 --- a/test/eth/eth_test.exs +++ b/test/eth/eth_test.exs @@ -59,7 +59,6 @@ defmodule ETH.Test do get_transaction_receipt!: 1, hash_transaction: 1, hash_transaction: 2, - keccak256: 1, pad_to_even: 1, parse: 1, secp256k1_signature: 2,