re-enable randao checks (#4187)

* re-enable randao checks

* use `asSigVerified` consistently

* fix spelling

* document why state_transition.makeBeaconBlock trusting signatures is safe
This commit is contained in:
tersec 2022-09-28 01:15:10 +00:00 committed by GitHub
parent b1bc830a92
commit 57d68d0f72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 15 deletions

View File

@ -591,4 +591,4 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
OK: 9/9 Fail: 0/9 Skip: 0/9 OK: 9/9 Fail: 0/9 Skip: 0/9
---TOTAL--- ---TOTAL---
OK: 327/332 Fail: 0/332 Skip: 5/332 OK: 328/333 Fail: 0/333 Skip: 5/333

View File

@ -787,6 +787,10 @@ template asSigVerified*(
TrustedSignedBeaconBlock): SigVerifiedSignedBeaconBlock = TrustedSignedBeaconBlock): SigVerifiedSignedBeaconBlock =
isomorphicCast[SigVerifiedSignedBeaconBlock](x) isomorphicCast[SigVerifiedSignedBeaconBlock](x)
template asSigVerified*(
x: BeaconBlock | TrustedBeaconBlock): SigVerifiedBeaconBlock =
isomorphicCast[SigVerifiedBeaconBlock](x)
template asMsgTrusted*( template asMsgTrusted*(
x: SignedBeaconBlock | x: SignedBeaconBlock |
SigVerifiedSignedBeaconBlock | SigVerifiedSignedBeaconBlock |

View File

@ -412,6 +412,10 @@ template asSigVerified*(
TrustedSignedBeaconBlock): SigVerifiedSignedBeaconBlock = TrustedSignedBeaconBlock): SigVerifiedSignedBeaconBlock =
isomorphicCast[SigVerifiedSignedBeaconBlock](x) isomorphicCast[SigVerifiedSignedBeaconBlock](x)
template asSigVerified*(
x: BeaconBlock | TrustedBeaconBlock): SigVerifiedBeaconBlock =
isomorphicCast[SigVerifiedBeaconBlock](x)
template asMsgTrusted*( template asMsgTrusted*(
x: SignedBeaconBlock | x: SignedBeaconBlock |
SigVerifiedSignedBeaconBlock | SigVerifiedSignedBeaconBlock |

View File

@ -319,6 +319,10 @@ template asSigVerified*(
TrustedSignedBeaconBlock): SigVerifiedSignedBeaconBlock = TrustedSignedBeaconBlock): SigVerifiedSignedBeaconBlock =
isomorphicCast[SigVerifiedSignedBeaconBlock](x) isomorphicCast[SigVerifiedSignedBeaconBlock](x)
template asSigVerified*(
x: BeaconBlock | TrustedBeaconBlock): SigVerifiedBeaconBlock =
isomorphicCast[SigVerifiedBeaconBlock](x)
template asMsgTrusted*( template asMsgTrusted*(
x: SignedBeaconBlock | x: SignedBeaconBlock |
SigVerifiedSignedBeaconBlock | SigVerifiedSignedBeaconBlock |

View File

@ -533,16 +533,19 @@ template withStateAndBlck*(
of BeaconStateFork.Bellatrix: of BeaconStateFork.Bellatrix:
const stateFork {.inject.} = BeaconStateFork.Bellatrix const stateFork {.inject.} = BeaconStateFork.Bellatrix
template state: untyped {.inject.} = s.bellatrixData template state: untyped {.inject.} = s.bellatrixData
template forkyState: untyped {.inject.} = s.bellatrixData
template blck: untyped {.inject.} = b.bellatrixData template blck: untyped {.inject.} = b.bellatrixData
body body
of BeaconStateFork.Altair: of BeaconStateFork.Altair:
const stateFork {.inject.} = BeaconStateFork.Altair const stateFork {.inject.} = BeaconStateFork.Altair
template state: untyped {.inject.} = s.altairData template state: untyped {.inject.} = s.altairData
template forkyState: untyped {.inject.} = s.altairData
template blck: untyped {.inject.} = b.altairData template blck: untyped {.inject.} = b.altairData
body body
of BeaconStateFork.Phase0: of BeaconStateFork.Phase0:
const stateFork {.inject.} = BeaconStateFork.Phase0 const stateFork {.inject.} = BeaconStateFork.Phase0
template state: untyped {.inject.} = s.phase0Data template state: untyped {.inject.} = s.phase0Data
template forkyState: untyped {.inject.} = s.phase0Data
template blck: untyped {.inject.} = b.phase0Data template blck: untyped {.inject.} = b.phase0Data
body body

View File

@ -352,7 +352,8 @@ proc makeBeaconBlock*(
randao_reveal, eth1_data, graffiti, attestations, deposits, randao_reveal, eth1_data, graffiti, attestations, deposits,
exits, sync_aggregate, execution_payload) exits, sync_aggregate, execution_payload)
let res = process_block(cfg, state.data, blck, verificationFlags, cache) let res = process_block(
cfg, state.data, blck.asSigVerified(), verificationFlags, cache)
if res.isErr: if res.isErr:
rollback(state) rollback(state)
@ -421,7 +422,9 @@ proc makeBeaconBlock*(
randao_reveal, eth1_data, graffiti, attestations, deposits, randao_reveal, eth1_data, graffiti, attestations, deposits,
exits, sync_aggregate, execution_payload) exits, sync_aggregate, execution_payload)
let res = process_block(cfg, state.data, blck, verificationFlags, cache) # Signatures are verified elsewhere, so don't duplicate inefficiently here
let res = process_block(
cfg, state.data, blck.asSigVerified(), verificationFlags, cache)
if res.isErr: if res.isErr:
rollback(state) rollback(state)
@ -491,7 +494,8 @@ proc makeBeaconBlock*(
randao_reveal, eth1_data, graffiti, attestations, deposits, randao_reveal, eth1_data, graffiti, attestations, deposits,
exits, sync_aggregate, execution_payload) exits, sync_aggregate, execution_payload)
let res = process_block(cfg, state.data, blck, verificationFlags, cache) let res = process_block(
cfg, state.data, blck.asSigVerified(), verificationFlags, cache)
if res.isErr: if res.isErr:
rollback(state) rollback(state)
@ -538,8 +542,9 @@ proc makeBeaconBlock*(
randao_reveal, eth1_data, graffiti, attestations, deposits, randao_reveal, eth1_data, graffiti, attestations, deposits,
exits, sync_aggregate, executionPayload)) exits, sync_aggregate, executionPayload))
let res = process_block(cfg, state.`kind Data`.data, blck.`kind Data`, let res = process_block(
verificationFlags, cache) cfg, state.`kind Data`.data, blck.`kind Data`.asSigVerified(),
verificationFlags, cache)
if res.isErr: if res.isErr:
rollback(state) rollback(state)
return err(res.error()) return err(res.error())

