以太坊源碼分析(41)hashimoto源碼分析

more memory intensive algorithm, Percival's "scrypt" password based key derivation function1. Many
implementations set the scrypt arguments to low memory requirements, defeating much ofthe purpose of
the key derivation algorithm. While changing to a new algorithm, coupled with the relative obscurity of the
various scrypt­based cryptocurrencies allowed for a delay, scrypt optimized ASICs are now available.
Similar attempts at variations or multiple heterogeneous hash functions can at best only delay ASIC
implementations.

 

「ASIC抗性」的初始嘗試包括改變比特幣的sha256算法,用不一樣的,更多的內存密集型算法,Percival's "scrypt" password based key derivation function。許多實現都將腳本參數設置爲低內存要求,這大大破壞了密鑰派生算法的目的。在改用新算法的同時,再加上各類以scrypt爲基礎的加密貨幣的相對朦朧可能致使延遲,並且scrypt優化的ASIC如今已經上市。相似的變化嘗試或多個異構散列函數最多隻能延遲ASIC實現。

 

Leveraging shared data sets to create I/O bound proofs

 

利用共享數據集建立I / O限制證實

 

    "A supercomputer is a device for turning compute-bound problems into I/O-bound problems."
    -Ken Batcher



    「超級計算機是將計算受限問題轉化爲I / O約束問題的一種設備。」
    Ken Batcher

 

Instead, an algorithm will have little room to be sped up by new hardware if it acts in a way that commodity computer systems are already optimized for.

 

相反,若是一種算法以商品計算機系統已經優化的方式運行,那麼算法將沒有多少空間能夠被新硬件加速。

 

Since I/O bounds are what decades ofcomputing research has gone towards solving, it's unlikely that the relatively small motivation ofmining a few coins would be able to advance the state ofthe art in cache hierarchies. In the case that advances are made, they will be likely to impact the entire industry of computer hardware.

 

因爲I / O界限是幾十年來計算研究已經解決的問題,挖掘一些加密貨幣的相對較小的動機將不可能提升緩存層次結構的藝術水平。 在取得進展的狀況下,可能會影響整個計算機硬件產業。

 

Fortuitously, all nodes participating in current implementations ofcryptocurrency have a large set of mutually agreed upon data; indeed this 「blockchain」 is the foundation ofthe currency. Using this large data set can both limit the advantage ofspecialized hardware, and require working nodes to have the entire data set.

 

幸運的是,參與當前加密貨幣實施的全部節點都有大量相互贊成的數據;實際上,「區塊鏈」是貨幣的基礎。 使用這個大數據集既能夠限制專用硬件的優勢,又可讓工做節點擁有整個數據集。

 

Hashimoto is based offBitcoin’s proofofwork2. In Bitcoin’s case, as in Hashimoto, a successful
proofsatisfies the following inequality:

 

Hashimoto是基於比特幣的工做量證實。 在比特幣的狀況下,和Hashimoto同樣,一個成功的證實知足如下不等式:

 

    hash_output < target

 

For bitcoin, the hash_output is determined by

 

在比特幣中, hash_output是由下面決定的。

 

    hash_output = sha256(prev_hash, merkle_root, nonce)

 

where prev_hash is the previous block’s hash and cannot be changed. The merkle_root is based on the transactions included in the block, and will be different for each individual node. The nonce is rapidly incremented as hash_outputs are calculated and do not satisfy the inequality. Thus the bottleneck of the proofis the sha256 function, and increasing the speed ofsha256 or parallelizing it is something ASICs can do very effectively.

 

prev_hash是前一個區塊的hash值,並且不能更改。merkle_root是基於區塊中的交易生成的,而且對於每一個單獨的節點將是不一樣的。咱們經過修改nonce的值來讓上面的不等式成立。這樣整個工做量證實的瓶頸在於sha256方法,並且經過ASIC能夠極大增長sha256的計算速度,或者並行的運行它。

 

Hashimoto uses this hash output as a starting point, which is used to generated inputs for a second hash function. We call the original hash hash_output_A, and the final result of the prooffinal_output.

 

Hashimoto使用這個hash_output做爲一個起點,用來生成第二個hash函數的輸入。咱們稱原始的hash爲hash_output_A, 最終的結果爲 prooffinal_output.

 

Hash_output_A can be used to select many transactions from the shared blockchain, which are then used as inputs to the second hash. Instead of organizing transactions into blocks, for this purpose it is simpler to organize all transactions sequentially. For example, the 47th transaction of the 815th block might be termed transaction 141,918. We will use 64 transactions, though higher and lower numbers could work, with different access properties. We define the following functions:

 

hash_output_a可用於從共享區塊鏈中選擇多個事務,而後將其用做第二個散列的輸入。 而不是組織交易成塊,爲此目的是順序組織全部交易更簡單。 例如,第815個區塊的第47個交易可能被稱爲交易141,918。 咱們將使用64個交易,儘管更高和更低的數字能夠工做,具備不一樣的訪問屬性。 咱們定義如下功能:

 

- nonce 64­bits. A new nonce is created for each attempt.
- get_txid(T) return the txid (a hash ofa transaction) of transaction number T from block B.
- block_height the current height ofthe block chain, which increases at each new block

 

- nonce 64­bits. 每次嘗試會生成一個新的nonce值.
- get_txid(T) 從block B中經過交易序號來獲取交易id
- block_height 當前的區塊高度

 

Hashimoto chooses transactions by doing the following:

 

Hashimoto 經過下面的算法來挑選交易:

 

    hash_output_A = sha256(prev_hash, merkle_root, nonce)
    for i = 0 to 63 do
        shifted_A = hash_output_A >> i
        transaction = shifted_A mod total_transactions
        txid[i] = get_txid(transaction) << i
    end for
    txid_mix = txid[0] ⊕ txid[1] … ⊕ txid[63]
    final_output = txid_mix ⊕ (nonce << 192)

 

The target is then compared with final_output, and smaller values are accepted as proofs.

 

若是 final_output 比 target小,那麼就會被接受。node

相關文章
相關標籤/搜索