Permalink
Browse files

Clone struct when picking item from array or map.

  • Loading branch information...
erikzhang committed Aug 20, 2018
1 parent 25723de commit ab74c36117ef1afa5ccf80e326655598fd4012d5
Showing with 5 additions and 6 deletions.
  1. +5 −6 src/neo-vm/ExecutionEngine.cs
@@ -732,6 +732,7 @@ private void ExecuteOp(OpCode opcode, ExecutionContext context)
State |= VMState.FAULT;
return;
}
StackItem item;
switch (context.EvaluationStack.Pop())
{
case VMArray array:
@@ -741,14 +742,10 @@ private void ExecuteOp(OpCode opcode, ExecutionContext context)
State |= VMState.FAULT;
return;
}
context.EvaluationStack.Push(array[index]);
item = array[index];
break;
case Map map:
if (map.TryGetValue(key, out StackItem value))
{
context.EvaluationStack.Push(value);
}
else
if (!map.TryGetValue(key, out item))
{
State |= VMState.FAULT;
return;
@@ -758,6 +755,8 @@ private void ExecuteOp(OpCode opcode, ExecutionContext context)
State |= VMState.FAULT;
return;
}
if (item is Struct s) item = s.Clone();
CurrentContext.EvaluationStack.Push(item);
}
break;
case OpCode.SETITEM:

4 comments on commit ab74c36

@dicarlo2

This comment has been minimized.

Copy link

dicarlo2 replied Aug 29, 2018

@erikzhang
This might actually break existing contracts depending on how their compiler is implemented. E.g. I'm almost certain it breaks the ICO template contract that most ICOs use and v1 switcheo DEX - I have test cases that test contract avm copied directly from the mainnet, and they started failing only after making this change. (Tests are here, though likely hard to grok https://github.com/neo-one-suite/neo-one/blob/master/packages/neo-one-node-vm/src/__tests__/execute.test.ts. At a high level, they test the concierge ICO and switcheo v1 DEX contracts).

@erikzhang

This comment has been minimized.

Copy link
Member

erikzhang replied Aug 29, 2018

Looking at the results of your test, do we have to roll back this commit? @dicarlo2

@dicarlo2

This comment has been minimized.

Copy link

dicarlo2 replied Sep 23, 2018

@erikzhang definitely a good thing it was rolled back - I went ahead and pushed the change to neo-one and our nodes are returning different results, most likely because of this change.

@dicarlo2

This comment has been minimized.

Copy link

dicarlo2 replied Sep 23, 2018

@erikzhang also, sorry for the delayed reply, it's been a hectic couple of weeks.

Please sign in to comment.