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

Destroy standard #182

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Changes from 18 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-X1.mediawiki
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<pre>
NEP: 31
Title: Contract Destroy Guideline
Author: Owen Zhang <[email protected]>
Type: Standard
Status: Draft
Created: 2024-09-11
</pre>

==Abstract==

This proposal standardizes the <code>destroy</code> function which is necessary for contract storage deletion and contract disposal from the system.

==Motivation==

Contracts that are not relevant anymore may need to be destroyed. Neo N3 has provided contract destroy mechanism but it hasn't been summarized in a standard. This standard will show details.
superboyiii marked this conversation as resolved.
Show resolved Hide resolved

==Specification==

Neo N3 has the native <code>ContractManagement</code> contract that is responsible for contract destruction via its <code>destroy</code> method. When <code>destroy</code> is executed, it will delete all storage entries of calling contract. It will block the calling contract address using the native <code>Policy</code> contract to prevent redeployment or calling any methods on the contract from that point forward. Contracts that want to be destroyable MUST implement the <code>destroy</code> method as described below.
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved

===Methods===

====destroy====

<pre>
{
"name": "destroy",
"safe": false,
"parameters": [],
"returntype": "Void"
}
superboyiii marked this conversation as resolved.
Show resolved Hide resolved
</pre>
This method MUST invoke the <code>destroy</code> method of <code>ContractManagement</code> contract when the contract is destroyed.
superboyiii marked this conversation as resolved.
Show resolved Hide resolved
superboyiii marked this conversation as resolved.
Show resolved Hide resolved

<code>destroy</code> method can have multi parameters for any specific purpose since it's an operation only for contract owner.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can avoid this and have a specific (parameterless) interface just like for update. Suppose I want to create a NEP-DESTROY-compatible CLI command, it'd be harder to do this if one contract has parameters and the other does not.

Copy link
Member

Choose a reason for hiding this comment

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

Should we strictly require zero parameters in the standard, or it is just a "SHOULD" requirement?

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the practical value of parameters here? I can only imagine moving tokens from contract address before deletion (which might require some address), but likely they'll be sent to owner or this can be handled in a different manner by contract. Conditional (based on parameters) destroy? Not likely to be useful, owner can do anything already, so if he decides to destroy he will do this. So I'd go with MUST here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still relevant, this NEP doesn't make much sense if parameters are not fixed.


<code>destroy</code> method SHOULD use the <code>SYSCALL</code> <code>CheckWitness</code> to verify the <code>signer</code>. Otherwise anyone will be able to destroy your contract.
superboyiii marked this conversation as resolved.
Show resolved Hide resolved

Contract SHOULD transfer any assets (_NEO/GAS_) that contract is currently holding before calling <code>ContractManagement.Destroy()</code> or else the assets will be lost.
superboyiii marked this conversation as resolved.
Show resolved Hide resolved
superboyiii marked this conversation as resolved.
Show resolved Hide resolved

superboyiii marked this conversation as resolved.
Show resolved Hide resolved
===Events===

====Destroy====

<pre>
{
"name": "Destroy",
"parameters": [
{
"name": "contract",
"type": "Hash160"
}
]
}
</pre>

<code>Destroy</code> notification is emitted automatically by native <code>ContractManagement</code> contract after all contract storage items and the contract itself are removed. This event contains destroyed contract hash.

==References==


==Implementation==

* C#: https://github.com/neo-project/neo-devpack-dotnet/blob/003a50095efe88f63f518a0c989921be086409f3/examples/Example.SmartContract.NFT/Loot.Admin.cs#L79
superboyiii marked this conversation as resolved.
Show resolved Hide resolved
* Go: https://github.com/nspcc-dev/neo-go/blob/e1d5ac8557d7e087158e6a766d059913a56df79f/examples/nft-nd/nft.go#L261