# Weak Subjectivity and Sync by Hsiu-Ping Lin (Devcon5)

- Channel: [Devcon](https://streameth.org/devcon)
- Date: 2020-10-09
- Duration: 11:41
- Topics: blockchain, smart contracts, distributed ledger, ethereum
- Watch: https://streameth.org/watch/yt-rxqVvu4trX4
- YouTube: https://www.youtube.com/watch?v=rxqVvu4trX4

## Description

Visit the https://archive.devcon.org/ to gain access to the entire library of Devcon talks with the ease of filtering, playlists, personalized suggestions, decentralized access on IPFS and more.
https://archive.devcon.org/archive/watch/5/weak-subjectivity-and-eth-20-sync

Hsiu-Ping Lin speaks on Weak Subjectivity and Eth 2.0.

Speaker(s): Hsiu-Ping Lin
Skill level: Advanced
Track: Consensus layer
Keywords: eth2, fork choice rule, PoS, technical

Follow us: https://twitter.com/efdevcon, https://twitter.com/ethereum
Learn more about devcon: https://www.devcon.org/
Learn more about ethereum: https://ethereum.org/ 

Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. 
Devcon 5 was held in Osaka, Japan on Oct 8 - 11, 2019.
Devcon is organized and presented by the Ethereum Foundation, with the support of our sponsors. To find out more, please visit https://ethereum.foundation/

## Transcript

Um hi. Um Shuhan Lin. You can call me also call me Nicholas. I'm a fellow at the Ethereum Foundation. Um today I'll be talking about weak subjectivity and how the sinking protocol works in Eth2. Um so this talk consists of three parts: weak subjectivity and Eth2 sync. And I'll let um Finally, I'll make a brief introduction on the fork choice rule used in Eth2 right now. So first, um I will talk about what subjectivity means in this context and why is it weak. So what is objectivity means in this context? So objectivity in this context could be for example like proof of work. Uh you know, how much work done, how much electricity spent. And so a node joining the Bitcoin or Ethereum network knows uh it can request proof of work from any peers. And then he can use this proof of work to objectively identify the canonical chain. But in proof of stake, the work could be like running state transition, creating, verifying signatures. But this work are tiny compared to proof of work. So every validator can create super long fork chains secretly at any time. And so this enables the the long range attack. So basically in long range attack, for example, say Eve is an attacker and he first requests withdrawal on the main chain. And after some time, his withdrawal is successfully processed. Now he she has no stake on the main chain. And later Alice goes online and now Eve can create a fork chain. And on that chain, she did not withdraw withdrawal and continues to vote on the fork chain. And now Eve can feed this fork chain to Alice. And later when Alice find out that Eve has been feeding her with the fork chains, she will try to use this fork chain as a proof to prove that Eve was double voting. And she will send this evidence to the main chain, but then she will find out that Eve no longer has any stake on the on the main chain. So uh subjectivity uh in this context means that you need to trust some sources to identify the canonical chain. And why is it weak? Uh it's weak because we only need to trust when first you join join the network for the first time. Or second, you were offline for a long time. Uh for how long? It depends on how long it takes for the the attacker to withdraw their stake. And this is called the weak subjectivity period. And weak subjectivity period is going to determine if we're going to need trust when we are sinking. So next, I will talk about how the sinking protocol works in Eth2. Um I will walk through how the client sync in three different situations. The first is how the client sync when you bootstrap your node the first time. And the second one is when you goes offline and logging back before the weak subjectivity period ends. Uh the third situation is when you stay offline for too long, for longer than weak subjectivity period. Okay, um first, how does the client sync when bootstrap your node the first time? You need to trust. You trust the bootstrap nodes, you trust the genesis blocks, genesis state. Or if the genesis is already way back in the past, you will trust latest point latest checkpoint instead. So say if now you have a trusted genesis or latest checkpoint, uh you will connect to peers and you will first exchange latest checkpoint and head blocks and some other infos to decide if you are you two are on the same chain. And if you are, then you will start requesting missing blocks. Or if you are not on the same chain, you will simply disconnect. So second situation, how does client sync when you goes offline but logging back in time? Uh first, you still need to trust. You trust You trust the bootstrap nodes. Or maybe you can use the peer info you persist in the database during last connection. But now you do not need to trust the latest checkpoint because you can use the checkpoint the last time you were online and start sinking from there. It is mostly same. You have the checkpoint and you connect to peers and you start exchanging latest checkpoint, head block and some other informations to decide if you are on the same chain. And if you are, you request missing blocks. Uh but note that the client will only support requesting blocks since the start of the weak subjectivity period, which means that you won't be able to sync the blocks that's older than the start of the weak subjectivity period. Okay, and if you are not on the same same chain, you will the peer will notify us and then we will disconnect. Okay, third situation, how does client sync when you stay offline for longer than weak subjectivity subjectivity period? So it's basically the same as when you as the way you sync when you bootstrap your node the first time. You trust genesis block or you trust the latest checkpoint and start sinking from there. Okay, once we done once we finish the sinking, we will have a picture of how the chain or how the block tree looks like. And then we'll apply the fork choice rule to get a score of each chain. And then we can identify the canonical chain. So before I get to the fork choice rule, there's two type of two types of checkpoints. Um first one is finalized checkpoint. The second one is justified checkpoint. And we do not override the finalized checkpoint unless there's an attack. But in that case, we can know for sure that at least a 1/3 of the validating is will be burned. Sorry, that's a typo here. And for finalized for justified checkpoint, it can be over it can be overridden. We will choose we will switch to the more recent justified checkpoint. Okay, so after justified checkpoint is decided, we will apply the fork choice rule on different fork chains. And the score counting starts from justified checkpoint. But here we cannot use longest chain rule because as I previously mentioned, the attacker can secret secretly create super long fork chains anytime. So what fork choice rule do we use? We use LMD Ghost. Stands for latest message driven Ghost. Ghost stands for greedy heaviest observed subtree. Okay, um how does the Ghost fork choice rule works? Say we have different fork chains here. And the white square is the block. And the green circle is the the attestation. The attestation is the validator. The vote cast by the validator. Uh the validator would vote for the block that they think is the head block of the canonical chain at that time. So we have the votes. And then we will do the score count. The score of a block is the sum of the score of all his child blocks. And once we have the score count, we will start from justified checkpoint and goes all the way down to the head block. And in each step each in in each step, when there's a fork, we choose the one with higher score. And so in Ghost fork choice rule, we will have the chain on the top as the winning chain, as the chain with higher highest score. Okay, next, how how does the LMD Ghost works? The post by their ex research summarized pretty well. You don't care test votes. Whose sender might not receive other messages due to the network latency. In short, it means that we only count the validators latest vote. So now say there are six validators and these are the votes they cast. And since in LMD Ghost, we only count the validators latest vote. So this will what the this will be what the vote count like. And so we will get different score count and apply the same rule same choosing rule, we will have now we will have the chain on on the bottom as the winning chain. And now I want to briefly mention the optimization on LMD Ghost. The idea of the optimization is basically that when we running a fork choice rule, we skip the blocks that no validators vote for. And so this will save us time and memory when traversing the block tree back and forth. Okay, there's one thing worth mentioning is that we sync blocks but not the attestations. So we wait for attestation to be propagated to us. It can come in as the form of single attestation, aggregated attestations, or attestations that included in the blocks. And we take all three kinds of attestation into account when in our fork choice rule. But since we do not sync the attestation. Uh that means every node could uh receive different attestation at different time. Uh so, every node could have different view. They have different They could have different vote count for each four chains. So, this creates uh a window for the attacker. The attacker can withhold attestation and broadcast them at once to make a victim switch between different chains repeatedly. But uh there's a a prerequisite for this attack is that there has to be a temporary network failure. And one attack is called decoy flip-flop attack. And we you can read more about it on the Eth Research Forum. And one possible mitigation is the recent proposed recently proposed uh variant of Ghost is called fresh message-driven Ghost. And in short, it's basically that we do not accept attestation too long ago. Uh for example, we do not accept attestation from maybe 2 weeks past ago. And okay, that's my introduction on weak subjectivity if you sync and fortress rule today. Thank you.
