Skip to content

Commit

Permalink
Eip2537 (NethermindEth#2039)
Browse files Browse the repository at this point in the history
* berlin chainspec

* bring the fix from another branch

* renamed precompiles

* playing with jumps

* struggl

* correct curve picked, fixed numbers

* works, needs polishing

* better, far from perfect

* some mor benchmarks, review of BigInt to UInt conversions

* untested testbit changes

* conversion improvements

* remove bn256 mcl project

* benchmarks with new dirichlet

* statics in pairing

* spans wherever possible

* fix jump experiment

* build fixes and pairing check WIP

* Nethermind/Nethermind.Crypto/ZkSnarks/PairingCheck.cs

* fix Fp

* Fp on BigInt

* running vm tests

* mul and add fine

* back to structs

* add comments

* pairing WIP

* pairing tests

* paaaairing

* lib resolvers

* missing libs

* native lib rename

* native fix

* remove directly added dll

* removing more

* tests master

* new precompiles - placeholders

* copy more libs to the output

* testing cmaked lib

* testing on linux machine

* evm tests

* checking dependencies

* checking dependencies of lib built with make

* testing runtimes

* replacing 384_256 with the one from cmake

* testing evm

* removing previously added files

* lib resolver diag

* nonative loader experiment

* native lib resolver back[

* testing with core libmcl included

* build fix

* various experiments with multiplication

* change namespaces

* change endianness

* NEvm solution

* bls g1 passing tests

* clean up of placeholders

* Common code and Mul and Add passing tests

* add G2 passing tests

* mul G2 tests

* DRY code

* map to diag

* mul by MCL working fine

* P and R fro BLS12

* added missing test cases

* BLS pairing is fine

* some cleaning of namespaces

* more namespace cleanup

* G! multiexp passing tests

* G2 multiexp

* map to G2 passing tests...

* verify order

* ecrecover allocs

* changed the Blake2f instance

* fix potential discount crash

* syntax change

* benchmarks with native

* ref struct and benchmarks

* checking windows only build

* ec recover null input fix

* fix beam sync miss logging (sorry for piggy-backing it on another PR)

* shamatar's lib added

* zk tests passing

* more of shamatar lib bindings

* benchmark arrays

* corrected mul and benchmarks

* vm to shamatar plus removed old benchmarks

* in progress 2537 with shamatar's lib

* shamatar lib resolver

* added shamatar lib for linux and osx

* more of shamatar lib for BLS

* remove warings

* ecrecover fix

* some more namespace changes

* shamatar lib everywhere bls

* map to g2 on shamatar

* remove new builds

* tests to develop

* remove non-avx unused code

Co-authored-by: matilote <mateusz.jedrzejewski@yahoo.pl>
  • Loading branch information
tkstanczak and matilote authored Jun 24, 2020
1 parent 9569b44 commit 878d9cb
Show file tree
Hide file tree
Showing 175 changed files with 7,161 additions and 768 deletions.
2 changes: 1 addition & 1 deletion src/Dirichlet
28 changes: 28 additions & 0 deletions src/Nethermind/Benchmarks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nethermind.Serialization.Js
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nethermind.Abi", "Nethermind.Abi\Nethermind.Abi.csproj", "{81AEA5F7-FC77-42F8-8162-CFC1E402D11B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nethermind.Cryptography.Bls", "Nethermind.Cryptography.Bls\Nethermind.Cryptography.Bls.csproj", "{6234B75E-16E1-4972-A6C7-B6252A9A76A9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nethermind.Dirichlet.Numerics", "..\Dirichlet\Nethermind.Dirichlet.Numerics\Nethermind.Dirichlet.Numerics.csproj", "{A00FEFD6-C90E-46EB-9A79-C3AB6BD58508}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nethermind.Crypto", "Nethermind.Crypto\Nethermind.Crypto.csproj", "{C2CE6F47-CB73-4272-AF65-E5FD6294360C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nethermind.Native", "Nethermind.Native\Nethermind.Native.csproj", "{C7EE6D69-99FA-403C-BF5B-A14173771B92}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -116,6 +124,22 @@ Global
{81AEA5F7-FC77-42F8-8162-CFC1E402D11B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81AEA5F7-FC77-42F8-8162-CFC1E402D11B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81AEA5F7-FC77-42F8-8162-CFC1E402D11B}.Release|Any CPU.Build.0 = Release|Any CPU
{6234B75E-16E1-4972-A6C7-B6252A9A76A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6234B75E-16E1-4972-A6C7-B6252A9A76A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6234B75E-16E1-4972-A6C7-B6252A9A76A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6234B75E-16E1-4972-A6C7-B6252A9A76A9}.Release|Any CPU.Build.0 = Release|Any CPU
{A00FEFD6-C90E-46EB-9A79-C3AB6BD58508}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A00FEFD6-C90E-46EB-9A79-C3AB6BD58508}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A00FEFD6-C90E-46EB-9A79-C3AB6BD58508}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A00FEFD6-C90E-46EB-9A79-C3AB6BD58508}.Release|Any CPU.Build.0 = Release|Any CPU
{C2CE6F47-CB73-4272-AF65-E5FD6294360C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2CE6F47-CB73-4272-AF65-E5FD6294360C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2CE6F47-CB73-4272-AF65-E5FD6294360C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2CE6F47-CB73-4272-AF65-E5FD6294360C}.Release|Any CPU.Build.0 = Release|Any CPU
{C7EE6D69-99FA-403C-BF5B-A14173771B92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7EE6D69-99FA-403C-BF5B-A14173771B92}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7EE6D69-99FA-403C-BF5B-A14173771B92}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7EE6D69-99FA-403C-BF5B-A14173771B92}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{0F53A016-3141-4384-A81F-6444AD116E39} = {57CE427C-455B-47A9-85D6-CEF379DC00F6}
Expand All @@ -130,5 +154,9 @@ Global
{31E5CB97-6437-4AE6-AA8A-7C08749E8D52} = {57CE427C-455B-47A9-85D6-CEF379DC00F6}
{38949E85-406D-4558-AD0D-0D181C1881E2} = {57CE427C-455B-47A9-85D6-CEF379DC00F6}
{81AEA5F7-FC77-42F8-8162-CFC1E402D11B} = {57CE427C-455B-47A9-85D6-CEF379DC00F6}
{6234B75E-16E1-4972-A6C7-B6252A9A76A9} = {57CE427C-455B-47A9-85D6-CEF379DC00F6}
{A00FEFD6-C90E-46EB-9A79-C3AB6BD58508} = {57CE427C-455B-47A9-85D6-CEF379DC00F6}
{C2CE6F47-CB73-4272-AF65-E5FD6294360C} = {57CE427C-455B-47A9-85D6-CEF379DC00F6}
{C7EE6D69-99FA-403C-BF5B-A14173771B92} = {57CE427C-455B-47A9-85D6-CEF379DC00F6}
EndGlobalSection
EndGlobal
4 changes: 3 additions & 1 deletion src/Nethermind/Benchmarks.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Keccak/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nethermind/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Precompiles/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=timestamper/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Shamatar/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=timestamper/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ulongs/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
9 changes: 8 additions & 1 deletion src/Nethermind/EthereumTests.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
#
#
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ethereum.Blockchain.Block.Test", "Ethereum.Blockchain.Block.Test\Ethereum.Blockchain.Block.Test.csproj", "{D841A8D7-BF03-4481-9CCB-014F67318DCA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ethereum.Blockchain.Test", "Ethereum.Blockchain.Test\Ethereum.Blockchain.Test.csproj", "{1717CD2A-1B8A-4F0E-A930-C6DA62AD19C7}"
Expand Down Expand Up @@ -73,6 +73,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ethereum.Blockchain.Legacy.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ethereum.Blockchain.Block.Legacy.Test", "Ethereum.Blockchain.Block.Legacy.Test\Ethereum.Blockchain.Block.Legacy.Test.csproj", "{14DC2EEE-9E39-47B9-9E3D-C75D6CFA2DF5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nethermind.Crypto.Bn256", "Nethermind.Crypto.Bn256\Nethermind.Crypto.Bn256.csproj", "{6E236E7A-939F-47F0-A501-B31841C9874C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -219,6 +221,10 @@ Global
{14DC2EEE-9E39-47B9-9E3D-C75D6CFA2DF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14DC2EEE-9E39-47B9-9E3D-C75D6CFA2DF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{14DC2EEE-9E39-47B9-9E3D-C75D6CFA2DF5}.Release|Any CPU.Build.0 = Release|Any CPU
{6E236E7A-939F-47F0-A501-B31841C9874C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6E236E7A-939F-47F0-A501-B31841C9874C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6E236E7A-939F-47F0-A501-B31841C9874C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6E236E7A-939F-47F0-A501-B31841C9874C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{DD4B1F0B-F939-4BE1-A846-EAA8DDB2B792} = {199F75FD-E02D-4434-B4F0-0B35B63A1D77}
Expand All @@ -239,5 +245,6 @@ Global
{4811B35C-3E42-4876-B4F3-B7AC12F47CE9} = {199F75FD-E02D-4434-B4F0-0B35B63A1D77}
{42D916B0-EE07-445B-9757-BE9FC289EDB9} = {199F75FD-E02D-4434-B4F0-0B35B63A1D77}
{38AF1B0B-E647-4A29-AEF1-D3EF2CCD1DD2} = {199F75FD-E02D-4434-B4F0-0B35B63A1D77}
{6E236E7A-939F-47F0-A501-B31841C9874C} = {199F75FD-E02D-4434-B4F0-0B35B63A1D77}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions src/Nethermind/EthereumTests.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nethermind/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ommer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ommers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Precompiles/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ropsten/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Storages/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
64 changes: 0 additions & 64 deletions src/Nethermind/Nethermind.Benchmark/Evm/Bn128AddBenchmark.cs

This file was deleted.

64 changes: 0 additions & 64 deletions src/Nethermind/Nethermind.Benchmark/Evm/Bn128MulBenchmark.cs

This file was deleted.

64 changes: 0 additions & 64 deletions src/Nethermind/Nethermind.Benchmark/Evm/Bn128PairingBenchmark.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public void Setup()
[Benchmark]
public bool Improved()
{
return _codeInfo.ValidateJump(0);
return _codeInfo.ValidateJump(0, false);
}

[Benchmark]
public bool Current()
{
return _codeInfo.ValidateJump(0);
return _codeInfo.ValidateJump(0, false);
}
}
}
12 changes: 6 additions & 6 deletions src/Nethermind/Nethermind.Core.Test/AddressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void Is_precompiled_1()
byte[] addressBytes = new byte[20];
addressBytes[19] = 1;
Address address = new Address(addressBytes);
Assert.True(address.IsPrecompiled(Frontier.Instance));
Assert.True(address.IsPrecompile(Frontier.Instance));
}

[Test]
Expand All @@ -136,7 +136,7 @@ public void Is_precompiled_4_regression()
byte[] addressBytes = new byte[20];
addressBytes[19] = 4;
Address address = new Address(addressBytes);
Assert.True(address.IsPrecompiled(Frontier.Instance));
Assert.True(address.IsPrecompile(Frontier.Instance));
}

[Test]
Expand All @@ -145,7 +145,7 @@ public void Is_precompiled_5_frontier()
byte[] addressBytes = new byte[20];
addressBytes[19] = 5;
Address address = new Address(addressBytes);
Assert.False(address.IsPrecompiled(Frontier.Instance));
Assert.False(address.IsPrecompile(Frontier.Instance));
}

[Test]
Expand All @@ -154,7 +154,7 @@ public void Is_precompiled_5_byzantium()
byte[] addressBytes = new byte[20];
addressBytes[19] = 5;
Address address = new Address(addressBytes);
Assert.True(address.IsPrecompiled(Byzantium.Instance));
Assert.True(address.IsPrecompile(Byzantium.Instance));
}

[Test]
Expand All @@ -163,7 +163,7 @@ public void Is_precompiled_9_byzantium()
byte[] addressBytes = new byte[20];
addressBytes[19] = 9;
Address address = new Address(addressBytes);
Assert.False(address.IsPrecompiled(Byzantium.Instance));
Assert.False(address.IsPrecompile(Byzantium.Instance));
}

[TestCase(0, false)]
Expand All @@ -172,7 +172,7 @@ public void Is_precompiled_9_byzantium()
public void From_number_for_precompile(int number, bool isPrecompile)
{
Address address = Address.FromNumber((UInt256)number);
Assert.AreEqual(isPrecompile, address.IsPrecompiled(Byzantium.Instance));
Assert.AreEqual(isPrecompile, address.IsPrecompile(Byzantium.Instance));
}

[TestCase(0, "0x24cd2edba056b7c654a50e8201b619d4f624fdda")]
Expand Down
11 changes: 11 additions & 0 deletions src/Nethermind/Nethermind.Core.Test/BytesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,17 @@ public void To_signed_big_int(string hex, int length, string expectedResult)
Assert.AreEqual(BigInteger.Parse(expectedResult), Bytes.FromHexString(hex).ToSignedBigInteger(length));
}

[TestCase("0x0123456789abcdef0123456789abcdef", "0xefcdab8967452301efcdab8967452301")]
[TestCase(
"0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"0xefcdab8967452301efcdab8967452301efcdab8967452301efcdab8967452301")]
public void Can_change_endianness(string hex, string expectedResult)
{
byte[] bytes = Bytes.FromHexString(hex);
Bytes.ChangeEndianness8(bytes);
bytes.ToHexString(true).Should().Be(expectedResult);
}

[TestCase("0x0001020304050607080910111213141516171819202122232425262728293031")]
public void Can_create_bit_array_from_bytes(string hex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 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.Crypto.ZkSnarks;
using Nethermind.Crypto.ZkSnarks.Obsolete;
using NUnit.Framework;

namespace Nethermind.Core.Test.Crypto.ZkSnarks
Expand Down
Loading

0 comments on commit 878d9cb

Please sign in to comment.