|
|
| (17 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| https://bitcointalk.org/index.php?topic=62842.0
| | This article covers some specific aspects of the Bitcoin and Blockchains in general. |
|
| |
|
| https://docs.google.com/document/d/1Gw7YPYgMgNNU42skibULbJJUx_suP_CpjSEdSi8_z9U/edit
| | == Overview == |
| | Bitcoin is built upon a blockchain database. A blockchain is a ledger consisting of many blocks, with each block containing a list of transactions and links to the previous block (hence, forming a 'chain' of blocks). Each successive block that is added generates a reward, starting with 50 BTC and halving every 210,000 blocks. |
|
| |
|
| https://github.com/jgarzik/pushpool
| | In Bitcoin, adding a new block is computationally hard work. It is the difficulty in adding blocks that makes the blockchain secure and consistent. In addition, the difficulty can be adjusted automatically to keep new blocks at a rate of 12 per hour. While adding new blocks is hard work, verifying this work is easy. |
|
| |
|
| | Bitcoin uses Hashcash as its proof of work algorithm and was initially developed to combat email spam. The algorithm hashes some data (ie. the block headers) with a nonce (an arbitrary value that is incremented for ever step) over and over until the hash meets a certain requirement (ie. the difficulty). The original Hashcash implementation requires the first ~20 bits to be zeros. In Bitcoin, this is adjusted based on the difficulty. As more miners participate in the protocol, the difficulty is driven up and the more zeros are needed in the hashes for blocks that are added to the blockchain. |
|
| |
|
| My Bitcoin Address is: 1HDp1gU3rgrRNKqrKorz8uWCpHUNdyGqXm
| | === Transactions === |
| | The Bitcoin blockchain contains only transactions. The blockchain itself contains no account information, no balances, and no coins. Balances are derived from the state generated by the transactions that have taken place. |
| | {{highlight|lang=text|code= |
| | type Transaction struct { |
| | ID []byte // transaction ID is a hash |
| | Inputs []TXInput // list of transaction inputs |
| | Outputs []TXOutput // list of transaction outputs |
| | } |
| | }} |
|
| |
|
| == CGMiner == | | Transaction outputs are what stores the actual 'coins' in the protocol. It contains the amount being transacted as well as a ScriptPubKey which defines conditions that must be met before this output can be used. In Bitcoin, the scripting language is a Forth-like scripting language. The most common script is a Pay-to-PubkeyHash where the script verifies that the public key hashes to the scriptPubKey and that the signature matches the public key. |
| | {{highlight|lang=text|code= |
| | type TXOutput struct { |
| | Value int // value being transferred in satoshi (0.00000001 BTC) |
| | ScriptPubKey string // Script used to verify who can use this output |
| | } |
| | }} |
|
| |
|
| === AMD Cards === | | Transaction inputs references the transaction that contains the transaction output, the amount being transacted, and a ScriptSig which provides data to be used in the transaction output's ScriptPubKey. If the data in ScriptSig is correct, the output can be unlocked and its value can be used to generate new outputs. This mechanism guarantees that only owners of the outputs can spend their coins. |
| Download the AMD SDK and ADL SDK from:
| | {{highlight|lang=text|code= |
| * http://developer.amd.com/tools-and-sdks/heterogeneous-computing/amd-accelerated-parallel-processing-app-sdk/downloads/
| | type TXInput struct { |
| * http://developer.amd.com/tools-and-sdks/graphics-development/display-library-adl-sdk/
| | PreviousTxID []byte // transaction ID of Output |
| | TxIndex int // index of the transaction's output |
| | ScriptSig string // signature data used to unlock the output's ScriptPubKey. RIPEMD16(SHA256(PubKey)) |
| | } |
| | }} |
|
| |
|
| For older cards or drivers, use the older SDK (such as 2.6). You will know that you need to downgrade when things don't work. For instance, if you get:
| | All transaction inputs must reference an output except for the Coinbase transaction. A coinbase transaction has no inputs but has an output and is generated as the first transaction in a block and contains the block reward as well as any difference between the inputs and output transactions in this block which is considered as a transaction fee. |
| * Segmentation Faults
| |
| * High "HW:##" values (hardware faults) from cgminer
| |
| * Not actually mining anything or other unexpected behavior.
| |
|
| |
|
| Extract the archives and copy:
| | Because transactions are linked to each other, a person's 'balance' can only be calculated by finding all unspent transaction outputs (UTXO). An unspent transaction output is unspent if it is not referenced by any transaction inputs. |
| * AMD-APP-SDK/include -> /build_dir/include
| |
| * AMD-APP-SDK/lib/x86_64 -> /build_dir/lib
| |
| * ADL-SDK/include/*.h -> /build_dir/cgminer-3.3.4/ADL_SDK/
| |
|
| |
|
| In the cgminer-3.3.4 source directory, run:
| | Pseudocode for finding unspent transaction outputs: |
| | {{highlight|lang=text|code= |
| | FindUnspentTransactionOutputs(address A) { |
| | unspentTransactions = {} |
| | spentTransactions = {} |
|
| |
|
| <syntaxhighlight lang="text" line start="1" enclose="div">
| | for each block B from the tip to the genesis block { |
| CFLAGS="-O2 -Wall -march=native -I/build_dir/include" LDFLAGS="-L/build_dir/lib" ./configure --prefix=/usr/local/miner --enable-scrypt
| | for each transaction T from block B { |
| make
| | for each index idx and output O from transaction T { |
| make install
| | // If the output exists in the spentTransaction list, the output has been spent by some other input |
| </syntaxhighlight>
| | if spentTransactions[T.ID] exists and idx in spentTransaction[T.ID] { |
| | // output has been spent |
| | break |
| | } |
|
| |
|
| Extract icd-registration.tgz and put the files in /etc/OpenCL/vendors/.
| | // If the output matches that of address A, and has not been used by some input, it is unspent. |
| | if output O CanUnlockWithAddress A { |
| | // index idx on transaction T is unspent for address A |
| | unspentTransactions[T.ID] += idx |
| | } |
| | } |
|
| |
|
| Since I do not want to install the OpenCL libs, I had to copy them (from AMD-APP-SDK/lib/x86_64) over to /usr/local/miner/libs manually, and run cgminer with the LD_LIBRARY_PATH variable defined:
| | // keep track of all inputs whose output is from address A |
| | // outputs used by these inputs here are spent. |
| | for each input I from transaction T { |
| | if input I OutputCanUnlockWithAddress A { |
| | spentTransaction[I.PreviousTxID] += I.TxIndex |
| | } |
| | } |
| | } |
| | } |
| | } |
|
| |
|
| LD_LIBRARY_PATH=/usr/local/miner/lib ./cgminer -n
| | // FindUnspentTransactions returns a list of transactions, each containing a list of indexes to unspent outputs. |
| | }} |
|
| |
|
| LD_LIBRARY_PATH=/usr/local/miner/lib ./cgminer -o http://p2pool.org:9332 -u 1HDp1gU3rgrRNKqrKorz8uWCpHUNdyGqXm -p password
| | === Hashes === |
| | Bitcoin typically uses double SHA256 for hashing and sometimes RIPEMD160 when a shorter hash is desired (such as Bitcoin Addresses). As the name suggests, a SHA256 hash is 256bits or 64 bytes long and a RIPEMD160 is 160bits or 40bytes long. |
|
| |
|
| | A Block ID that is generated is the double SHA256 of the block headers. Each block header contains the version, previous block hash, merkle root hash of all the transactions, the time, difficulty target, and the nonce. |
|
| |
|
| === NVidia Cards ===
| | The transaction ID is generated using double SHA256 of the transaction values (version, transaction inputs, transaction outputs, nlocktime). |
|
| |
|
| You will need to install the NVidia drivers and the cuda toolkit.
| | The Merkle root hash used in the block headers is built by building a binary tree containing all the transaction hashes. |
|
| |
|
| Once done, compile cgminer with the following paths:
| | Addresses are hashes of a ECDSA public key, prefixed with the version and suffixed with a checksum. A special encoding called Base58 is used to then encode the hash into a readable string without zeros. {{code|1=Address = Base58Encode(Version + RIPEMD160(SHA256(Public Key)) + SHA256(SHA256(KeyHash)))}} |
| CFLAGS="-O2 -Wall -march=native -I/usr/local/cuda/include" LDFLAGS="-L/usr/lib64/nvidia" ./configure --prefix=/usr/local/miner --enable-scrypt
| |
|
| |
|
| == P2Pool == | | === Signatures === |
| === Get the source === | | Digital signatures are algorithms that guarantee that the data wasn't modified and that the data was created only by the sender. Signing something requires the private key. Verification requires the data, signature, and the public key. |
| git clone git://github.com/forrestv/p2pool.git
| |
|
| |
|
| === Install Dependencies ===
| | Every transaction input in Bitcoin is signed by the sender and each transaction must be verified (ie. checking input permissions, and that transaction signatures are correct) before being added to a block. Transactions are signed using Elliptic Curve Digital Signature Algorithm (ECDSA). |
| Either install the packages from <code>yum</code> or from source. The dependencies that are needed are:
| |
| # Twisted
| |
| ## zope
| |
| # Argparse
| |
|
| |
|
| From yum, run:
| |
| yum install python-argparse python-twisted python-twisted-web
| |
|
| |
|
| Since the Twisted library is somewhat old, you might want to build it from source by getting it from:
| |
| # https://pypi.python.org/pypi/Twisted#downloads
| |
| And also the dependency:
| |
| # https://pypi.python.org/pypi/zope.interface/4.0.5#downloads
| |
|
| |
|
| Extract the archives, and run the setup.py script to build. (You will need python-devel and gcc to build)
| | == Bitcoin Core Client == |
| | Bitcoin Core is the reference client and wallet. |
|
| |
|
| | === Database === |
| | The core client uses LevelDB which is a key-value based database to store metadata, chainstate (Unspent Transaction Outputs, UTXO set), and block index information. The raw bitcoin blocks are stored inside the {{code|blk.dat}} files. |
|
| |
|
| === Running P2Pool === | | Block information: |
| Run run_p2pool.py
| | * b + 32byte block hash = block header, height, transactions, filename and offset |
| | * f + 4byte file number = file information, block ranges, time ranges, sizes |
| | * l + 4byte file number = last block file used |
| | * R = reindexing |
|
| |
|
| | UXTO Chainstate information: |
| | * c + 32byte transaction hash = block height, scriptPubKey and amount |
| | * B = block hash up to which this chainstate information represents |
|
| |
|
| | See also: https://en.bitcoin.it/wiki/Bitcoin_Core_0.11_(ch_2):_Data_Storage |
|
| |
|
| <syntaxhighlight lang="text" line start="1" enclose="div">
| |
|
| |
|
| #############################################################
| | === Importing a Private Key === |
| ####
| | Steps to add a private key to your wallet: |
| #### Installing mining Software on CEntOS or Fedora based distributions
| | # Open the console (Help -> Debug Window) |
| ####
| | # Unlock your wallet {{code|walletpassphrase "YourLongPassphrase" 600}} |
| #### Currently 2 GPU's working under Centos 6.4 w/SDK 12.7 & Driver 12.3
| | # Import Key: {{code|importprivkey <private key> "<label>"}} |
| #### Currently 4 GPU's working under Centos 6.0 w/SDK 12.4 & Driver 11.4
| |
| ####
| |
| #### testing to increase GPU's per motherboard
| |
| ####
| |
| #### by: Viceroy who accepts tips at 144RtpxYKbigosiqTyXNwzwtH6Z7s96xUx
| |
| ####
| |
| #############################################################
| |
| ####
| |
| #############################################################
| |
| #### Section 0 - Table of Contents
| |
| #############################################################
| |
| ####
| |
| #### Section 0 Table of Contents
| |
| #### Section 1 Disclaimers
| |
| #### Section 2 Setting up CentOS
| |
| #### Section 3 Setting up Base Packages
| |
| #### Section 4 Installing ATI Development Kit (SDK)
| |
| #### Section 5 Installing ATI Catalyst Drivers
| |
| #### Section 6 Testing ATI Catalyst Drivers
| |
| ####
| |
| #############################################################
| |
| #### Section 1 - Disclaimers
| |
| #############################################################
| |
| ####
| |
| #### I am not responsible for you using these instructions.
| |
| ####
| |
| #### If you choose to follow anything you read here that is
| |
| #### your problem, not mine. I have written these instructions
| |
| #### for my personal use for my particular machine in an effort
| |
| #### to help me mine bitcoin. If you follow these instructions
| |
| #### you may or may not have success, neither of which are any
| |
| #### concern of mine because you are the fool who followed me
| |
| #### off the bridge. I did not push you.
| |
| ####
| |
| #### I am proposing here to build a TOTALLY INSECURE HIGH
| |
| #### POWERED PASSWORD CRACKING MACHINE which MAY OR MAY NOT
| |
| #### BE LEGAL TO POSESS WHERE YOU LIVE. If the policeman
| |
| #### puts you in jail because you followed what I wrote here
| |
| #### that is your fault, not mine. You need to be aware of
| |
| #### local, national and international laws before you decide
| |
| #### to build a high powered password cracker. If this gets
| |
| #### into the wrong hands and it starts a nuclear war and
| |
| #### and some hostile government decides to end the world
| |
| #### guess what... that's not my fault either.
| |
| ####
| |
| #### Be responsible, do no let Kim Jong Un get this machine
| |
| #### http://en.wikipedia.org/wiki/Kim_Jong-un
| |
| ####
| |
| #############################################################
| |
| #### Section 2 - Setting up Centos
| |
| #############################################################
| |
| ####
| |
| #### While at your windows desktop machine you need to
| |
| #### download the ISO from http://vault.centos.org/6.0/isos/
| |
| #### | |
| #### (I will be using the 64 bit OS from here on out)
| |
| ####
| |
| #### The ISO can be burned to CD, DVD or USB
| |
| ####
| |
| #### (I will burn the ISO to a 2GB+ USB flash drive)
| |
| #### | |
| #### Download the ISO from:
| |
| #### http://vault.centos.org/6.0/isos/x86_64/CentOS-6.0-x86_64-LiveCD.iso
| |
| ####
| |
| #### Download and install Pendrivelinux Windows Software:
| |
| #### http://www.pendrivelinux.com/universal-usb-installer-easy-as-1-2-3/
| |
| ####
| |
| #### 0. Plug in your flash drive and wait for it to register
| |
| ####
| |
| #### 1. start pendrivelinux universal USB installer
| |
| #### 2. selects CentOS from "other distros alphabetically"
| |
| #### 3. select the CentOS LIVE iso you downloaded | |
| #### (CentOS-6.0-x86_64-LiveCD.iso)
| |
| #### 4. select your drive letter and format the drive
| |
| #### 5. safely remove flash drive and plug into new machine
| |
| #### 6. boot up and install CentOS with the menus
| |
| #### 7. after intallation log in as root (or su) and:
| |
| #### 7a. set up network so IP is fixed so you can log in remotely
| |
| #### 7b. turn on the SSH daemon so you can log in (service sshd start)
| |
| #### 7c. make sshd starts each time you boot (chkconfig sshd on)
| |
| #### 8. now I like to go back to my nice desk and chair
| |
| #### 8a. dowload and install putty so you can talk to your box
| |
| #### http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
| |
| #### using a new ssh connection, connect to your machine as the
| |
| #### user you set up during installation. (it's a bad idea to log
| |
| #### in as root from a remote location).
| |
| #### 9. while you are sitting there at your desk download and install
| |
| #### xming windows xwindow emulator from here:
| |
| #### http://sourceforge.net/project/downloading.php?group_id=156984&filename=Xming-6-9-0-31-setup.exe
| |
| #### 10. modify yum
| |
| ####
| |
| #### cut and paste one command at a time
| |
| ####
| |
|
| |
|
| #### become root user
| | Source: http://bitcoin.stackexchange.com/questions/5941/how-do-i-import-a-private-key-into-bitcoin-qt |
| su -
| |
|
| |
|
| #### change directory to yum repo directory
| |
| cd /etc/yum.repos.d
| |
|
| |
|
| #### move original file to backup
| |
| mv -f CentOS-Base.repo CentOS-Base.repo.old
| |
|
| |
|
| # COPY the following into your buffer | | == Brain Wallets == |
| ## (in windows you use ctrl-c) | | A brain wallet allows for the generation of the public/private key pair using a passphrase. It is accomplished by: |
| ## | | # Converting a pass phrase into a private key |
| ## start copy ---->> | | #* PrivateKey = SHA256(PassPhrase) |
| | # Generate a public key using the private key |
| | #* PublicKey = privateToPublic(PrivateKey) |
| | # Generate the bitcoin address |
| | #* Hash = SHA256(PublicKey) |
| | #* Hash160 = RIPEMD160(Hash) (used by transactions) |
| | #* Address = Base58Check(Hash160) |
|
| |
|
| # CentOS-Base.repo
| | The publickey can either be uncompressed or compressed. A compressed public key is simply a truncated key where the missing parts can be recomputed. |
| #
| |
| # The mirror system uses the connecting IP address of the client and the
| |
| # update status of each mirror to pick mirrors that are updated to and
| |
| # geographically close to the client. You should use this for CentOS updates
| |
| # unless you are manually picking other mirrors.
| |
| #
| |
| # If the #mirrorlist= does not work for you, as a fall back you can try the
| |
| # remarked out baseurl= line instead.
| |
| #
| |
| #
| |
|
| |
|
| [base]
| | === Attack === |
| name=CentOS-$releasever - Base
| | Ryan Castellucci did a talk on Defcon 23 on cracking brain wallets using his program called Brainflayer, available at https://github.com/ryancdotorg/brainflayer. |
| #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
| |
| baseurl=http://vault.centos.org/6.0/os/$basearch/
| |
| gpgcheck=1
| |
| gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
| |
|
| |
|
| #released updates
| | The basic idea is to extract all unique addresses in the bitcoin system. Dump the addresses into a bloom filter for almost constant time search, then use Brainflayer to bruteforce check on a word list that matches a specific address hash. |
| [updates]
| |
| name=CentOS-$releasever - Updates
| |
| #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
| |
| baseurl=http://vault.centos.org/6.0/updates/$basearch/
| |
| gpgcheck=1
| |
| gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
| |
|
| |
|
| #additional packages that may be useful | | That is: |
| [extras]
| | # get all Bitcoin Addresses as Hash160 > hashes.hex |
| name=CentOS-$releasever - Extras
| | # hex2blf hashes.hex hashes.blf |
| #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras | | # brainflayer -b hashes.blf -i phraselist.txt |
| baseurl=http://vault.centos.org/6.0/extras/$basearch/
| | # or cat password.txt | brainflayer -b hashes.blf |
| gpgcheck=1
| | # or john --incremental --stdout | brainflayer -b hashes.blf |
| gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
| |
|
| |
|
| #additional packages that extend functionality of existing packages
| | === Key Stretching === |
| [centosplus]
| | To make brain wallets stronger, the key generation can be made to be more expensive and thereby limiting the number of tries an attacker can made per second. |
| name=CentOS-$releasever - Plus
| |
| #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
| |
| baseurl=http://vault.centos.org/6.0/centosplus/$basearch/
| |
| gpgcheck=1
| |
| enabled=0
| |
| gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
| |
|
| |
|
| #contrib - packages by Centos Users
| | * https://keybase.io/warp/warp_1.0.6_SHA256_e68d4587b0e2ec34a7b554fbd1ed2d0fedfaeacf3e47fbb6c5403e252348cbfc.html |
| [contrib]
| |
| name=CentOS-$releasever - Contrib
| |
| #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
| |
| baseurl=http://vault.centos.org/6.0/contrib/$basearch/
| |
| gpgcheck=1
| |
| enabled=0
| |
| gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
| |
|
| |
|
| ## <<---- end copy
| | == Utilities == |
| ##
| | === Blockparser === |
| ## then using the built in world processor in linux type
| | Reads blocks and retrieves information. |
| | * https://github.com/znort987/blockparser |
|
| |
|
| vi CentOS-Base.repo
| | To build this project, install these dependencies: |
| | {{highlight|lang=terminal|code= |
| | # yum install openssl-devel perl-Data-Dumper perl-Digest-SHA boost-devel gcc-c++ gcc |
| | }} |
|
| |
|
| # while in Vi hit [insert key]
| | The project also depends on google dense hash map: https://github.com/sparsehash/sparsehash |
| # then paste the contents of your buffer with the right mouse button
| |
| # then hit the escape key
| |
| # hit :
| |
| # then hit x
| |
| # then hit the [enter key]
| |
| # this will save the file and exit
| |
|
| |
|
| # test out your changes
| | Run the {{code|make}} script to compile. |
|
| |
|
| yum check-update
| | ==== Usage ==== |
| | {{highlight|lang=terminal|code= |
| | # ./parser allBalances > allBalances.txt |
| | # cat allBalances.txt | awk '{print $2}' > hashes.hex |
| | ## TODO: Convert addresses to hash160?? http://lenschulwitz.com/base58 |
| | }} |
|
| |
|
|
| |
|
| | | [[Category:Blockchain]] |
| #############################################################
| | {{Navbox Blockchain}} |
| #### Section 3 - Setting up Base Packages
| |
| #############################################################
| |
| | |
| #### become root user
| |
| su -
| |
| | |
| yum -y groupinstall x11
| |
| | |
| #### if you see an error about yum being locked be patient it will unlock in a minute
| |
| yum -y install gcc rpm-build git wget make kernel-devel python python-libs numpy openssl openssl-devel ncurses ncurses-devel ncurses-libs autoconf automake m4 pkgconfig libcurl-devel libtool libudev libusb glx-utils libX11 libstdc++ compat-libstdc++*
| |
| | |
| #### create new user or place all items in personal home directory
| |
| useradd miner
| |
| | |
| #### become prefered user (no password needed)
| |
| su -l miner
| |
| | |
| #### create a directory to hold all the packages
| |
| cd ~
| |
| mkdir miningpacks
| |
| cd miningpacks
| |
| | |
| #### download all driver package as user "miner"
| |
| ####
| |
| #### wget http://download2-developer.amd.com/amd/APPSDK/AMD-APP-SDK-v2.4-lnx64.tgz
| |
| #### wget http://www2.ati.com/drivers/linux/amd-driver-installer-12-3-x86.x86_64.run
| |
| ####
| |
| #### goin old-school - working version is best ...
| |
| #### note: modern versions may break other things
| |
| ####
| |
| wget http://www2.ati.com/drivers/linux/ati-driver-installer-11-4-x86.x86_64.run
| |
| | |
| ####chmod a+x amd-driver-*
| |
| chmod a+x ati-driver-*
| |
| | |
| | |
| exit #go back to being root user
| |
| | |
| #############################################################
| |
| #### Section 4 - Installing ATI Development Kit (SDK)
| |
| #############################################################
| |
| ####
| |
| ####
| |
| #### Install this BEFORE you install the drivers
| |
| ####
| |
| #############################################################
| |
| ####
| |
| ####
| |
| #### preparing the machine for a new SDK install
| |
| ####
| |
| ####
| |
| #### First Seek and Destroy ALL Existing ATI Drivers:
| |
| #### only needed if you are rebuilding. If fresh
| |
| #### install this command will fail, no directory.
| |
| ####
| |
| cd /usr/share/ati
| |
| ./amd-uninstall.sh --force
| |
| | |
| #### more cleaning to be sure
| |
| ####
| |
| #rm -Rf /etc/ati
| |
| #rm -Rf /usr/lib/fglrx
| |
| #rm -Rf /usr/share/ati
| |
| #rm -Rf /opt/AMD*
| |
| #reboot #HIGHLY RECOMMENDED IF YOU REMOVED FILES
| |
| | |
| ####
| |
| #### installing the new SDK install
| |
| ####
| |
| | |
| #### become root user
| |
| su -
| |
| | |
| #### become prefered user (no password needed)
| |
| su -l miner
| |
| | |
| #### move to directory to where you are holding the packages
| |
| cd ~
| |
| cd miningpacks
| |
| | |
| #### download SDK
| |
| ####
| |
| #### wget http://download2-developer.amd.com/amd/APPSDK/AMD-APP-SDK-v2.4-lnx32.tgz
| |
| #### wget http://download2-developer.amd.com/amd/APPSDK/AMD-APP-SDK-v2.6-lnx32.tgz
| |
| #### wget http://developer.amd.com/wordpress/media/2012/11/AMD-APP-SDK-v2.8-lnx64.tgz
| |
| ####
| |
| #### again, oldschool because working beats not-working:
| |
| ##
| |
| wget http://download2-developer.amd.com/amd/APPSDK/AMD-APP-SDK-v2.4-lnx64.tgz
| |
| | |
| | |
| exit #go back to being root user
| |
| | |
| #### newer style SDK install
| |
| ####
| |
| #### cd /home/miner/miningpacks/
| |
| #### mkdir APP-SDK-2point7-temp
| |
| #### cd APP-SDK-2point7-temp
| |
| #### cp ../AMD-APP-SDK-v2.7-lnx64.tgz .
| |
| #### tar xzf AMD-APP-SDK-v2.7-lnx64.tgz
| |
| #### ./Install-AMD-APP.sh
| |
| #### cd ..
| |
| #### rm -rf APP-SDK-2point7-temp
| |
| #### #reboot
| |
| | |
| ### old school style SDK install
| |
| cd /opt
| |
| tar -xf /home/miner/miningpacks/AMD-APP-SDK*
| |
| cd /
| |
| tar xf /opt/AMD-APP-SDK-v2.4-lnx64/icd-registration.tgz
| |
| ln -sf /opt/AMD-APP-SDK-v2.4-lnx64/include/CL /usr/include
| |
| ln -sf /opt/AMD-APP-SDK-v2.4-lnx64/lib/x86_64/* /usr/lib/
| |
| ldconfig
| |
| reboot
| |
| | |
| #### echo AMDAPPSDKROOT=/root/AMD-APP-SDK-v2.4-lnx64 >> .bashrc
| |
| #### echo AMDAPPSDKSAMPLESROOT=/root/AMD-APP-SDK-v2.4-lnx64 >> .bashrc
| |
| #### echo LD_LIBRARY_PATH=/root/AMD-APP-SDK-v2.4-lnx64/lib/x86_64 >> .bashrc
| |
| | |
| | |
| #############################################################
| |
| #### Section 5 - Installing ATI Catalyst Drivers for linux
| |
| #############################################################
| |
| ####
| |
| ####
| |
| #### Install this AFTER you install the SDK
| |
| ####
| |
| #############################################################
| |
| | |
| #### become root user
| |
| su -
| |
| | |
| ##
| |
| ## important note on installing AMD Drivers under linux:
| |
| ##
| |
| ## be certain you have the kernel-devel for YOUR kernel
| |
| yum list installed | grep kernel-*
| |
| | |
| ##
| |
| ## output should look like this
| |
| #dracut-kernel.noarch 004-32.el6 installed
| |
| #kernel.x86_64 2.6.32-71.el6 installed
| |
| #kernel-devel.x86_64 2.6.32-71.29.1.el6 @updates
| |
| #kernel-firmware.noarch 2.6.32-71.el6 installed
| |
| #kernel-headers.x86_64 2.6.32-71.29.1.el6 @updates
| |
| #[root@localhost ~]#
| |
| #
| |
| # notice that I DO NOT have a matched kernel and kernel-devel version.
| |
| # they must match EXACTLY or you will not be successful in the
| |
| # next steps. I have:
| |
| # kernel.x86_64 2.6.32-71.el6 installed
| |
| # and
| |
| # kernel-devel.x86_64 2.6.32-71.29.1.el6 @updates
| |
| #
| |
| # the difference is so slight you may have missed it
| |
| # my subversion 32-71.29.1.el6 does NOT match 32-71.el6
| |
| | |
| ##
| |
| ## check your distribution
| |
| uname -r
| |
| | |
| ##
| |
| ## you can have multiple kernel-devel's that is not a problem
| |
| ## if you are lucky this command works
| |
| yum install kernel-devel-$(uname -r)
| |
| | |
| #### if this was successful move on to the next section
| |
| #### proceed to package generation
| |
| | |
| | |
| ####******#*#*#*#*#*##*#*####******#*#*#*#*#*##*#*
| |
| ####
| |
| #### optional section if kernels do not match
| |
| ####
| |
| ####
| |
| #### You will need to find another "kernel" with
| |
| ### a matching "kernel-devel" package
| |
| ####
| |
| #### yum --showduplicates list kernel-devel
| |
| ####
| |
| #### to download a specific package just add
| |
| #### the version to the name, for example if
| |
| #### I want kernel-devel 2.6.32-358.el6 I
| |
| #### just add a hyphen
| |
| ####
| |
| #### yum install kernel-devel-2.6.32-358.el6
| |
| ####
| |
| ####
| |
| ####******#*#*#*#*#*##*#*####******#*#*#*#*#*##*#*
| |
| | |
| | |
| #############################################################
| |
| #### Generate a Distribution Specific Package of fglrx
| |
| #############################################################
| |
| | |
| # as root
| |
| | |
| #### Move to package directory
| |
| #### using menus generate RPM package for your OS
| |
| #### (generate centos 64 packages)
| |
| ####
| |
| cd /home/miner/miningpacks/
| |
| | |
| #### chmod u+x *-driver-installer* #step taken earlier
| |
| #### //alternative:// sh amd-driver-installer
| |
| sh ati-driver-installer-*
| |
| | |
| #### (file was downloaded above)
| |
| ####
| |
| ####
| |
| #### Install generated package
| |
| cd /home/miner/miningpacks/
| |
| yum -y install fglrx64_p_i_c-* --nogpgcheck
| |
| aticonfig --adapter=all --initial --force
| |
| reboot
| |
| | |
| | |
| #############################################################
| |
| #### Section 6 - Testing ATI Catalyst Drivers
| |
| #############################################################
| |
| | |
| | |
| #### check installation by reading output from
| |
| more /usr/share/ati/fglrx-install.log
| |
| | |
| #### further testing SHOULD be done at this time against this page:
| |
| ####
| |
| #### http://wiki.cchtml.com/index.php/Frequently_Asked_Questions#How_do_I_know_fglrx_is_installed_correctly.3F
| |
| | |
| | |
| #### one possible error
| |
| ####
| |
| ####[Message] Kernel Module : Precompiled kernel module version mismatched.
| |
| ####[Error] Kernel Module : Kernel module build environment not found - please consult readme.
| |
| ####
| |
| ####
| |
| #### This error indicated you do not have the correct kernel-devel libs to match your kernel
| |
| #### (I told you it wouldn't work).
| |
| ####
| |
| #### with xming installed on my pc when I use putty I don't even need to
| |
| #### export my display. I can just start playing with opencl and opengl
| |
| #### libraries and samples. But only if I did everything correctly
| |
| #### and there were no hardware issues along the way.
| |
| ####
| |
| #### my machines 'hello world' test passed with flying colors
| |
| ####
| |
| aticonfig --lsa
| |
| | |
| ## output looks like this:
| |
| #* 0. 0e:00.0 AMD Radeon HD 6800 Series
| |
| # 1. 0f:00.0 AMD Radeon HD 6800 Series
| |
| # 2. 07:00.0 AMD Radeon HD 6800 Series
| |
| # 3. 06:00.0 AMD Radeon HD 6800 Series
| |
| #
| |
| #* - Default adapter
| |
| #
| |
| # which is EXACTLY what I want!!!
| |
| | |
| #### if you are not seeing all your GPU's at this stage something is wrong.
| |
| #### first check lspci
| |
| lspci -nn | grep VGA
| |
| | |
| #### if that does not show all your cards you need to hard-boot your computer.
| |
| #### it make take several attempts and some plugging and unpluggging monitor
| |
| #### cables. There seems to be little method to the madness but make sure
| |
| #### you can see all your GPU's now or you can't mine with them. Even though
| |
| #### centos was designed to handle multiple GPU's off the bat I still find the
| |
| #### best way to 'light up' a port is to have a monitor plugged in during hard
| |
| #### boot. I'm sure the resistor based dongle approach would work as well.
| |
| ####
| |
| glxgears
| |
| | |
| ## Segmentation fault
| |
| ##
| |
| ## uh-oh I broke something!
| |
| ## oh yea, I remember
| |
| ##
| |
| ## I forgot to log into the linux box.
| |
| ## so here's what I need to make this work
| |
| ## I go to the centos box and log in as my
| |
| ## regular user in the graphical interface.
| |
| ## then I pull down the menu and open a
| |
| ## terminal window which must be 'turning
| |
| ## x on for my local user'. Once I open
| |
| ## that terminal (xterm) I can walk away
| |
| ## and do everything else remotely. So
| |
| ## here we go, let's have some fun...
| |
| ##
| |
| glxgears
| |
| | |
| ## Segmentation fault
| |
| ## oh yea... duh
| |
| export DISPLAY=:0
| |
| glxgears
| |
| | |
| ##40014 frames in 5.0 seconds = 8002.695 FPS
| |
| ##40291 frames in 5.0 seconds = 8058.047 FPS
| |
| ##40288 frames in 5.0 seconds = 8057.494 FPS
| |
| ##40287 frames in 5.0 seconds = 8057.313 FPS
| |
| ## ^C
| |
| ##
| |
| ## don't be hatin on me now...
| |
| | |
| | |
| #############################################################
| |
| #### Install ATI Display Library Development Kit (ADL SDK):
| |
| #############################################################
| |
| | |
| ###wget http://developer.amd.com/wordpress/media/2012/11/AMD-APP-SDK-v2.8-lnx64.tgz
| |
| ### cannot find APP without going through website license
| |
| ### pain in the ass requires a browser download
| |
| ###
| |
| | |
| #### become root user
| |
| su -
| |
| | |
| #### become prefered user (no password needed)
| |
| su -l miner
| |
| | |
| #### move to directory to where you are holding the packages
| |
| cd ~
| |
| cd miningpacks
| |
| | |
| #### place ADL zip in current directory
| |
| | |
| wget http://download2-developer.amd.com/amd/GPU/zip/ADL_SDK_3.0.zip
| |
| | |
| #### unpack it and install it into the correct directory
| |
| | |
| mkdir ADL-SDK-3point0-temp
| |
| cd ADL-SDK-3point0-temp
| |
| cp ../ADL_SDK_3.0.zip .
| |
| unzip ADL_SDK_3.0.zip
| |
| | |
| cp /home/miner/miningpacks/ADL-SDK-3point0-temp/include/*.h /home/miner/cgminer/ADL_SDK
| |
| rm -rf /home/miner/ADL-SDK-3point0-temp
| |
| | |
| | |
| | |
| #############################################################
| |
| #### Install CGMiner
| |
| #############################################################
| |
| | |
| #### become root user
| |
| su -
| |
| | |
| #### become prefered user (no password needed)
| |
| su -l miner
| |
| | |
| #### move to home directory
| |
| cd ~
| |
| | |
| #### download CGMiner from author
| |
| git clone https://github.com/ckolivas/cgminer
| |
| | |
| | |
| #### copy ADL libraries to correct location
| |
| cd /home/miner/cgminer/ADL_SDK
| |
| cp /home/miner/miningpacks/ADL-SDK-5point0-temp/include/*.h .
| |
| rm -rf /home/miner/miningpacks/ADL-SDK-5point0-temp/
| |
| cd ..
| |
| | |
| ./autogen.sh
| |
| | |
| make
| |
| | |
| exit #go back to being root user
| |
| | |
| cd /home/miner/cgminer/
| |
| make install
| |
| | |
| reboot #if you have not after changes to libraries
| |
| | |
| #if you did everything as I have above you are finished
| |
| #and can run cgminer. test with ./cgminer -n
| |
| | |
| ####
| |
| #### Now test out your new miner for 24 hours and if you like all the time and effort I
| |
| #### put into this guide I encourage you to think about testing your new miner here:
| |
| | |
| ./cgminer -o stratum+tcp://mining.eligius.st:3334 -u 1NQc6tCtRmT8zBeLKNpboFaUBMLcxDwUm6 -p x0 -I 9 --per-device-stats 2>logfile.txt
| |
| | |
| ####
| |
| #### After 24hrs of burn in read the logfile. Make sure nothing strange happened.
| |
| #### Here's how you read the log:
| |
| | |
| more logfile.txt
| |
| | |
| #### If you don't see any errors set your miner to your favorite pool and off you go.
| |
| #### Then set that file aside so you can refer to it later.
| |
| | |
| cp logfile.txt burninlog.txt
| |
| | |
| #### in the future, unless you are having problems you can remove the --per-device-stats and the logging
| |
| #### from the command line, so it looks like this: (don't forget to change the address!!)
| |
| | |
| ./cgminer -o stratum+tcp://mining.eligius.st:3334 -u 1NQc6tCtRmT8zBeLKNpboFaUBMLcxDwUm6 -p x0 -I 9
| |
| | |
| | |
| | |
| #### Best of luck, greenhorn!
| |
| | |
| #############################################################
| |
| #### The End
| |
| #############################################################
| |
| | |
| </syntaxhighlight>
| |
This article covers some specific aspects of the Bitcoin and Blockchains in general.
Overview
Bitcoin is built upon a blockchain database. A blockchain is a ledger consisting of many blocks, with each block containing a list of transactions and links to the previous block (hence, forming a 'chain' of blocks). Each successive block that is added generates a reward, starting with 50 BTC and halving every 210,000 blocks.
In Bitcoin, adding a new block is computationally hard work. It is the difficulty in adding blocks that makes the blockchain secure and consistent. In addition, the difficulty can be adjusted automatically to keep new blocks at a rate of 12 per hour. While adding new blocks is hard work, verifying this work is easy.
Bitcoin uses Hashcash as its proof of work algorithm and was initially developed to combat email spam. The algorithm hashes some data (ie. the block headers) with a nonce (an arbitrary value that is incremented for ever step) over and over until the hash meets a certain requirement (ie. the difficulty). The original Hashcash implementation requires the first ~20 bits to be zeros. In Bitcoin, this is adjusted based on the difficulty. As more miners participate in the protocol, the difficulty is driven up and the more zeros are needed in the hashes for blocks that are added to the blockchain.
Transactions
The Bitcoin blockchain contains only transactions. The blockchain itself contains no account information, no balances, and no coins. Balances are derived from the state generated by the transactions that have taken place.
type Transaction struct {
ID []byte // transaction ID is a hash
Inputs []TXInput // list of transaction inputs
Outputs []TXOutput // list of transaction outputs
}
Transaction outputs are what stores the actual 'coins' in the protocol. It contains the amount being transacted as well as a ScriptPubKey which defines conditions that must be met before this output can be used. In Bitcoin, the scripting language is a Forth-like scripting language. The most common script is a Pay-to-PubkeyHash where the script verifies that the public key hashes to the scriptPubKey and that the signature matches the public key.
type TXOutput struct {
Value int // value being transferred in satoshi (0.00000001 BTC)
ScriptPubKey string // Script used to verify who can use this output
}
Transaction inputs references the transaction that contains the transaction output, the amount being transacted, and a ScriptSig which provides data to be used in the transaction output's ScriptPubKey. If the data in ScriptSig is correct, the output can be unlocked and its value can be used to generate new outputs. This mechanism guarantees that only owners of the outputs can spend their coins.
type TXInput struct {
PreviousTxID []byte // transaction ID of Output
TxIndex int // index of the transaction's output
ScriptSig string // signature data used to unlock the output's ScriptPubKey. RIPEMD16(SHA256(PubKey))
}
All transaction inputs must reference an output except for the Coinbase transaction. A coinbase transaction has no inputs but has an output and is generated as the first transaction in a block and contains the block reward as well as any difference between the inputs and output transactions in this block which is considered as a transaction fee.
Because transactions are linked to each other, a person's 'balance' can only be calculated by finding all unspent transaction outputs (UTXO). An unspent transaction output is unspent if it is not referenced by any transaction inputs.
Pseudocode for finding unspent transaction outputs:
FindUnspentTransactionOutputs(address A) {
unspentTransactions = {}
spentTransactions = {}
for each block B from the tip to the genesis block {
for each transaction T from block B {
for each index idx and output O from transaction T {
// If the output exists in the spentTransaction list, the output has been spent by some other input
if spentTransactions[T.ID] exists and idx in spentTransaction[T.ID] {
// output has been spent
break
}
// If the output matches that of address A, and has not been used by some input, it is unspent.
if output O CanUnlockWithAddress A {
// index idx on transaction T is unspent for address A
unspentTransactions[T.ID] += idx
}
}
// keep track of all inputs whose output is from address A
// outputs used by these inputs here are spent.
for each input I from transaction T {
if input I OutputCanUnlockWithAddress A {
spentTransaction[I.PreviousTxID] += I.TxIndex
}
}
}
}
}
// FindUnspentTransactions returns a list of transactions, each containing a list of indexes to unspent outputs.
Hashes
Bitcoin typically uses double SHA256 for hashing and sometimes RIPEMD160 when a shorter hash is desired (such as Bitcoin Addresses). As the name suggests, a SHA256 hash is 256bits or 64 bytes long and a RIPEMD160 is 160bits or 40bytes long.
A Block ID that is generated is the double SHA256 of the block headers. Each block header contains the version, previous block hash, merkle root hash of all the transactions, the time, difficulty target, and the nonce.
The transaction ID is generated using double SHA256 of the transaction values (version, transaction inputs, transaction outputs, nlocktime).
The Merkle root hash used in the block headers is built by building a binary tree containing all the transaction hashes.
Addresses are hashes of a ECDSA public key, prefixed with the version and suffixed with a checksum. A special encoding called Base58 is used to then encode the hash into a readable string without zeros. Address = Base58Encode(Version + RIPEMD160(SHA256(Public Key)) + SHA256(SHA256(KeyHash)))
Signatures
Digital signatures are algorithms that guarantee that the data wasn't modified and that the data was created only by the sender. Signing something requires the private key. Verification requires the data, signature, and the public key.
Every transaction input in Bitcoin is signed by the sender and each transaction must be verified (ie. checking input permissions, and that transaction signatures are correct) before being added to a block. Transactions are signed using Elliptic Curve Digital Signature Algorithm (ECDSA).
Bitcoin Core Client
Bitcoin Core is the reference client and wallet.
Database
The core client uses LevelDB which is a key-value based database to store metadata, chainstate (Unspent Transaction Outputs, UTXO set), and block index information. The raw bitcoin blocks are stored inside the blk.dat files.
Block information:
- b + 32byte block hash = block header, height, transactions, filename and offset
- f + 4byte file number = file information, block ranges, time ranges, sizes
- l + 4byte file number = last block file used
- R = reindexing
UXTO Chainstate information:
- c + 32byte transaction hash = block height, scriptPubKey and amount
- B = block hash up to which this chainstate information represents
See also: https://en.bitcoin.it/wiki/Bitcoin_Core_0.11_(ch_2):_Data_Storage
Importing a Private Key
Steps to add a private key to your wallet:
- Open the console (Help -> Debug Window)
- Unlock your wallet
walletpassphrase "YourLongPassphrase" 600
- Import Key:
importprivkey <private key> "<label>"
Source: http://bitcoin.stackexchange.com/questions/5941/how-do-i-import-a-private-key-into-bitcoin-qt
Brain Wallets
A brain wallet allows for the generation of the public/private key pair using a passphrase. It is accomplished by:
- Converting a pass phrase into a private key
- PrivateKey = SHA256(PassPhrase)
- Generate a public key using the private key
- PublicKey = privateToPublic(PrivateKey)
- Generate the bitcoin address
- Hash = SHA256(PublicKey)
- Hash160 = RIPEMD160(Hash) (used by transactions)
- Address = Base58Check(Hash160)
The publickey can either be uncompressed or compressed. A compressed public key is simply a truncated key where the missing parts can be recomputed.
Attack
Ryan Castellucci did a talk on Defcon 23 on cracking brain wallets using his program called Brainflayer, available at https://github.com/ryancdotorg/brainflayer.
The basic idea is to extract all unique addresses in the bitcoin system. Dump the addresses into a bloom filter for almost constant time search, then use Brainflayer to bruteforce check on a word list that matches a specific address hash.
That is:
- get all Bitcoin Addresses as Hash160 > hashes.hex
- hex2blf hashes.hex hashes.blf
- brainflayer -b hashes.blf -i phraselist.txt
- or cat password.txt | brainflayer -b hashes.blf
- or john --incremental --stdout | brainflayer -b hashes.blf
Key Stretching
To make brain wallets stronger, the key generation can be made to be more expensive and thereby limiting the number of tries an attacker can made per second.
Utilities
Blockparser
Reads blocks and retrieves information.
To build this project, install these dependencies:
# yum install openssl-devel perl-Data-Dumper perl-Digest-SHA boost-devel gcc-c++ gcc
The project also depends on google dense hash map: https://github.com/sparsehash/sparsehash
Run the make script to compile.
Usage
# ./parser allBalances > allBalances.txt
# cat allBalances.txt