Skip to content

Commit

Permalink
Merge branch 'master' into dBFT-stage-3
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored Aug 16, 2018
2 parents ef134fe + d592317 commit 77a5d37
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 234 deletions.
6 changes: 3 additions & 3 deletions neo/Core/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ internal static bool VerifyScripts(this IVerifiable verifiable)
using (StateReader service = new StateReader())
{
ApplicationEngine engine = new ApplicationEngine(TriggerType.Verification, verifiable, Blockchain.Default, service, Fixed8.Zero);
engine.LoadScript(verification, false);
engine.LoadScript(verifiable.Scripts[i].InvocationScript, true);
engine.LoadScript(verification);
engine.LoadScript(verifiable.Scripts[i].InvocationScript);
if (!engine.Execute()) return false;
if (engine.EvaluationStack.Count != 1 || !engine.EvaluationStack.Pop().GetBoolean()) return false;
if (engine.ResultStack.Count != 1 || !engine.ResultStack.Pop().GetBoolean()) return false;
}
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions neo/Implementations/Blockchains/LevelDB/LevelDBBlockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ private void Persist(Block block)
using (StateMachine service = new StateMachine(block, accounts, assets, contracts, storages))
{
ApplicationEngine engine = new ApplicationEngine(TriggerType.Application, tx_invocation, script_table, service, tx_invocation.Gas);
engine.LoadScript(tx_invocation.Script, false);
engine.LoadScript(tx_invocation.Script);
if (engine.Execute())
{
service.Commit();
Expand All @@ -597,7 +597,7 @@ private void Persist(Block block)
ScriptHash = tx_invocation.Script.ToScriptHash(),
VMState = engine.State,
GasConsumed = engine.GasConsumed,
Stack = engine.EvaluationStack.ToArray(),
Stack = engine.ResultStack.ToArray(),
Notifications = service.Notifications.ToArray()
});
}
Expand Down
2 changes: 1 addition & 1 deletion neo/Network/RPC/RpcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static JObject GetInvokeResult(byte[] script)
json["script"] = script.ToHexString();
json["state"] = engine.State;
json["gas_consumed"] = engine.GasConsumed.ToString();
json["stack"] = new JArray(engine.EvaluationStack.Select(p => p.ToParameter().ToJson()));
json["stack"] = new JArray(engine.ResultStack.Select(p => p.ToParameter().ToJson()));
return json;
}

Expand Down
67 changes: 34 additions & 33 deletions neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Neo.VM;
using Neo.VM.Types;
using System.Collections;
using System.Linq;
using System.Numerics;
using System.Text;

