import hashlib


def valid_proof(last_proof, proof, last_hash, difficulty):
	"""
	Validates the Proof

	:param last_proof: <int> Previous Proof
	:param proof: <int> Current Proof
	:param last_hash: <str> The hash of the Previous Block
	:return: <bool> True if correct, False if not.
	"""

	guess = f'{last_proof}{proof}{last_hash}'.encode()
	guess_hash = hashlib.sha256(guess)
	binary_hash = ''.join(format(n, '08b') for n in guess_hash.digest())

	return binary_hash[:difficulty] == '0' * difficulty