From cdf65a43853022643aa897fbd6ef5c1712a8dc9b Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Thu, 8 Feb 2024 23:21:02 +0100 Subject: [PATCH] bump `bls12-381-tests` to `v0.1.2` - https://github.com/ethereum/bls12-381-tests/releases/tag/v0.1.2 --- blscurve/bls_batch_verifier.nim | 8 ++-- tests/download_ef_bls12381_vectors.sh | 2 +- tests/eip2333_key_derivation.nim | 4 +- tests/eth2_vectors.nim | 64 +++++++++++++++------------ tests/serialization.nim | 4 +- tests/test_locator.nim | 2 +- 6 files changed, 46 insertions(+), 38 deletions(-) diff --git a/blscurve/bls_batch_verifier.nim b/blscurve/bls_batch_verifier.nim index d44c6ed..3ae7044 100644 --- a/blscurve/bls_batch_verifier.nim +++ b/blscurve/bls_batch_verifier.nim @@ -7,12 +7,12 @@ # This file may not be copied, modified, or distributed except according to # those terms. -import - stew/ptrops, - ./bls_backend, ./bls_sig_min_pubkey +import ./bls_backend, ./bls_sig_min_pubkey when compileOption("threads"): - import taskpools, ./parallel_chunks + import + stew/ptrops, + taskpools, ./parallel_chunks {.push raises: [].} diff --git a/tests/download_ef_bls12381_vectors.sh b/tests/download_ef_bls12381_vectors.sh index e6310a2..5cd473d 100755 --- a/tests/download_ef_bls12381_vectors.sh +++ b/tests/download_ef_bls12381_vectors.sh @@ -3,7 +3,7 @@ set -eu VERSIONS=( - "v0.1.1" + "v0.1.2" ) FLAVOURS=( "bls_tests_json" diff --git a/tests/eip2333_key_derivation.nim b/tests/eip2333_key_derivation.nim index a36a28d..28f7efe 100644 --- a/tests/eip2333_key_derivation.nim +++ b/tests/eip2333_key_derivation.nim @@ -13,9 +13,7 @@ import # Status libraries stew/byteutils, stint, # Public API - ../blscurve, - # Test helpers - ./test_locator + ../blscurve proc toDecimal(sk: SecretKey): string = # The spec does not use hex but decimal ... diff --git a/tests/eth2_vectors.nim b/tests/eth2_vectors.nim index c76e71d..3381f92 100644 --- a/tests/eth2_vectors.nim +++ b/tests/eth2_vectors.nim @@ -369,43 +369,51 @@ when BLS_BACKEND == BLST and compileOption("threads"): messages = seq[seq[byte]].aggFrom(test, "messages") signatures = seq[Signature].aggFrom(test, "signatures") - var tp = Taskpool.new(numThreads = 4) - var cache = BatchedBLSVerifierCache.init(tp) - var batch: seq[SignatureSet] + if not pubkeys.ok: + # Infinity pubkey in the mix + doAssert not expected.val + else: - proc hash[T: byte|char](message: openArray[T]): array[32, byte] {.noinit.} = - result.bls_sha256_digest(message) + var tp = Taskpool.new(numThreads = 4) + var cache = BatchedBLSVerifierCache.init(tp) + var batch: seq[SignatureSet] - proc asArray[T: byte|char](message: openArray[T]): array[32, byte] {.noinit.}= - result[0 ..< 32] = message - let fakeRandomBytes = hash"Mr F was here" + proc hash[T: byte|char]( + message: openArray[T]): array[32, byte] {.noinit.} = + result.bls_sha256_digest(message) - # Deserialization is OK - doAssert pubkeys.ok - doAssert messages.ok - doAssert signatures.ok - doAssert pubkeys.val.len == messages.val.len - doAssert pubkeys.val.len == signatures.val.len + proc asArray[T: byte|char]( + message: openArray[T]): array[32, byte] {.noinit.}= + result[0 ..< 32] = message - for i in 0 ..< pubkeys.val.len: - batch.add(( - pubkeys.val[i], - messages.val[i].asArray(), - signatures.val[i] - )) + let fakeRandomBytes = hash"Mr F was here" - let batchValid = tp.batchVerify(cache, batch, fakeRandomBytes) - let batchValid2 = tp.batchVerify(batch, fakeRandomBytes) + # Deserialization is OK + doAssert pubkeys.ok + doAssert messages.ok + doAssert signatures.ok + doAssert pubkeys.val.len == messages.val.len + doAssert pubkeys.val.len == signatures.val.len - doAssert batchValid == batchValid2 - doAssert batchValid == expected.val, block: - "\nBatch Verification differs from expected \n" & - " verified? " & $batchValid & "\n" & - " expected: " & $expected.val + for i in 0 ..< pubkeys.val.len: + batch.add(( + pubkeys.val[i], + messages.val[i].asArray(), + signatures.val[i] + )) + + let batchValid = tp.batchVerify(cache, batch, fakeRandomBytes) + let batchValid2 = tp.batchVerify(batch, fakeRandomBytes) + + doAssert batchValid == batchValid2 + doAssert batchValid == expected.val, block: + "\nBatch Verification differs from expected \n" & + " verified? " & $batchValid & "\n" & + " expected: " & $expected.val - tp.shutdown() + tp.shutdown() suite "ETH 2.0 " & BLS_ETH2_SPEC & " test vectors - " & $BLS_BACKEND: test "[" & BLS_ETH2_SPEC & "] sign(SecretKey, message) -> Signature": diff --git a/tests/serialization.nim b/tests/serialization.nim index bda70fa..4182154 100644 --- a/tests/serialization.nim +++ b/tests/serialization.nim @@ -7,13 +7,15 @@ # This file may not be copied, modified, or distributed except according to # those terms. -import ../blscurve, std/strutils +import ../blscurve # Infinite signatures serialization # A signature may be initialized at an infinity point # as a first step before aggregation. Inputs when BLS_BACKEND == BLST: + import std/strutils + echo "\nZero init signatures is serialized as infinity point" echo "----------------------------------\n" proc test_zero_sig() = diff --git a/tests/test_locator.nim b/tests/test_locator.nim index e46b788..66a6ed4 100644 --- a/tests/test_locator.nim +++ b/tests/test_locator.nim @@ -4,7 +4,7 @@ import export os, json -const ETH2_DIR = currentSourcePath.rsplit(DirSep, 1)[0] / "ef-bls12381-vectors-v0.1.1" +const ETH2_DIR = currentSourcePath.rsplit(DirSep, 1)[0] / "ef-bls12381-vectors-v0.1.2" proc parseTest*(file: string): JsonNode = json.parseFile(file)