Expand Down Expand Up @@ -73,24 +74,24 @@ private bool CheckArraySize(OpCode nextInstruction)
case OpCode.NEWARRAY:
case OpCode.NEWSTRUCT:
{
if (EvaluationStack.Count == 0) return false;
size = (int)EvaluationStack.Peek().GetBigInteger();
if (CurrentContext.EvaluationStack.Count == 0) return false;
size = (int)CurrentContext.EvaluationStack.Peek().GetBigInteger();
}
break;
case OpCode.SETITEM:
{
if (EvaluationStack.Count < 3) return false;
if (!(EvaluationStack.Peek(2) is Map map)) return true;
StackItem key = EvaluationStack.Peek(1);
if (CurrentContext.EvaluationStack.Count < 3) return false;
if (!(CurrentContext.EvaluationStack.Peek(2) is Map map)) return true;
StackItem key = CurrentContext.EvaluationStack.Peek(1);
if (key is ICollection) return false;
if (map.ContainsKey(key)) return true;
size = map.Count + 1;
}
break;
case OpCode.APPEND:
{
if (EvaluationStack.Count < 2) return false;
if (!(EvaluationStack.Peek(1) is Array array)) return false;
if (CurrentContext.EvaluationStack.Count < 2) return false;
if (!(CurrentContext.EvaluationStack.Peek(1) is Array array)) return false;
size = array.Count + 1;
}
break;
Expand Down Expand Up @@ -127,8 +128,8 @@ private bool CheckItemSize(OpCode nextInstruction)
}
case OpCode.CAT:
{
if (EvaluationStack.Count < 2) return false;
int length = EvaluationStack.Peek(0).GetByteArray().Length + EvaluationStack.Peek(1).GetByteArray().Length;
if (CurrentContext.EvaluationStack.Count < 2) return false;
int length = CurrentContext.EvaluationStack.Peek(0).GetByteArray().Length + CurrentContext.EvaluationStack.Peek(1).GetByteArray().Length;
if (length > MaxItemSize) return false;
return true;
}
Expand Down Expand Up @@ -157,12 +158,12 @@ private bool CheckBigIntegers(OpCode nextInstruction)
{
case OpCode.SHL:
{
BigInteger ishift = EvaluationStack.Peek(0).GetBigInteger();
BigInteger ishift = CurrentContext.EvaluationStack.Peek(0).GetBigInteger();

if ((ishift > Max_SHL_SHR || ishift < Min_SHL_SHR))
return false;

BigInteger x = EvaluationStack.Peek(1).GetBigInteger();
BigInteger x = CurrentContext.EvaluationStack.Peek(1).GetBigInteger();

if (!CheckBigInteger(x << (int)ishift))
return false;
Expand All @@ -171,12 +172,12 @@ private bool CheckBigIntegers(OpCode nextInstruction)
}
case OpCode.SHR:
{
BigInteger ishift = EvaluationStack.Peek(0).GetBigInteger();
BigInteger ishift = CurrentContext.EvaluationStack.Peek(0).GetBigInteger();

if ((ishift > Max_SHL_SHR || ishift < Min_SHL_SHR))
return false;

BigInteger x = EvaluationStack.Peek(1).GetBigInteger();
BigInteger x = CurrentContext.EvaluationStack.Peek(1).GetBigInteger();

if (!CheckBigInteger(x >> (int)ishift))
return false;
Expand All @@ -185,7 +186,7 @@ private bool CheckBigIntegers(OpCode nextInstruction)
}
case OpCode.INC:
{
BigInteger x = EvaluationStack.Peek().GetBigInteger();
BigInteger x = CurrentContext.EvaluationStack.Peek().GetBigInteger();

if (!CheckBigInteger(x) || !CheckBigInteger(x + 1))
return false;
Expand All @@ -194,7 +195,7 @@ private bool CheckBigIntegers(OpCode nextInstruction)
}
case OpCode.DEC:
{
BigInteger x = EvaluationStack.Peek().GetBigInteger();
BigInteger x = CurrentContext.EvaluationStack.Peek().GetBigInteger();

if (!CheckBigInteger(x) || (x.Sign <= 0 && !CheckBigInteger(x - 1)))
return false;
Expand All @@ -203,8 +204,8 @@ private bool CheckBigIntegers(OpCode nextInstruction)
}
case OpCode.ADD:
{
BigInteger x2 = EvaluationStack.Peek().GetBigInteger();
BigInteger x1 = EvaluationStack.Peek(1).GetBigInteger();
BigInteger x2 = CurrentContext.EvaluationStack.Peek().GetBigInteger();
BigInteger x1 = CurrentContext.EvaluationStack.Peek(1).GetBigInteger();

if (!CheckBigInteger(x2) || !CheckBigInteger(x1) || !CheckBigInteger(x1 + x2))
return false;
Expand All @@ -213,8 +214,8 @@ private bool CheckBigIntegers(OpCode nextInstruction)
}
case OpCode.SUB:
{
BigInteger x2 = EvaluationStack.Peek().GetBigInteger();
BigInteger x1 = EvaluationStack.Peek(1).GetBigInteger();
BigInteger x2 = CurrentContext.EvaluationStack.Peek().GetBigInteger();
BigInteger x1 = CurrentContext.EvaluationStack.Peek(1).GetBigInteger();

if (!CheckBigInteger(x2) || !CheckBigInteger(x1) || !CheckBigInteger(x1 - x2))
return false;
Expand All @@ -223,8 +224,8 @@ private bool CheckBigIntegers(OpCode nextInstruction)
}
case OpCode.MUL:
{
BigInteger x2 = EvaluationStack.Peek().GetBigInteger();
BigInteger x1 = EvaluationStack.Peek(1).GetBigInteger();
BigInteger x2 = CurrentContext.EvaluationStack.Peek().GetBigInteger();
BigInteger x1 = CurrentContext.EvaluationStack.Peek(1).GetBigInteger();

int lx1 = x1 == null ? 0 : x1.ToByteArray().Length;

Expand All @@ -240,8 +241,8 @@ private bool CheckBigIntegers(OpCode nextInstruction)
}
case OpCode.DIV:
{
BigInteger x2 = EvaluationStack.Peek().GetBigInteger();
BigInteger x1 = EvaluationStack.Peek(1).GetBigInteger();
BigInteger x2 = CurrentContext.EvaluationStack.Peek().GetBigInteger();
BigInteger x1 = CurrentContext.EvaluationStack.Peek(1).GetBigInteger();

if (!CheckBigInteger(x2) || !CheckBigInteger(x1))
return false;
Expand All @@ -250,8 +251,8 @@ private bool CheckBigIntegers(OpCode nextInstruction)
}
case OpCode.MOD:
{
BigInteger x2 = EvaluationStack.Peek().GetBigInteger();
BigInteger x1 = EvaluationStack.Peek(1).GetBigInteger();
BigInteger x2 = CurrentContext.EvaluationStack.Peek().GetBigInteger();
BigInteger x1 = CurrentContext.EvaluationStack.Peek(1).GetBigInteger();

if (!CheckBigInteger(x2) || !CheckBigInteger(x1))
return false;
Expand Down Expand Up @@ -279,15 +280,15 @@ private bool CheckStackSize(OpCode nextInstruction)
size = 1;
break;
case OpCode.UNPACK:
StackItem item = EvaluationStack.Peek();
StackItem item = CurrentContext.EvaluationStack.Peek();
if (item is Array array)
size = array.Count;
else
return false;
break;
}
if (size == 0) return true;
size += EvaluationStack.Count + AltStack.Count;
size += InvocationStack.Sum(p => p.EvaluationStack.Count + p.AltStack.Count);
if (size > MaxStackSize) return false;
return true;
}
Expand Down Expand Up @@ -370,8 +371,8 @@ protected virtual long GetPrice(OpCode nextInstruction)
return 100;
case OpCode.CHECKMULTISIG:
{
if (EvaluationStack.Count == 0) return 1;
int n = (int)EvaluationStack.Peek().GetBigInteger();
if (CurrentContext.EvaluationStack.Count == 0) return 1;
int n = (int)CurrentContext.EvaluationStack.Peek().GetBigInteger();
if (n < 1) return 1;
return 100 * n;
}
Expand Down Expand Up @@ -436,14 +437,14 @@ protected virtual long GetPriceForSysCall()
return 5000L * 100000000L / ratio;
case "Neo.Asset.Renew":
case "AntShares.Asset.Renew":
return (byte)EvaluationStack.Peek(1).GetBigInteger() * 5000L * 100000000L / ratio;
return (byte)CurrentContext.EvaluationStack.Peek(1).GetBigInteger() * 5000L * 100000000L / ratio;
case "Neo.Contract.Create":
case "Neo.Contract.Migrate":
case "AntShares.Contract.Create":
case "AntShares.Contract.Migrate":
long fee = 100L;

