# Protect against uncle bandits

**URL:** https://collective.flashbots.net/t/protect-against-uncle-bandits/772
**Category:** Searchers
**Tags:** question
**Created:** [November 24, 2022, 4:45pm UTC](https://collective.flashbots.net/t/protect-against-uncle-bandits/772 "2022-11-24T16:45:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![krypston](https://collective.flashbots.net/letter_avatar_proxy/v4/letter/k/977dab/32.png) [@krypston](https://collective.flashbots.net/u/krypston)
#### Post date: [November 24, 2022, 4:45pm UTC](https://collective.flashbots.net/t/protect-against-uncle-bandits/772/1 "2022-11-24T16:45:52Z")

</div>

In your docs it is stated that in order the get protection against uncled blocks, the following check should be included in the smart contratc function or transaction:

`require(blockhash(block.number - 1) == expectedParentHash, "block was uncled");`

My question is: where do I source the expectedParentHash? How can I implement this correctly? As far as I know, expectedParentHash is not a global variable. How can I make my contract find the right one?

Thanks

---

<div class="post-metadata">

### Author: ![krypston](https://collective.flashbots.net/letter_avatar_proxy/v4/letter/k/977dab/32.png) [@krypston](https://collective.flashbots.net/u/krypston)
#### Post date: [December 10, 2022, 11:43am UTC](https://collective.flashbots.net/t/protect-against-uncle-bandits/772/2 "2022-12-10T11:43:19Z")

</div>

can anybody please provide some support???

---

<div class="post-metadata">

### Author: ![Fred](https://collective.flashbots.net/user_avatar/collective.flashbots.net/fred/32/1288_2.png) [@Fred](https://collective.flashbots.net/u/Fred)
#### Post date: [December 11, 2022, 11:21pm UTC](https://collective.flashbots.net/t/protect-against-uncle-bandits/772/3 "2022-12-11T23:21:02Z")

</div>

`expectedParentHash` is the current head of the chain, the block which you are analyzing, and building upon.

In the case of your tx landing in an uncle block (or a reorg), this check would prevent the tx from being grabbed and then included in the canonical chain.

Uncle blocks aren’t a thing in PoS Ethereum thought, as each slot in an epoch already has a predetermined block proposer. [Reorgs](https://barnabe.substack.com/p/pos-ethereum-reorg) however can technically still happen.

cc @brock: does it makes sense to still include this check? 👀

---

<div class="post-metadata">

### Author: ![krypston](https://collective.flashbots.net/letter_avatar_proxy/v4/letter/k/977dab/32.png) [@krypston](https://collective.flashbots.net/u/krypston)
#### Post date: [December 12, 2022, 10:51am UTC](https://collective.flashbots.net/t/protect-against-uncle-bandits/772/4 "2022-12-12T10:51:02Z")

</div>

I am sorry. I am afraid I did not convey the doubt correctly.

I know how to search for the last block hash (for instance in the block explorer). My question is how to implement that variable in the contract I want to make the frontrunning-safe call to. Obviously, it cannot be hard coded in it, since it first has to be deployed and AFTERWARDS, in a later block, called upon, so the `expectedParentHash` **is unknown at the time of deployment**.

It can be an input of the called function, together with all the other parameters. But this method would require to keep an eye on the block explorer, grab the hash as soon as a new block is produced and run to input it in my transaction hoping I still make it on time before a newer block is produced. Is this the case or am I missing something? Can you please provide a sample / guideline of how this has been implemented?

Thank you very much for your replies.

---

<div class="post-metadata">

### Author: ![mateusz](https://collective.flashbots.net/user_avatar/collective.flashbots.net/mateusz/32/336_2.png) [@mateusz](https://collective.flashbots.net/u/mateusz)
#### Post date: [December 15, 2022, 3:56pm UTC](https://collective.flashbots.net/t/protect-against-uncle-bandits/772/5 "2022-12-15T15:56:06Z")

</div>

Since the timestamp is now deterministic (a 12-second multiple of the slot), could checking that help?
