Published in

6block

# 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.

More 6Block Mining Pool: Twitter, Telegram, Bitcointalk

--

--

## More from 6block

6block focuses on “Unicorn” projects in the blockchain area, providing solutions for cryptocurrency mining, including highly efficient mining programs, mining pools, hardware, cloud mining, and wallets.