ContractPropertyState contract_properties = (ContractPropertyState)(byte)EvaluationStack.Peek(3).GetBigInteger();
ContractPropertyState contract_properties = (ContractPropertyState)(byte)CurrentContext.EvaluationStack.Peek(3).GetBigInteger();

if (contract_properties.HasFlag(ContractPropertyState.HasStorage))
{
Expand All @@ -461,7 +462,7 @@ protected virtual long GetPriceForSysCall()
case "System.Storage.Put":
case "Neo.Storage.Put":
case "AntShares.Storage.Put":
return ((EvaluationStack.Peek(1).GetByteArray().Length + EvaluationStack.Peek(2).GetByteArray().Length - 1) / 1024 + 1) * 1000;
return ((CurrentContext.EvaluationStack.Peek(1).GetByteArray().Length + CurrentContext.EvaluationStack.Peek(2).GetByteArray().Length - 1) / 1024 + 1) * 1000;
case "System.Storage.Delete":
case "Neo.Storage.Delete":
case "AntShares.Storage.Delete":
Expand Down Expand Up @@ -498,7 +499,7 @@ public static ApplicationEngine Run(byte[] script, IScriptContainer container =
using (StateMachine service = new StateMachine(persisting_block, accounts, assets, contracts, storages))
{
ApplicationEngine engine = new ApplicationEngine(TriggerType.Application, container, script_table, service, Fixed8.Zero, true);
engine.LoadScript(script, false);
engine.LoadScript(script);
engine.Execute();
return engine;
}
Expand Down
Loading

0 comments on commit 77a5d37

Please sign in to comment.