TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How does a blockchain server verifies the hash sent by a miner?

2 点作者 0xhh超过 3 年前
I&#x27;m sorry if this is not the right place to ask. I did not find any relevant subreddit on reddit to ask, so I came here.<p>I&#x27;m trying to follow some python tutorials on implementing a blockchain. I implemented the mining function, where it generates a hash based on previous hash, timestamp and some data. And this hash is verified by checking whether there are 4 zeros in the starting hash and is then added to an array called chain.<p>But, How does a server hosted somewhere on the cloud verifies this hash sent by a miner? should the server calculate the hash before the miner does and check whether they are equal?<p>Or will the server only checks for the starting zeros in the hash? In this case, miners can cheat right? just by sending a random string with 4 starting zeros?<p>Please enlighten me and explain me like I&#x27;m five. Thank you!

2 条评论

brudgers超过 3 年前
Finding a new value that hashes to four leading zeros is computationally difficult. Because the hash function is designed so that very few values hash to four leading zeros.<p>But testing to see if a value hashes to zero is computationally simpler. Just take the value, hash it, and see if it has four leading zeros.<p>What is sent is the input value, not the output with four leading zeros.<p>The miner claims &quot;if you hash this value, you will get four leading zeros.&quot;
wmf超过 3 年前
<i>should the server calculate the hash before the miner does and check whether they are equal?</i><p>Yes, this is how it works.