From 803ebc085464ad909b1e08ddb797dd8b4857c314 Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Mon, 17 Jun 2019 13:57:01 +0200 Subject: [PATCH 1/5] Three new opcodes had been added --- quickcheck/aefate_code_eqc.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickcheck/aefate_code_eqc.erl b/quickcheck/aefate_code_eqc.erl index c9b03a7..29f7821 100644 --- a/quickcheck/aefate_code_eqc.erl +++ b/quickcheck/aefate_code_eqc.erl @@ -71,7 +71,7 @@ prop_opcodes() -> valid_opcodes() -> - lists:seq(0, 16#72) ++ lists:seq(16#fa, 16#fd). + lists:seq(0, 16#75) ++ lists:seq(16#fa, 16#fd). fate_code(Failure) -> From e3f843fd9186767306d05c8deadbee62f2fb4c33 Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Mon, 17 Jun 2019 13:57:41 +0200 Subject: [PATCH 2/5] Do not return types, create_calldata does not need those --- src/aeb_aevm_abi.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aeb_aevm_abi.erl b/src/aeb_aevm_abi.erl index 15bbd6c..1d62f36 100644 --- a/src/aeb_aevm_abi.erl +++ b/src/aeb_aevm_abi.erl @@ -43,7 +43,7 @@ create_calldata(FunName, Args, ArgTypes0, RetType) -> <> = function_type_hash(list_to_binary(FunName), ArgTypes, RetType), Data = aeb_heap:to_binary({TypeHashInt, list_to_tuple(Args)}), - {ok, Data, {tuple, [word, ArgTypes]}, RetType}. + {ok, Data}. -spec check_calldata(binary(), type_info()) -> {'ok', typerep(), typerep()} | {'error', atom()}. From 9840b225462ab2ad00c22a8ee71f2373fa389944 Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Tue, 18 Jun 2019 12:22:46 +0200 Subject: [PATCH 3/5] Add decoding function --- src/aeb_fate_abi.erl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/aeb_fate_abi.erl b/src/aeb_fate_abi.erl index 99f6af8..55fb5fc 100644 --- a/src/aeb_fate_abi.erl +++ b/src/aeb_fate_abi.erl @@ -10,6 +10,7 @@ -module(aeb_fate_abi). -export([ create_calldata/2 + , decode_calldata/2 , get_function_hash_from_calldata/1 , get_function_name_from_function_hash/2 , get_function_type_from_function_hash/2 ]). @@ -27,6 +28,14 @@ create_calldata(FunName, Args) -> aeb_fate_data:make_tuple({FunctionId, aeb_fate_data:make_tuple(list_to_tuple(Args))}))}. +-spec decode_calldata(list(), binary()) -> {ok, term()} | {error, term()}. +decode_calldata(FunName, Calldata) -> + FunctionId = aeb_fate_code:symbol_identifier(list_to_binary(FunName)), + case ?FATE_TUPLE_ELEMENTS(aeb_fate_encoding:deserialize(Calldata)) of + [FunctionId, FateArgs] -> {ok, ?FATE_TUPLE_ELEMENTS(FateArgs)}; + _ -> {error, decode_error} + end. + -spec get_function_name_from_function_hash(binary(), aeb_fate_code:fcode()) -> {ok, term()} | {error, term()}. get_function_name_from_function_hash(<>, FateCode) -> From cb83224c606737cb3ec3fdb190cc97bbb30e5286 Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Tue, 18 Jun 2019 14:29:01 +0200 Subject: [PATCH 4/5] Add query to generate QuickCheck data --- quickcheck/aefate_eqc.erl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/quickcheck/aefate_eqc.erl b/quickcheck/aefate_eqc.erl index 49df042..3cf183d 100644 --- a/quickcheck/aefate_eqc.erl +++ b/quickcheck/aefate_eqc.erl @@ -112,6 +112,7 @@ fate_data(0, _Options) -> fate_signature(), fate_contract(), fate_oracle(), + fate_oracle_q(), fate_name(), fate_bits(), fate_channel()])); @@ -142,6 +143,7 @@ fate_hash() -> {call, aeb_fate_data, make_hash, [non_zero_binary(32)]}. fate_signature() -> {call, aeb_fate_data, make_signature, [non_zero_binary(64)]}. fate_contract() -> {call, aeb_fate_data, make_contract, [non_zero_binary(256 div 8)]}. fate_oracle() -> {call, aeb_fate_data, make_oracle, [non_zero_binary(256 div 8)]}. +fate_oracle_q() -> {call, aeb_fate_data, make_oracle_query, [non_zero_binary(256 div 8)]}. fate_name() -> {call, aeb_fate_data, make_name, [non_zero_binary(256 div 8)]}. fate_channel() -> {call, aeb_fate_data, make_channel, [non_zero_binary(256 div 8)]}. From 1fda6912da4ba0c156b7fecb454927c30ba161f6 Mon Sep 17 00:00:00 2001 From: Thomas Arts Date: Wed, 19 Jun 2019 17:41:22 +0200 Subject: [PATCH 5/5] Fix error --- src/aeb_fate_encoding.erl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aeb_fate_encoding.erl b/src/aeb_fate_encoding.erl index 5e48113..48cceb3 100644 --- a/src/aeb_fate_encoding.erl +++ b/src/aeb_fate_encoding.erl @@ -373,6 +373,7 @@ deserialize2(<>) -> {?FATE_BITS(Bint), Rest2}; deserialize2(<>) -> {S, Rest2} = deserialize_one(Rest), + true = is_integer(S) andalso S >= 0, Size = S + ?SHORT_STRING_SIZE, String = binary:part(Rest2, 0, Size), Rest3 = binary:part(Rest2, byte_size(Rest2), - (byte_size(Rest2) - Size)),