diff --git a/eqc/ecu_crypto_eqc.erl b/eqc/ecu_crypto_eqc.erl new file mode 100644 index 0000000..64c3290 --- /dev/null +++ b/eqc/ecu_crypto_eqc.erl @@ -0,0 +1,25 @@ +%%% File : ecu_crypto_eqc.erl +%%% Author : Hans Svensson +%%% Description : +%%% Created : 7 Jan 2023 by Hans Svensson +-module(ecu_crypto_eqc). + +-compile([export_all, nowarn_export_all]). + +-include_lib("eqc/include/eqc.hrl"). + +gen_ecdsa_secp256k1_privkey() -> + <> = crypto:strong_rand_bytes(32), + P = (P0 rem (ecu_secp256k1:n() - 1)) + 1, + return(<>). + +prop_recover() -> + ?FORALL(PK, gen_ecdsa_secp256k1_privkey(), + begin + MsgHash = sha3:hash(256, PK), + Sig = ecu_crypto:eth_sign(MsgHash, PK), + Pub1 = ecrecover:recover(MsgHash, Sig), + Pub2 = ecu_crypto:ec_recover(MsgHash, Sig), + equals(Pub1, Pub2) + end). + diff --git a/rebar.config b/rebar.config index 193853e..8f01fce 100644 --- a/rebar.config +++ b/rebar.config @@ -9,5 +9,6 @@ {profiles, [{test, [{deps, [{enacl, {git, "https://github.com/aeternity/enacl.git", {ref, "5bae41c"}}}, {ecrecover, {git, "https://github.com/aeternity/ecrecover.git", {ref, "74b7816"}}}]}]}, - {eqc, [{deps, [{enacl, {git, "https://github.com/aeternity/enacl.git", {ref, "38ffc76"}}}]}]} + {eqc, [{deps, [{enacl, {git, "https://github.com/aeternity/enacl.git", {ref, "38ffc76"}}}, + {ecrecover, {git, "https://github.com/aeternity/ecrecover.git", {ref, "74b7816"}}}]}]} ]}.