Describe the bug
When I use the Storage.CurrentContext for a static field variable in a smart contract I cannot successfully call the calculatenetworkfee RPC method with a transaction that withdraws tokens from that contract.
To Reproduce
class DotnetContract : SmartContract
{
private static StorageContext sc = Storage.CurrentContext;
public static bool verify() {
return true;
}
public static void onNEP17Payment(UInt160 from, int amount, object data) {
return;
}
}
calculatenetworkfee RPC method to a neo-node in your network.Do the same but without the static StorageContext variable. Then it should work.
Expected behavior
Calling the calculatenetworkfee method with a transaction that withdraws tokens from a contract successfully calls the verify method and ends in VM state HALT even if the contract uses Storage.CurrentContext for a static field variable.
It would be cool if someone could take a look at this asap since it's affecting the functionality of "withdrawing assets from smart contracts" in neow3j, as well as some tests.
Looks like this to me:
--- a/src/neo/Wallets/Wallet.cs
+++ b/src/neo/Wallets/Wallet.cs
@@ -398,7 +398,7 @@ namespace Neo.Wallets
// Check verify cost
using ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.CreateSnapshot());
- engine.LoadContract(contract, md, CallFlags.None);
+ engine.LoadContract(contract, md, CallFlags.ReadOnly);
if (NativeContract.IsNative(hash)) engine.Push("verify");
if (engine.Execute() == VMState.FAULT) throw new ArgumentException($"Smart contract {contract.Hash} verification fault.");
if (!engine.ResultStack.Pop().GetBoolean()) throw new ArgumentException($"Smart contract {contract.Hash} returns false.");
It is because syscall of GetStorage require Read callFlags, so it failed when call with CallFlags.None.
Most helpful comment
Looks like this to me: