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

Merged
merged 30 commits into from
Dec 24, 2024
Merged
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
71 changes: 71 additions & 0 deletions nep-22.mediawiki
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<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 a standard for <code>update</code> method in contract to callback native <code>ContractManagement</code> correctly.

==Specification==

All contracts SHOULD implement this NEP in case of any bug hotfix or improvement. If no update method there, incorrect action can never be corrected.

===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 MUST CALL <code>update</code> method in native <code>ContractManagement</code> contract. It will update contract state if it's executed successfully.

Updating a smart contract MUST have <code>nefFile</code> or <code>manifest.json</code>. How do they work is in reference of [NEP-15](https://github.com/neo-project/proposals/blob/master/nep-15.mediawiki) and [NEP-16](https://github.com/neo-project/proposals/blob/master/nep-16.mediawiki). Just updating one of them at a time is OK. This means no change on another, so another SHOULD be set as null. It MUST be passed to ContractManagement.Update() in this method.

The parameter <code>data</code> can be any type of supported parameters for contract-specific purpose. For [example](https://github.com/nspcc-dev/neofs-contract/blob/99fb86c35a48ed12017423aa4fee13f7d07fa4c0/contracts/proxy/contract.go#L33) some kinds of parameters can be put into data for specific check. Also some reference in [NEP-29](https://github.com/neo-project/proposals/blob/master/nep-29.mediawiki).

This method SHOULD do <code>Checkwitness</code> for contract <code>owner</code> to avoid security risks. This function SHOULD use the SYSCALL <code>Neo.Runtime.CheckWitness</code> to verify the <code>signer</code>.

It's strongly recommended to execute all codes before calling ContractManagement.Update() to ensure they can be executed correctly.

===References===

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

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

https://github.com/neo-project/proposals/blob/master/nep-29.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