View File

@ -85,8 +85,7 @@ proc process_randao(
return err("process_randao: proposer index missing, probably along with any active validators") return err("process_randao: proposer index missing, probably along with any active validators")
# Verify RANDAO reveal # Verify RANDAO reveal
let let epoch = state.get_current_epoch()
epoch = state.get_current_epoch()
if skipRandaoVerification in flags: if skipRandaoVerification in flags:
if body.randao_reveal.toRaw != ValidatorSig.infinity.toRaw: if body.randao_reveal.toRaw != ValidatorSig.infinity.toRaw:
@ -94,9 +93,15 @@ proc process_randao(
elif skipBlsValidation notin flags: elif skipBlsValidation notin flags:
let proposer_pubkey = state.validators.item(proposer_index.get).pubkey let proposer_pubkey = state.validators.item(proposer_index.get).pubkey
# `state_transition.makeBeaconBlock` ensures this is run with a trusted
# signature, but unless the full skipBlsValidation is specified, RANDAO
# epoch signatures still have to be verified.
if not verify_epoch_signature( if not verify_epoch_signature(
state.fork, state.genesis_validators_root, epoch, proposer_pubkey, state.fork, state.genesis_validators_root, epoch, proposer_pubkey,
body.randao_reveal): when body.randao_reveal is ValidatorSig:
body.randao_reveal
else:
isomorphicCast[ValidatorSig](body.randao_reveal)):
return err("process_randao: invalid epoch signature") return err("process_randao: invalid epoch signature")

View File

@ -462,8 +462,7 @@ proc makeBeaconBlockForHeadAndSlot*(
execution_payload_root: Opt[Eth2Digest] = Opt.none(Eth2Digest)): execution_payload_root: Opt[Eth2Digest] = Opt.none(Eth2Digest)):
Future[ForkedBlockResult] {.async.} = Future[ForkedBlockResult] {.async.} =
# Advance state to the slot that we're proposing for # Advance state to the slot that we're proposing for
let let proposalState = assignClone(node.dag.headState)
proposalState = assignClone(node.dag.headState)
# TODO fails at checkpoint synced head # TODO fails at checkpoint synced head
node.dag.withUpdatedState( node.dag.withUpdatedState(
@ -532,11 +531,10 @@ proc makeBeaconBlockForHeadAndSlot*(
effectiveExecutionPayload, effectiveExecutionPayload,
noRollback, # Temporary state - no need for rollback noRollback, # Temporary state - no need for rollback
cache, cache,
# makeBeaconBlock doesn't verify BLS at all, but does have special case
# for skipRandaoVerification separately
verificationFlags = verificationFlags =
if skip_randao_verification_bool: if skip_randao_verification_bool: {skipRandaoVerification} else: {},
{skipBlsValidation, skipRandaoVerification}
else:
{skipBlsValidation},
transactions_root = transactions_root =
if transactions_root.isSome: if transactions_root.isSome:
Opt.some transactions_root.get Opt.some transactions_root.get