Filecoin Interpretation | What wins PoST?

Filecoin Interpretation | What wins PoST?

A part of LotusPoSt has been changed from the campaign PoSt to two new PoSt, one is winningPoSt and the other is windowPoSt .

Let's talk about winningPoSt first. As the name suggests, winningPoSt is the PoSt when winning. The so-called winning means obtaining the block right.

Simply put, winningPoSt is a randomly checked sector in which 66 randomly selected Merkle paths can be correct. Then let's talk about the code logic. From the Lotus code. It all starts with the block of the mineOne function of the Miner structure of lotus/miner/miner.go.

func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningBase) (*types.BlockMsg, error) {mbi, err := m.api.MinerGetBaseInfo(ctx, addr, round, base.TipSet.Key())rand, err := m.api.ChainGetRandomness(ctx, base.TipSet.Key(), crypto.DomainSeparationTag_WinningPoStChallengeSeed, base.TipSet.Height()+base.NullRounds, nil)
prand := abi.PoStRandomness(rand)
postProof, err := m.epp.ComputeProof(ctx, mbi.Sectors, prand)

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

Because the specific implementation of these logics is implemented in rust-fil-proofs (ie rust language). From rust to rust, many interfaces are crossed:

Only the two API functions provided by rust-fil-proofs are introduced, and the intermediate interface will not be introduced.

Challenge leaf count

The number of sectors and total number of leaves to challenge are defined in rust-fil-proofs/filecoin-proofs/src/constant.rs:

pub const WINNING_POST_CHALLENGE_COUNT: usize = 66;
pub const WINNING_POST_SECTOR_COUNT: usize = 1;

That is, a sector is extracted from the valid sectors and 66 leaf nodes to be challenged are selected on the sector.

The logic of industry selection facing challenges

The generate_winning_post_sector_challenge function implements the challenge logic of the department. How does the core logic check the department? The specific logic is:

In the fallback::generate_sector_challenges function:

let mut hasher = Sha256::new();
hasher.input(AsRef::<[u8]>::as_ref(&prover_id));
hasher.input(AsRef::<[u8]>::as_ref(&randomness));
hasher.input(&n.to_le_bytes()[..]);let hash = hasher.result();let sector_challenge = LittleEndian::read_u64(&hash.as_ref()[..8]);
let sector_index = sector_challenge % sector_set_len;

In short, it uses the random_information of the random_provider_id and the random number of the sector to calculate the hash value of sha256. The calculation result and the current limited number of sectors are modulo. That is, sector_index is the sector ID of the final query.

Challenging leaf selection logic

generate_winning_post checks the leaf node on the Merkle tree (replica_r_last) composed of the selected sectors. The calculation logic of the challenge leaf node is implemented by the fallback::generate_leaf_challenge function :

let mut hasher = Sha256::new();
hasher.input(AsRef::<[u8]>::as_ref(&randomness));
hasher.input(&sector_id.to_le_bytes()[..]);
hasher.input(&leaf_challenge_index.to_le_bytes()[..]);
let hash = hasher.result();let leaf_challenge = LittleEndian::read_u64(&hash.as_ref()[..8]);let challenged_range_index = leaf_challenge % (pub_params.sector_size / NODE_SIZE as u64);

Hash random information, sector ID and challenge leaf number. Calculate the result modulo the total number of leaves. 32G sector has 1G leaf number.

zk-SNARK Circuit

The computational part of the zero-knowledge proof can be viewed in the rust-fil-proofs/post/fallback directory.

The sector structure is discussed in rust/background/fallback/circuit.rs. This structure is a challenge. As can be seen from the synthesize function:

// 1. Verify comm_r
let comm_r_last_num = num::AllocatedNum::alloc(cs.namespace(|| "comm_r_last"), || {
comm_r_last
.map(Into::into)
.ok_or_else(|| SynthesisError::AssignmentMissing)
})?;let comm_c_num = num::AllocatedNum::alloc(cs.namespace(|| "comm_c"), || {
comm_c
.map(Into::into)
.ok_or_else(|| SynthesisError::AssignmentMissing)
})?;let comm_r_num = num::AllocatedNum::alloc(cs.namespace(|| "comm_r"), || {
comm_r
.map(Into::into)
.ok_or_else(|| SynthesisError::AssignmentMissing)
})?;comm_r_num.inputize(cs.namespace(|| "comm_r_input"))?;

comm_r as public input and other comm_r_last and comm_c as private inputs.

// 1. Verify H(Comm_C || comm_r_last) == comm_r
{
let hash_num = ::Function::hash2_circuit(
cs.namespace(|| "H_comm_c_comm_r_last"),
&comm_c_num,
&comm_r_last_num,
)?;// Check actual equality
constraint::equal(
cs,
|| "enforce_comm_c_comm_r_last_hash_comm_r",
&comm_r_num,
&hash_num,
);
}

Verify that comm_r is calculated from comm_c and comm_r_last.

// 2. Verify Inclusion Paths for(i,(leaf,path))in leafs.iter().zip(paths.iter()).enumerate() {
PoRCircuit:: ::synthesize(
cs.namespace(|| format!("challenge_inclusion_{}", i)),
Root::Val(*leaf),
path.clone(),
Root::from_allocated:: (comm_r_last_num.clone()),
true,
)?;

Verify that the leaf node can correctly calculate the root of the Merkle tree.

Abstract

Lotus PoSt consists of two parts: winningPoSt and windowPoSt . WinningPoSt is the PoSt certificate that needs to be provided when obtaining block authority. Extract a sector from all valid sectors and challenge the 66 leaves on the sector.

——End——


<<:  When will the 4.25 million Fil reward be launched? Officials say: The miners have the final say on the launch time!

>>:  [100 Questions and Answers about Filecoin in Pictures] Question 27: What is Tipset?

Recommend

The four signs of loneliness: living alone and in poverty

Human beings are social animals. We always have f...

Analysis of Sun Li's career fortune based on face reading

Analysis of Sun Li's career fortune based on ...

Australians want to trade surplus solar energy on blockchain

An organization in Australia will use blockchain ...

As new privacy coins take over, where will Monero, Dash, and Zcash go?

The more famous digital currencies in the industr...

Face analysis: What does it mean when a woman has dimples on her face?

Face analysis: What does it mean when a woman has...

Do Ox men prefer thin or strong women? They don't like weak women.

People of different zodiac signs actually like th...

The meaning of the wisdom line starting from the life line

If the wisdom line starts from the life line and ...

Bitcoin trading volume is approaching its peak, will the price increase trend stop?

Bitcoin’s growth this season has been driven by t...

Introduction to HNS, a new hotspot for graphics card mining

Click on the blue words above to follow us~ 0 1 P...

How to tell a woman's personality from her face

As the saying goes: Appearance reflects the heart...

Three signs of a life full of wealth

Physiognomy has been profound since ancient times...