diff --git a/src/aeb_fate_code.erl b/src/aeb_fate_code.erl index e0b1747..1c6b5a3 100644 --- a/src/aeb_fate_code.erl +++ b/src/aeb_fate_code.erl @@ -302,6 +302,9 @@ deserialize_functions(<>, Program#{ BB => lists:reverse(Code)}}}}, deserialize_functions(Rest2, Env2) end; +deserialize_functions(<>, + #{ function := none }) -> + error({code_without_function}); deserialize_functions(<>, #{ bb := BB , current_bb_code := Code @@ -343,6 +346,7 @@ deserialize_op(Op, Rest, Code) -> deserialize_n_args(N, <>) when N =< 4 -> ArgMods = lists:sublist([M0, M1, M2, M3], N), + %% If N == 1 then we take M0 and don't care about the others. Should we check that the others are 0?? lists:mapfoldl(fun(M, Acc) -> case bits_to_modifier(M) of stack -> diff --git a/src/aeb_fate_encoding.erl b/src/aeb_fate_encoding.erl index 59f7bbc..582839e 100644 --- a/src/aeb_fate_encoding.erl +++ b/src/aeb_fate_encoding.erl @@ -269,12 +269,18 @@ deserialize_types(N, Binary, Acc) -> rlp_encode_int(S) when S >= 0 -> aeser_rlp:encode(binary:encode_unsigned(S)). + +%% first byte of the binary gives the number of bytes we need <<129>> is 1, <<130>> = 2, +%% so <<129, 0>> is <<0>> and <<130, 0, 0>> is <<0, 0>> rlp_decode_int(Binary) -> - case aeser_rlp:decode_one(Binary) of - {<<>>, _} -> - error({illegal_integer_encoding, Binary}); - {Bin1, Rest} -> - {binary:decode_unsigned(Bin1), Rest} + {Bin1, Rest} = aeser_rlp:decode_one(Binary), + Int = binary:decode_unsigned(Bin1), + ReEncode = rlp_encode_int(Int), + case <> == Binary of + true -> + {Int, Rest}; + false -> + error({none_unique_encoding, Bin1, ReEncode}) end. serialize_integer(I) when ?IS_FATE_INTEGER(I) ->