improve batch crypto sanity checks error reporting

This commit is contained in:
Mamy André-Ratsimbazafy 2021-05-25 16:17:47 +02:00 committed by zah
parent 9ddf7fea23
commit d05c9dbcf4
2 changed files with 17 additions and 18 deletions

View File

@ -220,14 +220,14 @@ proc scheduleAttestationCheck*(
fork: Fork, genesis_validators_root: Eth2Digest, fork: Fork, genesis_validators_root: Eth2Digest,
epochRef: EpochRef, epochRef: EpochRef,
attestation: Attestation attestation: Attestation
): Option[(Future[BatchResult], CookedSig)] = ): Result[(Future[BatchResult], CookedSig), cstring] =
## Schedule crypto verification of an attestation ## Schedule crypto verification of an attestation
## ##
## The buffer is processed: ## The buffer is processed:
## - when eager processing is enabled and the batch is full ## - when eager processing is enabled and the batch is full
## - otherwise after 10ms (BatchAttAccumTime) ## - otherwise after 10ms (BatchAttAccumTime)
## ##
## This returns None if crypto sanity checks failed ## This returns an error if crypto sanity checks failed
## and a future with the deferred attestation check otherwise. ## and a future with the deferred attestation check otherwise.
## ##
let (batch, fresh) = batchCrypto.getBatch() let (batch, fresh) = batchCrypto.getBatch()
@ -241,7 +241,7 @@ proc scheduleAttestationCheck*(
attestation attestation
) )
if not sig.isSome(): if not sig.isSome():
return none((Future[BatchResult], CookedSig)) return err("Attestation batch validation: no attester found or invalid pubkey found.")
let fut = newFuture[BatchResult]( let fut = newFuture[BatchResult](
"batch_validation.scheduleAttestationCheck" "batch_validation.scheduleAttestationCheck"
@ -251,17 +251,18 @@ proc scheduleAttestationCheck*(
batchCrypto.scheduleBatch(fresh) batchCrypto.scheduleBatch(fresh)
return some((fut, sig.get())) return ok((fut, sig.get()))
proc scheduleAggregateChecks*( proc scheduleAggregateChecks*(
batchCrypto: ref BatchCrypto, batchCrypto: ref BatchCrypto,
fork: Fork, genesis_validators_root: Eth2Digest, fork: Fork, genesis_validators_root: Eth2Digest,
epochRef: EpochRef, epochRef: EpochRef,
signedAggregateAndProof: SignedAggregateAndProof signedAggregateAndProof: SignedAggregateAndProof
): Option[( ): Result[
tuple[slotCheck, aggregatorCheck, aggregateCheck: (
Future[BatchResult]], tuple[slotCheck, aggregatorCheck, aggregateCheck: Future[BatchResult]],
CookedSig)] = CookedSig
), cstring] =
## Schedule crypto verification of an aggregate ## Schedule crypto verification of an aggregate
## ##
## This involves 3 checks: ## This involves 3 checks:
@ -299,7 +300,7 @@ proc scheduleAggregateChecks*(
aggregator, aggregator,
aggregate_and_proof.selection_proof aggregate_and_proof.selection_proof
): ):
return none(R) return err("Aggregate batch validation: invalid pubkey or signature in addSlotSignature.")
let futSlot = newFuture[BatchResult]( let futSlot = newFuture[BatchResult](
"batch_validation.scheduleAggregateChecks.slotCheck" "batch_validation.scheduleAggregateChecks.slotCheck"
) )
@ -315,7 +316,7 @@ proc scheduleAggregateChecks*(
signed_aggregate_and_proof.signature signed_aggregate_and_proof.signature
): ):
batchCrypto.scheduleBatch(fresh) batchCrypto.scheduleBatch(fresh)
return none(R) return err("Aggregate batch validation: invalid pubkey or signature in addAggregateAndProofSignature.")
let futAggregator = newFuture[BatchResult]( let futAggregator = newFuture[BatchResult](
"batch_validation.scheduleAggregateChecks.aggregatorCheck" "batch_validation.scheduleAggregateChecks.aggregatorCheck"
@ -331,7 +332,7 @@ proc scheduleAggregateChecks*(
) )
if not sig.isSome(): if not sig.isSome():
batchCrypto.scheduleBatch(fresh) batchCrypto.scheduleBatch(fresh)
return none(R) return err("Attestation batch validation: no attester found or invalid pubkey found.")
let futAggregate = newFuture[BatchResult]( let futAggregate = newFuture[BatchResult](
"batch_validation.scheduleAggregateChecks.aggregateCheck" "batch_validation.scheduleAggregateChecks.aggregateCheck"
@ -340,4 +341,4 @@ proc scheduleAggregateChecks*(
batchCrypto.scheduleBatch(fresh) batchCrypto.scheduleBatch(fresh)
return some(((futSlot, futAggregator, futAggregate), sig.get())) return ok(((futSlot, futAggregator, futAggregate), sig.get()))

View File

@ -287,9 +287,8 @@ proc validateAttestation*(
fork, genesis_validators_root, epochRef, fork, genesis_validators_root, epochRef,
attestation attestation
) )
if deferredCrypto.isNone(): if deferredCrypto.isErr():
return err((ValidationResult.Reject, return err((ValidationResult.Reject, deferredCrypto.error))
cstring("validateAttestation: crypto sanity checks failure")))
# Await the crypto check # Await the crypto check
let let
@ -441,9 +440,8 @@ proc validateAggregate*(
fork, genesis_validators_root, epochRef, fork, genesis_validators_root, epochRef,
signed_aggregate_and_proof signed_aggregate_and_proof
) )
if deferredCrypto.isNone(): if deferredCrypto.isErr():
return err((ValidationResult.Reject, return err((ValidationResult.Reject, deferredCrypto.error))
cstring("validateAggregate: crypto sanity checks failure")))
let let
(cryptoFuts, sig) = deferredCrypto.get() (cryptoFuts, sig) = deferredCrypto.get()