Skip to content

Commit

Permalink
Handle infinite fake bls signature correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashatyrev committed Nov 6, 2024
1 parent ec9713e commit 3250a37
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.bls.impl.fake;

import java.util.Collections;
import java.util.List;
import java.util.Random;
import org.apache.tuweni.bytes.Bytes;
Expand All @@ -32,6 +33,7 @@ public class FakeBLS12381 implements BLS12381 {
private static final BatchSemiAggregate FAKE_AGGREGATE = new BatchSemiAggregate() {};

static final Signature RANDOM_SIGNATURE = DELEGATE.randomSignature(0);
static final Signature INFINITY_SIGNATURE = DELEGATE.aggregateSignatures(Collections.emptyList());

@Override
public KeyPair generateKeyPair(Random random) {
Expand All @@ -47,7 +49,11 @@ public PublicKey publicKeyFromCompressed(Bytes48 compressedPublicKeyBytes) throw

@Override
public Signature signatureFromCompressed(Bytes compressedSignatureBytes) {
return new FakeSignature();
if (compressedSignatureBytes.equals(INFINITY_SIGNATURE.toBytesCompressed())) {
return FakeSignature.INF_SIGNATURE;
} else {
return FakeSignature.ANY_SIGNATURE;
}
}

@Override
Expand All @@ -63,7 +69,7 @@ public PublicKey aggregatePublicKeys(List<? extends PublicKey> publicKeys) {
@Override
public Signature aggregateSignatures(List<? extends Signature> signatures)
throws IllegalArgumentException {
return new FakeSignature();
return signatures.isEmpty() ? FakeSignature.INF_SIGNATURE : FakeSignature.ANY_SIGNATURE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public PublicKey derivePublicKey() {

@Override
public Signature sign(Bytes message) {
return new FakeSignature();
return FakeSignature.ANY_SIGNATURE;
}

@Override
public Signature sign(Bytes message, String dst) {
return new FakeSignature();
return FakeSignature.ANY_SIGNATURE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@

public class FakeSignature implements Signature {

public FakeSignature() {}
public static final FakeSignature ANY_SIGNATURE = new FakeSignature(false);
public static final FakeSignature INF_SIGNATURE = new FakeSignature(true);

private final boolean isInfinity;

private FakeSignature(boolean isInfinity) {
this.isInfinity = isInfinity;
}

@Override
public Bytes toBytesCompressed() {
return FakeBLS12381.RANDOM_SIGNATURE.toBytesCompressed();
return (isInfinity ? FakeBLS12381.INFINITY_SIGNATURE : FakeBLS12381.RANDOM_SIGNATURE)
.toBytesCompressed();
}

@Override
Expand Down

0 comments on commit 3250a37

Please sign in to comment.