Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Stack Isolation #39

Merged
merged 11 commits into from
Jun 24, 2018
Merged

Stack Isolation #39

merged 11 commits into from
Jun 24, 2018

Conversation

erikzhang
Copy link
Member

@erikzhang erikzhang commented May 8, 2018

Implement NEP-8: Stack Isolation
neo-project/proposals#22

Close #35

@erikzhang
Copy link
Member Author

@lightszero @localhuman @shargon @anthdm

Can you guys check this PR for your repositories so that:

  1. For NeoVM in other language implementations, make sure that they also implement the Stack Isolation (NEP-8) scheme correctly.

  2. For each neo compiler, test whether the program they are compiling now can run in NeoVM compatibility mode.

  3. If the compiler works well with the compatibility mode, modify the compiler to support the new, more secure stack isolation mode.

@localhuman
Copy link
Contributor

In progress now!

@shargon
Copy link
Member

shargon commented May 16, 2018

A lot of changes to review, give me a couple of days please

Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

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

I still reviewing, the first problem that i find is this

PUSH1 (without RET)

Before the update:
Result: HALT, EvaluationStack[]{true};

After the update:
Result: HALT, ResultStack{}

If exists any script like this in all Blockchain, without versioning, is impossible to reconstruct the chain from the beginning

@@ -50,15 +63,21 @@ public void Push(T item)
public T Remove(int index)
{
if (index >= list.Count) throw new InvalidOperationException();
T item = list[list.Count - index - 1];
list.RemoveAt(list.Count - index - 1);
if (index < 0) index += list.Count;
Copy link
Member

Choose a reason for hiding this comment

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

if (index < 0) index = list.Count; ?

Copy link
Member Author

Choose a reason for hiding this comment

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

+=

Copy link
Member

Choose a reason for hiding this comment

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

We want to pass -2 or -3?

@erikzhang
Copy link
Member Author

erikzhang commented May 20, 2018

@shargon

PUSH1 (without RET)

OpCode opcode = CurrentContext.InstructionPointer >= CurrentContext.Script.Length ? OpCode.RET : (OpCode)CurrentContext.OpReader.ReadByte();

State |= VMState.FAULT;
return;
}
ExecutionContext context_call = LoadScript(context.Script, rvcount);
Copy link
Member

Choose a reason for hiding this comment

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

First of all, i love this change :) , but this is other point to consider

Maybe we need to define a new like this class:

class Script
{
public readonly byte[] Data;
public byte[] Hash;
...
}

Because i see a problem on optimization, now and before the change. When we make a CALL we copy all the current script in a new byte array (ExecutionContext) and yield it, but this is not neccessary, because we can use the same ScriptObject, without copy this values and save memory and time per any CALL

I think that in this line https://github.com/neo-project/neo-vm/pull/39/files#diff-c388295e4ed09df607113cde924c9fadR43 .net framework clone the byte array internally

Copy link
Member

Choose a reason for hiding this comment

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

This happens too when we compute the hash of the script, this class would optimize this multiple calls a lot of

Copy link
Member Author

Choose a reason for hiding this comment

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

No, byte array in .net is a reference type, which means it won't be cloned automatically.

Copy link
Member

Choose a reason for hiding this comment

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

But not the hash, this will be calculated in all ExecutionContext right? maybe we can save a lot of calls to SHA256

@erikzhang
Copy link
Member Author

But not the hash, this will be calculated in all ExecutionContext right? maybe we can save a lot of calls to SHA256

You can create a separate issue for it.

@shargon
Copy link
Member

shargon commented May 23, 2018

Do you have a sample for test the new opcodes? the old part (CALL,RET..) is reviewed and seems perfect!

@erikzhang
Copy link
Member Author

Do you have a sample for test the new opcodes? the old part (CALL,RET..) is reviewed and seems perfect!

No.

@@ -53,28 +58,23 @@ public void Execute()

private void ExecuteOp(OpCode opcode, ExecutionContext context)
{
if (opcode > OpCode.PUSH16 && opcode != OpCode.RET && context.PushOnly)

Choose a reason for hiding this comment

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

Is it possible that this might effect reprocessing the chain? Seems like executions of PushOnly = true scripts might now succeed where before they failed.

Copy link
Member Author

Choose a reason for hiding this comment

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

No. PushOnly will only be used in the verification process, and the verification result of history transactions will not change.

shargon
shargon previously approved these changes May 30, 2018
@erikzhang
Copy link
Member Author

Can I merge it now?

@shargon
Copy link
Member

shargon commented May 31, 2018

I tested the old opcodes and works fine, i need more test with the new opCodes, but it's fine to merge for pre-release

@erikzhang
Copy link
Member Author

I tested the old opcodes and works fine, i need more test with the new opCodes, but it's fine to merge for pre-release

Pre-release has been published to nuget: https://www.nuget.org/packages/Neo.VM/2.3.0-preview1

@shargon
Copy link
Member

shargon commented May 31, 2018

The compiler is not finished? i would like to test the new opcodes with a real smart contract. The code looks good

@erikzhang
Copy link
Member Author

Compiler is here: https://github.com/neo-project/neo-compiler/pull/109

@erikzhang
Copy link
Member Author

@shargon Any update?

@shargon
Copy link
Member

shargon commented Jun 14, 2018

Sorry about my delay, i wasn't see the last notification, im working on it

@erikzhang
Copy link
Member Author

@shargon The compiler issue has been fixed. neo-project/neo-compiler@282604fc4f8ff45a2a7456e073dadb5cf0ef8bbb

@shargon
Copy link
Member

shargon commented Jun 19, 2018

Ok, I will try again :)

@shargon
Copy link
Member

shargon commented Jun 19, 2018

It works :)

@erikzhang erikzhang merged commit 79c3aad into master Jun 24, 2018
@erikzhang erikzhang deleted the feature/nep-8 branch June 24, 2018 09:10
@dicarlo2
Copy link

@erikzhang ETA on when this will be live? I want to make sure NEO-ONE is updated.

@localhuman
Copy link
Contributor

I hope we can test this on testnet for a little while before going live 😉

@erikzhang
Copy link
Member Author

Sure, it will be tested on testnet before being merged into neo-project/neo

@shargon
Copy link
Member

shargon commented Jun 24, 2018

This is a great upgrade! great work @erikzhang :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants