Skip to content

Commit

Permalink
Add fast aggregate verify test (failing to wrong test - ethereum/cons…
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Feb 13, 2020
1 parent 56c6def commit eef3773
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/eth2_vectors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ proc getFrom(T: typedesc, test: JsonNode, inout: static InOut, name: string): T
else:
when T is seq[byte]:
result = hexToSeqByte(test["input"][name].getStr)
elif T is seq[PublicKey]:
for pubKeyHex in test["input"][name]:
result.setLen(result.len + 1)
doAssert result[^1].fromHex(pubKeyHex.getStr()),
"Couldn't parse input PublicKey: " & pubKeyHex.getStr()
else:
doAssert result.fromHex(test["input"][name].getStr()),
"Couldn't parse input '" & name & "' (" & $T &
Expand Down Expand Up @@ -127,10 +132,36 @@ testGen(aggregate, test):
" computed: " & libAggSig.toHex() & "\n" &
" expected: " & expectedAgg.toHex()

testGen(fast_aggregate_verify, test):
let expected = bool.getFrom(test, Output)
var
pubkeys: seq[PublicKey]
message: seq[byte]
signature: Signature
try:
pubKeys = seq[PublicKey].getFrom(test, Input, "pubkeys")
message = seq[byte].getFrom(test, Input, "message")
signature = Signature.getFrom(test, Input, "signature")
except:
let emsg = getCurrentExceptionMsg()
if expected:
doAssert false, "Verification was not supposed to fail, but one of the inputs was invalid." & emsg
else:
echo "[INFO] Expected verification failure at parsing stage: " & emsg

let libValid = pubKeys.fastAggregateVerify(message, signature)

doAssert libValid == expected, block:
"\nFast Aggregate Verification differs from expected \n" &
" computed: " & $libValid & "\n" &
" expected: " & $expected

suite "ETH 2.0 v0.10.1 test vectors":
test "sign(SecretKey, message) -> Signature":
test_sign()
test "verify(PublicKey, message, Signature) -> bool":
test_verify()
test "aggregate(openarray[Signature]) -> Signature":
test_aggregate()
test "fastAggregateVerify(openarray[PublicKey], message, Signature) -> bool":
test_fast_aggregate_verify()

0 comments on commit eef3773

Please sign in to comment.