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

Multisig support #10

Merged
merged 16 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Rust Toolchain
run: rustup default stable
xandkar marked this conversation as resolved.
Show resolved Hide resolved

- name: Cache Hex Packages
uses: actions/cache@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ cover:
$(REBAR) cover

test:
$(REBAR) as test do eunit
$(REBAR) as test do eunit, cover

ci:
$(REBAR) as test do eunit,cover && $(REBAR) do xref, dialyzer
$(REBAR) covertool generate
codecov --required -f _build/test/covertool/libp2p_crypto.covertool.xml

typecheck:
$(REBAR) dialyzer
$(REBAR) do dialyzer, xref

doc:
$(REBAR) edoc
61 changes: 61 additions & 0 deletions eqc/multisig_eqc.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
-module(multisig_eqc).

-include_lib("eqc/include/eqc.hrl").

-export([prop_multipubkey_test/0]).

-define(NETWORK, mainnet).

prop_multipubkey_test() ->
?FORALL(
{KeyType, {M, N}, Msg, HashType},
{gen_keytype(), gen_m_n(), gen_msg(), gen_hashtype()},
begin
KeySig = fun() ->
#{secret := SK, public := PK} = libp2p_crypto:generate_keys(KeyType),
{PK, (libp2p_crypto:mk_sig_fun(SK))(Msg)}
end,
IKeySigs = [{I, KeySig()} || I <- lists:seq(0, N - 1)],

ISigs = lists:sublist([{I, S} || {I, {_, S}} <- IKeySigs], M),

Keys0 = [K || {_, {K, _}} <- IKeySigs],

{ok, MultiPubKey} = libp2p_crypto:make_multisig_pubkey(?NETWORK, M, N, Keys0, HashType),
{ok, MultiSig} = libp2p_crypto:make_multisig_signature(?NETWORK, Msg, MultiPubKey, Keys0, ISigs),

?WHENFAIL(
begin
io:format("M ~p~n", [M]),
io:format("N ~p~n", [N]),
io:format("Msg ~p~n", [Msg]),
io:format("MultiPubKey ~p~n", [MultiPubKey]),
io:format("MultiSig ~p~n", [MultiSig])
end,
conjunction([
{valid_pubkey, libp2p_crypto:pubkey_is_multisig(MultiPubKey)},
{valid_multipubkey_roundtrip,
(MultiPubKey ==
libp2p_crypto:bin_to_pubkey(libp2p_crypto:pubkey_to_bin(MultiPubKey)))},
{valid_multi_sig, libp2p_crypto:verify(Msg, MultiSig, MultiPubKey)}
])
)
end
).

gen_keytype() ->
elements([ecc_compact, ed25519]).

gen_m_n() ->
?SUCHTHAT({M, N}, {int(), int()}, (N > M andalso N =< 255 andalso M >= 1)).

gen_msg() ->
binary(32).

%% NOTE: Use this generator if we ever support other hashtypes
gen_hashtype() ->
elements([
sha2_256,
sha3_256,
blake2b256
]).
7 changes: 6 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
]}.

{deps, [
{multihash, "2.0.2"},
{ecc_compact, "1.0.5"},
{enacl, "1.1.1"},
{erl_base58, "0.0.1"},
Expand All @@ -24,7 +25,11 @@
warnings_as_errors
]}.

{plugins, [covertool, erlfmt]}.
{plugins, [
covertool,
erlfmt,
{rebar3_eqc, {git, "https://github.com/Vagabond/rebar3-eqc-plugin", {branch, "master"}}}
]}.

{shell, [{apps, [libp2p_crypto]}]}.

Expand Down
2 changes: 2 additions & 0 deletions rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{<<"enacl">>,{pkg,<<"enacl">>,<<"1.1.1">>},0},
{<<"erl_base58">>,{pkg,<<"erl_base58">>,<<"0.0.1">>},0},
{<<"multiaddr">>,{pkg,<<"multiaddr">>,<<"1.1.3">>},0},
{<<"multihash">>,{pkg,<<"multihash">>,<<"2.0.2">>},0},
{<<"small_ints">>,{pkg,<<"small_ints">>,<<"0.1.0">>},1}]}.
[
{pkg_hash,[
Expand All @@ -12,5 +13,6 @@
{<<"enacl">>, <<"F65DC64D9BFF2D8A534CB77AEF14DA5E7A2FA148987D87856F79A4745C9C2627">>},
{<<"erl_base58">>, <<"37710854461D71DF338E73C65776302DB41C4BAB4674D2EC134ED7BCFC7B5552">>},
{<<"multiaddr">>, <<"978E58E28F6FACAF428C87AF933612B1E2F3F2775F1794EDA5E831A4EACD2984">>},
{<<"multihash">>, <<"DC1C06D226E4D90719A622ABEEC5F038D04425BE27D8048FA51C09DA3076A08B">>},
{<<"small_ints">>, <<"82A824C8794A2DDC73CB5CD00EAD11331DB296521AD16A619C13D668572B868A">>}]}
].
1 change: 1 addition & 0 deletions src/libp2p_crypto.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
enacl,
ecc_compact,
multiaddr,
multihash,
erl_base58
]},
{env,[]},
Expand Down
Loading