项目作者: miscellaneousbits

项目描述 :
DE10 NANO SHA3-256 Proof of Work Miner
高级语言: C
项目地址: git://github.com/miscellaneousbits/linux-socfpga-sha3-miner.git
创建时间: 2020-07-19T18:57:05Z
项目社区:https://github.com/miscellaneousbits/linux-socfpga-sha3-miner

开源协议:Other

下载


DE10 NANO SHA3 FPGA Miner

FPGA mining

Want to support this open source project? Please star it. Want to contribute?
Feel free to create pull requests following the normal github process.

Table of Contents

Introduction

In mining a proof-of-work (POW) is used to verify the authenticity of a blockchain entry. What is a POW?
A POW is a mathematical puzzle which is difficul to solve but easy to verify.

For this example an FPGA mining core is defined for a hypothetical blockchain that uses the SHA3-256 hash.

We are given:

  • H: 256 bit header of fixed value
  • N: 64 bit nonce
  • D: 256 bit difficulty

The problem we need to solve is to find any value of N, such that the SHA3-256 hash of the nonce concatenated
to the header, is less than or equal to the difficulty:

D >= SHA3({H, N})

NOTE: This will not mine a real blockchain. It would be well suited to mine the ETC chain as proposed
in ECIP-1049

Implementation

A bootable SD card image for the
DE10 NANO,
a low cost FPGA development board equipped with an Intel 5CSEBA6U23I7NDK FPGA. The FPGA includes a dual
core ARM hard processor. Ubuntu 16.04 is booted and supports the pre-installed FPGA image availlable
here and kernel driver support.

In order to provide the maximum FPGA routing resources to the mining core, HDMI, keyboard, and mouse
support have been removed. You can log in to the console either via the USB UART or SSH.

User API

The driver models the 23 32-bit miner core registers as file /dev/miner0. It supports these file operations.

  • open
  • close
  • lseek (must be to a 4 byte boundary)
  • read (must be for a length of 4 bytes)
  • write (must be for a length of 4 bytes)
  • poll/ppoll/select (wait for solution)

Only single register reads and writes are supported.

File map

Offset Name Read/Write Description
0 SOLN_REG RO 64-bit Solution
8 STATUS_REG RO 32-bit Status (see below)
12 SHA3_REG RO 32-bit Fingerprint “SHA3”
16 HDR_REG RW 256-bit Header
48 DIFF_REG RW 256-bit Difficulty
80 START_REG RW 64-bit Start nonce
88 CTL_REG RW 32-bit Control (see below)

Status register

Bit # Name Description
0 FOUND Solution found. Solution is stored and IRQ is set. IRQ cleared with next ctl. reg. read.
1 RUNNING The run ctl bit is set and the solution nonce is auto-incrementing
2 TESTING The test ctl bit is set and compare diff equal
15-8 MINER_FREQ Miner clock frequency in MHZ
19-16 MAJ_VER Miner core major version
23-20 MIN_VER Miner core minor version

Control register

Bit # Name Description
0 RUN 0 - clear, 1 - auto increment the solution nonce and check hashes
1 TEST 0 - normal mode, 1 - test mode, look for exact match with diff
2 HALT 0 - normal mode, 1 - halt mining and raise interrupt
23-16 PAD_LAST last pad byte, 0x80 for KECCACK-256 and SHA3-256
31-24 PAD_FIRST first pad byte, 0x01 for KECCACK-256, and 0x06 for SHA3-256

Installing

Prerequisites

FPGA mining

  • DE10-NANO
  • Desk/Laptop (Windows or Linux Ubuntu/Debian) to run terminal.

Download and install

Download the latest release version from this project. Using dd on Linux, or Win32DiskImager on Windows,
unzip and copy the image file a to an 8GB or greater SD card. Insert the SD card in the DE10-NANO card slot,
and power up. You can log in as user root and password miner.

