From 6ac76f52790f7b3177c4bdcbb44efe4be4b95dd6 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 25 Jul 2024 22:50:56 +0300 Subject: [PATCH 1/4] nep-Y: add verify NEP Signed-off-by: Roman Khimov --- nep-Y.mediawiki | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 nep-Y.mediawiki diff --git a/nep-Y.mediawiki b/nep-Y.mediawiki new file mode 100644 index 00000000..52fea362 --- /dev/null +++ b/nep-Y.mediawiki @@ -0,0 +1,58 @@ +
+  NEP: 30
+  Title: Contract witness verification callback
+  Author: Roman Khimov 
+  Type: Standard
+  Status: Accepted
+  Created: 2024-07-25
+
+ +==Abstract== + +This NEP standardizes a specific method that if implemented allows to use contracts as signers for transactions and pass witness checks for their address in other code. + +==Motivation== + +Contracts may want to act as transaction senders covering for fees from GAS they have, in this case their address is the first transaction signer and there needs to be some way to verify it which is made possible by this NEP. + +Contract addresses may also be used in other contexts like [[nep-17.mediawiki|NEP-17]] transfers, to successfully pass witness check there contract needs to either be a method caller or be a transaction signer in which case verification of the address is needed as well. + +The mechanism for this verification is provided by Neo N3 since its initial version, but it was never properly standardized. + +==Specification== + +Contracts that want their addresses to be used as transaction signers MUST implement verify method outlined below. This method will be automatically called during transaction verification (with Verification trigger), its return value signifies whether verification was successful (in which case transaction is considered to be valid) or not (in which case transaction is invalid). + +===Methods=== + +====verify==== + +
+{
+  "name": "verify",
+  "safe": true,
+  "parameters": [],
+  "returntype": "bool"
+}
+
+ +Parameters are contract-specific, any number of valid [[nep-14.mediawiki|NEP-14]] parameters can be added if contract needs them to perform verification. Compliant contract MUST have only one method with this name, otherwise the result is undefined. + +To prevent using this method in regular application calls contract can check for trigger returned from System.Runtime.GetTrigger interop function. + +Returning true from this method will make the contract signer verification pass. + +===Transaction scripts=== + +Transactions with contract address used as one of signers MUST include an appropriate witness. Just like a regular witness contract address witness consists of an invocation script and a verification script. Verification script MUST be empty, invocation script can have any code producing parameters for contract invocation if contract's verify method needs them or it can be empty as well if verify takes no parameters. + +==Rationale== + +Neo Legacy differentiated contract verification and application contexts only with VM trigger type, but Legacy contracts had only one entry point and their hashes were derived directly from the byte code, so they could be used as verification scripts as well. In N3 contract hashes are derived from the script that is intentionally made to abort execution, but N3 contracts also have multiple entry points described in [[nep-14.mediawiki|NEP-14]] ABI. Therefore a specific name was chosen to represent a method to be used for contract address verification. + +Since the system knows all deployed contract hashes and they can not intersect with valid verification scripts the choice was made to keep verification scripts attached to transactions empty. But as some contracts may need additional data for this method (typically, signatures or addresses) method parameters are not fixed and invocation scripts can be used to pass them. + +==Implementation== + +* https://github.com/nspcc-dev/neofs-contract/blob/99fb86c35a48ed12017423aa4fee13f7d07fa4c0/contracts/proxy/contract.go#L43 +* https://github.com/neo-project/neo-devpack-dotnet/blob/113651008c8873f983da962d9ab9ba378e1cc1bd/examples/Example.SmartContract.SampleRoyaltyNEP11Token/SampleRoyaltyNEP11Token.cs#L187 From 0e5342a1475f7aa9f23f72f1c9e163e0d47059eb Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 30 Aug 2024 10:48:25 +0300 Subject: [PATCH 2/4] nep-Y: make it a proper NEP-30 Signed-off-by: Roman Khimov --- README.mediawiki | 6 ++++++ nep-Y.mediawiki => nep-30.mediawiki | 0 2 files changed, 6 insertions(+) rename nep-Y.mediawiki => nep-30.mediawiki (100%) diff --git a/README.mediawiki b/README.mediawiki index e1a4bf49..0dbeb148 100644 --- a/README.mediawiki +++ b/README.mediawiki @@ -129,6 +129,12 @@ First review [[nep-1.mediawiki|NEP-1]]. Then clone the repository and add your N | Standard | Accepted |- +| [[nep-30.mediawiki|30]] +| Contract witness verification callback +| Roman Khimov +| Standard +| Accepted +|- | | Dynamic Sharding | diff --git a/nep-Y.mediawiki b/nep-30.mediawiki similarity index 100% rename from nep-Y.mediawiki rename to nep-30.mediawiki From 98deae90db2efb6b32a2153d3d447b9dffb5c4e6 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 3 Sep 2024 19:26:29 +0300 Subject: [PATCH 3/4] nep-30: add languages to implementations, order aphhabetically Signed-off-by: Roman Khimov --- nep-30.mediawiki | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nep-30.mediawiki b/nep-30.mediawiki index 52fea362..ae4a2449 100644 --- a/nep-30.mediawiki +++ b/nep-30.mediawiki @@ -54,5 +54,5 @@ Since the system knows all deployed contract hashes and they can not intersect w ==Implementation== -* https://github.com/nspcc-dev/neofs-contract/blob/99fb86c35a48ed12017423aa4fee13f7d07fa4c0/contracts/proxy/contract.go#L43 -* https://github.com/neo-project/neo-devpack-dotnet/blob/113651008c8873f983da962d9ab9ba378e1cc1bd/examples/Example.SmartContract.SampleRoyaltyNEP11Token/SampleRoyaltyNEP11Token.cs#L187 +* C#: https://github.com/neo-project/neo-devpack-dotnet/blob/113651008c8873f983da962d9ab9ba378e1cc1bd/examples/Example.SmartContract.SampleRoyaltyNEP11Token/SampleRoyaltyNEP11Token.cs#L187 +* Go: https://github.com/nspcc-dev/neofs-contract/blob/99fb86c35a48ed12017423aa4fee13f7d07fa4c0/contracts/proxy/contract.go#L43 From bd607a37986bdf0aad45284492ff1724983d94ad Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 3 Sep 2024 22:03:19 +0300 Subject: [PATCH 4/4] nep-30: split sentence, drop useless words Simplify reading this. Signed-off-by: Roman Khimov --- nep-30.mediawiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nep-30.mediawiki b/nep-30.mediawiki index ae4a2449..b2adc3be 100644 --- a/nep-30.mediawiki +++ b/nep-30.mediawiki @@ -44,7 +44,7 @@ Returning true from this method will make the contract signer verif ===Transaction scripts=== -Transactions with contract address used as one of signers MUST include an appropriate witness. Just like a regular witness contract address witness consists of an invocation script and a verification script. Verification script MUST be empty, invocation script can have any code producing parameters for contract invocation if contract's verify method needs them or it can be empty as well if verify takes no parameters. +Transactions with contract address used as one of signers MUST include an appropriate witness. Just like a regular witness contract address witness consists of an invocation script and a verification script. Verification script MUST be empty. Invocation script can have any code producing parameters for contract invocation if contract's verify method needs them or it can be empty if verify takes no parameters. ==Rationale==