From d10f0f1e5ee00a2d7104ad892ecd948a5502791b Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 9 Apr 2020 15:27:48 +0200 Subject: [PATCH 01/12] Allow to call a contract without states access --- src/neo/SmartContract/CallFlags.cs | 12 ++++++++---- src/neo/SmartContract/InteropService.Storage.cs | 10 +++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/neo/SmartContract/CallFlags.cs b/src/neo/SmartContract/CallFlags.cs index 99af3e0599..0b0cdceb09 100644 --- a/src/neo/SmartContract/CallFlags.cs +++ b/src/neo/SmartContract/CallFlags.cs @@ -7,11 +7,15 @@ public enum CallFlags : byte { None = 0, - AllowModifyStates = 0b00000001, - AllowCall = 0b00000010, - AllowNotify = 0b00000100, + AllowStates = 0b00000001, + /// + /// AllowModifyStates include AllowStates + /// + AllowModifyStates = 0b00000010, + AllowCall = 0b00000100, + AllowNotify = 0b00001000, - ReadOnly = AllowCall | AllowNotify, + ReadOnly = AllowCall | AllowNotify | AllowStates, All = AllowModifyStates | AllowCall | AllowNotify } } diff --git a/src/neo/SmartContract/InteropService.Storage.cs b/src/neo/SmartContract/InteropService.Storage.cs index b7df35ea26..c23eebeb41 100644 --- a/src/neo/SmartContract/InteropService.Storage.cs +++ b/src/neo/SmartContract/InteropService.Storage.cs @@ -16,11 +16,11 @@ public static class Storage public const int MaxKeySize = 64; public const int MaxValueSize = ushort.MaxValue; - public static readonly InteropDescriptor GetContext = Register("System.Storage.GetContext", Storage_GetContext, 0_00000400, TriggerType.Application, CallFlags.None); - public static readonly InteropDescriptor GetReadOnlyContext = Register("System.Storage.GetReadOnlyContext", Storage_GetReadOnlyContext, 0_00000400, TriggerType.Application, CallFlags.None); - public static readonly InteropDescriptor AsReadOnly = Register("System.Storage.AsReadOnly", Storage_AsReadOnly, 0_00000400, TriggerType.Application, CallFlags.None); - public static readonly InteropDescriptor Get = Register("System.Storage.Get", Storage_Get, 0_01000000, TriggerType.Application, CallFlags.None); - public static readonly InteropDescriptor Find = Register("System.Storage.Find", Storage_Find, 0_01000000, TriggerType.Application, CallFlags.None); + public static readonly InteropDescriptor GetContext = Register("System.Storage.GetContext", Storage_GetContext, 0_00000400, TriggerType.Application, CallFlags.AllowStates); + public static readonly InteropDescriptor GetReadOnlyContext = Register("System.Storage.GetReadOnlyContext", Storage_GetReadOnlyContext, 0_00000400, TriggerType.Application, CallFlags.AllowStates); + public static readonly InteropDescriptor AsReadOnly = Register("System.Storage.AsReadOnly", Storage_AsReadOnly, 0_00000400, TriggerType.Application, CallFlags.AllowStates); + public static readonly InteropDescriptor Get = Register("System.Storage.Get", Storage_Get, 0_01000000, TriggerType.Application, CallFlags.AllowStates); + public static readonly InteropDescriptor Find = Register("System.Storage.Find", Storage_Find, 0_01000000, TriggerType.Application, CallFlags.AllowStates); public static readonly InteropDescriptor Put = Register("System.Storage.Put", Storage_Put, GetStoragePrice, TriggerType.Application, CallFlags.AllowModifyStates); public static readonly InteropDescriptor PutEx = Register("System.Storage.PutEx", Storage_PutEx, GetStoragePrice, TriggerType.Application, CallFlags.AllowModifyStates); public static readonly InteropDescriptor Delete = Register("System.Storage.Delete", Storage_Delete, 1 * GasPerByte, TriggerType.Application, CallFlags.AllowModifyStates); From ef40731e29a4edb6a4ccc18c1485bd529b715e4f Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 10 Apr 2020 11:28:09 +0200 Subject: [PATCH 02/12] Update src/neo/SmartContract/CallFlags.cs Co-Authored-By: Erik Zhang --- src/neo/SmartContract/CallFlags.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neo/SmartContract/CallFlags.cs b/src/neo/SmartContract/CallFlags.cs index 0b0cdceb09..2ebe519fc8 100644 --- a/src/neo/SmartContract/CallFlags.cs +++ b/src/neo/SmartContract/CallFlags.cs @@ -16,6 +16,6 @@ public enum CallFlags : byte AllowNotify = 0b00001000, ReadOnly = AllowCall | AllowNotify | AllowStates, - All = AllowModifyStates | AllowCall | AllowNotify + All = AllowStates | AllowModifyStates | AllowCall | AllowNotify } } From a38b996b49ffb0cf860032ca8a7cce410c17fea5 Mon Sep 17 00:00:00 2001 From: erikzhang Date: Fri, 10 Apr 2020 18:04:39 +0800 Subject: [PATCH 03/12] Update CallFlags.cs --- src/neo/SmartContract/CallFlags.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/neo/SmartContract/CallFlags.cs b/src/neo/SmartContract/CallFlags.cs index 2ebe519fc8..86361e9b15 100644 --- a/src/neo/SmartContract/CallFlags.cs +++ b/src/neo/SmartContract/CallFlags.cs @@ -8,14 +8,11 @@ public enum CallFlags : byte None = 0, AllowStates = 0b00000001, - /// - /// AllowModifyStates include AllowStates - /// AllowModifyStates = 0b00000010, AllowCall = 0b00000100, AllowNotify = 0b00001000, - ReadOnly = AllowCall | AllowNotify | AllowStates, + ReadOnly = AllowStates | AllowCall | AllowNotify, All = AllowStates | AllowModifyStates | AllowCall | AllowNotify } } From 3cd9a4c42a41685eec4e93b88a3e206ad9201d98 Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 10 Apr 2020 15:23:34 +0200 Subject: [PATCH 04/12] Update InteropService.Blockchain.cs --- src/neo/SmartContract/InteropService.Blockchain.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/neo/SmartContract/InteropService.Blockchain.cs b/src/neo/SmartContract/InteropService.Blockchain.cs index 1183c5e462..a8ada65f45 100644 --- a/src/neo/SmartContract/InteropService.Blockchain.cs +++ b/src/neo/SmartContract/InteropService.Blockchain.cs @@ -14,12 +14,12 @@ public static class Blockchain { public const uint MaxTraceableBlocks = Transaction.MaxValidUntilBlockIncrement; - public static readonly InteropDescriptor GetHeight = Register("System.Blockchain.GetHeight", Blockchain_GetHeight, 0_00000400, TriggerType.Application, CallFlags.None); - public static readonly InteropDescriptor GetBlock = Register("System.Blockchain.GetBlock", Blockchain_GetBlock, 0_02500000, TriggerType.Application, CallFlags.None); - public static readonly InteropDescriptor GetTransaction = Register("System.Blockchain.GetTransaction", Blockchain_GetTransaction, 0_01000000, TriggerType.Application, CallFlags.None); - public static readonly InteropDescriptor GetTransactionHeight = Register("System.Blockchain.GetTransactionHeight", Blockchain_GetTransactionHeight, 0_01000000, TriggerType.Application, CallFlags.None); - public static readonly InteropDescriptor GetTransactionFromBlock = Register("System.Blockchain.GetTransactionFromBlock", Blockchain_GetTransactionFromBlock, 0_01000000, TriggerType.Application, CallFlags.None); - public static readonly InteropDescriptor GetContract = Register("System.Blockchain.GetContract", Blockchain_GetContract, 0_01000000, TriggerType.Application, CallFlags.None); + public static readonly InteropDescriptor GetHeight = Register("System.Blockchain.GetHeight", Blockchain_GetHeight, 0_00000400, TriggerType.Application, CallFlags.AllowStates); + public static readonly InteropDescriptor GetBlock = Register("System.Blockchain.GetBlock", Blockchain_GetBlock, 0_02500000, TriggerType.Application, CallFlags.AllowStates); + public static readonly InteropDescriptor GetTransaction = Register("System.Blockchain.GetTransaction", Blockchain_GetTransaction, 0_01000000, TriggerType.Application, CallFlags.AllowStates); + public static readonly InteropDescriptor GetTransactionHeight = Register("System.Blockchain.GetTransactionHeight", Blockchain_GetTransactionHeight, 0_01000000, TriggerType.Application, CallFlags.AllowStates); + public static readonly InteropDescriptor GetTransactionFromBlock = Register("System.Blockchain.GetTransactionFromBlock", Blockchain_GetTransactionFromBlock, 0_01000000, TriggerType.Application, CallFlags.AllowStates); + public static readonly InteropDescriptor GetContract = Register("System.Blockchain.GetContract", Blockchain_GetContract, 0_01000000, TriggerType.Application, CallFlags.AllowStates); private static bool Blockchain_GetHeight(ApplicationEngine engine) { From de99ae9a9bebef64348a6555ecd70e009ead3dda Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 10 Apr 2020 15:36:51 +0200 Subject: [PATCH 05/12] Native contract changes --- .../Native/ContractMethodAttribute.cs | 2 +- src/neo/SmartContract/Native/NativeContract.cs | 8 ++++---- src/neo/SmartContract/Native/PolicyContract.cs | 18 +++++++++--------- .../SmartContract/Native/Tokens/NeoToken.cs | 12 ++++++------ .../SmartContract/Native/Tokens/Nep5Token.cs | 12 ++++++------ 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/neo/SmartContract/Native/ContractMethodAttribute.cs b/src/neo/SmartContract/Native/ContractMethodAttribute.cs index 22051d72f7..57e2aef9a6 100644 --- a/src/neo/SmartContract/Native/ContractMethodAttribute.cs +++ b/src/neo/SmartContract/Native/ContractMethodAttribute.cs @@ -10,7 +10,7 @@ internal class ContractMethodAttribute : Attribute public ContractParameterType ReturnType { get; } public ContractParameterType[] ParameterTypes { get; set; } = Array.Empty(); public string[] ParameterNames { get; set; } = Array.Empty(); - public bool SafeMethod { get; set; } = false; + public CallFlags CallFlags { get; set; } = CallFlags.None; public ContractMethodAttribute(long price, ContractParameterType returnType) { diff --git a/src/neo/SmartContract/Native/NativeContract.cs b/src/neo/SmartContract/Native/NativeContract.cs index b28f55be14..d5677e5a8d 100644 --- a/src/neo/SmartContract/Native/NativeContract.cs +++ b/src/neo/SmartContract/Native/NativeContract.cs @@ -56,12 +56,12 @@ protected NativeContract() ReturnType = attribute.ReturnType, Parameters = attribute.ParameterTypes.Zip(attribute.ParameterNames, (t, n) => new ContractParameterDefinition { Type = t, Name = n }).ToArray() }); - if (attribute.SafeMethod) safeMethods.Add(name); + if (!attribute.CallFlags.HasFlag(CallFlags.AllowModifyStates)) safeMethods.Add(name); methods.Add(name, new ContractMethodMetadata { Delegate = (Func)method.CreateDelegate(typeof(Func), this), Price = attribute.Price, - RequiredCallFlags = attribute.SafeMethod ? CallFlags.None : CallFlags.AllowModifyStates + RequiredCallFlags = attribute.CallFlags }); } this.Manifest.Abi.Methods = descriptors.ToArray(); @@ -114,7 +114,7 @@ internal virtual bool Initialize(ApplicationEngine engine) return true; } - [ContractMethod(0, ContractParameterType.Boolean)] + [ContractMethod(0, ContractParameterType.Boolean, CallFlags = CallFlags.AllowModifyStates)] protected StackItem OnPersist(ApplicationEngine engine, Array args) { if (engine.Trigger != TriggerType.System) return false; @@ -126,7 +126,7 @@ protected virtual bool OnPersist(ApplicationEngine engine) return true; } - [ContractMethod(0, ContractParameterType.Array, Name = "supportedStandards", SafeMethod = true)] + [ContractMethod(0, ContractParameterType.Array, Name = "supportedStandards", CallFlags = CallFlags.None)] protected StackItem SupportedStandardsMethod(ApplicationEngine engine, Array args) { return new Array(engine.ReferenceCounter, SupportedStandards.Select(p => (StackItem)p)); diff --git a/src/neo/SmartContract/Native/PolicyContract.cs b/src/neo/SmartContract/Native/PolicyContract.cs index ee5f45376e..1bcb749083 100644 --- a/src/neo/SmartContract/Native/PolicyContract.cs +++ b/src/neo/SmartContract/Native/PolicyContract.cs @@ -67,7 +67,7 @@ internal override bool Initialize(ApplicationEngine engine) return true; } - [ContractMethod(0_01000000, ContractParameterType.Integer, SafeMethod = true)] + [ContractMethod(0_01000000, ContractParameterType.Integer, CallFlags = CallFlags.AllowStates)] private StackItem GetMaxTransactionsPerBlock(ApplicationEngine engine, Array args) { return GetMaxTransactionsPerBlock(engine.Snapshot); @@ -78,7 +78,7 @@ public uint GetMaxTransactionsPerBlock(StoreView snapshot) return BitConverter.ToUInt32(snapshot.Storages[CreateStorageKey(Prefix_MaxTransactionsPerBlock)].Value, 0); } - [ContractMethod(0_01000000, ContractParameterType.Integer, SafeMethod = true)] + [ContractMethod(0_01000000, ContractParameterType.Integer, CallFlags = CallFlags.AllowStates)] private StackItem GetMaxBlockSize(ApplicationEngine engine, Array args) { return GetMaxBlockSize(engine.Snapshot); @@ -89,7 +89,7 @@ public uint GetMaxBlockSize(StoreView snapshot) return BitConverter.ToUInt32(snapshot.Storages[CreateStorageKey(Prefix_MaxBlockSize)].Value, 0); } - [ContractMethod(0_01000000, ContractParameterType.Integer, SafeMethod = true)] + [ContractMethod(0_01000000, ContractParameterType.Integer, CallFlags = CallFlags.AllowStates)] private StackItem GetFeePerByte(ApplicationEngine engine, Array args) { return GetFeePerByte(engine.Snapshot); @@ -100,7 +100,7 @@ public long GetFeePerByte(StoreView snapshot) return BitConverter.ToInt64(snapshot.Storages[CreateStorageKey(Prefix_FeePerByte)].Value, 0); } - [ContractMethod(0_01000000, ContractParameterType.Array, SafeMethod = true)] + [ContractMethod(0_01000000, ContractParameterType.Array, CallFlags = CallFlags.AllowStates)] private StackItem GetBlockedAccounts(ApplicationEngine engine, Array args) { return new Array(engine.ReferenceCounter, GetBlockedAccounts(engine.Snapshot).Select(p => (StackItem)p.ToArray())); @@ -111,7 +111,7 @@ public UInt160[] GetBlockedAccounts(StoreView snapshot) return snapshot.Storages[CreateStorageKey(Prefix_BlockedAccounts)].Value.AsSerializableArray(); } - [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "value" })] + [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "value" }, CallFlags = CallFlags.AllowModifyStates)] private StackItem SetMaxBlockSize(ApplicationEngine engine, Array args) { if (!CheckValidators(engine)) return false; @@ -122,7 +122,7 @@ private StackItem SetMaxBlockSize(ApplicationEngine engine, Array args) return true; } - [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "value" })] + [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "value" }, CallFlags = CallFlags.AllowModifyStates)] private StackItem SetMaxTransactionsPerBlock(ApplicationEngine engine, Array args) { if (!CheckValidators(engine)) return false; @@ -132,7 +132,7 @@ private StackItem SetMaxTransactionsPerBlock(ApplicationEngine engine, Array arg return true; } - [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "value" })] + [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "value" }, CallFlags = CallFlags.AllowModifyStates)] private StackItem SetFeePerByte(ApplicationEngine engine, Array args) { if (!CheckValidators(engine)) return false; @@ -142,7 +142,7 @@ private StackItem SetFeePerByte(ApplicationEngine engine, Array args) return true; } - [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Hash160 }, ParameterNames = new[] { "account" })] + [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Hash160 }, ParameterNames = new[] { "account" }, CallFlags = CallFlags.AllowModifyStates)] private StackItem BlockAccount(ApplicationEngine engine, Array args) { if (!CheckValidators(engine)) return false; @@ -156,7 +156,7 @@ private StackItem BlockAccount(ApplicationEngine engine, Array args) return true; } - [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Hash160 }, ParameterNames = new[] { "account" })] + [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Hash160 }, ParameterNames = new[] { "account" }, CallFlags = CallFlags.AllowModifyStates)] private StackItem UnblockAccount(ApplicationEngine engine, Array args) { if (!CheckValidators(engine)) return false; diff --git a/src/neo/SmartContract/Native/Tokens/NeoToken.cs b/src/neo/SmartContract/Native/Tokens/NeoToken.cs index ec19edb85f..9226c3fccc 100644 --- a/src/neo/SmartContract/Native/Tokens/NeoToken.cs +++ b/src/neo/SmartContract/Native/Tokens/NeoToken.cs @@ -116,7 +116,7 @@ protected override bool OnPersist(ApplicationEngine engine) return true; } - [ContractMethod(0_03000000, ContractParameterType.Integer, ParameterTypes = new[] { ContractParameterType.Hash160, ContractParameterType.Integer }, ParameterNames = new[] { "account", "end" }, SafeMethod = true)] + [ContractMethod(0_03000000, ContractParameterType.Integer, ParameterTypes = new[] { ContractParameterType.Hash160, ContractParameterType.Integer }, ParameterNames = new[] { "account", "end" }, CallFlags = CallFlags.AllowStates)] private StackItem UnclaimedGas(ApplicationEngine engine, Array args) { UInt160 account = new UInt160(args[0].GetSpan()); @@ -132,7 +132,7 @@ public BigInteger UnclaimedGas(StoreView snapshot, UInt160 account, uint end) return CalculateBonus(snapshot, state.Balance, state.BalanceHeight, end); } - [ContractMethod(0_05000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.PublicKey }, ParameterNames = new[] { "pubkey" })] + [ContractMethod(0_05000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.PublicKey }, ParameterNames = new[] { "pubkey" }, CallFlags = CallFlags.AllowModifyStates)] private StackItem RegisterValidator(ApplicationEngine engine, Array args) { ECPoint pubkey = args[0].GetSpan().AsSerializable(); @@ -150,7 +150,7 @@ private bool RegisterValidator(StoreView snapshot, ECPoint pubkey) return true; } - [ContractMethod(5_00000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Hash160, ContractParameterType.Array }, ParameterNames = new[] { "account", "pubkeys" })] + [ContractMethod(5_00000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Hash160, ContractParameterType.Array }, ParameterNames = new[] { "account", "pubkeys" }, CallFlags = CallFlags.AllowModifyStates)] private StackItem Vote(ApplicationEngine engine, Array args) { UInt160 account = new UInt160(args[0].GetSpan()); @@ -193,7 +193,7 @@ private StackItem Vote(ApplicationEngine engine, Array args) return true; } - [ContractMethod(1_00000000, ContractParameterType.Array, SafeMethod = true)] + [ContractMethod(1_00000000, ContractParameterType.Array, CallFlags = CallFlags.AllowStates)] private StackItem GetRegisteredValidators(ApplicationEngine engine, Array args) { return new Array(engine.ReferenceCounter, GetRegisteredValidators(engine.Snapshot).Select(p => new Struct(engine.ReferenceCounter, new StackItem[] { p.PublicKey.ToArray(), p.Votes }))); @@ -209,7 +209,7 @@ public IEnumerable<(ECPoint PublicKey, BigInteger Votes)> GetRegisteredValidator )); } - [ContractMethod(1_00000000, ContractParameterType.Array, SafeMethod = true)] + [ContractMethod(1_00000000, ContractParameterType.Array, CallFlags = CallFlags.AllowStates)] private StackItem GetValidators(ApplicationEngine engine, Array args) { return new Array(engine.ReferenceCounter, GetValidators(engine.Snapshot).Select(p => (StackItem)p.ToArray())); @@ -234,7 +234,7 @@ public ECPoint[] GetValidators(StoreView snapshot) return GetRegisteredValidators(snapshot).Where(p => (p.Votes.Sign > 0) || sv.Contains(p.PublicKey)).OrderByDescending(p => p.Votes).ThenBy(p => p.PublicKey).Select(p => p.PublicKey).Take(count).OrderBy(p => p).ToArray(); } - [ContractMethod(1_00000000, ContractParameterType.Array, SafeMethod = true)] + [ContractMethod(1_00000000, ContractParameterType.Array, CallFlags = CallFlags.AllowStates)] private StackItem GetNextBlockValidators(ApplicationEngine engine, Array args) { return new Array(engine.ReferenceCounter, GetNextBlockValidators(engine.Snapshot).Select(p => (StackItem)p.ToArray())); diff --git a/src/neo/SmartContract/Native/Tokens/Nep5Token.cs b/src/neo/SmartContract/Native/Tokens/Nep5Token.cs index 3e331de487..9e4c98cdf1 100644 --- a/src/neo/SmartContract/Native/Tokens/Nep5Token.cs +++ b/src/neo/SmartContract/Native/Tokens/Nep5Token.cs @@ -115,25 +115,25 @@ internal protected virtual void Burn(ApplicationEngine engine, UInt160 account, engine.SendNotification(Hash, new Array(new StackItem[] { "Transfer", account.ToArray(), StackItem.Null, amount })); } - [ContractMethod(0, ContractParameterType.String, Name = "name", SafeMethod = true)] + [ContractMethod(0, ContractParameterType.String, Name = "name")] protected StackItem NameMethod(ApplicationEngine engine, Array args) { return Name; } - [ContractMethod(0, ContractParameterType.String, Name = "symbol", SafeMethod = true)] + [ContractMethod(0, ContractParameterType.String, Name = "symbol")] protected StackItem SymbolMethod(ApplicationEngine engine, Array args) { return Symbol; } - [ContractMethod(0, ContractParameterType.Integer, Name = "decimals", SafeMethod = true)] + [ContractMethod(0, ContractParameterType.Integer, Name = "decimals")] protected StackItem DecimalsMethod(ApplicationEngine engine, Array args) { return (uint)Decimals; } - [ContractMethod(0_01000000, ContractParameterType.Integer, SafeMethod = true)] + [ContractMethod(0_01000000, ContractParameterType.Integer, CallFlags = CallFlags.AllowStates)] protected StackItem TotalSupply(ApplicationEngine engine, Array args) { return TotalSupply(engine.Snapshot); @@ -146,7 +146,7 @@ public virtual BigInteger TotalSupply(StoreView snapshot) return new BigInteger(storage.Value); } - [ContractMethod(0_01000000, ContractParameterType.Integer, ParameterTypes = new[] { ContractParameterType.Hash160 }, ParameterNames = new[] { "account" }, SafeMethod = true)] + [ContractMethod(0_01000000, ContractParameterType.Integer, ParameterTypes = new[] { ContractParameterType.Hash160 }, ParameterNames = new[] { "account" }, CallFlags = CallFlags.AllowStates)] protected StackItem BalanceOf(ApplicationEngine engine, Array args) { return BalanceOf(engine.Snapshot, new UInt160(args[0].GetSpan())); @@ -160,7 +160,7 @@ public virtual BigInteger BalanceOf(StoreView snapshot, UInt160 account) return state.Balance; } - [ContractMethod(0_08000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Hash160, ContractParameterType.Hash160, ContractParameterType.Integer }, ParameterNames = new[] { "from", "to", "amount" })] + [ContractMethod(0_08000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Hash160, ContractParameterType.Hash160, ContractParameterType.Integer }, ParameterNames = new[] { "from", "to", "amount" }, CallFlags = CallFlags.AllowModifyStates)] protected StackItem Transfer(ApplicationEngine engine, Array args) { UInt160 from = new UInt160(args[0].GetSpan()); From 178b2a955ebd1b5bc27931705a54cfe5e727e4ab Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 10 Apr 2020 15:42:03 +0200 Subject: [PATCH 06/12] Mandatory CallFlags in ContractMethod --- .../Native/ContractMethodAttribute.cs | 5 +++-- src/neo/SmartContract/Native/NativeContract.cs | 4 ++-- src/neo/SmartContract/Native/PolicyContract.cs | 18 +++++++++--------- .../SmartContract/Native/Tokens/NeoToken.cs | 12 ++++++------ .../SmartContract/Native/Tokens/Nep5Token.cs | 12 ++++++------ 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/neo/SmartContract/Native/ContractMethodAttribute.cs b/src/neo/SmartContract/Native/ContractMethodAttribute.cs index 57e2aef9a6..88c16c870d 100644 --- a/src/neo/SmartContract/Native/ContractMethodAttribute.cs +++ b/src/neo/SmartContract/Native/ContractMethodAttribute.cs @@ -10,12 +10,13 @@ internal class ContractMethodAttribute : Attribute public ContractParameterType ReturnType { get; } public ContractParameterType[] ParameterTypes { get; set; } = Array.Empty(); public string[] ParameterNames { get; set; } = Array.Empty(); - public CallFlags CallFlags { get; set; } = CallFlags.None; + public CallFlags CallFlags { get; } - public ContractMethodAttribute(long price, ContractParameterType returnType) + public ContractMethodAttribute(long price, ContractParameterType returnType, CallFlags callFlags) { this.Price = price; this.ReturnType = returnType; + this.CallFlags = callFlags; } } } diff --git a/src/neo/SmartContract/Native/NativeContract.cs b/src/neo/SmartContract/Native/NativeContract.cs index d5677e5a8d..b7f3fcad5b 100644 --- a/src/neo/SmartContract/Native/NativeContract.cs +++ b/src/neo/SmartContract/Native/NativeContract.cs @@ -114,7 +114,7 @@ internal virtual bool Initialize(ApplicationEngine engine) return true; } - [ContractMethod(0, ContractParameterType.Boolean, CallFlags = CallFlags.AllowModifyStates)] + [ContractMethod(0, ContractParameterType.Boolean, CallFlags.AllowModifyStates)] protected StackItem OnPersist(ApplicationEngine engine, Array args) { if (engine.Trigger != TriggerType.System) return false; @@ -126,7 +126,7 @@ protected virtual bool OnPersist(ApplicationEngine engine) return true; } - [ContractMethod(0, ContractParameterType.Array, Name = "supportedStandards", CallFlags = CallFlags.None)] + [ContractMethod(0, ContractParameterType.Array, CallFlags.None, Name = "supportedStandards")] protected StackItem SupportedStandardsMethod(ApplicationEngine engine, Array args) { return new Array(engine.ReferenceCounter, SupportedStandards.Select(p => (StackItem)p)); diff --git a/src/neo/SmartContract/Native/PolicyContract.cs b/src/neo/SmartContract/Native/PolicyContract.cs index 1bcb749083..ac9e9de471 100644 --- a/src/neo/SmartContract/Native/PolicyContract.cs +++ b/src/neo/SmartContract/Native/PolicyContract.cs @@ -67,7 +67,7 @@ internal override bool Initialize(ApplicationEngine engine) return true; } - [ContractMethod(0_01000000, ContractParameterType.Integer, CallFlags = CallFlags.AllowStates)] + [ContractMethod(0_01000000, ContractParameterType.Integer, CallFlags.AllowStates)] private StackItem GetMaxTransactionsPerBlock(ApplicationEngine engine, Array args) { return GetMaxTransactionsPerBlock(engine.Snapshot); @@ -78,7 +78,7 @@ public uint GetMaxTransactionsPerBlock(StoreView snapshot) return BitConverter.ToUInt32(snapshot.Storages[CreateStorageKey(Prefix_MaxTransactionsPerBlock)].Value, 0); } - [ContractMethod(0_01000000, ContractParameterType.Integer, CallFlags = CallFlags.AllowStates)] + [ContractMethod(0_01000000, ContractParameterType.Integer, CallFlags.AllowStates)] private StackItem GetMaxBlockSize(ApplicationEngine engine, Array args) { return GetMaxBlockSize(engine.Snapshot); @@ -89,7 +89,7 @@ public uint GetMaxBlockSize(StoreView snapshot) return BitConverter.ToUInt32(snapshot.Storages[CreateStorageKey(Prefix_MaxBlockSize)].Value, 0); } - [ContractMethod(0_01000000, ContractParameterType.Integer, CallFlags = CallFlags.AllowStates)] + [ContractMethod(0_01000000, ContractParameterType.Integer, CallFlags.AllowStates)] private StackItem GetFeePerByte(ApplicationEngine engine, Array args) { return GetFeePerByte(engine.Snapshot); @@ -100,7 +100,7 @@ public long GetFeePerByte(StoreView snapshot) return BitConverter.ToInt64(snapshot.Storages[CreateStorageKey(Prefix_FeePerByte)].Value, 0); } - [ContractMethod(0_01000000, ContractParameterType.Array, CallFlags = CallFlags.AllowStates)] + [ContractMethod(0_01000000, ContractParameterType.Array, CallFlags.AllowStates)] private StackItem GetBlockedAccounts(ApplicationEngine engine, Array args) { return new Array(engine.ReferenceCounter, GetBlockedAccounts(engine.Snapshot).Select(p => (StackItem)p.ToArray())); @@ -111,7 +111,7 @@ public UInt160[] GetBlockedAccounts(StoreView snapshot) return snapshot.Storages[CreateStorageKey(Prefix_BlockedAccounts)].Value.AsSerializableArray(); } - [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "value" }, CallFlags = CallFlags.AllowModifyStates)] + [ContractMethod(0_03000000, ContractParameterType.Boolean, CallFlags.AllowModifyStates, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "value" })] private StackItem SetMaxBlockSize(ApplicationEngine engine, Array args) { if (!CheckValidators(engine)) return false; @@ -122,7 +122,7 @@ private StackItem SetMaxBlockSize(ApplicationEngine engine, Array args) return true; } - [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "value" }, CallFlags = CallFlags.AllowModifyStates)] + [ContractMethod(0_03000000, ContractParameterType.Boolean, CallFlags.AllowModifyStates, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "value" })] private StackItem SetMaxTransactionsPerBlock(ApplicationEngine engine, Array args) { if (!CheckValidators(engine)) return false; @@ -132,7 +132,7 @@ private StackItem SetMaxTransactionsPerBlock(ApplicationEngine engine, Array arg return true; } - [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "value" }, CallFlags = CallFlags.AllowModifyStates)] + [ContractMethod(0_03000000, ContractParameterType.Boolean, CallFlags.AllowModifyStates, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "value" })] private StackItem SetFeePerByte(ApplicationEngine engine, Array args) { if (!CheckValidators(engine)) return false; @@ -142,7 +142,7 @@ private StackItem SetFeePerByte(ApplicationEngine engine, Array args) return true; } - [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Hash160 }, ParameterNames = new[] { "account" }, CallFlags = CallFlags.AllowModifyStates)] + [ContractMethod(0_03000000, ContractParameterType.Boolean, CallFlags.AllowModifyStates, ParameterTypes = new[] { ContractParameterType.Hash160 }, ParameterNames = new[] { "account" })] private StackItem BlockAccount(ApplicationEngine engine, Array args) { if (!CheckValidators(engine)) return false; @@ -156,7 +156,7 @@ private StackItem BlockAccount(ApplicationEngine engine, Array args) return true; } - [ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Hash160 }, ParameterNames = new[] { "account" }, CallFlags = CallFlags.AllowModifyStates)] + [ContractMethod(0_03000000, ContractParameterType.Boolean, CallFlags.AllowModifyStates, ParameterTypes = new[] { ContractParameterType.Hash160 }, ParameterNames = new[] { "account" })] private StackItem UnblockAccount(ApplicationEngine engine, Array args) { if (!CheckValidators(engine)) return false; diff --git a/src/neo/SmartContract/Native/Tokens/NeoToken.cs b/src/neo/SmartContract/Native/Tokens/NeoToken.cs index 9226c3fccc..fced850f03 100644 --- a/src/neo/SmartContract/Native/Tokens/NeoToken.cs +++ b/src/neo/SmartContract/Native/Tokens/NeoToken.cs @@ -116,7 +116,7 @@ protected override bool OnPersist(ApplicationEngine engine) return true; } - [ContractMethod(0_03000000, ContractParameterType.Integer, ParameterTypes = new[] { ContractParameterType.Hash160, ContractParameterType.Integer }, ParameterNames = new[] { "account", "end" }, CallFlags = CallFlags.AllowStates)] + [ContractMethod(0_03000000, ContractParameterType.Integer, CallFlags.AllowStates, ParameterTypes = new[] { ContractParameterType.Hash160, ContractParameterType.Integer }, ParameterNames = new[] { "account", "end" })] private StackItem UnclaimedGas(ApplicationEngine engine, Array args) { UInt160 account = new UInt160(args[0].GetSpan()); @@ -132,7 +132,7 @@ public BigInteger UnclaimedGas(StoreView snapshot, UInt160 account, uint end) return CalculateBonus(snapshot, state.Balance, state.BalanceHeight, end); } - [ContractMethod(0_05000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.PublicKey }, ParameterNames = new[] { "pubkey" }, CallFlags = CallFlags.AllowModifyStates)] + [ContractMethod(0_05000000, ContractParameterType.Boolean, CallFlags.AllowModifyStates, ParameterTypes = new[] { ContractParameterType.PublicKey }, ParameterNames = new[] { "pubkey" })] private StackItem RegisterValidator(ApplicationEngine engine, Array args) { ECPoint pubkey = args[0].GetSpan().AsSerializable(); @@ -150,7 +150,7 @@ private bool RegisterValidator(StoreView snapshot, ECPoint pubkey) return true; } - [ContractMethod(5_00000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Hash160, ContractParameterType.Array }, ParameterNames = new[] { "account", "pubkeys" }, CallFlags = CallFlags.AllowModifyStates)] + [ContractMethod(5_00000000, ContractParameterType.Boolean, CallFlags.AllowModifyStates, ParameterTypes = new[] { ContractParameterType.Hash160, ContractParameterType.Array }, ParameterNames = new[] { "account", "pubkeys" })] private StackItem Vote(ApplicationEngine engine, Array args) { UInt160 account = new UInt160(args[0].GetSpan()); @@ -193,7 +193,7 @@ private StackItem Vote(ApplicationEngine engine, Array args) return true; } - [ContractMethod(1_00000000, ContractParameterType.Array, CallFlags = CallFlags.AllowStates)] + [ContractMethod(1_00000000, ContractParameterType.Array, CallFlags.AllowStates)] private StackItem GetRegisteredValidators(ApplicationEngine engine, Array args) { return new Array(engine.ReferenceCounter, GetRegisteredValidators(engine.Snapshot).Select(p => new Struct(engine.ReferenceCounter, new StackItem[] { p.PublicKey.ToArray(), p.Votes }))); @@ -209,7 +209,7 @@ public IEnumerable<(ECPoint PublicKey, BigInteger Votes)> GetRegisteredValidator )); } - [ContractMethod(1_00000000, ContractParameterType.Array, CallFlags = CallFlags.AllowStates)] + [ContractMethod(1_00000000, ContractParameterType.Array, CallFlags.AllowStates)] private StackItem GetValidators(ApplicationEngine engine, Array args) { return new Array(engine.ReferenceCounter, GetValidators(engine.Snapshot).Select(p => (StackItem)p.ToArray())); @@ -234,7 +234,7 @@ public ECPoint[] GetValidators(StoreView snapshot) return GetRegisteredValidators(snapshot).Where(p => (p.Votes.Sign > 0) || sv.Contains(p.PublicKey)).OrderByDescending(p => p.Votes).ThenBy(p => p.PublicKey).Select(p => p.PublicKey).Take(count).OrderBy(p => p).ToArray(); } - [ContractMethod(1_00000000, ContractParameterType.Array, CallFlags = CallFlags.AllowStates)] + [ContractMethod(1_00000000, ContractParameterType.Array, CallFlags.AllowStates)] private StackItem GetNextBlockValidators(ApplicationEngine engine, Array args) { return new Array(engine.ReferenceCounter, GetNextBlockValidators(engine.Snapshot).Select(p => (StackItem)p.ToArray())); diff --git a/src/neo/SmartContract/Native/Tokens/Nep5Token.cs b/src/neo/SmartContract/Native/Tokens/Nep5Token.cs index 9e4c98cdf1..5863e9636a 100644 --- a/src/neo/SmartContract/Native/Tokens/Nep5Token.cs +++ b/src/neo/SmartContract/Native/Tokens/Nep5Token.cs @@ -115,25 +115,25 @@ internal protected virtual void Burn(ApplicationEngine engine, UInt160 account, engine.SendNotification(Hash, new Array(new StackItem[] { "Transfer", account.ToArray(), StackItem.Null, amount })); } - [ContractMethod(0, ContractParameterType.String, Name = "name")] + [ContractMethod(0, ContractParameterType.String, CallFlags.None, Name = "name")] protected StackItem NameMethod(ApplicationEngine engine, Array args) { return Name; } - [ContractMethod(0, ContractParameterType.String, Name = "symbol")] + [ContractMethod(0, ContractParameterType.String, CallFlags.None, Name = "symbol")] protected StackItem SymbolMethod(ApplicationEngine engine, Array args) { return Symbol; } - [ContractMethod(0, ContractParameterType.Integer, Name = "decimals")] + [ContractMethod(0, ContractParameterType.Integer, CallFlags.None, Name = "decimals")] protected StackItem DecimalsMethod(ApplicationEngine engine, Array args) { return (uint)Decimals; } - [ContractMethod(0_01000000, ContractParameterType.Integer, CallFlags = CallFlags.AllowStates)] + [ContractMethod(0_01000000, ContractParameterType.Integer, CallFlags.AllowStates)] protected StackItem TotalSupply(ApplicationEngine engine, Array args) { return TotalSupply(engine.Snapshot); @@ -146,7 +146,7 @@ public virtual BigInteger TotalSupply(StoreView snapshot) return new BigInteger(storage.Value); } - [ContractMethod(0_01000000, ContractParameterType.Integer, ParameterTypes = new[] { ContractParameterType.Hash160 }, ParameterNames = new[] { "account" }, CallFlags = CallFlags.AllowStates)] + [ContractMethod(0_01000000, ContractParameterType.Integer, CallFlags.AllowStates, ParameterTypes = new[] { ContractParameterType.Hash160 }, ParameterNames = new[] { "account" })] protected StackItem BalanceOf(ApplicationEngine engine, Array args) { return BalanceOf(engine.Snapshot, new UInt160(args[0].GetSpan())); @@ -160,7 +160,7 @@ public virtual BigInteger BalanceOf(StoreView snapshot, UInt160 account) return state.Balance; } - [ContractMethod(0_08000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Hash160, ContractParameterType.Hash160, ContractParameterType.Integer }, ParameterNames = new[] { "from", "to", "amount" }, CallFlags = CallFlags.AllowModifyStates)] + [ContractMethod(0_08000000, ContractParameterType.Boolean, CallFlags.AllowModifyStates, ParameterTypes = new[] { ContractParameterType.Hash160, ContractParameterType.Hash160, ContractParameterType.Integer }, ParameterNames = new[] { "from", "to", "amount" })] protected StackItem Transfer(ApplicationEngine engine, Array args) { UInt160 from = new UInt160(args[0].GetSpan()); From 4c8ab94a5043bb004fea93b93b2f99ba04db5195 Mon Sep 17 00:00:00 2001 From: Shargon Date: Sat, 18 Apr 2020 22:35:02 +0200 Subject: [PATCH 07/12] Update NeoToken.cs --- src/neo/SmartContract/Native/Tokens/NeoToken.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neo/SmartContract/Native/Tokens/NeoToken.cs b/src/neo/SmartContract/Native/Tokens/NeoToken.cs index 9171daca09..218d8638e6 100644 --- a/src/neo/SmartContract/Native/Tokens/NeoToken.cs +++ b/src/neo/SmartContract/Native/Tokens/NeoToken.cs @@ -225,7 +225,7 @@ private bool Vote(StoreView snapshot, UInt160 account, ECPoint voteTo) } [ContractMethod(1_00000000, ContractParameterType.Array, CallFlags.AllowStates)] - private StackItem GetRegisteredValidators(ApplicationEngine engine, Array args) + private StackItem GetCandidates(ApplicationEngine engine, Array args) { return new Array(engine.ReferenceCounter, GetCandidates(engine.Snapshot).Select(p => new Struct(engine.ReferenceCounter, new StackItem[] { p.PublicKey.ToArray(), p.Votes }))); } From 6555aede4b3b9f7f01f8bcd4aa567a1f0129b860 Mon Sep 17 00:00:00 2001 From: Shargon Date: Sat, 18 Apr 2020 22:35:38 +0200 Subject: [PATCH 08/12] Update NeoToken.cs --- src/neo/SmartContract/Native/Tokens/NeoToken.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neo/SmartContract/Native/Tokens/NeoToken.cs b/src/neo/SmartContract/Native/Tokens/NeoToken.cs index 218d8638e6..bd35c975f1 100644 --- a/src/neo/SmartContract/Native/Tokens/NeoToken.cs +++ b/src/neo/SmartContract/Native/Tokens/NeoToken.cs @@ -135,7 +135,7 @@ public BigInteger UnclaimedGas(StoreView snapshot, UInt160 account, uint end) } [ContractMethod(0_05000000, ContractParameterType.Boolean, CallFlags.AllowModifyStates, ParameterTypes = new[] { ContractParameterType.PublicKey }, ParameterNames = new[] { "pubkey" })] - private StackItem RegisterValidator(ApplicationEngine engine, Array args) + private StackItem RegisterCandidate(ApplicationEngine engine, Array args) { ECPoint pubkey = args[0].GetSpan().AsSerializable(); if (!InteropService.Runtime.CheckWitnessInternal(engine, Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash())) From 36ddfe2bdf3ba8a555a8a0378d4b12c933435ee4 Mon Sep 17 00:00:00 2001 From: Shargon Date: Sat, 18 Apr 2020 22:39:53 +0200 Subject: [PATCH 09/12] Fix merge --- src/neo/SmartContract/Native/Tokens/NeoToken.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/neo/SmartContract/Native/Tokens/NeoToken.cs b/src/neo/SmartContract/Native/Tokens/NeoToken.cs index bd35c975f1..ce91bfa912 100644 --- a/src/neo/SmartContract/Native/Tokens/NeoToken.cs +++ b/src/neo/SmartContract/Native/Tokens/NeoToken.cs @@ -156,7 +156,7 @@ private bool RegisterCandidate(StoreView snapshot, ECPoint pubkey) return true; } - [ContractMethod(0_05000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.PublicKey }, ParameterNames = new[] { "pubkey" })] + [ContractMethod(0_05000000, ContractParameterType.Boolean, CallFlags.AllowModifyStates, ParameterTypes = new[] { ContractParameterType.PublicKey }, ParameterNames = new[] { "pubkey" })] private StackItem UnregisterCandidate(ApplicationEngine engine, Array args) { ECPoint pubkey = args[0].GetSpan().AsSerializable(); @@ -251,7 +251,7 @@ public ECPoint[] GetValidators(StoreView snapshot) return GetCommitteeMembers(snapshot, Blockchain.ValidatorsCount).OrderBy(p => p).ToArray(); } - [ContractMethod(1_00000000, ContractParameterType.Array, SafeMethod = true)] + [ContractMethod(1_00000000, ContractParameterType.Array, CallFlags.AllowStates)] private StackItem GetCommittee(ApplicationEngine engine, Array args) { return new Array(engine.ReferenceCounter, GetCommittee(engine.Snapshot).Select(p => (StackItem)p.ToArray())); From b903177ac7b179c480ef2366cdc09b0924171399 Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 24 Apr 2020 12:12:33 +0200 Subject: [PATCH 10/12] Change GetTime to require states --- src/neo/SmartContract/InteropService.Runtime.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neo/SmartContract/InteropService.Runtime.cs b/src/neo/SmartContract/InteropService.Runtime.cs index aa525c1600..215698f4d5 100644 --- a/src/neo/SmartContract/InteropService.Runtime.cs +++ b/src/neo/SmartContract/InteropService.Runtime.cs @@ -19,7 +19,7 @@ public static class Runtime public static readonly InteropDescriptor Platform = Register("System.Runtime.Platform", Runtime_Platform, 0_00000250, TriggerType.All, CallFlags.None); public static readonly InteropDescriptor GetTrigger = Register("System.Runtime.GetTrigger", Runtime_GetTrigger, 0_00000250, TriggerType.All, CallFlags.None); - public static readonly InteropDescriptor GetTime = Register("System.Runtime.GetTime", Runtime_GetTime, 0_00000250, TriggerType.Application, CallFlags.None); + public static readonly InteropDescriptor GetTime = Register("System.Runtime.GetTime", Runtime_GetTime, 0_00000250, TriggerType.Application, CallFlags.AllowStates); public static readonly InteropDescriptor GetScriptContainer = Register("System.Runtime.GetScriptContainer", Runtime_GetScriptContainer, 0_00000250, TriggerType.All, CallFlags.None); public static readonly InteropDescriptor GetExecutingScriptHash = Register("System.Runtime.GetExecutingScriptHash", Runtime_GetExecutingScriptHash, 0_00000400, TriggerType.All, CallFlags.None); public static readonly InteropDescriptor GetCallingScriptHash = Register("System.Runtime.GetCallingScriptHash", Runtime_GetCallingScriptHash, 0_00000400, TriggerType.All, CallFlags.None); From 211c1bc80c051f71116b58bdc37850a7f44cf888 Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 24 Apr 2020 12:13:44 +0200 Subject: [PATCH 11/12] Change check witness to require states --- src/neo/SmartContract/InteropService.Runtime.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neo/SmartContract/InteropService.Runtime.cs b/src/neo/SmartContract/InteropService.Runtime.cs index 215698f4d5..9942555cba 100644 --- a/src/neo/SmartContract/InteropService.Runtime.cs +++ b/src/neo/SmartContract/InteropService.Runtime.cs @@ -24,7 +24,7 @@ public static class Runtime public static readonly InteropDescriptor GetExecutingScriptHash = Register("System.Runtime.GetExecutingScriptHash", Runtime_GetExecutingScriptHash, 0_00000400, TriggerType.All, CallFlags.None); public static readonly InteropDescriptor GetCallingScriptHash = Register("System.Runtime.GetCallingScriptHash", Runtime_GetCallingScriptHash, 0_00000400, TriggerType.All, CallFlags.None); public static readonly InteropDescriptor GetEntryScriptHash = Register("System.Runtime.GetEntryScriptHash", Runtime_GetEntryScriptHash, 0_00000400, TriggerType.All, CallFlags.None); - public static readonly InteropDescriptor CheckWitness = Register("System.Runtime.CheckWitness", Runtime_CheckWitness, 0_00030000, TriggerType.All, CallFlags.None); + public static readonly InteropDescriptor CheckWitness = Register("System.Runtime.CheckWitness", Runtime_CheckWitness, 0_00030000, TriggerType.All, CallFlags.AllowStates); public static readonly InteropDescriptor GetInvocationCounter = Register("System.Runtime.GetInvocationCounter", Runtime_GetInvocationCounter, 0_00000400, TriggerType.All, CallFlags.None); public static readonly InteropDescriptor Log = Register("System.Runtime.Log", Runtime_Log, 0_01000000, TriggerType.All, CallFlags.AllowNotify); public static readonly InteropDescriptor Notify = Register("System.Runtime.Notify", Runtime_Notify, 0_01000000, TriggerType.All, CallFlags.AllowNotify); From a0a335ec0501b79af555ad6901e88e3059070715 Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 24 Apr 2020 12:36:49 +0200 Subject: [PATCH 12/12] Rename --- src/neo/SmartContract/Native/ContractMethodAttribute.cs | 6 +++--- src/neo/SmartContract/Native/NativeContract.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/neo/SmartContract/Native/ContractMethodAttribute.cs b/src/neo/SmartContract/Native/ContractMethodAttribute.cs index 88c16c870d..6cb745fee5 100644 --- a/src/neo/SmartContract/Native/ContractMethodAttribute.cs +++ b/src/neo/SmartContract/Native/ContractMethodAttribute.cs @@ -10,13 +10,13 @@ internal class ContractMethodAttribute : Attribute public ContractParameterType ReturnType { get; } public ContractParameterType[] ParameterTypes { get; set; } = Array.Empty(); public string[] ParameterNames { get; set; } = Array.Empty(); - public CallFlags CallFlags { get; } + public CallFlags RequiredCallFlags { get; } - public ContractMethodAttribute(long price, ContractParameterType returnType, CallFlags callFlags) + public ContractMethodAttribute(long price, ContractParameterType returnType, CallFlags requiredCallFlags) { this.Price = price; this.ReturnType = returnType; - this.CallFlags = callFlags; + this.RequiredCallFlags = requiredCallFlags; } } } diff --git a/src/neo/SmartContract/Native/NativeContract.cs b/src/neo/SmartContract/Native/NativeContract.cs index 20513dc5e5..ce34011e32 100644 --- a/src/neo/SmartContract/Native/NativeContract.cs +++ b/src/neo/SmartContract/Native/NativeContract.cs @@ -56,12 +56,12 @@ protected NativeContract() ReturnType = attribute.ReturnType, Parameters = attribute.ParameterTypes.Zip(attribute.ParameterNames, (t, n) => new ContractParameterDefinition { Type = t, Name = n }).ToArray() }); - if (!attribute.CallFlags.HasFlag(CallFlags.AllowModifyStates)) safeMethods.Add(name); + if (!attribute.RequiredCallFlags.HasFlag(CallFlags.AllowModifyStates)) safeMethods.Add(name); methods.Add(name, new ContractMethodMetadata { Delegate = (Func)method.CreateDelegate(typeof(Func), this), Price = attribute.Price, - RequiredCallFlags = attribute.CallFlags + RequiredCallFlags = attribute.RequiredCallFlags }); } this.Manifest = new ContractManifest