The first thing to do is to expand the root partition. Making sure you note the partition
start sector.

  1. de10nano login: root
  2. Password:
  3. Last login: Fri Jul 24 20:51:03 UTC 2020 on ttyS0
  4. root@de10nano:~# fdisk /dev/mmcblk0
  5. Welcome to fdisk (util-linux 2.27.1).
  6. Changes will remain in memory only, until you decide to write them.
  7. Be careful before using the write command.
  8. Command (m for help): p
  9. Disk /dev/mmcblk0: 119.4 GiB, 128177930240 bytes, 250347520 sectors
  10. Units: sectors of 1 * 512 = 512 bytes
  11. Sector size (logical/physical): 512 bytes / 512 bytes
  12. I/O size (minimum/optimal): 512 bytes / 512 bytes
  13. Disklabel type: dos
  14. Disk identifier: 0xbdf7f996
  15. Device Boot Start End Sectors Size Id Type
  16. /dev/mmcblk0p1 2048 206848 204801 100M b W95 FAT32
  17. /dev/mmcblk0p2 227331 5309243 5081913 2.4G 83 Linux <<== Make note of partition two'2 start sector
  18. /dev/mmcblk0p3 206849 227330 20482 10M a2 unknown
  19. Partition table entries are not in disk order.
  20. Command (m for help): d
  21. Partition number (1-3, default 3): 2
  22. Partition 2 has been deleted.
  23. Command (m for help): n
  24. Partition type
  25. p primary (2 primary, 0 extended, 2 free)
  26. e extended (container for logical partitions)
  27. Select (default p):
  28. Partition number (2,4, default 2):
  29. First sector (227331-250347519, default 229376): 227331 <<== Use the same partition start address as noted above
  30. Last sector, +sectors or +size{K,M,G,T,P} (227331-250347519, default 250347519):
  31. Created a new partition 2 of type 'Linux' and of size 119.3 GiB.
  32. Command (m for help): w
  33. The partition table has been altered.
  34. Calling ioctl() to re-read partition table.
  35. Re-reading the partition table failed.: Device or resource busy
  36. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpa.
  37. root@de10nano:~# sync; reboot

Now that the partition is expanded, resize the root file system.

  1. de10nano login: root
  2. Password:
  3. Last login: Thu Feb 11 16:28:12 UTC 2016 on ttyS0
  4. root@de10nano:~# lsblk
  5. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  6. mmcblk0 179:0 0 119.4G 0 disk
  7. ├─mmcblk0p2 179:2 0 119.3G 0 part /
  8. ├─mmcblk0p3 179:3 0 10M 0 part
  9. └─mmcblk0p1 179:1 0 100M 0 part
  10. root@de10nano:~# resize2fs /dev/mmcblk0p2
  11. resize2fs 1.42.13 (17-May-2015)
  12. Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
  13. old_desc_blocks = 1, new_desc_blocks = 8
  14. The filesystem on /dev/mmcblk0p2 is now 31265023 (4k) blocks long.
  15. root@de10nano:~# df -h
  16. Filesystem Size Used Avail Use% Mounted on
  17. /dev/root 118G 2.4G 111G 3% /
  18. devtmpfs 503M 0 503M 0% /dev
  19. tmpfs 504M 0 504M 0% /dev/shm
  20. tmpfs 504M 6.7M 497M 2% /run
  21. tmpfs 5.0M 0 5.0M 0% /run/lock
  22. tmpfs 504M 0 504M 0% /sys/fs/cgroup
  23. tmpfs 101M 0 101M 0% /run/user/0
  24. root@de10nano:~# sync; reboot

