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

BLS tests: cover both implementations #2490

Merged
merged 105 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
fc11c9f
Draft initial experiments
Nashatyrev Jun 25, 2020
1532577
Merge remote-tracking branch 'pegasys/master' into experimental-supra
Nashatyrev Jul 3, 2020
745ca3a
Add JNA library draft
Nashatyrev Jul 7, 2020
f442a69
Move SWIG wrappers to a separate package
Nashatyrev Jul 7, 2020
986c4a8
Updated SWIG wrappers
Nashatyrev Jul 9, 2020
3eff96d
Initial BLS Blst classes. Tests updated
Nashatyrev Jul 9, 2020
7413682
Merge remote-tracking branch 'pegasys/master' into experimental-supra
Nashatyrev Jul 10, 2020
5cb89b4
Update the draft
Nashatyrev Jul 10, 2020
54f7a01
Merge remote-tracking branch 'pegasys/master' into experimental-supra
Nashatyrev Jul 15, 2020
9256c93
temp commit
Nashatyrev Jul 15, 2020
67b1a9d
Upgrade blst classes
Nashatyrev Jul 16, 2020
f8da728
Update tests
Nashatyrev Jul 16, 2020
a7439d5
Update dll
Nashatyrev Jul 16, 2020
939e301
Temp disable json-simple lib
Nashatyrev Jul 16, 2020
7fd531b
Initial draft for BLS interfaces
Nashatyrev Jul 16, 2020
69300d6
exclude outdated junit transitive dependency from json-simple module
Nashatyrev Jul 16, 2020
8724e7f
Rename test file to Win compatible
Nashatyrev Jul 16, 2020
84691cd
Merge branch 'fix-bls-tests-1' into feature-bls-interfaces
Nashatyrev Jul 16, 2020
a8bafde
Another portion of draft changes
Nashatyrev Jul 17, 2020
b5762f4
Adjust bls tests by separating them to abstract and implementation sp…
Nashatyrev Jul 17, 2020
27aace7
Add NoopBLS12381 implementation
Nashatyrev Jul 17, 2020
5f93ac4
Fix warnings
Nashatyrev Jul 17, 2020
7c4faf6
Fix more warns
Nashatyrev Jul 17, 2020
c221980
Merge remote-tracking branch 'pegasys/master' into feature-bls-interf…
Nashatyrev Jul 17, 2020
8c41c8d
Resolve merge conflicts
Nashatyrev Jul 17, 2020
aab091f
Fix the test
Nashatyrev Jul 17, 2020
2040313
Fix the test
Nashatyrev Jul 20, 2020
69313d7
Merge remote-tracking branch 'pegasys/master' into feature-bls-interf…
Nashatyrev Jul 20, 2020
59e59c1
Merge branch 'feature-bls-interfaces' into experimental-supra
Nashatyrev Jul 20, 2020
5b48be7
Remove JNA binding
Nashatyrev Jul 20, 2020
6c4314b
Move Blst code to the appropriate package, rename classes
Nashatyrev Jul 20, 2020
3c653a5
Derive Blst classes from common impl interfaces
Nashatyrev Jul 20, 2020
edf288a
Merge remote-tracking branch 'pegasys/master' into feature-blst
Nashatyrev Jul 21, 2020
a6aafa1
Load native library from resources
Nashatyrev Jul 21, 2020
763bdde
BlstSecretKey should be created from 48 bytes and return 48 bytes fro…
Nashatyrev Jul 21, 2020
950622b
Make Mikuli specific test relying on the mikuli implementation
Nashatyrev Jul 21, 2020
c20d6cb
Merge remote-tracking branch 'pegasys/master' into feature-blst
Nashatyrev Jul 21, 2020
d32eed8
Add latest Blst DLL
Nashatyrev Jul 21, 2020
28f099a
Merge remote-tracking branch 'pegasys/master' into feature-blst
Nashatyrev Jul 22, 2020
cc7f83b
BlstSecretKey is created from Bytes32
Nashatyrev Jul 22, 2020
27f8cb3
Fix Mikuli specific test to use Mikuli implementation
Nashatyrev Jul 22, 2020
f06b765
Implement BlstPublicKey validation
Nashatyrev Jul 22, 2020
922254f
Replace BLSPublicKey.isValid() with fromBytesCompressedValidate() method
Nashatyrev Jul 22, 2020
dd744d1
Make BLSPublicKey fromBytesCompressed/toBytesCompressed operating wit…
Nashatyrev Jul 22, 2020
dcef1b3
Rename BLSPublicKey/BLSSignature.from/toBytes() methods to from/toSSZ…
Nashatyrev Jul 22, 2020
a8ae35b
Hide constructors. Make PublicKey and Signature implementations to be…
Nashatyrev Jul 22, 2020
3e13b6e
Fix DLL binary attribute
Nashatyrev Jul 22, 2020
2f4d590
Again add DLL
Nashatyrev Jul 22, 2020
706f888
Validate BlstSignature when creating from bytes
Nashatyrev Jul 22, 2020
66a854c
Add comments
Nashatyrev Jul 22, 2020
4db7dc4
Fix BlstPublicKey validation
Nashatyrev Jul 22, 2020
14e7f97
Fix accidentally committed wrong ETH2_DST
Nashatyrev Jul 23, 2020
1b2f04b
Add a BLS test
Nashatyrev Jul 23, 2020
54c6d4e
Add mikuli and blst specific infinity signature tests
Nashatyrev Jul 23, 2020
d65ec86
Add BlstPublicKey.fromBytesUncompressed for testing
Nashatyrev Jul 23, 2020
87d4cd5
Convert pre-generated keypairs dump to 32-byte secretKeys and compres…
Nashatyrev Jul 23, 2020
d4e5ca8
For BLSPublicKey/BLSSignature use bytes representation for hashCode()…
Nashatyrev Jul 23, 2020
5b308dd
Move the test case to BLSSignatureTest since empty() case is not hand…
Nashatyrev Jul 23, 2020
1af5520
Apply spotless. Remove obsolete file
Nashatyrev Jul 23, 2020
e87006d
In case of fail fast when deserializing invalid signature bytes, just…
Nashatyrev Jul 23, 2020
902ec56
Fix reference tests running on Windows
Nashatyrev Jul 23, 2020
47ca1c6
Merge remote-tracking branch 'pegasys/master' into feature-blst
Nashatyrev Jul 23, 2020
b204b52
Add Mikuli fallback when couldn't load Blst
Nashatyrev Jul 24, 2020
569e742
Apply spotless
Nashatyrev Jul 24, 2020
e683667
Move SWIG wrapper to a separate project
Nashatyrev Jul 24, 2020
41e647a
Fix errorprone warns
Nashatyrev Jul 24, 2020
e08b756
Update license for jblst
Nashatyrev Jul 24, 2020
65f0f50
Put the blst artifact version to versions.gradle
Nashatyrev Jul 24, 2020
acebcca
Implement BlstSecretKey.destroy()
Nashatyrev Jul 27, 2020
db88ac0
Temporary handling infinite pubkey/signature as a special case until …
Nashatyrev Jul 27, 2020
6047663
Apply spotless
Nashatyrev Jul 27, 2020
8318548
Resolve warnings
Nashatyrev Jul 27, 2020
1f9f688
Merge remote-tracking branch 'pegasys/master' into feature-blst
Nashatyrev Jul 27, 2020
aae5ea0
Generate KeyPair from seed in an implementation independent way. Thro…
Nashatyrev Jul 28, 2020
193c8f5
Fix tests
Nashatyrev Jul 28, 2020
90a35da
Apply spotless
Nashatyrev Jul 28, 2020
ce26e6a
Rename method to a more specific: aggregateSignatures()
Nashatyrev Jul 28, 2020
6c02825
Fix test compilation error
Nashatyrev Jul 28, 2020
8a2069c
Apply spotless
Nashatyrev Jul 28, 2020
d82db16
Make BLSPublicKey.getPublicKey() package private
Nashatyrev Jul 28, 2020
1de2060
Allow empty list signatures aggregation
Nashatyrev Jul 28, 2020
1659356
Disallow empty list signatures aggregation (revert prev commit)
Nashatyrev Jul 28, 2020
d0b27d4
Fix verify aggregated signature against multiple pubKey:message
Nashatyrev Jul 28, 2020
4978c2b
Fix blst equal pubkeys aggregation
Nashatyrev Jul 29, 2020
ef1fa1c
Make BLSSignature.getSignature() package private
Nashatyrev Jul 29, 2020
fa8ec98
Merge remote-tracking branch 'pegasys/master' into feature-blst
Nashatyrev Jul 29, 2020
f9577a0
Remove obsolete comment
Nashatyrev Jul 30, 2020
0c248d9
Moved BlstSignature specific methods from BlstBLS12381 to BlstSignatu…
Nashatyrev Jul 30, 2020
7447b6f
Fix batch verify case with invalid infinity signature
Nashatyrev Jul 30, 2020
fd219cc
Add lost test case
Nashatyrev Jul 30, 2020
654e2fa
Left comment for disabled test
Nashatyrev Jul 30, 2020
ea92796
Add explicit assertion to the test
Nashatyrev Jul 30, 2020
d903419
Apply spotless
Nashatyrev Jul 30, 2020
d17224f
Make BlstBLS12381.INSTANCE initialization more reliable and make it a…
Nashatyrev Jul 30, 2020
25fb802
Move BLS constants to BLSConstants class. Make a clear separation of …
Nashatyrev Jul 30, 2020
5dca043
Make a distinction of BLSSignature from/toSSZBytes() and from/toBytes…
Nashatyrev Jul 30, 2020
913e484
Add try/catch/finally to explicitly delete native structures
Nashatyrev Jul 30, 2020
7ade0ab
Minor BLS tests cleanups
Nashatyrev Jul 30, 2020
b60a046
Move BLS.aggregatePublicKeys() -> BLSPublicKey.aggregate(), rename BL…
Nashatyrev Jul 30, 2020
af77c6c
Make BLS*Test tests to cover all BLS implementations
Nashatyrev Jul 31, 2020
b45e157
Merge remote-tracking branch 'pegasys/master' into feature-multi-impl…
Nashatyrev Jul 31, 2020
e71fbae
Apply spotless
Nashatyrev Jul 31, 2020
a3bdac6
Change static field cap
Nashatyrev Jul 31, 2020
5048f5f
Merge branch 'master' into feature-multi-impl-bls-tests
Nashatyrev Aug 1, 2020
04f3d96
Merge branch 'master' into feature-multi-impl-bls-tests
ajsutton Aug 4, 2020
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: 14 additions & 3 deletions bls/src/main/java/tech/pegasys/teku/bls/BLS.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,19 @@ public class BLS {

private static final Logger LOG = LogManager.getLogger();

private static final BLS12381 BlsImpl =
BlstBLS12381.INSTANCE.map(bls -> (BLS12381) bls).orElse(MikuliBLS12381.INSTANCE);
private static BLS12381 BLS_IMPL;

static {
resetBlsImplementation();
}

public static void setBlsImplementation(BLS12381 blsImpl) {
BLS_IMPL = blsImpl;
}

public static void resetBlsImplementation() {
BLS_IMPL = BlstBLS12381.INSTANCE.map(bls -> (BLS12381) bls).orElse(MikuliBLS12381.INSTANCE);
}

/*
* The following are the methods used directly in the Ethereum 2.0 specifications. These strictly adhere to the standard.
Expand Down Expand Up @@ -347,6 +358,6 @@ public static boolean completeBatchVerify(List<BatchSemiAggregate> preparedSigna
}

static BLS12381 getBlsImpl() {
return BlsImpl;
return BLS_IMPL;
}
}
31 changes: 30 additions & 1 deletion bls/src/test/java/tech/pegasys/teku/bls/BLSPublicKeyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,38 @@
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes48;
import org.apache.tuweni.ssz.SSZ;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.bls.impl.blst.BlstBLS12381;
import tech.pegasys.teku.bls.impl.mikuli.MikuliBLS12381;

abstract class BLSPublicKeyTest {

public static class BlstPublicKeyTest extends BLSPublicKeyTest {
@BeforeAll
public static void init() {
BLS.setBlsImplementation(BlstBLS12381.INSTANCE.get());
}

@AfterAll
public static void cleanup() {
BLS.resetBlsImplementation();
}
}

public static class MikuliPublicKeyTest extends BLSPublicKeyTest {
@BeforeAll
public static void init() {
BLS.setBlsImplementation(MikuliBLS12381.INSTANCE);
}

@AfterAll
public static void cleanup() {
BLS.resetBlsImplementation();
}
}

class BLSPublicKeyTest {
private static final Bytes InfinityPublicKey =
Bytes.fromHexString(
"0xc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
Expand Down
30 changes: 29 additions & 1 deletion bls/src/test/java/tech/pegasys/teku/bls/BLSSecretKeyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,40 @@
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.bytes.Bytes48;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import tech.pegasys.teku.bls.impl.blst.BlstBLS12381;
import tech.pegasys.teku.bls.impl.mikuli.MikuliBLS12381;

public class BLSSecretKeyTest {
public abstract class BLSSecretKeyTest {

public static class BlstSecretKeyTest extends BLSSecretKeyTest {
@BeforeAll
public static void init() {
BLS.setBlsImplementation(BlstBLS12381.INSTANCE.get());
}

@AfterAll
public static void cleanup() {
BLS.resetBlsImplementation();
}
}

public static class MikuliSecretKeyTest extends BLSSecretKeyTest {
@BeforeAll
public static void init() {
BLS.setBlsImplementation(MikuliBLS12381.INSTANCE);
}

@AfterAll
public static void cleanup() {
BLS.resetBlsImplementation();
}
}

@ParameterizedTest
@ValueSource(
Expand Down
30 changes: 29 additions & 1 deletion bls/src/test/java/tech/pegasys/teku/bls/BLSSignatureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,37 @@

import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.ssz.SSZ;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.bls.impl.blst.BlstBLS12381;
import tech.pegasys.teku.bls.impl.mikuli.MikuliBLS12381;

class BLSSignatureTest {
abstract class BLSSignatureTest {

public static class BlstSignatureTest extends BLSSignatureTest {
@BeforeAll
public static void init() {
BLS.setBlsImplementation(BlstBLS12381.INSTANCE.get());
}

@AfterAll
public static void cleanup() {
BLS.resetBlsImplementation();
}
}

public static class MikuliSignatureTest extends BLSSignatureTest {
@BeforeAll
public static void init() {
BLS.setBlsImplementation(MikuliBLS12381.INSTANCE);
}

@AfterAll
public static void cleanup() {
BLS.resetBlsImplementation();
}
}

@Test
void succeedsWhenEqualsReturnsTrueForTheSameEmptySignature() {
Expand Down
30 changes: 29 additions & 1 deletion bls/src/test/java/tech/pegasys/teku/bls/BLSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,37 @@
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.bytes.Bytes48;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.bls.impl.blst.BlstBLS12381;
import tech.pegasys.teku.bls.impl.mikuli.MikuliBLS12381;

class BLSTest {
public abstract class BLSTest {

public static class BlstBlsTest extends BLSTest {
@BeforeAll
public static void init() {
BLS.setBlsImplementation(BlstBLS12381.INSTANCE.get());
}

@AfterAll
public static void cleanup() {
BLS.resetBlsImplementation();
}
}

public static class MikuliBlsTest extends BLSTest {
@BeforeAll
public static void init() {
BLS.setBlsImplementation(MikuliBLS12381.INSTANCE);
}

@AfterAll
public static void cleanup() {
BLS.resetBlsImplementation();
}
}

@Test
void succeedsWhenWeCanSignAndVerify() {
Expand Down