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

[NEP4] Feature-dynamic-invoke verification #120

Merged
merged 17 commits into from
Dec 9, 2017

Conversation

localhuman
Copy link
Contributor

In regards to NEP4 neo-project/proposals#19

Works in tandem with these PR

Adds the following changes

  • Add neo.Core.ContractPropertyState
  • Remove HasStorage as attribute of neo.Core.ContractState and replace with ContractProperties
  • Add check in neo.SmartContract.ApplicationEngine that a Contract has the HasDynamicInvoke property set before using the DYNAMICCALL opcode
  • Adds proposed implementation for calculating gas fees for Neo.Contract.Create and Neo.Contract.Migrate with differing amounts based on the ContractProperties of the contract to be created.

byte[] script_hash = EvaluationStack.Peek().GetByteArray();
CachedScriptTable script_table = (CachedScriptTable)this.table;
ContractState contract_state = script_table.GetContractState(script_hash);
return contract_state.HasDynamicInvoke;
Copy link
Member

Choose a reason for hiding this comment

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

Here you obtain HasDynamicInvoke from the first item of the stack, but in fee calculation at the third.
If both are good, im prefer the third for save CachedScriptTable logics

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good point. Better to make both of them use CachedScriptTable

Copy link
Member

Choose a reason for hiding this comment

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

what is the faster way?

Copy link
Contributor Author

@localhuman localhuman Dec 5, 2017

Choose a reason for hiding this comment

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

The fee calculation one would be fastest ( EvaluationStack.Peek(3) )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shargon I changed them to both use EvaluationStack.Peek(3) as it is faster. This also allows me to not need to use CachedScriptTable, and keep the IScriptTable table property on ExecutionEngine.cs in the VM private instead of protected.

neo/neo.csproj Outdated
</PackageReference>
</ItemGroup>

<ItemGroup>
Copy link
Member

Choose a reason for hiding this comment

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

Before neo-vm was in Nuget, is this change an oversight?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I should not have committed that :)

@@ -228,6 +228,16 @@ private bool CheckStackSize(OpCode nextInstruction)
return true;
}

private bool CheckDynamicInvoke(OpCode nextInstruction)
{
if(nextInstruction == OpCode.APPCALL)
Copy link
Member

Choose a reason for hiding this comment

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

Need to check both APPCALL and TAILCALL.

@@ -201,6 +201,7 @@ private bool Contract_Create(ExecutionEngine engine)
ContractParameterType[] parameter_list = engine.EvaluationStack.Pop().GetByteArray().Select(p => (ContractParameterType)p).ToArray();
if (parameter_list.Length > 252) return false;
ContractParameterType return_type = (ContractParameterType)(byte)engine.EvaluationStack.Pop().GetBigInteger();
ContractPropertyState contract_properties = (ContractPropertyState)(byte)engine.EvaluationStack.Pop().GetBigInteger();
bool need_storage = engine.EvaluationStack.Pop().GetBoolean();
Copy link
Member

Choose a reason for hiding this comment

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

This line should be removed.

@@ -98,6 +103,7 @@ public override JObject ToJson()
json["parameters"] = new JArray(ParameterList.Select(p => (JObject)p));
json["returntype"] = ReturnType;
json["storage"] = HasStorage;
json["dynamic_invoke"] = HasDynamicInvoke;
Copy link
Member

Choose a reason for hiding this comment

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

json["properties"] = new JObject();
json["properties"]["storage"] = HasStorage;
json["properties"]["dynamic_invoke"] = HasDynamicInvoke;

Is this better?

{
if(nextInstruction == OpCode.APPCALL || nextInstruction == OpCode.TAILCALL)
{
for (int i = CurrentContext.InstructionPointer + 1; i < CurrentContext.InstructionPointer + 20; i++)
Copy link
Member

Choose a reason for hiding this comment

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

if (CurrentContext.InstructionPointer + 20 > CurrentContext.Script.Length) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if we need this check. If we go beyond the end of the script, the error will be caught in the Execute method

@erikzhang
Copy link
Member

erikzhang commented Dec 7, 2017

One more thing, if we have an invocation chain: A -> B -> C
If A.HasDynamicInvoke == false, and B.HasDynamicInvoke == true
Can B invoke C dynamically?

@localhuman
Copy link
Contributor Author

It should behave that way. I will test it out to make sure.

@erikzhang
Copy link
Member

Is it ready to merge?

@localhuman
Copy link
Contributor Author

Still want to test an invocation chain

@localhuman
Copy link
Contributor Author

all set

@erikzhang erikzhang merged commit b3b195e into neo-project:master Dec 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants