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

Fix CallFlags #2292

Merged
merged 2 commits into from
Feb 5, 2021
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
2 changes: 1 addition & 1 deletion src/neo/SmartContract/ApplicationEngine.Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Neo.SmartContract
{
partial class ApplicationEngine
{
public static readonly InteropDescriptor System_Contract_Call = Register("System.Contract.Call", nameof(CallContract), 1 << 15, CallFlags.AllowCall);
public static readonly InteropDescriptor System_Contract_Call = Register("System.Contract.Call", nameof(CallContract), 1 << 15, CallFlags.ReadStates | CallFlags.AllowCall);
public static readonly InteropDescriptor System_Contract_CallNative = Register("System.Contract.CallNative", nameof(CallNativeContract), 0, CallFlags.None);
public static readonly InteropDescriptor System_Contract_IsStandard = Register("System.Contract.IsStandard", nameof(IsStandardContract), 1 << 10, CallFlags.ReadStates);
public static readonly InteropDescriptor System_Contract_GetCallFlags = Register("System.Contract.GetCallFlags", nameof(GetCallFlags), 1 << 10, CallFlags.None);
Expand Down
6 changes: 2 additions & 4 deletions src/neo/SmartContract/ApplicationEngine.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ protected internal bool CheckWitnessInternal(UInt160 hash)
{
// Check allow state callflag

if (!CurrentContext.GetState<ExecutionContextState>().CallFlags.HasFlag(CallFlags.ReadStates))
throw new InvalidOperationException($"Cannot call this SYSCALL without the flag AllowStates.");
ValidateCallFlags(CallFlags.ReadStates);

var contract = NativeContract.ContractManagement.GetContract(Snapshot, CallingScriptHash);
// check if current group is the required one
Expand All @@ -102,8 +101,7 @@ protected internal bool CheckWitnessInternal(UInt160 hash)

// Check allow state callflag

if (!CurrentContext.GetState<ExecutionContextState>().CallFlags.HasFlag(CallFlags.ReadStates))
throw new InvalidOperationException($"Cannot call this SYSCALL without the flag AllowStates.");
ValidateCallFlags(CallFlags.ReadStates);

// only for non-Transaction types (Block, etc)

Expand Down
7 changes: 4 additions & 3 deletions src/neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public ExecutionContext LoadScript(Script script, int rvcount = -1, int initialP

protected override ExecutionContext LoadToken(ushort tokenId)
{
ValidateCallFlags(CallFlags.ReadStates | CallFlags.AllowCall);
ContractState contract = CurrentContext.GetState<ExecutionContextState>().Contract;
if (contract is null || tokenId >= contract.Nef.Tokens.Length)
throw new InvalidOperationException();
Expand Down Expand Up @@ -281,17 +282,17 @@ public override void Dispose()
base.Dispose();
}

protected void ValidateCallFlags(InteropDescriptor descriptor)
protected void ValidateCallFlags(CallFlags requiredCallFlags)
{
ExecutionContextState state = CurrentContext.GetState<ExecutionContextState>();
if (!state.CallFlags.HasFlag(descriptor.RequiredCallFlags))
if (!state.CallFlags.HasFlag(requiredCallFlags))
throw new InvalidOperationException($"Cannot call this SYSCALL with the flag {state.CallFlags}.");
}

protected override void OnSysCall(uint method)
{
InteropDescriptor descriptor = services[method];
ValidateCallFlags(descriptor);
ValidateCallFlags(descriptor.RequiredCallFlags);
AddGas(descriptor.FixedPrice * exec_fee_factor);
List<object> parameters = descriptor.Parameters.Count > 0
? new List<object>()
Expand Down