From c0bc71b0b740574d0ebf3a78bbd38765cea2e5c5 Mon Sep 17 00:00:00 2001 From: John Newby Date: Fri, 9 Aug 2019 16:32:00 +0200 Subject: [PATCH 1/6] Added opcode for ecrecover --- include/aeb_opcodes.hrl | 1 + 1 file changed, 1 insertion(+) diff --git a/include/aeb_opcodes.hrl b/include/aeb_opcodes.hrl index 7f8fe75..372bfcd 100644 --- a/include/aeb_opcodes.hrl +++ b/include/aeb_opcodes.hrl @@ -193,6 +193,7 @@ -define(PRIM_CALL_CRYPTO_SHA256_STRING, 404). -define(PRIM_CALL_CRYPTO_BLAKE2B_STRING, 405). -define(PRIM_CALL_CRYPTO_ECVERIFY_SECP256K1, 410). +-define(PRIM_CALL_CRYPTO_ECRECOVER, 420). -define(PRIM_CALL_IN_AUTH_RANGE(__TTYPE__), (((__TTYPE__) > 499) andalso ((__TTYPE__) < 600))). -define(PRIM_CALL_AUTH_TX_HASH, 500). -- 2.30.2 From 7c6a80fef7abac5303bd514a1031fcb9b1dafa8c Mon Sep 17 00:00:00 2001 From: johnsnewby <45353567+johnsnewby@users.noreply.github.com> Date: Mon, 12 Aug 2019 10:52:47 +0200 Subject: [PATCH 2/6] Update include/aeb_opcodes.hrl Co-Authored-By: Hans Svensson --- include/aeb_opcodes.hrl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/aeb_opcodes.hrl b/include/aeb_opcodes.hrl index 372bfcd..1543f0c 100644 --- a/include/aeb_opcodes.hrl +++ b/include/aeb_opcodes.hrl @@ -193,7 +193,7 @@ -define(PRIM_CALL_CRYPTO_SHA256_STRING, 404). -define(PRIM_CALL_CRYPTO_BLAKE2B_STRING, 405). -define(PRIM_CALL_CRYPTO_ECVERIFY_SECP256K1, 410). --define(PRIM_CALL_CRYPTO_ECRECOVER, 420). +-define(PRIM_CALL_CRYPTO_ECRECOVER_SECP256K1, 420). -define(PRIM_CALL_IN_AUTH_RANGE(__TTYPE__), (((__TTYPE__) > 499) andalso ((__TTYPE__) < 600))). -define(PRIM_CALL_AUTH_TX_HASH, 500). -- 2.30.2 From 8fde1e5e2489d7e13bc17d106f36e975cf8daac2 Mon Sep 17 00:00:00 2001 From: John Newby Date: Mon, 12 Aug 2019 13:36:49 +0200 Subject: [PATCH 3/6] Added FATE opcode for ecrecover --- src/aeb_fate_generate_ops.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aeb_fate_generate_ops.erl b/src/aeb_fate_generate_ops.erl index 55396d4..fb48e4e 100644 --- a/src/aeb_fate_generate_ops.erl +++ b/src/aeb_fate_generate_ops.erl @@ -163,6 +163,7 @@ ops_defs() -> , { 'ECVERIFY', 16#72, false, true, true, 1300, [a,a,a,a], ecverify, {bytes, address, bytes}, boolean, "Arg0 := ecverify(Hash, PubKey, Signature)"} , { 'ECVERIFY_SECP256K1', 16#73, false, true, true, 1300, [a,a,a,a], ecverify_secp256k1, {bytes, bytes, bytes}, boolean, "Arg0 := ecverify_secp256k1(Hash, PubKey, Signature)"} + , { 'ECRECOVER_SECP256K1', 16#7d, false, true, true, 1300, [a,a,a,a], ecrecover_secp256k1, {bytes, bytes, bytes}, bytes, "Arg0 := ecrecover_secp256k1(Hash, V, R, S)"} , { 'CONTRACT_TO_ADDRESS', 16#74, false, true, true, 3, [a,a], contract_to_address, {contract}, address, "Arg0 := Arg1 - A no-op type conversion"} , { 'AUTH_TX_HASH', 16#75, false, true, true, 3, [a], auth_tx_hash, {}, variant, "If in GA authentication context return Some(TxHash) otherwise None."} @@ -752,4 +753,3 @@ format_arg_doc({is,_N}) -> "Identifier"; format_arg_doc({ii,_N}) -> "Integer"; format_arg_doc({li,_N}) -> "[Integers]"; format_arg_doc({t,_N}) -> "Type". - -- 2.30.2 From 44ec31d95856d3d0f398245f0de78cb926cda827 Mon Sep 17 00:00:00 2001 From: John Newby Date: Mon, 12 Aug 2019 13:52:27 +0200 Subject: [PATCH 4/6] fixed ordering --- include/aeb_opcodes.hrl | 2 +- src/aeb_fate_generate_ops.erl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/aeb_opcodes.hrl b/include/aeb_opcodes.hrl index 1543f0c..b7af36a 100644 --- a/include/aeb_opcodes.hrl +++ b/include/aeb_opcodes.hrl @@ -193,7 +193,7 @@ -define(PRIM_CALL_CRYPTO_SHA256_STRING, 404). -define(PRIM_CALL_CRYPTO_BLAKE2B_STRING, 405). -define(PRIM_CALL_CRYPTO_ECVERIFY_SECP256K1, 410). --define(PRIM_CALL_CRYPTO_ECRECOVER_SECP256K1, 420). +-define(PRIM_CALL_CRYPTO_ECRECOVER_SECP256K1,420). -define(PRIM_CALL_IN_AUTH_RANGE(__TTYPE__), (((__TTYPE__) > 499) andalso ((__TTYPE__) < 600))). -define(PRIM_CALL_AUTH_TX_HASH, 500). diff --git a/src/aeb_fate_generate_ops.erl b/src/aeb_fate_generate_ops.erl index fb48e4e..d42bd25 100644 --- a/src/aeb_fate_generate_ops.erl +++ b/src/aeb_fate_generate_ops.erl @@ -163,8 +163,6 @@ ops_defs() -> , { 'ECVERIFY', 16#72, false, true, true, 1300, [a,a,a,a], ecverify, {bytes, address, bytes}, boolean, "Arg0 := ecverify(Hash, PubKey, Signature)"} , { 'ECVERIFY_SECP256K1', 16#73, false, true, true, 1300, [a,a,a,a], ecverify_secp256k1, {bytes, bytes, bytes}, boolean, "Arg0 := ecverify_secp256k1(Hash, PubKey, Signature)"} - , { 'ECRECOVER_SECP256K1', 16#7d, false, true, true, 1300, [a,a,a,a], ecrecover_secp256k1, {bytes, bytes, bytes}, bytes, "Arg0 := ecrecover_secp256k1(Hash, V, R, S)"} - , { 'CONTRACT_TO_ADDRESS', 16#74, false, true, true, 3, [a,a], contract_to_address, {contract}, address, "Arg0 := Arg1 - A no-op type conversion"} , { 'AUTH_TX_HASH', 16#75, false, true, true, 3, [a], auth_tx_hash, {}, variant, "If in GA authentication context return Some(TxHash) otherwise None."} @@ -177,6 +175,8 @@ ops_defs() -> , { 'IS_ORACLE', 16#7a, false, false, true, 3, [a,a], is_oracle, {address}, bool, "Arg0 := is Arg1 an oracle"} , { 'IS_CONTRACT', 16#7b, false, false, true, 3, [a,a], is_contract, {address}, bool, "Arg0 := is Arg1 a contract"} , { 'CREATOR', 16#7c, false, true, true, 3, [a], contract_creator, {}, address, "Arg0 := contract creator"} + , { 'ECRECOVER_SECP256K1', 16#7d, false, true, true, 1300, [a,a,a,a], ecrecover_secp256k1, {bytes, bytes, bytes}, bytes, "Arg0 := ecrecover_secp256k1(Hash, V, R, S)"} + , { 'DEACTIVATE', 16#fa, false, true, true, 3, [], deactivate, {}, none, "Mark the current contract for deactivation."} , { 'ABORT', 16#fb, true, true, true, 3, [a], abort, {string}, none, "Abort execution (dont use all gas) with error message in Arg0."} -- 2.30.2 From 197dfd5da1ae07aa6a82048bb0c5b7eeccaadb13 Mon Sep 17 00:00:00 2001 From: Tino Breddin Date: Tue, 13 Aug 2019 15:15:03 +0200 Subject: [PATCH 5/6] Let ecrecover only require two parameters --- include/aeb_opcodes.hrl | 16 ++++++++-------- src/aeb_fate_generate_ops.erl | 5 ++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/aeb_opcodes.hrl b/include/aeb_opcodes.hrl index b7af36a..31fff90 100644 --- a/include/aeb_opcodes.hrl +++ b/include/aeb_opcodes.hrl @@ -186,14 +186,14 @@ -define(PRIM_CALL_MAP_TOLIST, 305). -define(PRIM_CALL_IN_CRYPTO_RANGE(__TTYPE__), (((__TTYPE__) > 399) andalso ((__TTYPE__) < 500))). --define(PRIM_CALL_CRYPTO_ECVERIFY, 400). --define(PRIM_CALL_CRYPTO_SHA3, 401). --define(PRIM_CALL_CRYPTO_SHA256, 402). --define(PRIM_CALL_CRYPTO_BLAKE2B, 403). --define(PRIM_CALL_CRYPTO_SHA256_STRING, 404). --define(PRIM_CALL_CRYPTO_BLAKE2B_STRING, 405). --define(PRIM_CALL_CRYPTO_ECVERIFY_SECP256K1, 410). --define(PRIM_CALL_CRYPTO_ECRECOVER_SECP256K1,420). +-define(PRIM_CALL_CRYPTO_ECVERIFY, 400). +-define(PRIM_CALL_CRYPTO_SHA3, 401). +-define(PRIM_CALL_CRYPTO_SHA256, 402). +-define(PRIM_CALL_CRYPTO_BLAKE2B, 403). +-define(PRIM_CALL_CRYPTO_SHA256_STRING, 404). +-define(PRIM_CALL_CRYPTO_BLAKE2B_STRING, 405). +-define(PRIM_CALL_CRYPTO_ECVERIFY_SECP256K1, 410). +-define(PRIM_CALL_CRYPTO_ECRECOVER_SECP256K1, 420). -define(PRIM_CALL_IN_AUTH_RANGE(__TTYPE__), (((__TTYPE__) > 499) andalso ((__TTYPE__) < 600))). -define(PRIM_CALL_AUTH_TX_HASH, 500). diff --git a/src/aeb_fate_generate_ops.erl b/src/aeb_fate_generate_ops.erl index d42bd25..3396abe 100644 --- a/src/aeb_fate_generate_ops.erl +++ b/src/aeb_fate_generate_ops.erl @@ -4,7 +4,7 @@ , generate/0 , generate_documentation/1 , get_ops/0 - , test_asm_generator/1]). + , test_asm_generator/1 ]). gen_and_halt([SrcDirArg, IncludeDirArg]) -> generate(atom_to_list(SrcDirArg), @@ -175,8 +175,7 @@ ops_defs() -> , { 'IS_ORACLE', 16#7a, false, false, true, 3, [a,a], is_oracle, {address}, bool, "Arg0 := is Arg1 an oracle"} , { 'IS_CONTRACT', 16#7b, false, false, true, 3, [a,a], is_contract, {address}, bool, "Arg0 := is Arg1 a contract"} , { 'CREATOR', 16#7c, false, true, true, 3, [a], contract_creator, {}, address, "Arg0 := contract creator"} - , { 'ECRECOVER_SECP256K1', 16#7d, false, true, true, 1300, [a,a,a,a], ecrecover_secp256k1, {bytes, bytes, bytes}, bytes, "Arg0 := ecrecover_secp256k1(Hash, V, R, S)"} - + , { 'ECRECOVER_SECP256K1', 16#7d, false, true, true, 1300, [a,a,a], ecrecover_secp256k1, {bytes, bytes}, bytes, "Arg0 := ecrecover_secp256k1(Hash, Signature)"} , { 'DEACTIVATE', 16#fa, false, true, true, 3, [], deactivate, {}, none, "Mark the current contract for deactivation."} , { 'ABORT', 16#fb, true, true, true, 3, [a], abort, {string}, none, "Abort execution (dont use all gas) with error message in Arg0."} -- 2.30.2 From 23ee7e0ca44d5f3041135415e9935da6021051d8 Mon Sep 17 00:00:00 2001 From: Tino Breddin Date: Tue, 13 Aug 2019 16:24:17 +0200 Subject: [PATCH 6/6] Add missing crypto entries to all_instructions --- test/asm_code/all_instructions.fate | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/asm_code/all_instructions.fate b/test/asm_code/all_instructions.fate index 0516967..807cba1 100644 --- a/test/asm_code/all_instructions.fate +++ b/test/asm_code/all_instructions.fate @@ -1,7 +1,7 @@ ;; CONTRACT all_instructions ;; Dont expect this contract to typecheck or run. -;; Just used to check assembler rountrip of all instructions. +;; Just used to check assembler roundtrip of all instructions. FUNCTION foo () : {tuple, []} RETURN @@ -224,8 +224,12 @@ FUNCTION foo () : {tuple, []} AENS_REVOKE + ECRECOVER_SECP256K1 + ECVERIFY + ECVERIFY_SECP256K1 + SHA3 a SHA256 a -- 2.30.2