Skip to content

Storage.CurrentContext as static variable leads to error when contract's verify method is called #2371

@csmuller

Description

@csmuller

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

  1. Run a Neo network based on the Neo3-preview5 release.
  2. Create, compile, and deploy a simple dummy smart contract like the following one:
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;
    }
}
  1. Send some GAS to the contract's address.
  2. Create a transaction withdrawing GAS from the contract (make sure to attach the correct witnesses).
  3. Send the transaction hex with the calculatenetworkfee RPC method to a neo-node in your network.
  4. Should return the following error: "Smart contract {contract.Hash} verification fault."

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions