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

Add zkp - Groth16 #2691

Merged
merged 128 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
6b9cb8c
Merge pull request #16 from neo-project/master
longfeiWan9 Jul 20, 2020
69d2b45
Merge pull request #17 from neo-project/master
longfeiWan9 Jul 31, 2020
61fa3a5
Merge pull request #3 from neo-project/master
longfeiWan9 Nov 3, 2020
9866e97
Merge branch 'master' of https://github.com/neo-ngd/neo
Ashuaidehao Nov 3, 2020
4abe12f
Merge pull request #4 from neo-project/master
Ashuaidehao Dec 21, 2020
c80b546
Merge pull request #5 from neo-project/master
Ashuaidehao Feb 3, 2021
1363486
Merge https://github.com/neo-project/neo
Ashuaidehao Mar 5, 2021
69f33cd
Merge https://github.com/neo-project/neo
Ashuaidehao Mar 8, 2021
7c001f1
Merge https://github.com/neo-project/neo
Ashuaidehao Mar 10, 2021
3f06ee3
Merge https://github.com/neo-project/neo
Ashuaidehao Mar 15, 2021
bbabfde
Merge https://github.com/neo-project/neo
Ashuaidehao Mar 17, 2021
28f874a
Merge https://github.com/neo-project/neo
Ashuaidehao Mar 18, 2021
1aebbe6
Merge branch 'master' of https://github.com/neo-ngd/neo
Ashuaidehao Apr 25, 2021
88c17f3
Merge https://github.com/neo-project/neo
Ashuaidehao Apr 25, 2021
c2d2629
Merge https://github.com/neo-project/neo
Ashuaidehao May 7, 2021
9603c84
Merge pull request #6 from neo-project/master
Ashuaidehao Jun 9, 2021
9d1b65d
Merge branch 'neo-project:master' into master
vang1ong7ang Jul 14, 2021
815001c
Merge https://github.com/neo-project/neo
Ashuaidehao Jul 20, 2021
326adee
Merge branch 'master' of https://github.com/neo-ngd/neo
Ashuaidehao Jul 20, 2021
0d081a9
Merge https://github.com/neo-project/neo
Ashuaidehao Aug 2, 2021
5468abd
Merge https://github.com/neo-project/neo
Ashuaidehao Aug 4, 2021
26e9b6d
Merge https://github.com/neo-project/neo
Ashuaidehao Aug 8, 2021
26444b1
Merge branch 'neo-project:master' into master
doubiliu Jan 6, 2022
30907ec
Merge https://github.com/neo-project/neo
Ashuaidehao Mar 1, 2022
4523a46
Merge branch 'master' of https://github.com/neo-ngd/neo
Ashuaidehao Mar 1, 2022
45ee380
add bls12381
passer-byzhang Mar 16, 2022
57195d3
fixed
passer-byzhang Mar 16, 2022
c44cd5e
fixed
passer-byzhang Mar 16, 2022
7ba9ef6
fixed
passer-byzhang Mar 16, 2022
133a310
change function name
passer-byzhang Mar 17, 2022
1473e15
update
passer-byzhang Mar 17, 2022
e3fcfa5
update
passer-byzhang Mar 17, 2022
c54b909
Merge pull request #10 from passer-byzhang/master
doubiliu Mar 18, 2022
1823a3e
format
doubiliu Mar 18, 2022
d8367f9
format
doubiliu Mar 18, 2022
7087b77
fixed format
passer-byzhang Mar 23, 2022
e028ac3
Merge pull request #13 from passer-byzhang/Add-zkp
doubiliu Mar 28, 2022
ba51c8d
format
doubiliu Mar 28, 2022
e867061
add neg function && fixed IntPtr alloc
passer-byzhang Mar 28, 2022
dff905e
Fix bug
doubiliu Mar 28, 2022
d390b07
Merge branch 'neo-ngd:Add-zkp' into Add-zkp
passer-byzhang Mar 28, 2022
9841a12
Merge pull request #14 from passer-byzhang/Add-zkp
doubiliu Mar 28, 2022
22e9dae
format
doubiliu Mar 29, 2022
5a9c8eb
Fix bug
doubiliu Mar 29, 2022
e43f95b
Fix
doubiliu Apr 8, 2022
79d819f
Fix bug
doubiliu Apr 8, 2022
9750950
Fix bug
doubiliu Apr 8, 2022
5dcc45a
format
doubiliu Apr 8, 2022
e1bcc3d
format
ZhangTao1596 Apr 8, 2022
0fdb595
Update src/neo/Cryptography/Bls12381.cs
doubiliu Apr 8, 2022
f1781d6
Update src/neo/Cryptography/Bls12381.cs
doubiliu Apr 8, 2022
1793561
Update src/neo/Cryptography/Bls12381.cs
doubiliu Apr 8, 2022
2497ac3
Update src/neo/Cryptography/Bls12381.cs
doubiliu Apr 8, 2022
2229ecb
Update src/neo/Cryptography/Bls12381.cs
doubiliu Apr 8, 2022
f645bfc
Fix bug
doubiliu Apr 8, 2022
5530808
format
doubiliu Apr 8, 2022
9517011
remove unused
doubiliu Apr 9, 2022
7ca644e
Add linux support
doubiliu Apr 9, 2022
f70d022
Update src/neo/Cryptography/Bls12381.cs
doubiliu Apr 11, 2022
5887f69
Update src/neo/Cryptography/Bls12381.cs
doubiliu Apr 11, 2022
afa01bd
Update src/neo/Cryptography/Bls12381.cs
doubiliu Apr 11, 2022
7c95e1a
Update src/neo/Cryptography/Bls12381.cs
doubiliu Apr 11, 2022
bc1d30d
Update src/neo/Cryptography/Bls12381.cs
doubiliu Apr 11, 2022
7f3d7d1
Update src/neo/Cryptography/Bls12381.cs
doubiliu Apr 11, 2022
a39ba86
Update src/neo/Cryptography/Bls12381.cs
doubiliu Apr 11, 2022
1fd3ba6
Update src/neo/Cryptography/Bls12381.cs
doubiliu Apr 11, 2022
ae7773c
Fix bug
doubiliu Apr 11, 2022
75bded8
change function name
doubiliu Apr 11, 2022
d699c33
change nuget
doubiliu Apr 19, 2022
2a2fe06
Fix conflicts
doubiliu Apr 19, 2022
53816ed
Fix bug
doubiliu Apr 19, 2022
0563056
fix bug
doubiliu Apr 19, 2022
54f51fc
move BLS helper to nuget
doubiliu Apr 20, 2022
a1f9f11
format and remove unused class
doubiliu Apr 21, 2022
6abb1dc
change nuget ref
doubiliu Apr 26, 2022
e48e7c2
Fix bug
doubiliu May 26, 2022
3e61251
Fix bug
doubiliu May 26, 2022
fba8eed
change ref
doubiliu May 26, 2022
e00f82e
change price
doubiliu May 26, 2022
8d458ff
change gas fee
doubiliu May 27, 2022
f4fa786
Merge branch 'master' into Add-zkp
doubiliu May 27, 2022
18f69cc
Update neo.csproj
erikzhang May 28, 2022
873fb43
move function to native contract
doubiliu May 28, 2022
c268bd2
Merge branch 'Add-zkp' of github.com:neo-ngd/neo into Add-zkp
doubiliu May 28, 2022
00bf507
Merge branch 'master' of https://github.com/neo-ngd/neo
Ashuaidehao Jun 6, 2022
7d7c595
Merge https://github.com/neo-project/neo
Ashuaidehao Jun 6, 2022
387b919
solve conflict
doubiliu Jun 16, 2022
3cf934d
Fix bug
doubiliu Jun 16, 2022
f6a71cc
Fix conflicts
doubiliu Jul 14, 2022
1919e1d
Fix UT
doubiliu Jul 15, 2022
0a031bd
solve conflicts
doubiliu Jul 15, 2022
6a9036d
Fix bug
doubiliu Jul 15, 2022
b7738ff
Update Neo.csproj
shargon Jul 15, 2022
b239da7
Update Neo.csproj
erikzhang Jul 16, 2022
f96d4c0
Move bls12381 code to a separate file
erikzhang Jul 16, 2022
5a25ec9
Update CryptoLib.BLS12_381.cs
erikzhang Jul 16, 2022
2b12b88
Update CryptoLib.BLS12_381.cs
erikzhang Jul 16, 2022
3e76942
Apply suggestions from code review
erikzhang Jul 16, 2022
cbec831
change compress to memorymarshal
doubiliu Jul 19, 2022
1bf380b
Add negative number
doubiliu Jul 19, 2022
7eae8bd
change Multiplier range
doubiliu Jul 20, 2022
7442d36
Format UT
shargon Jul 21, 2022
6400a00
rename
doubiliu Jul 21, 2022
955119e
merge
doubiliu Jul 21, 2022
6e9354e
fix ut
doubiliu Jul 21, 2022
ff9acfc
Merge branch 'master' into Add-zkp
erikzhang Jul 23, 2022
aeb657a
Merge branch 'master' of https://github.com/neo-ngd/neo
Ashuaidehao Aug 16, 2022
8df287e
Merge github.com:neo-project/neo
Ashuaidehao Aug 16, 2022
ec73b0d
Merge branch 'neo-project:master' into master
doubiliu Sep 18, 2022
fbd9e4f
update
lmy0930 Sep 18, 2022
f521c4a
fix
lmy0930 Sep 18, 2022
a985eb3
Merge https://github.com/neo-project/neo
Ashuaidehao Dec 14, 2022
105e849
Merge branch 'neo-project:master' into master
doubiliu Jan 9, 2023
8e4b400
fix conflicts
doubiliu Jan 9, 2023
5ccb6b7
update
doubiliu Jan 10, 2023
cb154f7
fix
doubiliu Jan 10, 2023
f3ac452
Indent
shargon Jan 10, 2023
344ed83
Neo.Cryptography.BLS12_381 0.2.0
erikzhang Jan 18, 2023
9dbce44
Use InteropInterface
erikzhang Jan 18, 2023
c48cb61
Remove RequiresPreviewFeatures
erikzhang Jan 18, 2023
7bb9297
Fix Bls12381Pairing
erikzhang Jan 18, 2023
5fee2cb
Add Bls12381Equal
erikzhang Jan 18, 2023
3baba14
update UT
doubiliu Jan 19, 2023
b38a4a2
Merge branch 'master' into Add-zkp
shargon Jan 19, 2023
8d9038d
Merge branch 'master' into Add-zkp
erikzhang Feb 5, 2023
248c39e
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
doubiliu Feb 6, 2023
f506922
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
doubiliu Feb 6, 2023
29bc3b2
Update CryptoLib.BLS12_381.cs
erikzhang Feb 6, 2023
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
1 change: 1 addition & 0 deletions src/Neo/Neo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="BouncyCastle.NetCore" Version="1.9.0" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.2.16" />
<PackageReference Include="Neo.VM" Version="3.5.0" />
<PackageReference Include="Neo.Cryptography.BLS12_381" Version="0.2.0" />
</ItemGroup>

<ItemGroup>
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
Loading