From 336a474cba5464f880ec41165c802a1bfb29df4a Mon Sep 17 00:00:00 2001 From: Erik Stenman Date: Mon, 25 Feb 2019 16:01:35 +0100 Subject: [PATCH 1/8] Removed unused lib. --- rebar.lock | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/rebar.lock b/rebar.lock index 3c625aa..4e9f21a 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,9 +1,6 @@ {"1.1.0", -[{<<"enacl">>, - {git,"https://github.com/aeternity/enacl.git", - {ref,"26180f42c0b3a450905d2efd8bc7fd5fd9cece75"}}, - 0}, - {<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},0}]}. +[ + {<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},0}]}. [ {pkg_hash,[ {<<"getopt">>, <<"C73A9FA687B217F2FF79F68A3B637711BB1936E712B521D8CE466B29CBF7808A">>}]} -- 2.30.2 From 71bf754600cc57232641e82fa72dea5632cddedd Mon Sep 17 00:00:00 2001 From: Erik Stenman Date: Mon, 25 Feb 2019 16:13:20 +0100 Subject: [PATCH 2/8] Replace local blake2 implementation with eblake2. --- rebar.lock | 7 +- src/aeb_blake2.erl | 148 ------------------------------------------- src/aeb_fate_asm.erl | 2 +- 3 files changed, 6 insertions(+), 151 deletions(-) delete mode 100644 src/aeb_blake2.erl diff --git a/rebar.lock b/rebar.lock index 4e9f21a..3c079cd 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,6 +1,9 @@ {"1.1.0", -[ - {<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},0}]}. +[{<<"eblake2">>, + {git,"https://github.com/aeternity/eblake2.git", + {ref,"ac1fed46f90a7bada781ee78fa30a1b5239ea613"}}, + 0}, + {<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},0}]}. [ {pkg_hash,[ {<<"getopt">>, <<"C73A9FA687B217F2FF79F68A3B637711BB1936E712B521D8CE466B29CBF7808A">>}]} diff --git a/src/aeb_blake2.erl b/src/aeb_blake2.erl deleted file mode 100644 index 37fda39..0000000 --- a/src/aeb_blake2.erl +++ /dev/null @@ -1,148 +0,0 @@ -%%%============================================================================= -%%% @copyright (C) 2019, Aeternity Anstalt -%%% @doc -%%% BLAKE2b implementation in Erlang - for details see: https://blake2.net -%%% @end -%%%============================================================================= - --module(aeb_blake2). - --export([ blake2b/2 - , blake2b/3 - ]). - --define(MAX_64BIT, 16#ffffffffffffffff). - --spec blake2b(HashLen :: integer(), Msg :: binary()) -> {ok, binary()}. -blake2b(HashLen, Msg) -> - blake2b(HashLen, Msg, <<>>). - --spec blake2b(HashLen :: integer(), Msg :: binary(), Key :: binary()) -> {ok, binary()}. -blake2b(HashLen, Msg0, Key) -> - %% If message should be keyed, prepend message with padded key. - Msg = <<(pad(128, Key))/binary, Msg0/binary>>, - - %% Set up the initial state - Init = (16#01010000 + (byte_size(Key) bsl 8) + HashLen), - <> = blake_iv(), - H = <<(H0 bxor Init):64, H1_7/binary>>, - - %% Perform the compression - message will be chopped into 128-byte chunks. - State = blake2b_compress(H, Msg, 0), - - %% Just return the requested part of the hash - {ok, binary_part(to_little_endian(State), {0, HashLen})}. - -blake2b_compress(H, <>, BCompr) when Rest /= <<>> -> - H1 = blake2b_compress(H, <>, BCompr + 128, false), - blake2b_compress(H1, Rest, BCompr + 128); -blake2b_compress(H, SmallChunk, BCompr) -> - Size = byte_size(SmallChunk), - FillSize = (128 - Size) * 8, - blake2b_compress(H, <>, BCompr + Size, true). - -blake2b_compress(H, Chunk0, BCompr, Last) -> - Chunk = to_big_endian(Chunk0), - <> = <>, - V12_ = V12 bxor (BCompr band ?MAX_64BIT), - V13_ = V13 bxor ((BCompr bsr 64) band ?MAX_64BIT), - V14_ = case Last of - false -> V14; - true -> V14 bxor ?MAX_64BIT - end, - V = <>, - - <> = - lists:foldl(fun(Round, Vx) -> blake2b_mix(Round, Chunk, Vx) end, V, lists:seq(0, 11)), - - <> = H, - <<((HInt bxor VLow) bxor VHigh):(8*64)>>. - -blake2b_mix(Rnd, Chunk, V) -> - <> = V, - <> = Chunk, - Ms = {M0, M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13, M14, M15}, - M = fun(Ix) -> element(Ix+1, Ms) end, - - [S0, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, S13, S14, S15] = sigma(Rnd rem 10), - - {Vx0, Vx4, Vx8, Vx12} = blake2b_mix(V0, V4, V8, V12, M(S0), M(S1)), - {Vx1, Vx5, Vx9, Vx13} = blake2b_mix(V1, V5, V9, V13, M(S2), M(S3)), - {Vx2, Vx6, Vx10, Vx14} = blake2b_mix(V2, V6, V10, V14, M(S4), M(S5)), - {Vx3, Vx7, Vx11, Vx15} = blake2b_mix(V3, V7, V11, V15, M(S6), M(S7)), - - {Vy0, Vy5, Vy10, Vy15} = blake2b_mix(Vx0, Vx5, Vx10, Vx15, M(S8), M(S9)), - {Vy1, Vy6, Vy11, Vy12} = blake2b_mix(Vx1, Vx6, Vx11, Vx12, M(S10), M(S11)), - {Vy2, Vy7, Vy8, Vy13} = blake2b_mix(Vx2, Vx7, Vx8, Vx13, M(S12), M(S13)), - {Vy3, Vy4, Vy9, Vy14} = blake2b_mix(Vx3, Vx4, Vx9, Vx14, M(S14), M(S15)), - - <>. - -blake2b_mix(Va, Vb, Vc, Vd, X, Y) -> - Va1 = (Va + Vb + X) band ?MAX_64BIT, - Vd1 = rotr64(32, Vd bxor Va1), - - Vc1 = (Vc + Vd1) band ?MAX_64BIT, - Vb1 = rotr64(24, Vb bxor Vc1), - - Va2 = (Va1 + Vb1 + Y) band ?MAX_64BIT, - Vd2 = rotr64(16, Va2 bxor Vd1), - - Vc2 = (Vc1 + Vd2) band ?MAX_64BIT, - Vb2 = rotr64(63, Vb1 bxor Vc2), - - {Va2, Vb2, Vc2, Vd2}. - -blake_iv() -> - IV0 = 16#6A09E667F3BCC908, - IV1 = 16#BB67AE8584CAA73B, - IV2 = 16#3C6EF372FE94F82B, - IV3 = 16#A54FF53A5F1D36F1, - IV4 = 16#510E527FADE682D1, - IV5 = 16#9B05688C2B3E6C1F, - IV6 = 16#1F83D9ABFB41BD6B, - IV7 = 16#5BE0CD19137E2179, - <>. - -sigma(N) -> - {_, Row} = lists:keyfind(N, 1, sigma()), Row. - -sigma() -> - [{0, [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]}, - {1, [14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3]}, - {2, [11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4]}, - {3, [ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8]}, - {4, [ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13]}, - {5, [ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9]}, - {6, [12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11]}, - {7, [13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10]}, - {8, [ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5]}, - {9, [10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0]}]. - -rotr64(N, I64) -> - <> = rotr641(N, <>), - I64rot. - -rotr641(16, <>) -> <>; -rotr641(24, <>) -> <>; -rotr641(32, <>) -> <>; -rotr641(63, <>) -> <>. - -pad(N, Bin) -> - case (N - (byte_size(Bin) rem N)) rem N of - 0 -> Bin; - Pad -> <> - end. - -to_big_endian(Bin) -> to_big_endian(Bin, <<>>). -to_big_endian(<<>>, Acc) -> Acc; -to_big_endian(<>, Acc) -> - to_big_endian(Rest, <>). - -to_little_endian(Bin) -> to_little_endian(Bin, <<>>). -to_little_endian(<<>>, Acc) -> Acc; -to_little_endian(<>, Acc) -> - to_little_endian(Rest, <>). diff --git a/src/aeb_fate_asm.erl b/src/aeb_fate_asm.erl index 75228b8..b3ea0ea 100644 --- a/src/aeb_fate_asm.erl +++ b/src/aeb_fate_asm.erl @@ -844,7 +844,7 @@ insert_fun({Name, Type, RetType}, Code, #{functions := Functions} = Env) -> mk_hash(Id) -> %% Use first 4 bytes of blake hash - {ok, <> } = aeb_blake2:blake2b(?HASH_BYTES, list_to_binary(Id)), + {ok, <> } = eblake2:blake2b(?HASH_BYTES, list_to_binary(Id)), <>. %% Handle annotations -- 2.30.2 From e890860221f21b9e41c570879479f14176400460 Mon Sep 17 00:00:00 2001 From: Erik Stenman Date: Mon, 25 Feb 2019 16:20:23 +0100 Subject: [PATCH 3/8] Add eblake2 dep to app file. --- src/aebytecode.app.src | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aebytecode.app.src b/src/aebytecode.app.src index e8c0021..3dec1c7 100644 --- a/src/aebytecode.app.src +++ b/src/aebytecode.app.src @@ -5,6 +5,7 @@ {applications, [kernel, stdlib, + eblake2, getopt ]}, {env,[]}, -- 2.30.2 From 25c91d7c8284796e00adb3eb8854244bc287d761 Mon Sep 17 00:00:00 2001 From: Erik Stenman Date: Mon, 25 Feb 2019 16:32:52 +0100 Subject: [PATCH 4/8] Add eblake2 to rebar config. --- rebar.config | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rebar.config b/rebar.config index 2b23e8e..4e3c4df 100644 --- a/rebar.config +++ b/rebar.config @@ -2,10 +2,13 @@ {erl_opts, [debug_info]}. -{deps, [ {getopt, "1.0.1"} +{deps, [ + {eblake2, {git, "https://github.com/aeternity/eblake2.git", + {tag,"v1.0.0"}}}, + {getopt, "1.0.1"} ]}. -{escript_incl_apps, [aebytecode, getopt]}. +{escript_incl_apps, [aebytecode, eblake2, getopt]}. {escript_main_app, aebytecode}. {escript_name, aefateasm}. {escript_emu_args, "%%!"}. @@ -20,7 +23,7 @@ {relx, [{release, {aessembler, "0.0.1"}, - [aebytecode, getopt]}, + [aebytecode, eblake2, getopt]}, {dev_mode, true}, {include_erts, false}, -- 2.30.2 From 36d7ec29ca62cfe5a6881e9dd9990d37861a5a6f Mon Sep 17 00:00:00 2001 From: Erik Stenman Date: Tue, 26 Feb 2019 07:47:52 +0100 Subject: [PATCH 5/8] Use hex for eblake2. --- rebar.config | 11 +++++------ rebar.lock | 6 ++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/rebar.config b/rebar.config index 4e3c4df..01fb0d7 100644 --- a/rebar.config +++ b/rebar.config @@ -2,10 +2,8 @@ {erl_opts, [debug_info]}. -{deps, [ - {eblake2, {git, "https://github.com/aeternity/eblake2.git", - {tag,"v1.0.0"}}}, - {getopt, "1.0.1"} +{deps, [ {eblake2, "1.0.0"} + , {getopt, "1.0.1"} ]}. {escript_incl_apps, [aebytecode, eblake2, getopt]}. @@ -22,7 +20,7 @@ ]}. -{relx, [{release, {aessembler, "0.0.1"}, +{relx, [{release, {aebytecode, "2.0.0"}, [aebytecode, eblake2, getopt]}, {dev_mode, true}, @@ -31,7 +29,8 @@ {extended_start_script, true}]}. {profiles, [{binary, [ - {deps, [ {getopt, "1.0.1"} + {deps, [ {eblake2, "1.0.0"} + , {getopt, "1.0.1"} ]}, {post_hooks, [{"(linux|darwin|solaris|freebsd|netbsd|openbsd)", diff --git a/rebar.lock b/rebar.lock index 3c079cd..ca74f91 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,10 +1,8 @@ {"1.1.0", -[{<<"eblake2">>, - {git,"https://github.com/aeternity/eblake2.git", - {ref,"ac1fed46f90a7bada781ee78fa30a1b5239ea613"}}, - 0}, +[{<<"eblake2">>,{pkg,<<"eblake2">>,<<"1.0.0">>},0}, {<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},0}]}. [ {pkg_hash,[ + {<<"eblake2">>, <<"EC8AD20E438AAB3F2E8D5D118C366A0754219195F8A0F536587440F8F9BCF2EF">>}, {<<"getopt">>, <<"C73A9FA687B217F2FF79F68A3B637711BB1936E712B521D8CE466B29CBF7808A">>}]} ]. -- 2.30.2 From c4410a25488bd49be1d1e5d3300a1f3c7b6aec56 Mon Sep 17 00:00:00 2001 From: Erik Stenman Date: Tue, 26 Feb 2019 07:53:22 +0100 Subject: [PATCH 6/8] Bump version. --- rebar.config | 2 +- src/aebytecode.app.src | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rebar.config b/rebar.config index 01fb0d7..f27d50a 100644 --- a/rebar.config +++ b/rebar.config @@ -20,7 +20,7 @@ ]}. -{relx, [{release, {aebytecode, "2.0.0"}, +{relx, [{release, {aebytecode, "2.0.1"}, [aebytecode, eblake2, getopt]}, {dev_mode, true}, diff --git a/src/aebytecode.app.src b/src/aebytecode.app.src index 3dec1c7..cbd443f 100644 --- a/src/aebytecode.app.src +++ b/src/aebytecode.app.src @@ -1,6 +1,6 @@ {application, aebytecode, [{description, "Bytecode definitions, serialization and deserialization for aeternity."}, - {vsn, "2.0.0"}, + {vsn, "2.0.1"}, {registered, []}, {applications, [kernel, -- 2.30.2 From d60eb5eab5bcb7948498add78b8a61ca0aeabcfd Mon Sep 17 00:00:00 2001 From: Erik Stenman Date: Tue, 26 Feb 2019 08:05:34 +0100 Subject: [PATCH 7/8] Replace local rlp with aeserialization repo. Use ref till first release is available. --- rebar.config | 6 ++- rebar.lock | 10 ++++- src/aeb_fate_asm.erl | 18 ++++---- src/aeb_fate_encoding.erl | 24 +++++------ src/aeb_rlp.erl | 91 --------------------------------------- src/aebytecode.app.src | 1 + 6 files changed, 36 insertions(+), 114 deletions(-) delete mode 100644 src/aeb_rlp.erl diff --git a/rebar.config b/rebar.config index f27d50a..08234fd 100644 --- a/rebar.config +++ b/rebar.config @@ -3,10 +3,12 @@ {erl_opts, [debug_info]}. {deps, [ {eblake2, "1.0.0"} + , {aeserialization, {git, "https://github.com/aeternity/aeserialization.git", + {ref, "b55c372"}}} , {getopt, "1.0.1"} ]}. -{escript_incl_apps, [aebytecode, eblake2, getopt]}. +{escript_incl_apps, [aebytecode, eblake2, aeserialization, getopt]}. {escript_main_app, aebytecode}. {escript_name, aefateasm}. {escript_emu_args, "%%!"}. @@ -30,6 +32,8 @@ {profiles, [{binary, [ {deps, [ {eblake2, "1.0.0"} + , {aeserialization, {git, "https://github.com/aeternity/aeserialization.git", + {ref, "b55c372"}}} , {getopt, "1.0.1"} ]}, diff --git a/rebar.lock b/rebar.lock index ca74f91..ee15e69 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,5 +1,13 @@ {"1.1.0", -[{<<"eblake2">>,{pkg,<<"eblake2">>,<<"1.0.0">>},0}, +[{<<"aeserialization">>, + {git,"https://github.com/aeternity/aeserialization.git", + {ref,"b55c3726f4a21063721c68d6fa7fda39121edf11"}}, + 0}, + {<<"base58">>, + {git,"https://github.com/aeternity/erl-base58.git", + {ref,"60a335668a60328a29f9731b67c4a0e9e3d50ab6"}}, + 1}, + {<<"eblake2">>,{pkg,<<"eblake2">>,<<"1.0.0">>},0}, {<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},0}]}. [ {pkg_hash,[ diff --git a/src/aeb_fate_asm.erl b/src/aeb_fate_asm.erl index b3ea0ea..1ea0bcb 100644 --- a/src/aeb_fate_asm.erl +++ b/src/aeb_fate_asm.erl @@ -350,10 +350,10 @@ asm_to_bytecode(AssemblerCode, Options) -> Signatures = serialize_sigs(Env), SymbolTable = serialize_symbol_table(Env), Annotatations = serialize_annotations(Env), - ByteCode = << (aeb_rlp:encode(list_to_binary(ByteList)))/binary, - (aeb_rlp:encode(list_to_binary(Signatures)))/binary, - (aeb_rlp:encode(SymbolTable))/binary, - (aeb_rlp:encode(Annotatations))/binary + ByteCode = << (aeser_rlp:encode(list_to_binary(ByteList)))/binary, + (aeser_rlp:encode(list_to_binary(Signatures)))/binary, + (aeser_rlp:encode(SymbolTable))/binary, + (aeser_rlp:encode(Annotatations))/binary >>, case proplists:lookup(pp_hex_string, Options) of @@ -366,14 +366,14 @@ asm_to_bytecode(AssemblerCode, Options) -> {Env, ByteCode}. strip(ByteCode) -> - {Code, _Rest} = aeb_rlp:decode_one(ByteCode), + {Code, _Rest} = aeser_rlp:decode_one(ByteCode), Code. bytecode_to_fate_code(Bytes, _Options) -> - {ByteCode, Rest1} = aeb_rlp:decode_one(Bytes), - {Signatures, Rest2} = aeb_rlp:decode_one(Rest1), - {SymbolTable, Rest3} = aeb_rlp:decode_one(Rest2), - {Annotations, <<>>} = aeb_rlp:decode_one(Rest3), + {ByteCode, Rest1} = aeser_rlp:decode_one(Bytes), + {Signatures, Rest2} = aeser_rlp:decode_one(Rest1), + {SymbolTable, Rest3} = aeser_rlp:decode_one(Rest2), + {Annotations, <<>>} = aeser_rlp:decode_one(Rest3), Env1 = deserialize(ByteCode, #{ function => none , bb => 0 diff --git a/src/aeb_fate_encoding.erl b/src/aeb_fate_encoding.erl index 4a5daa2..1fcbd9e 100644 --- a/src/aeb_fate_encoding.erl +++ b/src/aeb_fate_encoding.erl @@ -104,9 +104,9 @@ serialize(String) when ?IS_FATE_STRING(String), ?FATE_STRING_SIZE(String) > 0, ?FATE_STRING_SIZE(String) >= ?SHORT_STRING_SIZE -> Bytes = ?FATE_STRING_VALUE(String), - <>; + <>; serialize(?FATE_ADDRESS(Address)) when is_binary(Address) -> - <>; + <>; serialize(?FATE_TUPLE(T)) when size(T) > 0 -> S = size(T), L = tuple_to_list(T), @@ -148,7 +148,7 @@ serialize(?FATE_VARIANT(Size, Tag, Values)) when 0 =< Size %% ----------------------------------------------------- rlp_integer(S) when S >= 0 -> - aeb_rlp:encode(binary:encode_unsigned(S)). + aeser_rlp:encode(binary:encode_unsigned(S)). serialize_integer(I) when ?IS_FATE_INTEGER(I) -> V = ?FATE_INTEGER_VALUE(I), @@ -187,28 +187,28 @@ deserialize2(<>) -> deserialize2(<>) -> {?MAKE_FATE_INTEGER(-I), Rest}; deserialize2(<>) -> - {Bint, Rest2} = aeb_rlp:decode_one(Rest), + {Bint, Rest2} = aeser_rlp:decode_one(Rest), {?MAKE_FATE_INTEGER(-binary:decode_unsigned(Bint) - ?SMALL_INT_SIZE), Rest2}; deserialize2(<>) -> - {Bint, Rest2} = aeb_rlp:decode_one(Rest), + {Bint, Rest2} = aeser_rlp:decode_one(Rest), {?MAKE_FATE_INTEGER(binary:decode_unsigned(Bint) + ?SMALL_INT_SIZE), Rest2}; deserialize2(<>) -> - {Bint, Rest2} = aeb_rlp:decode_one(Rest), + {Bint, Rest2} = aeser_rlp:decode_one(Rest), {?FATE_BITS(-binary:decode_unsigned(Bint)), Rest2}; deserialize2(<>) -> - {Bint, Rest2} = aeb_rlp:decode_one(Rest), + {Bint, Rest2} = aeser_rlp:decode_one(Rest), {?FATE_BITS(binary:decode_unsigned(Bint)), Rest2}; deserialize2(<>) -> - {String, Rest2} = aeb_rlp:decode_one(Rest), + {String, Rest2} = aeser_rlp:decode_one(Rest), {?MAKE_FATE_STRING(String), Rest2}; deserialize2(<>) -> String = binary:part(Rest, 0, S), Rest2 = binary:part(Rest, byte_size(Rest), - (byte_size(Rest) - S)), {?MAKE_FATE_STRING(String), Rest2}; deserialize2(<>) -> - {A, Rest2} = aeb_rlp:decode_one(Rest), + {A, Rest2} = aeser_rlp:decode_one(Rest), {?FATE_ADDRESS(A), Rest2}; deserialize2(<>) -> {?FATE_TRUE, Rest}; @@ -223,7 +223,7 @@ deserialize2(<>) -> deserialize2(<>) -> {?FATE_EMPTY_STRING, Rest}; deserialize2(<>) -> - {BSize, Rest1} = aeb_rlp:decode_one(Rest), + {BSize, Rest1} = aeser_rlp:decode_one(Rest), N = binary:decode_unsigned(BSize) + ?SHORT_TUPLE_SIZE, {List, Rest2} = deserialize_elements(N, Rest1), {?FATE_TUPLE(list_to_tuple(List)), Rest2}; @@ -231,7 +231,7 @@ deserialize2(<>) -> {List, Rest1} = deserialize_elements(S, Rest), {?FATE_TUPLE(list_to_tuple(List)), Rest1}; deserialize2(<>) -> - {BLength, Rest1} = aeb_rlp:decode_one(Rest), + {BLength, Rest1} = aeser_rlp:decode_one(Rest), Length = binary:decode_unsigned(BLength) + ?SHORT_LIST_SIZE, {List, Rest2} = deserialize_elements(Length, Rest1), {?MAKE_FATE_LIST(List), Rest2}; @@ -239,7 +239,7 @@ deserialize2(<>) -> {List, Rest1} = deserialize_elements(S, Rest), {?MAKE_FATE_LIST(List), Rest1}; deserialize2(<>) -> - {BSize, Rest1} = aeb_rlp:decode_one(Rest), + {BSize, Rest1} = aeser_rlp:decode_one(Rest), Size = binary:decode_unsigned(BSize), {List, Rest2} = deserialize_elements(2*Size, Rest1), Map = insert_kv(List, #{}), diff --git a/src/aeb_rlp.erl b/src/aeb_rlp.erl deleted file mode 100644 index 46a27fa..0000000 --- a/src/aeb_rlp.erl +++ /dev/null @@ -1,91 +0,0 @@ -%%%------------------------------------------------------------------- -%%% @copyright (C) 2017, Aeternity Anstalt -%%% @doc -%%% Implementation of the Recursive Length Prefix. -%%% -%%% https://github.com/ethereum/wiki/wiki/RLP -%%% -%%% @end -%%%------------------------------------------------------------------- - --module(aeb_rlp). --export([ decode/1 - , decode_one/1 - , encode/1 - ]). - --export_type([ encodable/0 - , encoded/0 - ]). - --type encodable() :: [encodable()] | binary(). --type encoded() :: <<_:8, _:_*8>>. - --define(UNTAGGED_SIZE_LIMIT , 55). --define(UNTAGGED_LIMIT , 127). --define(BYTE_ARRAY_OFFSET , 128). --define(LIST_OFFSET , 192). - - --spec encode(encodable()) -> encoded(). -encode(X) -> - encode(X, []). - -encode(<> = X,_Opts) when B =< ?UNTAGGED_LIMIT -> - %% An untagged value - X; -encode(X,_Opts) when is_binary(X) -> - %% Byte array - add_size(?BYTE_ARRAY_OFFSET, X); -encode(L, Opts) when is_list(L) -> - %% Lists items are encoded and concatenated - ByteArray = << << (encode(X, Opts))/binary >> || X <- L >>, - add_size(?LIST_OFFSET, ByteArray). - -add_size(Offset, X) when byte_size(X) =< ?UNTAGGED_SIZE_LIMIT -> - %% The size fits in one tagged byte - <<(Offset + byte_size(X)), X/binary>>; -add_size(Offset, X) when is_binary(X) -> - %% The size itself needs to be encoded as a byte array - %% Add the tagged size of the size byte array - SizeBin = binary:encode_unsigned(byte_size(X)), - TaggedSize = ?UNTAGGED_SIZE_LIMIT + Offset + byte_size(SizeBin), - true = (TaggedSize < 256 ), %% Assert - <>. - --spec decode(encoded()) -> encodable(). -decode(Bin) when is_binary(Bin), byte_size(Bin) > 0 -> - case decode_one(Bin) of - {X, <<>>} -> X; - {X, Left} -> error({trailing, X, Bin, Left}) - end. - -decode_one(<>) when X =< ?UNTAGGED_LIMIT -> - %% Untagged value - {<>, B}; -decode_one(<> = B) when L < ?LIST_OFFSET -> - %% Byte array - {Size, Rest} = decode_size(B, ?BYTE_ARRAY_OFFSET), - <> = Rest, - {X, Tail}; -decode_one(<<_/binary>> = B) -> - %% List - {Size, Rest} = decode_size(B, ?LIST_OFFSET), - <> = Rest, - {decode_list(X), Tail}. - -decode_size(<>, Offset) when L =< Offset + ?UNTAGGED_SIZE_LIMIT-> - %% One byte tagged size. - {L - Offset, B}; -decode_size(<<_, 0, _/binary>>,_Offset) -> - error(leading_zeroes_in_size); -decode_size(<>, Offset) -> - %% Actual size is in a byte array. - BinSize = L - Offset - ?UNTAGGED_SIZE_LIMIT, - <> = B, - {Size, Rest}. - -decode_list(<<>>) -> []; -decode_list(B) -> - {Element, Rest} = decode_one(B), - [Element|decode_list(Rest)]. diff --git a/src/aebytecode.app.src b/src/aebytecode.app.src index cbd443f..7116b7e 100644 --- a/src/aebytecode.app.src +++ b/src/aebytecode.app.src @@ -6,6 +6,7 @@ [kernel, stdlib, eblake2, + aeserialization, getopt ]}, {env,[]}, -- 2.30.2 From 9f3860fe3371471caa517595272e0f46d1f7921f Mon Sep 17 00:00:00 2001 From: Erik Stenman Date: Tue, 26 Feb 2019 08:11:04 +0100 Subject: [PATCH 8/8] Remove unused vars. --- test/aeb_fate_asm_test.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/aeb_fate_asm_test.erl b/test/aeb_fate_asm_test.erl index e177c6c..dd32af6 100644 --- a/test/aeb_fate_asm_test.erl +++ b/test/aeb_fate_asm_test.erl @@ -54,12 +54,12 @@ sources() -> check_roundtrip(File) -> AssemblerCode = read_file(File), - {Env, ByteCode} = assemble(AssemblerCode), + {_Env, ByteCode} = assemble(AssemblerCode), FateCode = disassemble(ByteCode), DissasmCode = aeb_fate_asm:to_asm(FateCode), io:format("~s~n", [AssemblerCode]), io:format("~s~n", [DissasmCode]), - {Env2, ByteCode2} = assemble(DissasmCode), + {_Env2, ByteCode2} = assemble(DissasmCode), Code1 = aeb_fate_asm:strip(ByteCode), Code2 = aeb_fate_asm:strip(ByteCode2), ?assertEqual(Code1, Code2). -- 2.30.2