Skip to content

Commit

Permalink
Merge branch 'master' into conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored Mar 5, 2023
2 parents 7d75211 + e786ab4 commit 100f97b
Show file tree
Hide file tree
Showing 18 changed files with 355 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

env:
DOTNET_VERSION: 6.0.x
DOTNET_VERSION: 7.0.x

jobs:

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Neo.Benchmarks/Neo.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>Neo</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

<PropertyGroup>
<Copyright>2015-2022 The Neo Project</Copyright>
<VersionPrefix>3.4.0</VersionPrefix>
<VersionPrefix>3.5.0</VersionPrefix>
<Authors>The Neo Project</Authors>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<PackageProjectUrl>https://github.com/neo-project/neo</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
Expand Down
5 changes: 3 additions & 2 deletions src/Neo/Neo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Akka" Version="1.4.40" />
<PackageReference Include="Akka" Version="1.4.47" />
<PackageReference Include="BouncyCastle.NetCore" Version="1.9.0" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.2.16" />
<PackageReference Include="Neo.VM" Version="3.4.0" />
<PackageReference Include="Neo.VM" Version="3.5.0" />
<PackageReference Include="Neo.Cryptography.BLS12_381" Version="0.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/Neo/NeoSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc

public void Dispose()
{
EnsureStopped(LocalNode);
EnsureStopped(Blockchain);
foreach (var p in Plugin.Plugins)
p.Dispose();
EnsureStopped(LocalNode);
// Dispose will call ActorSystem.Terminate()
ActorSystem.Dispose();
ActorSystem.WhenTerminated.Wait();
Expand Down
18 changes: 4 additions & 14 deletions src/Neo/Plugins/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ static Plugin()
{
EnableRaisingEvents = true,
IncludeSubdirectories = true,
NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.LastWrite | NotifyFilters.Size,
NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.CreationTime | NotifyFilters.LastWrite | NotifyFilters.Size,
};
configWatcher.Changed += ConfigWatcher_Changed;
configWatcher.Created += ConfigWatcher_Changed;
configWatcher.Renamed += ConfigWatcher_Changed;
configWatcher.Deleted += ConfigWatcher_Changed;
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}

Expand All @@ -102,20 +104,8 @@ private static void ConfigWatcher_Changed(object sender, FileSystemEventArgs e)
switch (GetExtension(e.Name))
{
case ".json":
try
{
Plugins.FirstOrDefault(p => p.ConfigFile == e.FullPath)?.Configure();
}
catch (FormatException) { }
break;
case ".dll":
if (e.ChangeType != WatcherChangeTypes.Created) return;
if (GetDirectoryName(GetDirectoryName(e.FullPath)) != PluginsDirectory) return;
try
{
LoadPlugin(Assembly.Load(File.ReadAllBytes(e.FullPath)));
}
catch { }
Utility.Log(nameof(Plugin), LogLevel.Warning, $"File {e.Name} is {e.ChangeType}, please restart node.");
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Neo/SmartContract/ApplicationEngine.OpCodePrices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ partial class ApplicationEngine
[OpCode.PUSHINT64] = 1 << 0,
[OpCode.PUSHINT128] = 1 << 2,
[OpCode.PUSHINT256] = 1 << 2,
[OpCode.PUSHT] = 1 << 0,
[OpCode.PUSHF] = 1 << 0,
[OpCode.PUSHA] = 1 << 2,
[OpCode.PUSHNULL] = 1 << 0,
[OpCode.PUSHDATA1] = 1 << 3,
Expand Down
2 changes: 1 addition & 1 deletion src/Neo/SmartContract/ApplicationEngine.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ protected internal void RuntimeLoadScript(byte[] script, CallFlags callFlags, Ar
throw new ArgumentOutOfRangeException(nameof(callFlags));

ExecutionContextState state = CurrentContext.GetState<ExecutionContextState>();
ExecutionContext context = LoadScript(script, configureState: p =>
ExecutionContext context = LoadScript(new Script(script, true), configureState: p =>
{
p.CallingContext = CurrentContext;
p.CallFlags = callFlags & state.CallFlags & CallFlags.ReadOnly;
Expand Down
1 change: 1 addition & 0 deletions src/Neo/SmartContract/Native/ContractManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ internal override async ContractTask OnPersist(ApplicationEngine engine)
Hash = contract.Hash,
Manifest = contract.Manifest
}));
engine.Snapshot.Add(CreateStorageKey(Prefix_ContractHash).AddBigEndian(contract.Id), new StorageItem(contract.Hash.ToArray()));
await contract.Initialize(engine);
}
}
Expand Down
134 changes: 134 additions & 0 deletions src/Neo/SmartContract/Native/CryptoLib.BLS12_381.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
using Neo.Cryptography.BLS12_381;
using Neo.VM.Types;
using System;

namespace Neo.SmartContract.Native;

