Skip to content

Commit

Permalink
bump bls12-381-tests to v0.1.2 (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
etan-status committed Feb 8, 2024
1 parent c0ca7cf commit 3638942
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 38 deletions.
8 changes: 4 additions & 4 deletions blscurve/bls_batch_verifier.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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: [].}

Expand Down
2 changes: 1 addition & 1 deletion tests/download_ef_bls12381_vectors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -eu

VERSIONS=(
"v0.1.1"
"v0.1.2"
)
FLAVOURS=(
"bls_tests_json"
Expand Down
4 changes: 1 addition & 3 deletions tests/eip2333_key_derivation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand Down
64 changes: 36 additions & 28 deletions tests/eth2_vectors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
4 changes: 3 additions & 1 deletion tests/serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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() =
Expand Down
2 changes: 1 addition & 1 deletion tests/test_locator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3638942

Please sign in to comment.