Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
* remove unused variables
* avoid enlarging casts
* don't try to catch defects
  • Loading branch information
arnetheduck committed Aug 17, 2023
1 parent 3956f63 commit 343499a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
16 changes: 3 additions & 13 deletions blscurve/bls_batch_verifier.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,21 @@ type

# Per-batch contexts for multithreaded batch verification
batchContexts: seq[ContextMultiAggregateVerify[DST]]
when compileOption("threads"):
flows: seq[Flowvar[bool]]

# Serial Batch Verifier
# ----------------------------------------------------------------------

func init*(T: type BatchedBLSVerifierCache): T =
## Initialise the cache for single-threaded usage
when compileOption("threads"):
BatchedBLSVerifierCache(
batchContexts: newSeq[ContextMultiAggregateVerify[DST]](1),
flows: @[]
)
else:
BatchedBLSVerifierCache(
batchContexts: newSeq[ContextMultiAggregateVerify[DST]](1),
)

BatchedBLSVerifierCache(
batchContexts: newSeq[ContextMultiAggregateVerify[DST]](1),
)

when compileOption("threads"):
func init*(T: type BatchedBLSVerifierCache, tp: Taskpool): T =
## Initialise the cache for multi-threaded usage
BatchedBLSVerifierCache(
batchContexts: newSeq[ContextMultiAggregateVerify[DST]](tp.numThreads),
flows: newSeq[Flowvar[bool]](tp.numThreads)
)

func batchVerifySerial*(
Expand Down
10 changes: 5 additions & 5 deletions blscurve/miracl/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func fromBytes*(res: var BIG_384, a: openArray[byte]): bool =
let length = if len(a) > MODBYTES_384: MODBYTES_384 else: len(a)
for i in 0..<length:
discard BIG_384_fshl(res, 8)
res[0] = res[0] + cast[Chunk](a[i])
res[0] = res[0] + Chunk(a[i])
true

func fromBytes*(res: var DBIG_384, a: openArray[byte]): bool =
Expand All @@ -547,7 +547,7 @@ func fromBytes*(res: var DBIG_384, a: openArray[byte]): bool =
zeroMem(res.addr, sizeof(res))
for rawByte in a:
BIG_384_dshl(res, 8)
res[0] = res[0] + cast[Chunk](rawByte)
res[0] = res[0] + Chunk(rawByte)
true

func fromHex*(res: var BIG_384, a: string): bool {.inline.} =
Expand All @@ -556,7 +556,7 @@ func fromHex*(res: var BIG_384, a: string): bool {.inline.} =
## Returns ``true`` if conversion was successful.
try:
fromBytes(res, hexToSeqByte(a))
except ValueError, IndexError:
except ValueError:
# TODO: change to exception-free
# https://github.com/status-im/nim-blscurve/issues/57
false
Expand Down Expand Up @@ -651,7 +651,7 @@ func fromHex*(res: var ECP2_BLS12381, a: string): bool {.inline.} =
## Returns ``true`` if conversion was successfull.
try:
fromBytes(res, hexToSeqByte(a))
except ValueError, IndexError:
except ValueError:
# TODO: change to exception-free
# https://github.com/status-im/nim-blscurve/issues/57
false
Expand Down Expand Up @@ -737,7 +737,7 @@ func fromHex*(res: var ECP_BLS12381, a: string): bool {.inline.} =
## Returns ``true`` if conversion was successfull.
try:
fromBytes(res, hexToSeqByte(a))
except ValueError, IndexError:
except ValueError:
# TODO: change to exception-free
# https://github.com/status-im/nim-blscurve/issues/57
false
Expand Down

0 comments on commit 343499a

Please sign in to comment.