def beacon_block_validator(msg_forwarder: ID, msg: rpc_pb2.Message) -> bool: try: block = ssz.decode(msg.data, BeaconBlock) except (TypeError, ssz.DeserializationError) as error: logger.debug( bold_red("Failed to validate block=%s, error=%s"), encode_hex(block.signing_root), str(error), ) return False state_machine = chain.get_state_machine(block.slot - 1) state = chain.get_state_by_slot(block.slot - 1) state_transition = state_machine.state_transition # Fast forward to state in future slot in order to pass # block.slot validity check state = state_transition.apply_state_transition( state, future_slot=block.slot, ) try: process_block_header(state, block, state_machine.config, True) except (ValidationError, SignatureError) as error: logger.debug( bold_red("Failed to validate block=%s, error=%s"), encode_hex(block.signing_root), str(error), ) return False else: return True
def FuzzerRunOne(input_data: bytes) -> typing.Optional[bytes]: test_case = ssz.decode(input_data, sedes=BlockHeaderTestCase) # TODO(gnattishness) any other relevant exceptions to catch? try: post = process_block_header( state=test_case.pre, block=test_case.block, config=SERENITY_CONFIG, check_proposer_signature=False, ) except ValidationError as e: return None return ssz.encode(post)
def run_with(_cls, inputs: Tuple[BeaconState, BeaconBlock], config: Optional[Eth2Config]) -> BeaconState: state, block = inputs return process_block_header(state, block, config)