Skip to content

Commit

Permalink
api: add skip_randao_verification for produceBlockV2 (#3837)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul authored Sep 21, 2022
1 parent f7db505 commit d6325b1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions beacon_chain/extras.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##\
Expand Down
2 changes: 2 additions & 0 deletions beacon_chain/rpc/rest_constants.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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* =
Expand Down
13 changes: 11 additions & 2 deletions beacon_chain/rpc/rest_validator_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion beacon_chain/spec/state_transition_block.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions beacon_chain/validators/validator_duties.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d6325b1

Please sign in to comment.