Skip to content

Commit

Permalink
Added Blake2Fast lib #816
Browse files Browse the repository at this point in the history
  • Loading branch information
spetz committed Aug 23, 2019
1 parent dba208e commit 12f6ec1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Evm/Metrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ public class Metrics
public static long ModExpPrecompile { get; set; }
public static long Ripemd160Precompile { get; set; }
public static long Sha256Precompile { get; set; }
public static long Blake2BPrecompile { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Evm/Nethermind.Evm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="1.2.2" />
<PackageReference Include="SauceControl.Blake2Fast" Version="1.0.0" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2018 Demerzel Solutions Limited
* This file is part of the Nethermind library.
*
* The Nethermind library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Nethermind library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
*/

using Nethermind.Core;
using Nethermind.Core.Crypto.ZkSnarks;
using Nethermind.Core.Extensions;
using Nethermind.Core.Specs;
using SauceControl.Blake2Fast;

namespace Nethermind.Evm.Precompiles
{
public class Blake2BPrecompiledContract : IPrecompiledContract
{
public static readonly IPrecompiledContract Instance = new Blake2BPrecompiledContract();

public Address Address { get; } = Address.FromNumber(9);

public long BaseGasCost(IReleaseSpec releaseSpec) => 0;

public long DataGasCost(byte[] inputData, IReleaseSpec releaseSpec) => 12;

public (byte[], bool) Run(byte[] inputData)
{
Metrics.Blake2BPrecompile++;

return (inputData, true);
}
}
}
3 changes: 2 additions & 1 deletion src/Nethermind/Nethermind.Evm/VirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ private void InitializePrecompiledContracts()
[Bn128AddPrecompiledContract.Instance.Address] = Bn128AddPrecompiledContract.Instance,
[Bn128MulPrecompiledContract.Instance.Address] = Bn128MulPrecompiledContract.Instance,
[Bn128PairingPrecompiledContract.Instance.Address] = Bn128PairingPrecompiledContract.Instance,
[ModExpPrecompiledContract.Instance.Address] = ModExpPrecompiledContract.Instance
[ModExpPrecompiledContract.Instance.Address] = ModExpPrecompiledContract.Instance,
[Blake2BPrecompiledContract.Instance.Address] = Blake2BPrecompiledContract.Instance,
};
}

Expand Down

0 comments on commit 12f6ec1

Please sign in to comment.