Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEP 22: Contract Update Standard #154

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions nep-22.mediawiki
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<pre>
NEP: 22
Title: Contract Update Function
Author: Owen Zhang <[email protected]>, Fernando Díaz Toledano <[email protected]>, Erik Zhang <[email protected]>, Roman Khimov <[email protected]>
Type: Standard
Status: Accepted
Created: 2021-04-19
</pre>


==Abstract==

This proposal outlines a standard for the NEO blockchain that will provide systems with a generalized interaction mechanism for smart contract update.

==Motivation==

As the NEO blockchain scales, Smart Contract Update will become increasingly important. We need standize <code>update</code> method in contract to callback native <code>ContractManagement</code> correctly.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/NEO/Neo. s/standize/a standard/? I'm also not sure we need to say anything about callbacks. It's about standard API to update contracts, what it does internally is not motivation probably.


==Specification==

Neo N3 has a native <code>ContractManagement</code> contract that is used for contract deployment and update via <code>deploy</code> and <code>update</code> methods of it. After settling with the new NEF and manifest both of them will invoke a special <code>_deploy</code> method if it's implemented by the contract. More details in [NEP-29](https://github.com/neo-project/proposals/blob/master/nep-29.mediawiki)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a part of specification. We're specifying something different here.


===Methods===

====update====

<pre>
{
"name": "update",
"safe": false,
"parameters": [
{
"name": "nefFile",
"type": "ByteArray"
},
{
"name": "manifest",
"type": "ByteArray"
},
{
"name": "data",
"type": "Any"
}
],
"returntype": "Void"
}
</pre>

This method will will callback <code>Update</code> method in native <code>ContractManagement</code> contract. It will update contract state if it's exectued successfully.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will will

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just MUST call


Updating a smart contract MUST have <code>nefFile</code> or <code>manifest.json</code>. If just update one of them at a time is OK, another SHOULD be set as null. It will be passed to <code>_deploy</code>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe refer to NEP-16 and NEP-15 here. I also don't understand

It will be passed to _deploy.

here. Only data is going to be passed and that's exactly where a reference to NEP-29 is needed.


The parameter <code>data</code> can be any type of supported parameters for contract-specific purpose. For example some kinds of json parameters can be put into data for specific check.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"For example some kinds of json parameters can be put into data for specific check."
Some examples here?


This function SHOULD check whether the <code>signer</code> address equals the <code>owner</code> hash of contract. This function SHOULD use the SYSCALL <code>Neo.Runtime.CheckWitness</code> to verify the <code>signer</code>. Details has been explained in [NEP-30](https://github.com/superboyiii/proposals/blob/upgrade-standard/nep-30.mediawiki).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function? Which function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better as this method, since we're talking about update method here. Also, I don't understand what is to check whether the <code>signer</code> address equals the <code>owner</code> hash of contract. Transaction can have a lot of signers. We should care more about owner allowing this action (CheckWitness). And NEP-30 is a different thing in general, most of contracts will not have contract-based owners, they're usually just multisig.


===References===

https://github.com/neo-project/proposals/blob/master/nep-29.mediawiki

https://github.com/neo-project/proposals/blob/master/nep-30.mediawiki

===Implementation===

* C#: https://github.com/neo-project/neo-devpack-dotnet/blob/003a50095efe88f63f518a0c989921be086409f3/examples/Example.SmartContract.NEP17/SampleNep17Token.cs#L130

* Go: https://github.com/nspcc-dev/neofs-contract/blob/99fb86c35a48ed12017423aa4fee13f7d07fa4c0/contracts/proxy/contract.go#L33