Skip to content

NEP: Stack Isolation for NeoVM #22

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

Merged
merged 7 commits into from
Oct 27, 2018
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions README.mediawiki
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ First review [[nep-1.mediawiki|NEP-1]]. Then clone the repository and add your N
| Dynamic Contract Invocation
| localhuman, unignorant
| Standard
| Final
| [[nep-8.mediawiki|Replaced]]
|-
| [[nep-5.mediawiki|5]]
| Token Standard
Expand All @@ -57,11 +57,11 @@ First review [[nep-1.mediawiki|NEP-1]]. Then clone the repository and add your N
| Standard
| Accepted
|-
| [https://github.com/neo-project/proposals/pull/22 8]
| [[nep-8.mediawiki|8]]
| Stack Isolation for NeoVM
| Erik Zhang
| Standard
| Accepted
| Final
|-
| [https://github.com/neo-project/proposals/pull/25 9]
| URI Scheme
Expand Down
3 changes: 2 additions & 1 deletion nep-4.mediawiki
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
Title: Dynamic Contract Invocation
Author: localhuman, unignorant
Type: Standard
Status: Final
Status: Replaced
Created: 2017-11-06
Superseded-By: 8
</pre>

==Abstract==
Expand Down
55 changes: 55 additions & 0 deletions nep-8.mediawiki
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<pre>
NEP: 8
Title: Stack Isolation for NeoVM
Author: Erik Zhang <erik@neo.org>
Type: Standard
Status: Final
Created: 2017-12-26
Replaces: 4
</pre>

==Abstract==

This NEP proposes that stack isolation of the NeoVM evaluation stack should be carried out to ensure the security of dynamic invocations and provide support for future new features.

==Motivation==

Now that [[nep-4.mediawiki|NEP-4 (dynamic invocation)]] has been implemented, but because the NeoVM evaluation stack is not isolated, a dynamically invoked contract may break the caller's stack at runtime, resulting in the contract not being executed as expected.

On the other hand, some features, such as exception handling, also require stack isolation to be implemented.

==Rationale==

We need a new set of instructions so that each invocation creates a separate evaluation stack and automatically copies the arguments of the function to the new stack. After the function has finished running, the return value is automatically copied to the caller's stack. In this way, the invoked contract will no longer affect the caller's behavior by modifying with the stack.

==Specification==

We add five new instructions for starting invocations with stack isolation: <code>CALL_I</code>, <code>CALL_E</code>, <code>CALL_ED</code>, <code>CALL_ET</code>, <code>CALL_EDT</code>.

===CALL_I===

The instruction <code>CALL_I</code> is very similar to the old instruction <code>CALL</code>. The difference is that <code>CALL_I</code> requires an operand behind the instruction for representing the number of parameters and return values to copy.

===CALL_E===

The instruction <code>CALL_E</code> is very similar to the old instruction <code>APPCALL</code> for static invocations. The difference is that <code>CALL_E</code> requires an operand behind the instruction for representing the number of parameters and return values to copy.

===CALL_ED===

The instruction <code>CALL_ED</code> is very similar to the old instruction <code>APPCALL</code> for dynamic invocations. The difference is that <code>CALL_ED</code> requires an operand behind the instruction for representing the number of parameters and return values to copy.

===CALL_ET===

The instruction <code>CALL_ET</code> is very similar to the instruction <code>CALL_E</code>. The difference is that <code>CALL_ET</code> will start a tail call.

===CALL_EDT===

The instruction <code>CALL_EDT</code> is very similar to the instruction <code>CALL_ED</code>. The difference is that <code>CALL_EDT</code> will start a tail call.

==Backwards Compatibility==

All old contracts can be executed correctly in the original instruction set, but no new contracts are proposed to continue using the old instructions. When a new contract requires dynamic invocation, the old instructions should be avoided.

==Implementation==

https://github.com/neo-project/neo-vm/pull/39