3 Commits

Author SHA1 Message Date
Ulf Wiger d2ccf9429d remove debug printouts 2019-11-01 14:02:01 +01:00
Ulf Wiger a7b1a70e42 Filter rebar.lock if disabling cuckoo 2019-10-31 15:26:25 +01:00
Ulf Wiger 495fcb30d6 WIP: AE_DISABLE_CUCKOO env var support
revert rebar.lock to original
2019-10-31 13:03:52 +01:00
18 changed files with 121 additions and 70 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ version: 2.1
executors:
aebuilder:
docker:
- image: aeternity/builder:bionic-otp23
- image: aeternity/builder
user: builder
working_directory: ~/src
+2 -2
View File
@@ -12,10 +12,10 @@ dialyzer:
$(REBAR) dialyzer
ct: all
$(REBAR) ct --suite=test/gmcuckoo_SUITE
$(REBAR) ct --suite=test/aecuckoo_SUITE
eunit:
$(REBAR) eunit --module=gmminer_pow_tests,gmminer_pow_cuckoo_tests
$(REBAR) eunit --module=aeminer_pow_tests,aeminer_pow_cuckoo_tests
clean:
$(REBAR) clean
+1 -1
View File
@@ -1,4 +1,4 @@
# gmminer
# aeminer
Erlang library to work with CPU and CUDA cuckoo miners.
+3 -3
View File
@@ -8,11 +8,11 @@
%% Cuckoo CPU miners (not prebuilt).
{aecuckoo, {git, "https://github.com/aeternity/aecuckoo.git",
{ref, "996ffcd"}}},
{ref, "a1bff574dd0a965d3f9f2e23f980bbead8b4638d"}}},
%% This is used just in one place, just to get blake2b_256 hash.
{enacl, {git, "https://gitlab.com/ioecs/enacl.git",
{ref, "4eb7ec70"}}}
{enacl, {git, "https://github.com/aeternity/enacl.git",
{ref, "26180f4"}}}
]}.
{plugins, [{rebar_aecuckooprebuilt_dep, {git, "https://github.com/aeternity/rebar3-cuckoo-prebuilt-plugin.git",
+16
View File
@@ -0,0 +1,16 @@
%% -*- mode:erlang; erlang-indent-level:4; indent-tabs-mode:nil -*-
case os:getenv("AE_DISABLE_CUCKOO") =/= false of
true ->
RemoveApps = [aecuckoo, aecuckooprebuilt],
RemovePlugins = [rebar_aecuckooprebuilt_dep],
{_, Deps} = lists:keyfind(deps, 1, CONFIG),
NewDeps = [D || D <- Deps,
not lists:member(element(1,D), RemoveApps)],
Plugins = proplists:get_value(plugins, CONFIG, []),
CONFIG1 = lists:keyreplace(deps, 1, CONFIG, {deps, NewDeps}),
Plugins1 = [P || P <- Plugins,
not lists:member(element(1,P), RemovePlugins)],
lists:keystore(plugins, 1, CONFIG1, {plugins, Plugins1});
false ->
CONFIG
end.
+5 -7
View File
@@ -1,7 +1,7 @@
{"1.2.0",
{"1.1.0",
[{<<"aecuckoo">>,
{git,"https://github.com/aeternity/aecuckoo.git",
{ref,"996ffcdb336f1c2254ea8e1b1a657b05b7ea4a81"}},
{ref,"a1bff574dd0a965d3f9f2e23f980bbead8b4638d"}},
0},
{<<"aecuckooprebuilt">>,
{aecuckooprebuilt_app_with_priv_from_git,
@@ -9,13 +9,11 @@
{ref,"90afb699dc9cc41d033a7c8551179d32b3bd569d"}}},
0},
{<<"enacl">>,
{git,"https://gitlab.com/ioecs/enacl.git",
{ref,"4eb7ec70084ba7c87b1af8797c4c4e90c84f95a2"}},
{git,"https://github.com/aeternity/enacl.git",
{ref,"26180f42c0b3a450905d2efd8bc7fd5fd9cece75"}},
0},
{<<"hut">>,{pkg,<<"hut">>,<<"1.3.0">>},0}]}.
[
{pkg_hash,[
{<<"hut">>, <<"71F2F054E657C03F959CF1ACC43F436EA87580696528CA2A55C8AFB1B06C85E7">>}]},
{pkg_hash_ext,[
{<<"hut">>, <<"7E15D28555D8A1F2B5A3A931EC120AF0753E4853A4C66053DB354F35BF9AB563">>}]}
{<<"hut">>, <<"71F2F054E657C03F959CF1ACC43F436EA87580696528CA2A55C8AFB1B06C85E7">>}]}
].
+29
View File
@@ -0,0 +1,29 @@
%% -*- erlang -*-
FilterCheck = (os:getenv("AE_DISABLE_CUCKOO") =/= false),
RemoveApps = [<<"aecuckoo">>, <<"aecuckooprebuilt">>],
Filter = fun(Apps) ->
case FilterCheck of
false ->
Apps;
true ->
lists:foldl(
fun(App, Acc) ->
lists:keydelete(App, 1, Acc)
end,
Apps,
RemoveApps
)
end
end,
case CONFIG of
[] ->
%% no lock file present, usually during unlock/upgrade
CONFIG;
[{Version, Deps}, [{pkg_hash, Pkgs}]] ->
Deps1 = Filter(Deps),
Pkgs1 = Filter(Pkgs),
[{Version, Deps1}, [{pkg_hash, Pkgs1}]]
end.
BIN
View File
Binary file not shown.
+2 -2
View File
@@ -1,5 +1,5 @@
{application, gmminer,
[{description, "Gajumaru miner"},
{application, aeminer,
[{description, "Aeternity miner"},
{vsn, "1.0.0"},
{registered, []},
{applications,
+18
View File
@@ -0,0 +1,18 @@
%% -*- mode:erlang; erlang-indent-level:4; indent-tabs-mode:nil -*-
RemoveApps = [aecuckoo, aecuckooprebuilt].
Base = filename:basename(SCRIPT, ".script").
Dir = filename:dirname(SCRIPT).
{ok, [{application,_,Opts} = App]} = file:consult(filename:join(Dir, Base)).
case os:getenv("AE_DISABLE_CUCKOO") =/= false of
true ->
{_, Apps} = lists:keyfind(applications, 1, Opts),
Env = proplists:get_value(env, Opts, []),
Env1 = lists:keystore(use_cuckoo, 1, Env, {use_cuckoo, false}),
Apps1 = Apps -- RemoveApps,
Opts1 = lists:keyreplace(applications, 1, Opts, {applications, Apps1}),
Opts2 = lists:keystore(env, 1, Opts1, {env, Env1}),
setelement(3, App, Opts2);
false ->
App
end.
@@ -1,4 +1,4 @@
-module(gmminer_blake2b_256).
-module(aeminer_blake2b_256).
-export([hash/1]).
@@ -14,5 +14,6 @@
-spec hash(hashable()) -> hash().
hash(Bin) ->
enacl:generichash(?HASH_BYTES_SIZE, Bin).
{ok, Hash} = enacl:generichash(?HASH_BYTES_SIZE, Bin),
Hash.
+5 -5
View File
@@ -4,7 +4,7 @@
%%% Common functions and behaviour for Proof of Work
%%% @end
%%%=============================================================================
-module(gmminer_pow).
-module(aeminer_pow).
-export([integer_to_scientific/1,
next_nonce/2,
@@ -22,7 +22,7 @@
instance/0
]).
-include("gmminer.hrl").
-include("aeminer.hrl").
-type nonce() :: ?MIN_NONCE..?MAX_NONCE.
@@ -38,7 +38,7 @@
-type instance() :: non_neg_integer().
-type config() :: gmminer_pow_cuckoo:config().
-type config() :: aeminer_pow_cuckoo:config().
%%------------------------------------------------------------------------------
%% Target threshold and difficulty
@@ -114,7 +114,7 @@ target_to_difficulty(SciTgt) ->
-spec next_nonce(nonce(), config()) -> nonce().
next_nonce(Nonce, Cfg) ->
Nonce + gmminer_pow_cuckoo:repeats(Cfg).
Nonce + aeminer_pow_cuckoo:repeats(Cfg).
-spec pick_nonce() -> nonce().
pick_nonce() ->
@@ -122,7 +122,7 @@ pick_nonce() ->
-spec trim_nonce(nonce(), config()) -> nonce().
trim_nonce(Nonce, Cfg) ->
case Nonce + gmminer_pow_cuckoo:repeats(Cfg) < ?MAX_NONCE of
case Nonce + aeminer_pow_cuckoo:repeats(Cfg) < ?MAX_NONCE of
true -> Nonce;
false -> 0
end.
@@ -1,5 +1,4 @@
%%%-------------------------------------------------------------------
%%% @copyright (C) 2025, QPQ AG
%%% @copyright (C) 2019, Aeternity Anstalt
%%% @doc
%%% A library providing Cuckoo Cycle PoW generation and verification.
@@ -14,7 +13,7 @@
%%%
%%% @end
%%%-------------------------------------------------------------------
-module(gmminer_pow_cuckoo).
-module(aeminer_pow_cuckoo).
-export([config/7,
addressed_instances/1,
@@ -34,8 +33,6 @@
get_target/2
]).
-export([ set_edge_bits/2 ]).
-export_type([hashable/0,
hash/0,
exec/0,
@@ -57,19 +54,19 @@
-endif.
-include_lib("hut/include/hut.hrl").
-include("gmminer.hrl").
-include("aeminer.hrl").
-type hashable() :: gmminer_blake2b_256:hashable().
-type hashable() :: aeminer_blake2b_256:hashable().
-type hash() :: gmminer_blake2b_256:hash().
-type hash() :: aeminer_blake2b_256:hash().
-type nonce() :: gmminer_pow:nonce().
-type nonce() :: aeminer_pow:nonce().
-type int_target() :: gmminer_pow:int_target().
-type int_target() :: aeminer_pow:int_target().
-type sci_target() :: gmminer_pow:sci_target().
-type sci_target() :: aeminer_pow:sci_target().
-type instance() :: gmminer_pow:instance()
-type instance() :: aeminer_pow:instance()
| undefined.
-type exec() :: binary().
@@ -84,7 +81,7 @@
-type edge_bits() :: pos_integer().
-type instances() :: [gmminer_pow:instance()]
-type instances() :: [aeminer_pow:instance()]
| undefined.
-type solution() :: [integer()].
@@ -159,12 +156,7 @@ hex_enc_header(#config{hex_enc_header = HexEncHdr}) ->
-spec hash_data(hashable()) -> hash().
hash_data(Data) ->
gmminer_blake2b_256:hash(Data).
-spec set_edge_bits(edge_bits(), config()) -> config().
set_edge_bits(Bits, Config)
when is_integer(Bits), Bits > 0, is_record(Config, config) ->
Config#config{edge_bits = Bits}.
aeminer_blake2b_256:hash(Data).
%%------------------------------------------------------------------------------
%% Proof of Work generation with default settings
@@ -187,7 +179,7 @@ set_edge_bits(Bits, Config)
{ok, {nonce(), solution()}} | {error, no_solution} | {error, {runtime, term()}}.
generate(Data, Target, Nonce, Config, Instance) when
Nonce >= 0, Nonce =< ?MAX_NONCE ->
Hash = gmminer_blake2b_256:hash(Data),
Hash = aeminer_blake2b_256:hash(Data),
generate_from_hash(Hash, Target, Nonce, Config, Instance).
-spec generate_from_hash(hash(), sci_target(), nonce(), config(), instance()) ->
@@ -230,7 +222,7 @@ verify(Data, Nonce, Soln, Target, EdgeBits) when
verify_proof(Data, Nonce, Solution, EdgeBits) ->
%% Cuckoo has an 80 byte header, we have to use that as well
%% packed Hash + Nonce = 56 bytes, add 24 bytes of 0:s
Hash = gmminer_blake2b_256:hash(Data),
Hash = aeminer_blake2b_256:hash(Data),
verify_proof_from_hash(Hash, Nonce, Solution, EdgeBits).
-spec verify_proof_from_hash(hash(), nonce(), solution(), edge_bits()) -> boolean().
@@ -243,7 +235,7 @@ verify_proof_from_hash(Hash, Nonce, Solution, EdgeBits) ->
get_target(Soln, EdgeBits) when is_list(Soln), length(Soln) =:= ?SOLUTION_SIZE ->
NodeSize = get_node_size(EdgeBits),
Bin = solution_to_binary(lists:sort(Soln), NodeSize * 8, <<>>),
Hash = gmminer_blake2b_256:hash(Bin),
Hash = aeminer_blake2b_256:hash(Bin),
<<Val:32/big-unsigned-integer-unit:8>> = Hash,
Val.
@@ -317,7 +309,7 @@ exec_bin_dir(#config{exec_group = ExecGroup}) ->
-define(POW_SHORT_CYCLE, {error, cycle_too_short}).
verify_proof_(Header, Solution, EdgeBits) ->
{K0, K1, K2, K3} = gmminer_siphash24:create_keys(Header),
{K0, K1, K2, K3} = aeminer_siphash24:create_keys(Header),
EdgeMask = (1 bsl EdgeBits) - 1,
try
@@ -353,7 +345,7 @@ verify_proof_(Header, Solution, EdgeBits) ->
end.
sipnode(K0, K1, K2, K3, Proof, UOrV, EdgeMask) ->
SipHash = gmminer_siphash24:hash(K0, K1, K2, K3, 2*Proof + UOrV) band EdgeMask,
SipHash = aeminer_siphash24:hash(K0, K1, K2, K3, 2*Proof + UOrV) band EdgeMask,
(SipHash bsl 1) bor UOrV.
check_cycle(Nodes0) ->
@@ -406,7 +398,7 @@ find_node(X, [N1, N2 | Nodes], Acc) ->
%% Since this hash is purely internal, we don't use api encoding.
%% @end
%%------------------------------------------------------------------------------
-spec pack_header_and_nonce(binary(), gmminer_pow:nonce()) -> string().
-spec pack_header_and_nonce(binary(), aeminer_pow:nonce()) -> string().
pack_header_and_nonce(Hash, Nonce) when byte_size(Hash) == 32 ->
%% Cuckoo originally uses 32-bit nonces inserted at the end of its 80-byte buffer.
%% This buffer is hashed into the keys used by the main algorithm.
@@ -607,8 +599,8 @@ test_target(Soln, Target, EdgeBits) ->
test_target1(Soln, Target, NodeSize) ->
Bin = solution_to_binary(lists:sort(Soln), NodeSize * 8),
Hash = gmminer_blake2b_256:hash(Bin),
gmminer_pow:test_target(Hash, Target).
Hash = aeminer_blake2b_256:hash(Bin),
aeminer_pow:test_target(Hash, Target).
%%------------------------------------------------------------------------------
%% Convert solution (a list of 42 numbers) to a binary
@@ -5,7 +5,7 @@
%%% @end
%%%=============================================================================
-module(gmminer_siphash24).
-module(aeminer_siphash24).
-export([create_keys/1,
hash/5]).
@@ -28,12 +28,12 @@
%%%=============================================================================
-spec create_keys(binary()) ->
{gmminer_siphash24:siphash_key(),
gmminer_siphash24:siphash_key(),
gmminer_siphash24:siphash_key(),
gmminer_siphash24:siphash_key()}.
{aeminer_siphash24:siphash_key(),
aeminer_siphash24:siphash_key(),
aeminer_siphash24:siphash_key(),
aeminer_siphash24:siphash_key()}.
create_keys(Header) ->
AuxHash = <<_:32/binary>> = gmminer_blake2b_256:hash(Header),
AuxHash = <<_:32/binary>> = aeminer_blake2b_256:hash(Header),
<<K0:64/little-unsigned,
K1:64/little-unsigned,
K2:64/little-unsigned,
@@ -1,10 +1,9 @@
%%%-------------------------------------------------------------------
%%% @copyright (C) 2025, QPQ AG
%%% @copyright (C) 2019, Aeternity Anstalt
%%% @doc Basic sanity checks and examples on Cuckoo cycle PoW executables.
%%% @end
%%%-------------------------------------------------------------------
-module(gmcuckoo_SUITE).
-module(aecuckoo_SUITE).
%% common_test exports
-export(
@@ -57,7 +56,7 @@ smoke_test(Config) ->
HeaderEquivalent = <<0:(44*8), (base64:encode(<<Nonce:64/little-unsigned-integer>>))/binary, 0:(24*8)>>,
42 = length(Solution),
true = gmminer_pow_cuckoo:verify_proof_(HeaderEquivalent, Solution, 15),
true = aeminer_pow_cuckoo:verify_proof_(HeaderEquivalent, Solution, 15),
ok.
@@ -1,18 +1,17 @@
%%%=============================================================================
%%% @copyright (C) 2025, QPQ AG
%%% @copyright (C) 2019, Aeternity Anstalt
%%% @doc
%%% Unit tests for the gmminer_pow_cuckoo module
%%% Unit tests for the aeminer_pow_cuckoo module
%%% @end
%%%=============================================================================
-module(gmminer_pow_cuckoo_tests).
-module(aeminer_pow_cuckoo_tests).
-include_lib("eunit/include/eunit.hrl").
-include("gmminer.hrl").
-include("aeminer.hrl").
-define(TEST_MODULE, gmminer_pow_cuckoo).
-define(POW_MODULE, gmminer_pow).
-define(TEST_MODULE, aeminer_pow_cuckoo).
-define(POW_MODULE, aeminer_pow).
-define(TEST_BIN, <<"wsffgujnjkqhduihsahswgdf">>).
-define(TEST_HIGH_NONCE, 38). %% Nonce with solution with high target.
@@ -1,17 +1,16 @@
%%%=============================================================================
%%% @copyright (C) 2025, QPQ AG
%%% @copyright (C) 2019, Aeternity Anstalt
%%% @doc
%%% Unit tests for the gmminer_pow module
%%% Unit tests for the aeminer_pow module
%%% @end
%%%=============================================================================
-module(gmminer_pow_tests).
-module(aeminer_pow_tests).
-include_lib("eunit/include/eunit.hrl").
-define(TEST_MODULE, gmminer_pow).
-define(TEST_MODULE, aeminer_pow).
-include("gmminer.hrl").
-include("aeminer.hrl").
conversion_test_() ->
{setup,
@@ -48,7 +47,7 @@ conversion_test_() ->
?assertEqual(255, ?TEST_MODULE:scientific_to_integer(16#0200ff00)),
?assertEqual(16#800000, ?TEST_MODULE:scientific_to_integer(16#04008000)),
?assertEqual(?HIGHEST_TARGET_INT,
gmminer_pow:scientific_to_integer(?HIGHEST_TARGET_SCI))
aeminer_pow:scientific_to_integer(?HIGHEST_TARGET_SCI))
end},
{"Integer to scientific and back",
fun() ->