api: add skip_randao_verification for produceBlockV2 (#3837)

This commit is contained in:
Michael Sproul 2022-09-21 17:38:08 +10:00 committed by GitHub
parent f7db50522b
commit d6325b1ab5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 3 deletions

View File

@ -27,6 +27,9 @@ type
## Skip verification of BLS signatures in block processing.
## Predominantly intended for use in testing, e.g. to allow extra coverage.
## Also useful to avoid unnecessary work when replaying known, good blocks.
skipRandaoVerification ##\
## Skip verification of the proposer's randao reveal in block processing, but do ensure
## that they set the randao reveal to the point at infinity.
skipStateRootValidation ##\
## Skip verification of block state root.
strictVerification ##\

View File

@ -90,6 +90,8 @@ const
"Missing `randao_reveal` value"
InvalidRandaoRevealValue* =
"Invalid randao reveal value"
InvalidSkipRandaoVerificationValue* =
"Invalid skip_randao_verification value"
InvalidGraffitiBytesValue* =
"Invalid graffiti bytes value"
InvalidEpochValueError* =

View File

@ -369,7 +369,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
# https://ethereum.github.io/beacon-APIs/#/Validator/produceBlockV2
router.api(MethodGet, "/eth/v2/validator/blocks/{slot}") do (
slot: Slot, randao_reveal: Option[ValidatorSig],
graffiti: Option[GraffitiBytes]) -> RestApiResponse:
graffiti: Option[GraffitiBytes], skip_randao_verification: Option[string]) -> RestApiResponse:
let message =
block:
let qslot = block:
@ -387,6 +387,15 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
return RestApiResponse.jsonError(Http400, InvalidSlotValueError,
"Slot cannot be in the future")
res
let qskip_randao_verification =
if skip_randao_verification.isNone():
false
else:
let res = skip_randao_verification.get()
if res.isErr() or res.get() != "":
return RestApiResponse.jsonError(Http400,
InvalidSkipRandaoVerificationValue)
true
let qrandao =
if randao_reveal.isNone():
return RestApiResponse.jsonError(Http400, MissingRandaoRevealValue)
@ -418,7 +427,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
if proposer.isNone():
return RestApiResponse.jsonError(Http400, ProposerNotFoundError)
let res = await makeBeaconBlockForHeadAndSlot(
node, qrandao, proposer.get(), qgraffiti, qhead, qslot)
node, qrandao, proposer.get(), qgraffiti, qhead, qslot, qskip_randao_verification)
if res.isErr():
return RestApiResponse.jsonError(Http400, res.error())
res.get()

View File

@ -88,7 +88,10 @@ proc process_randao(
let
epoch = state.get_current_epoch()
if skipBlsValidation notin flags:
if skipRandaoVerification in flags:
if body.randao_reveal.toRaw != ValidatorSig.infinity.toRaw:
return err("process_randao: expected point-at-infinity for skipRandaoVerification")
elif skipBlsValidation notin flags:
let proposer_pubkey = state.validators.item(proposer_index.get).pubkey
if not verify_epoch_signature(

View File

@ -446,6 +446,7 @@ proc makeBeaconBlockForHeadAndSlot*(
node: BeaconNode, randao_reveal: ValidatorSig,
validator_index: ValidatorIndex, graffiti: GraffitiBytes, head: BlockRef,
slot: Slot,
skip_randao_verification_bool: bool = false,
execution_payload: Opt[ExecutionPayload] = Opt.none(ExecutionPayload),
transactions_root: Opt[Eth2Digest] = Opt.none(Eth2Digest),
execution_payload_root: Opt[Eth2Digest] = Opt.none(Eth2Digest)):
@ -521,6 +522,7 @@ proc makeBeaconBlockForHeadAndSlot*(
effectiveExecutionPayload,
noRollback, # Temporary state - no need for rollback
cache,
verificationFlags = if skip_randao_verification_bool: {skipRandaoVerification} else: {},
transactions_root =
if transactions_root.isSome:
Opt.some transactions_root.get