**Filecoin-Introduction to WinningPoSt Logic**

Written by Star Li, translated from the original article.

Part of Lotus PoSt (Proof of Spacetime) has changed from electionPoSt to two new PoSt; one is winningPoSt and the other is windowPoSt. Let ’s talk about winningPoSt first. winningPoSt, as the name suggests, is PoSt when it is winning. The so-called winning is to obtain the block reward.

Simply put, winningPoSt is a sector randomly checked, and the 66 randomly selected Merkle paths in this sector are correct. The code logic begins with the code of Lotus go. It all starts with the block-the mineOne function of the Miner structure of lotus / miner / miner.go.

Among them, the MinerGetBaseInfo function is to obtain some basic information, including the sector information that needs to be extracted. The ComputeProof function is to calculate the winningPoSt proof.

The specific implementation of this logic is implemented in rust-fil-proofs, which is the rust language. From go to rust-fil-proofs, many interfaces are crossed:

Among them, the MinerGetBaseInfo function is to obtain some basic information, including the sector information that needs to be extracted. The ComputeProof function is to calculate the winningPoSt proof.

The specific implementation of this logic is implemented in rust-fil-proofs, which is the rust language. From go to rust-fil-proofs, many interfaces are crossed:

The interface in the middle will not be discussed, we will just look at the two API functions provided by rust-fil-proofs.

# 01 Random Number Setting

The number of sectors and the total number of leaves for random inspection are defined in rust-fil-proofs / filecoin-proofs / src / constants.rs:

That is to say, to extract a sector from the effective sector, and spot check 66 leaf nodes on this sector.

# 02** Sector Random Check Logic**

The generate_winning_post_sector_challenge function implements the spot check logic of the sector. How does the core logic spot check the sector? The specific logic is in the function of fallback :: generate_sector_challenges:

Simply put, the sha256 hash is calculated by using the random_information of random_provider_id and the random number of the sector and calculating the result with the current limited number of sectors. That is, the sector_index is the sector ID of the final spot check.

# 03** Challenge Leaf Spot Check Logic**

generate_winning_post checks the leaf nodes on the Merkle tree (replica_r_last) formed by the selected sectors. The calculation logic of spot checking leaf nodes is in the function of fallback :: generate_leaf_challenge:

Hash the random information, sector id, and challenge leaf number. Then challenged_range_index is the hash result modulo the total number of leaves. The 32G Sector has 1G leaves.

# 04** Zero-Knowledge Proof Circuit**

The calculation part of zero-knowledge proof can be viewed in the rust-fil-proofs / post / fallback directory. The general logic module and structure can be seen in the previous article introduction: Filecoin-PoREP Circuit Introduction

Next we look at the sector structure in rust-fil-proofs / post / fallback / circuit.rs. This structure represents a spot check. It can be seen from the synthesize function:

comm_r is a public input, while comm_r_last and comm_c are private inputs.

Verify that comm_r is calculated by comm_c and comm_r_last.

**Conclusion**

Lotus PoSt includes two parts: winningPoSt and windowPoSt. winningPoSt is the PoSt certificate that needs to be provided when obtaining the block reward. From all valid sectors, extract a sector and check the 66 leaves on the sector.

**Star Idea**

Technology changes the world

Long press the QR code to follow me

Technical translation by K. Branigan.

Wonderful review of past articles (use translator)

**Filecoin logic and zero-knowledge proof applications:**

- Filecoin — Logic combing and source code introduction
- Filecoin — Introduction to the source code of the PoRep and PoSt algorithms
- Filecoin — What Lotus storage proves
- Filecoin — Deep understanding of SDR algorithm
- Filecoin — Sector processing logic changes in testnet3
- Filecoin — PoREP circuit introduction
- Filecoin — Snark as a Service data analysis

**Elliptic curve:**

**The theoretical knowledge of zk-SNARK (Groth16)**:

- Zero-knowledge proof-getting started with zkSNARK
- Zero-knowledge proof-from QSP to QAP
- Zero-knowledge proofs-constructing zero-knowledge proofs based on polynomials
- Zero-knowledge Proof-Introduction to Groth16 Algorithm
- Zero-knowledge Proof-Detailed Explanation of Groth16 Calculation
- Zero-knowledge proof-zkSNARK’s Nullifier Hash attack
- Zero-knowledge proof-a new type of Merkle tree (Shrubs)

**Basic library source code analysis of zero-knowledge proof:**

- Zero-knowledge proof-libsnark source code analysis
- Zero-knowledge proof-bellman source code analysis
- Proof of zero-knowledge-ethsnarks source code introduction
- Zero-knowledge proof-deep understanding of ZoKrates
- Zero-knowledge proof-introduction to DIZK
- Zero-knowledge proof-DIZK source code introduction

**Practical examples of zero-knowledge proof:**

**GPU accelerated theory and practice**

- CUDA-cuda-fixnum source code guide
- Zero-knowledge Proof-Coda SNARK Challenge (Stage1)
- Zero-knowledge Proof-Coda SNARK Challenge (Stage2)

**Zero-knowledge proof application scenarios:**

- Loopring DEX 3.0 Zero Knowledge Proof-Loopring DEX 3.0
- Zero-knowledge proof-in-depth understanding of EYBlockchain
- Zero-knowledge proof-talk about EYBlockchain again
- Zero-knowledge proof-zk-SNARK application scenario analysis
- Zero knowledge proof-Semaphore source code introduction
- Zero-knowledge proof-Mixer application analysis

**Zcash logic introduction:**

- Zcash-various keys and signatures, do you understand?
- Zcash-Graphical Transaction structure
- Zcash-Pedersen Hash calculation

**Summary at the end of the year:**

**Source code analysis**

**Other**

**More 6Block Mining Pool:** Twitter, Telegram, Bitcointalk