You can now build and run the miner core test

  1. root@de10nano:~# cd linux-socfpga-sha3-miner/tools/testing/miner/
  2. root@de10nano:~/linux-socfpga-sha3-miner/tools/testing/miner# make
  3. main.c -> main.o
  4. sha3.c -> sha3.o
  5. main.o sha3.o -> test
  6. root@de10nano:~/linux-socfpga-sha3-miner/tools/testing/miner# ./test
  7. Permutation stage test
  8. Test 0 407e0758049d0b43 ................................................
  9. Test 1 582acaed0a5b2461 ................................................
  10. Test 2 783c26f63f572ed8 ................................................
  11. Test 3 6b4d3be558640236 ................................................
  12. Test 4 100e19fc5bb454bc ................................................
  13. Test 5 472bec212ebc9746 ................................................
  14. Test 6 4a4ceb022c632c02 ................................................
  15. Test 7 4769389949d7c4e6 ................................................
  16. Test 8 402ecfda45b559ed ................................................
  17. Test 9 263cc2ad13c68104 ................................................
  18. PASS
  19. Interrupt test
  20. Test 0 1c39c47e0a343594 ................................................
  21. Test 1 5774c4a41d654b74 ................................................
  22. Test 2 38cd2c903d4f61a8 ................................................
  23. Test 3 64ba1fdb75250e7d ................................................
  24. Test 4 230a37d027d8fc18 ................................................
  25. Test 5 7fa75b5279c17342 ................................................
  26. Test 6 44141d410d935089 ................................................
  27. Test 7 7f86870c3fe0fa5d ................................................
  28. Test 8 273b032b331bfb8e ................................................
  29. Test 9 56c541f173231eb6 ................................................
  30. PASS
  31. Hash rate test
  32. Miner clock 93 MHz, pipeline stages 8, expected hash rate 31.00 MH/S
  33. Measured 31.00 MH/S
  34. PASS
  35. Mining test
  36. Search 1
  37. Header: 8c70c521f02d6c0d2e5bf63c580e19596006ee44a2f78b59639f37221457f31f
  38. Start: 59dc07574dc801a2
  39. Solution: 59dc075750f39248 (53,186,726 hashes)
  40. Hash: 0000000189ffbac8ce8d11e655a700ab78892d379227becac54fdbed98f2fa78
  41. Difficulty: 00000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  42. PASS
  43. Search 2
  44. Header: 10836d3238fe0265629bdc49c237032a06715a29310aab5d4a3d5821a7990a7c
  45. Start: 5ad3f8a135ac2f9a
  46. Solution: 5ad3f8a1841dbcc8 (1,316,064,558 hashes)
  47. Hash: 000000054f0279237c0cc086e2c95afd231514925567f0d9b1df63092870defb
  48. Difficulty: 00000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  49. PASS
  50. Search 3
  51. Header: d6a1cd543ab6591d6a2d5d465ed979148e7c0874d3b960027da0f201df2aa114
  52. Start: 6cb423f27e56b7ae
  53. Solution: 6cb423f283995212 (88,250,980 hashes)
  54. Hash: 00000003c031045e1117b61c13d9689e5ba4e69d4b70cf33e6b1ced8f1ae585c
  55. Difficulty: 00000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  56. PASS
  57. Search 4
  58. Header: aac179487e94790e9ee5c20bd81c7005d7a29267feebb0507b14fc5e3a42ca09
  59. Start: 70a4431238d81bd2
  60. Solution: 70a44312bf88d8c6 (2,259,729,652 hashes)
  61. Hash: 000000068019e27f3aecb15ab5ba7b8d44c5ba8ab913a21502c647358703fb68
  62. Difficulty: 00000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  63. PASS
  64. Search 5
  65. Header: dc43925723c611230a1adb1d3fdf6e21e5fd144d108b354770e9197f303b6d6e
  66. Start: 434024b759ede211
  67. Solution: 434024b76391f6cc (161,748,155 hashes)
  68. Hash: 00000000ea972c480a4386347bdb9765f847c7d3fe0434d875737b4ce616da1f
  69. Difficulty: 00000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  70. PASS
  71. Search 6
  72. Header: ca6a19248dc60d184b9847773498766aec9f872cd914506b0752d76c69407a2e
  73. Start: 7ff13fb9598b75fa
  74. Solution: 7ff13fb95f36fb91 (95,126,935 hashes)
  75. Hash: 00000002e97e6b6c814c85a4bf38dcac30a07c69893ab7e88cada26fc774f853
  76. Difficulty: 00000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  77. PASS
  78. Search 7
  79. Header: 17f8d02c63016b48780a0568b5dd93383c1edb4d4fad974fb3c94409b732d72c
  80. Start: 5961ef8979e90cc6
  81. Solution: 5961ef898edca07b (351,507,381 hashes)
  82. Hash: 00000006acce4539f97d0610957b7e93d3b8aecbe9d4933a034f89e4b8815926
  83. Difficulty: 00000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  84. PASS
  85. Search 8
  86. Header: 894eaf656633f430e9d2fa1c93688a03a5126352ced00f6aa4f3bf4a15fc7c51
  87. Start: 587d0bfe0e00185b
  88. Solution: 587d0bfe1c25ecc0 (237,360,229 hashes)
  89. Hash: 000000016283025bc9db671f42549f1ce8d9468a147567446d8634af91a07e73
  90. Difficulty: 00000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  91. PASS
  92. Search 9
  93. Header: 26de6a2bc876967ce9de0d267176b222fc0e0d67d57e95524a8b020e0461e453
  94. Start: 010fbf3e0df3cb03
  95. Solution: 010fbf3e28c7f27a (450,111,351 hashes)
  96. Hash: 00000007c8f5966cf709f935618e5ee7f1530d721cb287e5bd2233db03306549
  97. Difficulty: 00000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  98. PASS
  99. Search 10
  100. Header: fed66f2d55b7e02d67cc5e5676e174150a957466a3ea3924c68e0c65bd5eb96f
  101. Start: 51111d5a3e6e7e4f
  102. Solution: 51111d5a7ec004d0 (1,079,084,673 hashes)
  103. Hash: 000000007d6548b93febbe7811c7b454e9db4a8ab995e3b76a20a133f202e502
  104. Difficulty: 00000007ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
  105. PASS
  106. root@de10nano:~/linux-socfpga-sha3-miner/tools/testing/miner#

