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

How to learn fortune telling and horoscope reading

From face reading to fortune telling, are there a...

Women with moles on their collarbones should look at the specific location

Women usually have high requirements for their bo...

The look of being devastated after failure

Failure is something that is unavoidable for ever...

MinerOS opens AE mining for free today! No limit on the number of units!

Source: minerOS Subscription Account No nonsense ...

What does a fierce face mean for a man? What kind of man is the most fierce?

A kind person gives people a very good first impr...

Bitcoin price drops, but Bitcoin network hashrate remains around 100Eh/s

Despite the recent drop in cryptocurrency prices,...

How to know your health by looking at your palm lines

A person's health condition will be shown in ...

ATH season! Will Ethereum break through $2,500? Laptop mining boom reappears

There are two English abbreviations that coin inv...

Palmistry: How to tell if two people are compatible

Palmistry can tell whether two people are compati...

Fidelity Marketing Executive: 90% of Top Clients Are Asking About Bitcoin

On August 16, Christine Sandle, head of sales and...

How to read the palm lines and start fortune-telling career

In today's fast-paced society, everyone is wo...