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 fee of CreateMultisigAccount #2712

Merged
merged 7 commits into from
May 5, 2022
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
17 changes: 17 additions & 0 deletions src/neo/Hardfork.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (C) 2015-2022 The Neo Project.
//
// The neo is free software distributed under the MIT software license,
// see the accompanying file LICENSE in the main directory of the
// project or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

namespace Neo
{
public enum Hardfork : byte
{
HF_2712_FixSyscallFees
}
}
11 changes: 9 additions & 2 deletions src/neo/ProtocolSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Neo.SmartContract.Native;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;

namespace Neo
Expand Down Expand Up @@ -88,6 +89,8 @@ public record ProtocolSettings
/// </summary>
public IReadOnlyDictionary<string, uint[]> NativeUpdateHistory { get; init; }

public ImmutableDictionary<Hardfork, uint> Hardforks { get; init; }

/// <summary>
/// Indicates the amount of gas to distribute during initialization.
/// </summary>
Expand Down Expand Up @@ -157,7 +160,8 @@ public record ProtocolSettings
[nameof(PolicyContract)] = new[] { 0u },
[nameof(RoleManagement)] = new[] { 0u },
[nameof(OracleContract)] = new[] { 0u }
}
},
Hardforks = ImmutableDictionary<Hardfork, uint>.Empty
};

/// <summary>
Expand Down Expand Up @@ -198,7 +202,10 @@ public static ProtocolSettings Load(IConfigurationSection section)
InitialGasDistribution = section.GetValue("InitialGasDistribution", Default.InitialGasDistribution),
NativeUpdateHistory = section.GetSection("NativeUpdateHistory").Exists()
? section.GetSection("NativeUpdateHistory").GetChildren().ToDictionary(p => p.Key, p => p.GetChildren().Select(q => uint.Parse(q.Value)).ToArray())
: Default.NativeUpdateHistory
: Default.NativeUpdateHistory,
Hardforks = section.GetSection("Hardforks").Exists()
? section.GetSection("Hardforks").GetChildren().ToImmutableDictionary(p => Enum.Parse<Hardfork>(p.Key), p => uint.Parse(p.Value))
: Default.Hardforks
};
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/neo/SmartContract/ApplicationEngine.Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ partial class ApplicationEngine
/// The <see cref="InteropDescriptor"/> of System.Contract.CreateStandardAccount.
/// Calculates corresponding account scripthash for the given public key.
/// </summary>
public static readonly InteropDescriptor System_Contract_CreateStandardAccount = Register("System.Contract.CreateStandardAccount", nameof(CreateStandardAccount), 1 << 8, CallFlags.None);
public static readonly InteropDescriptor System_Contract_CreateStandardAccount = Register("System.Contract.CreateStandardAccount", nameof(CreateStandardAccount), 0, CallFlags.None);

/// <summary>
/// The <see cref="InteropDescriptor"/> of System.Contract.CreateMultisigAccount.
/// Calculates corresponding multisig account scripthash for the given public keys.
/// </summary>
public static readonly InteropDescriptor System_Contract_CreateMultisigAccount = Register("System.Contract.CreateMultisigAccount", nameof(CreateMultisigAccount), 1 << 8, CallFlags.None);
public static readonly InteropDescriptor System_Contract_CreateMultisigAccount = Register("System.Contract.CreateMultisigAccount", nameof(CreateMultisigAccount), 0, CallFlags.None);

/// <summary>
/// The <see cref="InteropDescriptor"/> of System.Contract.NativeOnPersist.
Expand Down Expand Up @@ -120,8 +120,12 @@ protected internal CallFlags GetCallFlags()
/// </summary>
/// <param name="pubKey">The public key of the account.</param>
/// <returns>The hash of the account.</returns>
internal protected static UInt160 CreateStandardAccount(ECPoint pubKey)
internal protected UInt160 CreateStandardAccount(ECPoint pubKey)
{
long fee = IsHardforkEnabled(Hardfork.HF_2712_FixSyscallFees)
? CheckSigPrice
: 1 << 8;
AddGas(fee * ExecFeeFactor);
return Contract.CreateSignatureRedeemScript(pubKey).ToScriptHash();
}

Expand All @@ -132,8 +136,12 @@ internal protected static UInt160 CreateStandardAccount(ECPoint pubKey)
/// <param name="m">The minimum number of correct signatures that need to be provided in order for the verification to pass.</param>
/// <param name="pubKeys">The public keys of the account.</param>
/// <returns>The hash of the account.</returns>
internal protected static UInt160 CreateMultisigAccount(int m, ECPoint[] pubKeys)
internal protected UInt160 CreateMultisigAccount(int m, ECPoint[] pubKeys)
{
long fee = IsHardforkEnabled(Hardfork.HF_2712_FixSyscallFees)
? CheckSigPrice * pubKeys.Length
: 1 << 8;
AddGas(fee * ExecFeeFactor);
return Contract.CreateMultiSigRedeemScript(m, pubKeys).ToScriptHash();
}

Expand Down
9 changes: 9 additions & 0 deletions src/neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,5 +579,14 @@ public void SetState<T>(T state)
states ??= new Dictionary<Type, object>();
states[typeof(T)] = state;
}

private bool IsHardforkEnabled(Hardfork hardfork)
{
if (PersistingBlock is null)
return true;
if (!ProtocolSettings.Hardforks.TryGetValue(hardfork, out uint height))
return true;
return PersistingBlock.Index >= height;
}
}
}
2 changes: 1 addition & 1 deletion tests/neo.UnitTests/SmartContract/UT_InteropService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public void TestContract_Destroy()
public void TestContract_CreateStandardAccount()
{
ECPoint pubkey = ECPoint.Parse("024b817ef37f2fc3d4a33fe36687e592d9f30fe24b3e28187dc8f12b3b3b2b839e", ECCurve.Secp256r1);
ApplicationEngine.CreateStandardAccount(pubkey).ToArray().ToHexString().Should().Be("c44ea575c5f79638f0e73f39d7bd4b3337c81691");
GetEngine().CreateStandardAccount(pubkey).ToArray().ToHexString().Should().Be("c44ea575c5f79638f0e73f39d7bd4b3337c81691");
}

public static void LogEvent(object sender, LogEventArgs args)
Expand Down