You can also rebuild the kernel (it will take a very long time on the NANO)

  1. root@de10nano:~# cd linux-socfpga-sha3-miner/
  2. root@de10nano:~/linux-socfpga-sha3-miner# make zImage modules
  3. CHK include/config/kernel.release
  4. CHK include/generated/uapi/linux/version.h
  5. CHK include/generated/utsrelease.h
  6. CHK include/generated/bounds.h
  7. CHK include/generated/timeconst.h
  8. CHK include/generated/asm-offsets.h
  9. CALL scripts/checksyscalls.sh
  10. CHK scripts/mod/devicetable-offsets.h
  11. CHK include/generated/compile.h
  12. CHK kernel/config_data.h
  13. ...
  14. AS arch/arm/boot/compressed/piggy.o
  15. LD arch/arm/boot/compressed/vmlinux
  16. OBJCOPY arch/arm/boot/zImage
  17. Kernel: arch/arm/boot/zImage is ready
  18. root@de10nano:~/linux-socfpga-sha3-miner# make modules_install
  19. INSTALL crypto/drbg.ko
  20. INSTALL crypto/echainiv.ko
  21. INSTALL crypto/hmac.ko
  22. INSTALL crypto/jitterentropy_rng.ko
  23. INSTALL crypto/sha256_generic.ko
  24. INSTALL drivers/char/hw_random/rng-core.ko
  25. INSTALL drivers/dma/dmatest.ko
  26. INSTALL drivers/i2c/algos/i2c-algo-bit.ko
  27. INSTALL drivers/misc/miner/miner.ko
  28. INSTALL drivers/net/ethernet/altera/altera_tse.ko
  29. INSTALL drivers/net/ethernet/intel/e1000e/e1000e.ko
  30. INSTALL drivers/net/ethernet/intel/igb/igb.ko
  31. INSTALL drivers/net/ethernet/intel/ixgbe/ixgbe.ko
  32. INSTALL drivers/net/mdio.ko
  33. DEPMOD 4.14.130-ltsi+
  34. root@de10nano:~/linux-socfpga-sha3-miner# mount /dev/mmcblk0p1 /media
  35. root@de10nano:~/linux-socfpga-sha3-miner# cp arch/arm/boot/zImage /media
  36. root@de10nano:~/linux-socfpga-sha3-miner# umount /media
  37. root@de10nano:~/linux-socfpga-sha3-miner# sync
  38. root@de10nano:~/linux-socfpga-sha3-miner# reboot

Disclaimer

This software is provided “AS IS” and any expressed or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the regents or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.