Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions src/neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public partial class ApplicationEngine : ExecutionEngine
/// The maximum cost that can be spent when a contract is executed in test mode.
/// </summary>
public const long TestModeGas = 20_00000000;
private const long MAX_REFUEL = 1_00000000;

/// <summary>
/// Triggered when a contract calls System.Runtime.Notify.
Expand All @@ -41,6 +42,7 @@ public partial class ApplicationEngine : ExecutionEngine
private static IApplicationEngineProvider applicationEngineProvider;
private static Dictionary<uint, InteropDescriptor> services;
private long gas_amount;
private long gas_refuel = 0;
private List<NotifyEventArgs> notifications;
private List<IDisposable> disposables;
private readonly Dictionary<UInt160, int> invocationCounter = new();
Expand Down Expand Up @@ -160,6 +162,9 @@ internal void Refuel(long gas)
{
checked
{
gas_refuel += gas;
if (gas_refuel > MAX_REFUEL)
throw new InvalidOperationException();
gas_amount += gas;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/neo/SmartContract/Native/GasToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal override async ContractTask OnPersist(ApplicationEngine engine)
[ContractMethod(CpuFee = 1 << 15, RequiredCallFlags = CallFlags.States | CallFlags.AllowNotify)]
private async ContractTask Refuel(ApplicationEngine engine, UInt160 account, long amount)
{
if (amount < 0) throw new ArgumentOutOfRangeException(nameof(amount));
if (amount <= 0) throw new ArgumentOutOfRangeException(nameof(amount));
if (!engine.CheckWitnessInternal(account)) throw new InvalidOperationException();
await Burn(engine, account, amount);
engine.Refuel(amount);
Expand Down