Compare commits
1 Commits
master
...
uw-migrate
Author | SHA1 | Date | |
---|---|---|---|
![]() |
720f5600d4 |
4
Makefile
4
Makefile
@ -12,10 +12,10 @@ dialyzer:
|
|||||||
$(REBAR) dialyzer
|
$(REBAR) dialyzer
|
||||||
|
|
||||||
ct: all
|
ct: all
|
||||||
$(REBAR) ct --suite=test/gmcuckoo_SUITE
|
$(REBAR) ct --suite=test/aecuckoo_SUITE
|
||||||
|
|
||||||
eunit:
|
eunit:
|
||||||
$(REBAR) eunit --module=gmminer_pow_tests,gmminer_pow_cuckoo_tests
|
$(REBAR) eunit --module=aeminer_pow_tests,aeminer_pow_cuckoo_tests
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(REBAR) clean
|
$(REBAR) clean
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# gmminer
|
# aeminer
|
||||||
|
|
||||||
Erlang library to work with CPU and CUDA cuckoo miners.
|
Erlang library to work with CPU and CUDA cuckoo miners.
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
{deps, [
|
{deps, [
|
||||||
{hut, "1.3.0"},
|
|
||||||
|
|
||||||
%% Cuckoo prebuilt CUDA binaries.
|
%% Cuckoo prebuilt CUDA binaries.
|
||||||
{aecuckooprebuilt,
|
{aecuckooprebuilt,
|
||||||
@ -11,8 +10,8 @@
|
|||||||
{ref, "996ffcd"}}},
|
{ref, "996ffcd"}}},
|
||||||
|
|
||||||
%% This is used just in one place, just to get blake2b_256 hash.
|
%% This is used just in one place, just to get blake2b_256 hash.
|
||||||
{enacl, {git, "https://git.qpq.swiss/QPQ-AG/enacl.git",
|
{enacl, {git, "https://github.com/aeternity/enacl.git",
|
||||||
{ref, "4eb7ec70"}}}
|
{ref, "67fceef"}}}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
{plugins, [{rebar_aecuckooprebuilt_dep, {git, "https://github.com/aeternity/rebar3-cuckoo-prebuilt-plugin.git",
|
{plugins, [{rebar_aecuckooprebuilt_dep, {git, "https://github.com/aeternity/rebar3-cuckoo-prebuilt-plugin.git",
|
||||||
|
13
rebar.lock
13
rebar.lock
@ -9,13 +9,10 @@
|
|||||||
{ref,"90afb699dc9cc41d033a7c8551179d32b3bd569d"}}},
|
{ref,"90afb699dc9cc41d033a7c8551179d32b3bd569d"}}},
|
||||||
0},
|
0},
|
||||||
{<<"enacl">>,
|
{<<"enacl">>,
|
||||||
{git,"https://git.qpq.swiss/QPQ-AG/enacl.git",
|
{git,"https://github.com/aeternity/enacl.git",
|
||||||
{ref,"4eb7ec70084ba7c87b1af8797c4c4e90c84f95a2"}},
|
{ref,"67fceef42c0d055570f2e67b571f8d1f8de2f204"}},
|
||||||
0},
|
0}]}.
|
||||||
{<<"hut">>,{pkg,<<"hut">>,<<"1.3.0">>},0}]}.
|
|
||||||
[
|
[
|
||||||
{pkg_hash,[
|
{pkg_hash,[]},
|
||||||
{<<"hut">>, <<"71F2F054E657C03F959CF1ACC43F436EA87580696528CA2A55C8AFB1B06C85E7">>}]},
|
{pkg_hash_ext,[]}
|
||||||
{pkg_hash_ext,[
|
|
||||||
{<<"hut">>, <<"7E15D28555D8A1F2B5A3A931EC120AF0753E4853A4C66053DB354F35BF9AB563">>}]}
|
|
||||||
].
|
].
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
{application, gmminer,
|
{application, aeminer,
|
||||||
[{description, "Gajumaru miner"},
|
[{description, "Aeternity miner"},
|
||||||
{vsn, "1.0.0"},
|
{vsn, "1.0.0"},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{applications,
|
{applications,
|
||||||
[kernel,
|
[kernel,
|
||||||
stdlib,
|
stdlib,
|
||||||
enacl,
|
enacl,
|
||||||
hut,
|
|
||||||
aecuckoo,
|
aecuckoo,
|
||||||
aecuckooprebuilt
|
aecuckooprebuilt
|
||||||
]},
|
]},
|
@ -1,4 +1,4 @@
|
|||||||
-module(gmminer_blake2b_256).
|
-module(aeminer_blake2b_256).
|
||||||
|
|
||||||
-export([hash/1]).
|
-export([hash/1]).
|
||||||
|
|
@ -4,7 +4,7 @@
|
|||||||
%%% Common functions and behaviour for Proof of Work
|
%%% Common functions and behaviour for Proof of Work
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%=============================================================================
|
%%%=============================================================================
|
||||||
-module(gmminer_pow).
|
-module(aeminer_pow).
|
||||||
|
|
||||||
-export([integer_to_scientific/1,
|
-export([integer_to_scientific/1,
|
||||||
next_nonce/2,
|
next_nonce/2,
|
||||||
@ -22,7 +22,7 @@
|
|||||||
instance/0
|
instance/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-include("gmminer.hrl").
|
-include("aeminer.hrl").
|
||||||
|
|
||||||
-type nonce() :: ?MIN_NONCE..?MAX_NONCE.
|
-type nonce() :: ?MIN_NONCE..?MAX_NONCE.
|
||||||
|
|
||||||
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
-type instance() :: non_neg_integer().
|
-type instance() :: non_neg_integer().
|
||||||
|
|
||||||
-type config() :: gmminer_pow_cuckoo:config().
|
-type config() :: aeminer_pow_cuckoo:config().
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% Target threshold and difficulty
|
%% Target threshold and difficulty
|
||||||
@ -114,7 +114,7 @@ target_to_difficulty(SciTgt) ->
|
|||||||
|
|
||||||
-spec next_nonce(nonce(), config()) -> nonce().
|
-spec next_nonce(nonce(), config()) -> nonce().
|
||||||
next_nonce(Nonce, Cfg) ->
|
next_nonce(Nonce, Cfg) ->
|
||||||
Nonce + gmminer_pow_cuckoo:repeats(Cfg).
|
Nonce + aeminer_pow_cuckoo:repeats(Cfg).
|
||||||
|
|
||||||
-spec pick_nonce() -> nonce().
|
-spec pick_nonce() -> nonce().
|
||||||
pick_nonce() ->
|
pick_nonce() ->
|
||||||
@ -122,7 +122,7 @@ pick_nonce() ->
|
|||||||
|
|
||||||
-spec trim_nonce(nonce(), config()) -> nonce().
|
-spec trim_nonce(nonce(), config()) -> nonce().
|
||||||
trim_nonce(Nonce, Cfg) ->
|
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;
|
true -> Nonce;
|
||||||
false -> 0
|
false -> 0
|
||||||
end.
|
end.
|
@ -1,5 +1,4 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
%%% @copyright (C) 2025, QPQ AG
|
|
||||||
%%% @copyright (C) 2019, Aeternity Anstalt
|
%%% @copyright (C) 2019, Aeternity Anstalt
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% A library providing Cuckoo Cycle PoW generation and verification.
|
%%% A library providing Cuckoo Cycle PoW generation and verification.
|
||||||
@ -14,7 +13,7 @@
|
|||||||
%%%
|
%%%
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(gmminer_pow_cuckoo).
|
-module(aeminer_pow_cuckoo).
|
||||||
|
|
||||||
-export([config/7,
|
-export([config/7,
|
||||||
addressed_instances/1,
|
addressed_instances/1,
|
||||||
@ -27,18 +26,13 @@
|
|||||||
|
|
||||||
-export([hash_data/1,
|
-export([hash_data/1,
|
||||||
generate/5,
|
generate/5,
|
||||||
generate_all/5,
|
|
||||||
generate_from_hash/5,
|
generate_from_hash/5,
|
||||||
generate_from_hash/6,
|
|
||||||
verify/5,
|
verify/5,
|
||||||
verify_proof/4,
|
verify_proof/4,
|
||||||
verify_proof_from_hash/4,
|
verify_proof_from_hash/4,
|
||||||
get_target/2,
|
get_target/2
|
||||||
test_target/3
|
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([ set_edge_bits/2 ]).
|
|
||||||
|
|
||||||
-export_type([hashable/0,
|
-export_type([hashable/0,
|
||||||
hash/0,
|
hash/0,
|
||||||
exec/0,
|
exec/0,
|
||||||
@ -59,20 +53,24 @@
|
|||||||
]).
|
]).
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
-include_lib("hut/include/hut.hrl").
|
-include("aeminer.hrl").
|
||||||
-include("gmminer.hrl").
|
|
||||||
|
|
||||||
-type hashable() :: gmminer_blake2b_256:hashable().
|
-define(logger_meta, #{domain => [gaj, pow_cuckoo]}).
|
||||||
|
-define(debug(Fmt, Args) , logger:debug(Fmt, Args, ?logger_meta)).
|
||||||
|
-define(info(Fmt, Args) , logger:info(Fmt, Args, ?logger_meta)).
|
||||||
|
-define(warning(Fmt, Args), logger:warning(Fmt, Args, ?logger_meta)).
|
||||||
|
|
||||||
-type hash() :: gmminer_blake2b_256:hash().
|
-type hashable() :: aeminer_blake2b_256:hashable().
|
||||||
|
|
||||||
-type nonce() :: gmminer_pow:nonce().
|
-type hash() :: aeminer_blake2b_256:hash().
|
||||||
|
|
||||||
-type int_target() :: gmminer_pow:int_target().
|
-type nonce() :: aeminer_pow:nonce().
|
||||||
|
|
||||||
-type sci_target() :: gmminer_pow:sci_target().
|
-type int_target() :: aeminer_pow:int_target().
|
||||||
|
|
||||||
-type instance() :: gmminer_pow:instance()
|
-type sci_target() :: aeminer_pow:sci_target().
|
||||||
|
|
||||||
|
-type instance() :: aeminer_pow:instance()
|
||||||
| undefined.
|
| undefined.
|
||||||
|
|
||||||
-type exec() :: binary().
|
-type exec() :: binary().
|
||||||
@ -87,11 +85,10 @@
|
|||||||
|
|
||||||
-type edge_bits() :: pos_integer().
|
-type edge_bits() :: pos_integer().
|
||||||
|
|
||||||
-type instances() :: [gmminer_pow:instance()]
|
-type instances() :: [aeminer_pow:instance()]
|
||||||
| undefined.
|
| undefined.
|
||||||
|
|
||||||
-type solution() :: [integer()].
|
-type solution() :: [integer()].
|
||||||
-type solutions() :: [{nonce(), solution()}].
|
|
||||||
|
|
||||||
-type output_parser_fun() :: fun(([string()], state()) ->
|
-type output_parser_fun() :: fun(([string()], state()) ->
|
||||||
{ok, term(), term()} | {error, term()}).
|
{ok, term(), term()} | {error, term()}).
|
||||||
@ -112,8 +109,6 @@
|
|||||||
os_pid :: integer() | undefined,
|
os_pid :: integer() | undefined,
|
||||||
port :: port() | undefined,
|
port :: port() | undefined,
|
||||||
buffer = [] :: string(),
|
buffer = [] :: string(),
|
||||||
solutions = [] :: solutions(),
|
|
||||||
keep_going = false :: boolean(),
|
|
||||||
target :: sci_target() | undefined,
|
target :: sci_target() | undefined,
|
||||||
edge_bits :: edge_bits(),
|
edge_bits :: edge_bits(),
|
||||||
parser :: output_parser_fun()
|
parser :: output_parser_fun()
|
||||||
@ -165,12 +160,7 @@ hex_enc_header(#config{hex_enc_header = HexEncHdr}) ->
|
|||||||
|
|
||||||
-spec hash_data(hashable()) -> hash().
|
-spec hash_data(hashable()) -> hash().
|
||||||
hash_data(Data) ->
|
hash_data(Data) ->
|
||||||
gmminer_blake2b_256:hash(Data).
|
aeminer_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}.
|
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% Proof of Work generation with default settings
|
%% Proof of Work generation with default settings
|
||||||
@ -193,35 +183,20 @@ set_edge_bits(Bits, Config)
|
|||||||
{ok, {nonce(), solution()}} | {error, no_solution} | {error, {runtime, term()}}.
|
{ok, {nonce(), solution()}} | {error, no_solution} | {error, {runtime, term()}}.
|
||||||
generate(Data, Target, Nonce, Config, Instance) when
|
generate(Data, Target, Nonce, Config, Instance) when
|
||||||
Nonce >= 0, Nonce =< ?MAX_NONCE ->
|
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).
|
generate_from_hash(Hash, Target, Nonce, Config, Instance).
|
||||||
|
|
||||||
-spec generate_all(hashable(), sci_target(), nonce(), config(), instance()) ->
|
|
||||||
{ok, solutions()} | {error, no_solution} | {error, {runtime, term()}}.
|
|
||||||
generate_all(Data, Target, Nonce, Config, Instance) when
|
|
||||||
Nonce >= 0, Nonce =< ?MAX_NONCE ->
|
|
||||||
Hash = gmminer_blake2b_256:hash(Data),
|
|
||||||
generate_from_hash(Hash, Target, Nonce, Config, Instance, true).
|
|
||||||
|
|
||||||
-spec generate_from_hash(hash(), sci_target(), nonce(), config(), instance()) ->
|
-spec generate_from_hash(hash(), sci_target(), nonce(), config(), instance()) ->
|
||||||
{ok, {nonce(), solution()}} | {error, no_solution} | {error, {runtime, term()}}.
|
{ok, {nonce(), solution()}} | {error, no_solution} | {error, {runtime, term()}}.
|
||||||
generate_from_hash(Hash, Target, Nonce, Config, Instance) ->
|
generate_from_hash(Hash, Target, Nonce, Config, Instance) ->
|
||||||
generate_from_hash(Hash, Target, Nonce, Config, Instance, false).
|
|
||||||
|
|
||||||
|
|
||||||
-spec generate_from_hash(hash(), sci_target(), nonce(), config(), instance(), boolean()) ->
|
|
||||||
{ok, {nonce(), solution()}} | {ok, solutions()} | {error, no_solution} | {error, {runtime, term()}}.
|
|
||||||
generate_from_hash(Hash, Target, Nonce, Config, Instance, KeepGoing) ->
|
|
||||||
Hash64 = base64:encode_to_string(Hash),
|
Hash64 = base64:encode_to_string(Hash),
|
||||||
?log(debug, "Generating solution for data hash ~p and nonce ~p with target ~p.",
|
?debug("Generating solution for data hash ~p and nonce ~p with target ~p.",
|
||||||
[Hash, Nonce, Target]),
|
[Hash, Nonce, Target]),
|
||||||
case generate_int(Hash64, Nonce, Target, Config, Instance, KeepGoing) of
|
case generate_int(Hash64, Nonce, Target, Config, Instance) of
|
||||||
{ok, Nonce1, Soln} ->
|
{ok, Nonce1, Soln} ->
|
||||||
{ok, {Nonce1, Soln}};
|
{ok, {Nonce1, Soln}};
|
||||||
{ok, _} = Ok ->
|
|
||||||
Ok;
|
|
||||||
{error, no_value} ->
|
{error, no_value} ->
|
||||||
?log(debug, "No cuckoo solution found", []),
|
?debug("No cuckoo solution found", []),
|
||||||
{error, no_solution};
|
{error, no_solution};
|
||||||
{error, Rsn} ->
|
{error, Rsn} ->
|
||||||
%% Exec failed (segfault, not found, etc.): let miner decide
|
%% Exec failed (segfault, not found, etc.): let miner decide
|
||||||
@ -251,7 +226,7 @@ verify(Data, Nonce, Soln, Target, EdgeBits) when
|
|||||||
verify_proof(Data, Nonce, Solution, EdgeBits) ->
|
verify_proof(Data, Nonce, Solution, EdgeBits) ->
|
||||||
%% Cuckoo has an 80 byte header, we have to use that as well
|
%% Cuckoo has an 80 byte header, we have to use that as well
|
||||||
%% packed Hash + Nonce = 56 bytes, add 24 bytes of 0:s
|
%% 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).
|
verify_proof_from_hash(Hash, Nonce, Solution, EdgeBits).
|
||||||
|
|
||||||
-spec verify_proof_from_hash(hash(), nonce(), solution(), edge_bits()) -> boolean().
|
-spec verify_proof_from_hash(hash(), nonce(), solution(), edge_bits()) -> boolean().
|
||||||
@ -264,7 +239,7 @@ verify_proof_from_hash(Hash, Nonce, Solution, EdgeBits) ->
|
|||||||
get_target(Soln, EdgeBits) when is_list(Soln), length(Soln) =:= ?SOLUTION_SIZE ->
|
get_target(Soln, EdgeBits) when is_list(Soln), length(Soln) =:= ?SOLUTION_SIZE ->
|
||||||
NodeSize = get_node_size(EdgeBits),
|
NodeSize = get_node_size(EdgeBits),
|
||||||
Bin = solution_to_binary(lists:sort(Soln), NodeSize * 8, <<>>),
|
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:32/big-unsigned-integer-unit:8>> = Hash,
|
||||||
Val.
|
Val.
|
||||||
|
|
||||||
@ -272,7 +247,7 @@ get_target(Soln, EdgeBits) when is_list(Soln), length(Soln) =:= ?SOLUTION_SIZE -
|
|||||||
|
|
||||||
generate_int(Hash, Nonce, Target,
|
generate_int(Hash, Nonce, Target,
|
||||||
#config{exec = Exec0, extra_args = ExtraArgs0,
|
#config{exec = Exec0, extra_args = ExtraArgs0,
|
||||||
hex_enc_header = HexEncHdr} = Config, Instance, KeepGoing) ->
|
hex_enc_header = HexEncHdr} = Config, Instance) ->
|
||||||
ExtraArgs =
|
ExtraArgs =
|
||||||
case is_miner_instance_addressation_enabled(Config) of
|
case is_miner_instance_addressation_enabled(Config) of
|
||||||
true -> binary_to_list(ExtraArgs0) ++ " -d " ++ integer_to_list(Instance);
|
true -> binary_to_list(ExtraArgs0) ++ " -d " ++ integer_to_list(Instance);
|
||||||
@ -285,13 +260,13 @@ generate_int(Hash, Nonce, Target,
|
|||||||
end,
|
end,
|
||||||
ExecBinDir = exec_bin_dir(Config),
|
ExecBinDir = exec_bin_dir(Config),
|
||||||
Exec = binary_to_list(Exec0),
|
Exec = binary_to_list(Exec0),
|
||||||
generate_int(EncodedHash, Nonce, Target, ExecBinDir, Exec, ExtraArgs, Config, KeepGoing).
|
generate_int(EncodedHash, Nonce, Target, ExecBinDir, Exec, ExtraArgs, Config).
|
||||||
|
|
||||||
generate_int(Hash, Nonce, Target, MinerBinDir, MinerBin, MinerExtraArgs,
|
generate_int(Hash, Nonce, Target, MinerBinDir, MinerBin, MinerExtraArgs,
|
||||||
#config{repeats = Repeats0, edge_bits = EdgeBits}, KeepGoing) ->
|
#config{repeats = Repeats0, edge_bits = EdgeBits}) ->
|
||||||
Repeats = integer_to_list(Repeats0),
|
Repeats = integer_to_list(Repeats0),
|
||||||
Args = ["-h", Hash, "-n", integer_to_list(Nonce), "-r", Repeats | string:tokens(MinerExtraArgs, " ")],
|
Args = ["-h", Hash, "-n", integer_to_list(Nonce), "-r", Repeats | string:tokens(MinerExtraArgs, " ")],
|
||||||
?log(info, "Executing cmd '~s ~s'", [MinerBin, lists:concat(lists:join(" ", Args))]),
|
?info("Executing cmd '~s ~s'", [MinerBin, lists:concat(lists:join(" ", Args))]),
|
||||||
Old = process_flag(trap_exit, true),
|
Old = process_flag(trap_exit, true),
|
||||||
try exec_run(MinerBin, MinerBinDir, Args) of
|
try exec_run(MinerBin, MinerBinDir, Args) of
|
||||||
{ok, Port, OsPid} ->
|
{ok, Port, OsPid} ->
|
||||||
@ -299,7 +274,6 @@ generate_int(Hash, Nonce, Target, MinerBinDir, MinerBin, MinerExtraArgs,
|
|||||||
port = Port,
|
port = Port,
|
||||||
buffer = [],
|
buffer = [],
|
||||||
target = Target,
|
target = Target,
|
||||||
keep_going = KeepGoing,
|
|
||||||
edge_bits = EdgeBits,
|
edge_bits = EdgeBits,
|
||||||
parser = fun parse_generation_result/2});
|
parser = fun parse_generation_result/2});
|
||||||
{error, _Rsn} = Err ->
|
{error, _Rsn} = Err ->
|
||||||
@ -339,7 +313,7 @@ exec_bin_dir(#config{exec_group = ExecGroup}) ->
|
|||||||
-define(POW_SHORT_CYCLE, {error, cycle_too_short}).
|
-define(POW_SHORT_CYCLE, {error, cycle_too_short}).
|
||||||
|
|
||||||
verify_proof_(Header, Solution, EdgeBits) ->
|
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,
|
EdgeMask = (1 bsl EdgeBits) - 1,
|
||||||
try
|
try
|
||||||
@ -370,12 +344,12 @@ verify_proof_(Header, Solution, EdgeBits) ->
|
|||||||
end
|
end
|
||||||
catch
|
catch
|
||||||
throw:{error, Rsn} ->
|
throw:{error, Rsn} ->
|
||||||
?log(info, "Proof verification failed for ~p: ~p", [Solution, Rsn]),
|
?info("Proof verification failed for ~p: ~p", [Solution, Rsn]),
|
||||||
false
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
sipnode(K0, K1, K2, K3, Proof, UOrV, EdgeMask) ->
|
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.
|
(SipHash bsl 1) bor UOrV.
|
||||||
|
|
||||||
check_cycle(Nodes0) ->
|
check_cycle(Nodes0) ->
|
||||||
@ -428,7 +402,7 @@ find_node(X, [N1, N2 | Nodes], Acc) ->
|
|||||||
%% Since this hash is purely internal, we don't use api encoding.
|
%% Since this hash is purely internal, we don't use api encoding.
|
||||||
%% @end
|
%% @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 ->
|
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.
|
%% 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.
|
%% This buffer is hashed into the keys used by the main algorithm.
|
||||||
@ -475,21 +449,7 @@ wait_for_result(#state{os_pid = OsPid, port = Port, buffer = Buffer} = State) ->
|
|||||||
exit(shutdown);
|
exit(shutdown);
|
||||||
{'EXIT', Port, normal} ->
|
{'EXIT', Port, normal} ->
|
||||||
%% Process ended but no value found
|
%% Process ended but no value found
|
||||||
case State#state.solutions of
|
|
||||||
[] ->
|
|
||||||
{error, no_value};
|
{error, no_value};
|
||||||
|
|
||||||
[_|_] = Sols0 ->
|
|
||||||
Sols = lists:reverse(Sols0),
|
|
||||||
case State#state.keep_going of
|
|
||||||
false ->
|
|
||||||
%% For compatibility, pick the one first found
|
|
||||||
[{N, S}|_] = Sols,
|
|
||||||
{ok, N, S};
|
|
||||||
true ->
|
|
||||||
{ok, Sols}
|
|
||||||
end
|
|
||||||
end;
|
|
||||||
_Other ->
|
_Other ->
|
||||||
wait_for_result(State)
|
wait_for_result(State)
|
||||||
end.
|
end.
|
||||||
@ -531,41 +491,28 @@ handle_fragmented_lines(Str, Buffer) ->
|
|||||||
parse_generation_result([], State) ->
|
parse_generation_result([], State) ->
|
||||||
wait_for_result(State);
|
wait_for_result(State);
|
||||||
parse_generation_result(["Solution" ++ NonceValuesStr | Rest],
|
parse_generation_result(["Solution" ++ NonceValuesStr | Rest],
|
||||||
#state{os_pid = OsPid, edge_bits = EdgeBits,
|
#state{os_pid = OsPid, edge_bits = EdgeBits, target = Target} = State) ->
|
||||||
target = Target, keep_going = KeepGoing} = State) ->
|
|
||||||
[NonceStr | SolStrs] = string:tokens(NonceValuesStr, " "),
|
[NonceStr | SolStrs] = string:tokens(NonceValuesStr, " "),
|
||||||
Soln = [list_to_integer(string:trim(V, both, [$\r]), 16) || V <- SolStrs],
|
Soln = [list_to_integer(string:trim(V, both, [$\r]), 16) || V <- SolStrs],
|
||||||
case {length(Soln), test_target(Soln, Target, EdgeBits)} of
|
case {length(Soln), test_target(Soln, Target, EdgeBits)} of
|
||||||
{?SOLUTION_SIZE, true} ->
|
{?SOLUTION_SIZE, true} ->
|
||||||
?log(debug, "Solution found, KeepGoing = ~p", [KeepGoing]),
|
stop_execution(OsPid),
|
||||||
case KeepGoing of
|
|
||||||
true -> ok;
|
|
||||||
false ->
|
|
||||||
stop_execution(OsPid)
|
|
||||||
end,
|
|
||||||
case parse_nonce_str(NonceStr) of
|
case parse_nonce_str(NonceStr) of
|
||||||
{ok, Nonce} ->
|
{ok, Nonce} ->
|
||||||
?log(debug, "Solution found: ~p", [Soln]),
|
?debug("Solution found: ~p", [Soln]),
|
||||||
case KeepGoing of
|
{ok, Nonce, Soln};
|
||||||
true ->
|
|
||||||
Sols = State#state.solutions,
|
|
||||||
State1 = State#state{solutions = [{Nonce, Soln}|Sols]},
|
|
||||||
parse_generation_result(Rest, State1);
|
|
||||||
false ->
|
|
||||||
{ok, Nonce, Soln}
|
|
||||||
end;
|
|
||||||
Err = {error, _} ->
|
Err = {error, _} ->
|
||||||
?log(debug, "Bad nonce: ~p", [Err]),
|
?debug("Bad nonce: ~p", [Err]),
|
||||||
Err
|
Err
|
||||||
end;
|
end;
|
||||||
{N, _} when N /= ?SOLUTION_SIZE ->
|
{N, _} when N /= ?SOLUTION_SIZE ->
|
||||||
?log(debug, "Solution has wrong length (~p) should be ~p", [N, ?SOLUTION_SIZE]),
|
?debug("Solution has wrong length (~p) should be ~p", [N, ?SOLUTION_SIZE]),
|
||||||
%% No nonce in solution, old miner exec?
|
%% No nonce in solution, old miner exec?
|
||||||
stop_execution(OsPid),
|
stop_execution(OsPid),
|
||||||
{error, bad_miner};
|
{error, bad_miner};
|
||||||
{_, false} ->
|
{_, false} ->
|
||||||
%% failed to meet target: go on, we may find another solution
|
%% failed to meet target: go on, we may find another solution
|
||||||
?log(debug, "Failed to meet target (~p)", [Target]),
|
?debug("Failed to meet target (~p)", [Target]),
|
||||||
parse_generation_result(Rest, State)
|
parse_generation_result(Rest, State)
|
||||||
end;
|
end;
|
||||||
parse_generation_result([_Msg | T], State) ->
|
parse_generation_result([_Msg | T], State) ->
|
||||||
@ -583,7 +530,7 @@ parse_nonce_str(S) ->
|
|||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
stop_execution(OsPid) ->
|
stop_execution(OsPid) ->
|
||||||
exec_kill(OsPid),
|
exec_kill(OsPid),
|
||||||
?log(debug, "Mining OS process ~p stopped", [OsPid]),
|
?debug("Mining OS process ~p stopped", [OsPid]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
@ -615,10 +562,10 @@ exec_run(Cmd, Dir, Args) ->
|
|||||||
Port = erlang:open_port(PortName, PortSettings),
|
Port = erlang:open_port(PortName, PortSettings),
|
||||||
case erlang:port_info(Port, os_pid) of
|
case erlang:port_info(Port, os_pid) of
|
||||||
{os_pid, OsPid} ->
|
{os_pid, OsPid} ->
|
||||||
?log(debug, "External mining process started with OS pid ~p", [OsPid]),
|
?debug("External mining process started with OS pid ~p", [OsPid]),
|
||||||
{ok, Port, OsPid};
|
{ok, Port, OsPid};
|
||||||
undefined ->
|
undefined ->
|
||||||
?log(warning, "External mining process finished before ~p could acquire the OS pid", [?MODULE]),
|
?warning("External mining process finished before ~p could acquire the OS pid", [?MODULE]),
|
||||||
{ok, Port, undefined}
|
{ok, Port, undefined}
|
||||||
end
|
end
|
||||||
catch
|
catch
|
||||||
@ -656,8 +603,8 @@ test_target(Soln, Target, EdgeBits) ->
|
|||||||
|
|
||||||
test_target1(Soln, Target, NodeSize) ->
|
test_target1(Soln, Target, NodeSize) ->
|
||||||
Bin = solution_to_binary(lists:sort(Soln), NodeSize * 8),
|
Bin = solution_to_binary(lists:sort(Soln), NodeSize * 8),
|
||||||
Hash = gmminer_blake2b_256:hash(Bin),
|
Hash = aeminer_blake2b_256:hash(Bin),
|
||||||
gmminer_pow:test_target(Hash, Target).
|
aeminer_pow:test_target(Hash, Target).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% Convert solution (a list of 42 numbers) to a binary
|
%% Convert solution (a list of 42 numbers) to a binary
|
@ -5,7 +5,7 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
%%%=============================================================================
|
%%%=============================================================================
|
||||||
|
|
||||||
-module(gmminer_siphash24).
|
-module(aeminer_siphash24).
|
||||||
|
|
||||||
-export([create_keys/1,
|
-export([create_keys/1,
|
||||||
hash/5]).
|
hash/5]).
|
||||||
@ -28,12 +28,12 @@
|
|||||||
%%%=============================================================================
|
%%%=============================================================================
|
||||||
|
|
||||||
-spec create_keys(binary()) ->
|
-spec create_keys(binary()) ->
|
||||||
{gmminer_siphash24:siphash_key(),
|
{aeminer_siphash24:siphash_key(),
|
||||||
gmminer_siphash24:siphash_key(),
|
aeminer_siphash24:siphash_key(),
|
||||||
gmminer_siphash24:siphash_key(),
|
aeminer_siphash24:siphash_key(),
|
||||||
gmminer_siphash24:siphash_key()}.
|
aeminer_siphash24:siphash_key()}.
|
||||||
create_keys(Header) ->
|
create_keys(Header) ->
|
||||||
AuxHash = <<_:32/binary>> = gmminer_blake2b_256:hash(Header),
|
AuxHash = <<_:32/binary>> = aeminer_blake2b_256:hash(Header),
|
||||||
<<K0:64/little-unsigned,
|
<<K0:64/little-unsigned,
|
||||||
K1:64/little-unsigned,
|
K1:64/little-unsigned,
|
||||||
K2:64/little-unsigned,
|
K2:64/little-unsigned,
|
@ -1,10 +1,9 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
%%% @copyright (C) 2025, QPQ AG
|
|
||||||
%%% @copyright (C) 2019, Aeternity Anstalt
|
%%% @copyright (C) 2019, Aeternity Anstalt
|
||||||
%%% @doc Basic sanity checks and examples on Cuckoo cycle PoW executables.
|
%%% @doc Basic sanity checks and examples on Cuckoo cycle PoW executables.
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(gmcuckoo_SUITE).
|
-module(aecuckoo_SUITE).
|
||||||
|
|
||||||
%% common_test exports
|
%% common_test exports
|
||||||
-export(
|
-export(
|
||||||
@ -57,7 +56,7 @@ smoke_test(Config) ->
|
|||||||
HeaderEquivalent = <<0:(44*8), (base64:encode(<<Nonce:64/little-unsigned-integer>>))/binary, 0:(24*8)>>,
|
HeaderEquivalent = <<0:(44*8), (base64:encode(<<Nonce:64/little-unsigned-integer>>))/binary, 0:(24*8)>>,
|
||||||
|
|
||||||
42 = length(Solution),
|
42 = length(Solution),
|
||||||
true = gmminer_pow_cuckoo:verify_proof_(HeaderEquivalent, Solution, 15),
|
true = aeminer_pow_cuckoo:verify_proof_(HeaderEquivalent, Solution, 15),
|
||||||
|
|
||||||
ok.
|
ok.
|
||||||
|
|
@ -1,18 +1,17 @@
|
|||||||
%%%=============================================================================
|
%%%=============================================================================
|
||||||
%%% @copyright (C) 2025, QPQ AG
|
|
||||||
%%% @copyright (C) 2019, Aeternity Anstalt
|
%%% @copyright (C) 2019, Aeternity Anstalt
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% Unit tests for the gmminer_pow_cuckoo module
|
%%% Unit tests for the aeminer_pow_cuckoo module
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%=============================================================================
|
%%%=============================================================================
|
||||||
-module(gmminer_pow_cuckoo_tests).
|
-module(aeminer_pow_cuckoo_tests).
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
-include("gmminer.hrl").
|
-include("aeminer.hrl").
|
||||||
|
|
||||||
-define(TEST_MODULE, gmminer_pow_cuckoo).
|
-define(TEST_MODULE, aeminer_pow_cuckoo).
|
||||||
-define(POW_MODULE, gmminer_pow).
|
-define(POW_MODULE, aeminer_pow).
|
||||||
|
|
||||||
-define(TEST_BIN, <<"wsffgujnjkqhduihsahswgdf">>).
|
-define(TEST_BIN, <<"wsffgujnjkqhduihsahswgdf">>).
|
||||||
-define(TEST_HIGH_NONCE, 38). %% Nonce with solution with high target.
|
-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
|
%%% @copyright (C) 2019, Aeternity Anstalt
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% Unit tests for the gmminer_pow module
|
%%% Unit tests for the aeminer_pow module
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%=============================================================================
|
%%%=============================================================================
|
||||||
-module(gmminer_pow_tests).
|
-module(aeminer_pow_tests).
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
-define(TEST_MODULE, gmminer_pow).
|
-define(TEST_MODULE, aeminer_pow).
|
||||||
|
|
||||||
-include("gmminer.hrl").
|
-include("aeminer.hrl").
|
||||||
|
|
||||||
conversion_test_() ->
|
conversion_test_() ->
|
||||||
{setup,
|
{setup,
|
||||||
@ -48,7 +47,7 @@ conversion_test_() ->
|
|||||||
?assertEqual(255, ?TEST_MODULE:scientific_to_integer(16#0200ff00)),
|
?assertEqual(255, ?TEST_MODULE:scientific_to_integer(16#0200ff00)),
|
||||||
?assertEqual(16#800000, ?TEST_MODULE:scientific_to_integer(16#04008000)),
|
?assertEqual(16#800000, ?TEST_MODULE:scientific_to_integer(16#04008000)),
|
||||||
?assertEqual(?HIGHEST_TARGET_INT,
|
?assertEqual(?HIGHEST_TARGET_INT,
|
||||||
gmminer_pow:scientific_to_integer(?HIGHEST_TARGET_SCI))
|
aeminer_pow:scientific_to_integer(?HIGHEST_TARGET_SCI))
|
||||||
end},
|
end},
|
||||||
{"Integer to scientific and back",
|
{"Integer to scientific and back",
|
||||||
fun() ->
|
fun() ->
|
Loading…
x
Reference in New Issue
Block a user