partial class CryptoLib
{
/// <summary>
/// Serialize a bls12381 point.
/// </summary>
/// <param name="g">The point to be serialized.</param>
/// <returns></returns>
[ContractMethod(CpuFee = 1 << 19)]
public static byte[] Bls12381Serialize(InteropInterface g)
{
return g.GetInterface<object>() switch
{
G1Affine p => p.ToCompressed(),
G1Projective p => new G1Affine(p).ToCompressed(),
G2Affine p => p.ToCompressed(),
G2Projective p => new G2Affine(p).ToCompressed(),
Gt p => p.ToArray(),
_ => throw new ArgumentException($"Bls12381 operation fault, type:format, error:type mismatch")
};
}

/// <summary>
/// Deserialize a bls12381 point.
/// </summary>
/// <param name="data">The point as byte array.</param>
/// <returns></returns>
[ContractMethod(CpuFee = 1 << 19)]
public static InteropInterface Bls12381Deserialize(byte[] data)
{
return data.Length switch
{
48 => new InteropInterface(G1Affine.FromCompressed(data)),
96 => new InteropInterface(G2Affine.FromCompressed(data)),
576 => new InteropInterface(Gt.FromBytes(data)),
_ => throw new ArgumentException($"Bls12381 operation fault, type:format, error:valid point length"),
};
}

/// <summary>
/// Determines whether the specified points are equal.
/// </summary>
/// <param name="x">The first point.</param>
/// <param name="y">Teh second point.</param>
/// <returns><c>true</c> if the specified points are equal; otherwise, <c>false</c>.</returns>
[ContractMethod(CpuFee = 1 << 5)]
public static bool Bls12381Equal(InteropInterface x, InteropInterface y)
{
return (x.GetInterface<object>(), y.GetInterface<object>()) switch
{
(G1Affine p1, G1Affine p2) => p1.Equals(p2),
(G1Projective p1, G1Projective p2) => p1.Equals(p2),
(G2Affine p1, G2Affine p2) => p1.Equals(p2),
(G2Projective p1, G2Projective p2) => p1.Equals(p2),
(Gt p1, Gt p2) => p1.Equals(p2),
_ => throw new ArgumentException($"Bls12381 operation fault, type:format, error:type mismatch")
};
}

/// <summary>
/// Add operation of two points.
/// </summary>
/// <param name="x">The first point.</param>
/// <param name="y">The second point.</param>
/// <returns></returns>
[ContractMethod(CpuFee = 1 << 19)]
public static InteropInterface Bls12381Add(InteropInterface x, InteropInterface y)
{
return (x.GetInterface<object>(), y.GetInterface<object>()) switch
{
(G1Affine p1, G1Affine p2) => new(new G1Projective(p1) + p2),
(G1Affine p1, G1Projective p2) => new(p1 + p2),
(G1Projective p1, G1Affine p2) => new(p1 + p2),
(G1Projective p1, G1Projective p2) => new(p1 + p2),
(G2Affine p1, G2Affine p2) => new(new G2Projective(p1) + p2),
(G2Affine p1, G2Projective p2) => new(p1 + p2),
(G2Projective p1, G2Affine p2) => new(p1 + p2),
(G2Projective p1, G2Projective p2) => new(p1 + p2),
(Gt p1, Gt p2) => new(p1 + p2),
_ => throw new ArgumentException($"Bls12381 operation fault, type:format, error:type mismatch")
};
}

/// <summary>
/// Mul operation of gt point and multiplier
/// </summary>
/// <param name="x">The point</param>
/// <param name="mul">Multiplier,32 bytes,little-endian</param>
/// <param name="neg">negative number</param>
/// <returns></returns>
[ContractMethod(CpuFee = 1 << 21)]
public static InteropInterface Bls12381Mul(InteropInterface x, byte[] mul, bool neg)
{
Scalar X = neg ? -Scalar.FromBytes(mul) : Scalar.FromBytes(mul);
return x.GetInterface<object>() switch
{
G1Affine p => new(p * X),
G1Projective p => new(p * X),
G2Affine p => new(p * X),
G2Projective p => new(p * X),
Gt p => new(p * X),
_ => throw new ArgumentException($"Bls12381 operation fault, type:format, error:type mismatch")
};
}

/// <summary>
/// Pairing operation of g1 and g2
/// </summary>
/// <param name="g1">The g1 point.</param>
/// <param name="g2">The g2 point.</param>
/// <returns></returns>
[ContractMethod(CpuFee = 1 << 23)]
public static InteropInterface Bls12381Pairing(InteropInterface g1, InteropInterface g2)
{
G1Affine g1a = g1.GetInterface<object>() switch
{
G1Affine g => g,
G1Projective g => new(g),
_ => throw new ArgumentException($"Bls12381 operation fault, type:format, error:type mismatch")
};
G2Affine g2a = g2.GetInterface<object>() switch
{
G2Affine g => g,
G2Projective g => new(g),
_ => throw new ArgumentException($"Bls12381 operation fault, type:format, error:type mismatch")
};
return new(Bls12.Pairing(in g1a, in g2a));
}
}
2 changes: 1 addition & 1 deletion src/Neo/SmartContract/Native/CryptoLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Neo.SmartContract.Native
/// <summary>
/// A native contract library that provides cryptographic algorithms.
/// </summary>
public sealed class CryptoLib : NativeContract
public sealed partial class CryptoLib : NativeContract
{
private static readonly Dictionary<NamedCurve, ECCurve> curves = new()
{
Expand Down
12 changes: 6 additions & 6 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions tests/Neo.UnitTests/Neo.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka.TestKit" Version="1.4.40" />
<PackageReference Include="Akka.TestKit.Xunit2" Version="1.4.40" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="Akka.TestKit" Version="1.4.47" />
<PackageReference Include="Akka.TestKit.Xunit2" Version="1.4.47" />
<PackageReference Include="Moq" Version="4.18.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 100f97b

Please sign in to comment.