diff --git a/rebar.config b/rebar.config index 4e1a926..aba57e9 100644 --- a/rebar.config +++ b/rebar.config @@ -4,6 +4,7 @@ {deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref,"c63ac88"}}} , {getopt, "1.0.1"} + , {eblake2, "1.0.0"} , {jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "2.8.0"}}} ]}. diff --git a/src/aeso_ast_to_fcode.erl b/src/aeso_ast_to_fcode.erl index c20e569..16b0309 100644 --- a/src/aeso_ast_to_fcode.erl +++ b/src/aeso_ast_to_fcode.erl @@ -137,6 +137,7 @@ vars => [var_name()], functions := #{ fun_name() => fun_def() } }. +-define(HASH_BYTES, 32). %% -- Entrypoint ------------------------------------------------------------- %% Main entrypoint. Takes typed syntax produced by aeso_ast_infer_types:infer/1,2 @@ -829,8 +830,8 @@ event_function(_Env = #{event_type := {variant_t, EventCons}}, EventType = {vari || {I, {constr_t, Ann, {con, _, Name}, _}} <- indexed(EventCons) ], Arities = [length(Ts) || Ts <- FCons], Case = fun({Name, Tag, Ixs}) -> - %% TODO: precompute (needs dependency) - Hash = {op, crypto_sha3, [{lit, {string, list_to_binary(Name)}}]}, + {ok, HashValue} = eblake2:blake2b(?HASH_BYTES, list_to_binary(Name)), + Hash = {lit, {bytes, HashValue}}, Vars = [ "arg" ++ integer_to_list(I) || I <- lists:seq(1, length(Ixs)) ], IVars = lists:zip(Ixs, Vars), Payload = diff --git a/src/aeso_builtins.erl b/src/aeso_builtins.erl index daf638f..93c1c57 100644 --- a/src/aeso_builtins.erl +++ b/src/aeso_builtins.erl @@ -62,6 +62,8 @@ v(X) when is_list(X) -> #var_ref{name = X}. option_none() -> {tuple, [{integer, 0}]}. option_some(X) -> {tuple, [{integer, 1}, X]}. +-define(HASH_BYTES, 32). + -define(call(Fun, Args), #funcall{ function = #var_ref{ name = {builtin, Fun} }, args = Args }). -define(I(X), {integer, X}). -define(V(X), v(X)). @@ -93,12 +95,6 @@ operand(A) when is_atom(A) -> v(A); operand(I) when is_integer(I) -> {integer, I}; operand(T) -> T. -str_to_icode(String) when is_list(String) -> - str_to_icode(list_to_binary(String)); -str_to_icode(BinStr) -> - Cpts = [size(BinStr) | aeb_memory:binary_to_words(BinStr)], - #tuple{ cpts = [ #integer{value = X} || X <- Cpts ] }. - check_event_type(Icode) -> case maps:get(event_type, Icode) of {variant_t, Cons} -> @@ -192,7 +188,8 @@ builtin_event(EventT) -> Types = [ T || {_Ix, T} <- IxTypes ], Indexed = [ Ix(Type, Var) || {Var, {indexed, Type}} <- lists:zip(ArgPats(Types), IxTypes) ], Data = [ {Type, Var} || {Var, {notindexed, Type}} <- lists:zip(ArgPats(Types), IxTypes) ], - EvtIndex = {unop, 'sha3', str_to_icode(Con)}, + {ok, <>} = eblake2:blake2b(?HASH_BYTES, list_to_binary(Con)), + EvtIndex = {integer, EvtIndexN}, {event, lists:reverse(Indexed) ++ [EvtIndex], Payload(Data)} end, Pat = fun(Tag, Types) -> {tuple, [{integer, Tag} | ArgPats(Types)]} end, diff --git a/src/aesophia.app.src b/src/aesophia.app.src index 1547ee4..6b16408 100644 --- a/src/aesophia.app.src +++ b/src/aesophia.app.src @@ -8,7 +8,8 @@ jsx, syntax_tools, getopt, - aebytecode + aebytecode, + eblake2 ]}, {env,[]}, {modules, []},