Is there a light (SPV) version of bitcoin core (bitcoind)? I'm trying to develop an SPV Bitcoin client which makes use of a library requiring bitcoin core (a running bitcoind service).
However, from what I understand, Bitcoin Core is full node, meaning that it stores the whole blockchain.

My question is: there exists a service which is similar to bitcoind (that is it provides a JSON-RPC server), without needing the whole blockchain?

Yes, bitcoind with pruning is similar to bitcoind, though some RPCs are disabled (naturally, because of pruning).

bitcoind in pruning mode does not store the whole blockchain, and can reduce your space usage to 2GB instead of 85GB.

See the release notes here and here.

Update: There is also a Full Block SPV wallet PR by Jonas Schnelli. Which is even lighter than pruning mode, since it only downloads blocks from the creation of the wallet.


Same setup different hash rate I have one computer with windows 8.1 13.11 driver and a 280x which gets 720KHS and another computer with the same setup which gets 620KHS.

They have a different cpu ram and psu (both have quality ones).

How can this be?

I have one computer with windows 8.1 13.11 driver and a 280x which
  gets 720KHS and another computer with the same setup which gets
  620KHS.

  They have a different cpu ram and psu (both have quality ones).

  How can this be?

It's because they have a different ram. With scrypt mining RAM is of up most importance. The faster/higher quality the ram, the faster you can mine.

Scrypt was made to require ram so it would slow down the over all hashing power and to resist asics.


Is it viable to CPU/GPU mine popular cryptocurrencies given that they have dramatically spiked in value recently? In the past two months the value of bitcoin has dramatically spiked (and fallen and spiked and fallen), with a general upward trend in value. Many websites about cryptocurrency mining give a loud disclaimer that it is not effective to mine coins with your CPU/GPU. I was wondering if this is still the case given that the value of the coins has dramatically risen? Where before 0.001 bitcoin was worth 12 bucks, now it's worth 12000 bucks (I am pulling these numbers out of my ass, but you get the idea). So even just grinding away to get a small percentage of a bitcoin might still pay out a decent little bonus right?

Taking Bitcoin as an example, a typical CPU is about 10,000 times less efficient than an ASIC (compare the Mhash/J numbers here vs here), so the cost to mine is roughly 10,000 times higher than the reward.  In the last few months, the price of Bitcoin has maybe doubled or tripled from $5,000 to $15,000, which is nowhere close to enough.  Check back when the price hits $150,000,000.  Assuming the difficulty doesn't go up by then, which it will.


PEM format for ECDSA I have been looking at Coinapult's API documentation which details the use of PEM format in python-ecdsa. Specifically, private keys and public keys need to be formatted using PEM.

Let's take Coinapult's specified public key:

-----BEGIN PUBLIC KEY-----
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEWp9wd4EuLhIZNaoUgZxQztSjrbqgTT0w
LBq8RwigNE6nOOXFEoGCjGfekugjrHWHUi8ms7bcfrowpaJKqMfZXg==
-----END PUBLIC KEY-----

Using python-ecdsa:

vk = ecdsa.VerifyingKey.from_pem(ECC_COINAPULT_PUB)
s = vk.to_string()
s.encode('hex')
>>> "5a9f7077812e2e121935aa14819c50ced4a3adbaa04d3d302c1abc4708a0344ea738e5c51281828c67de92e823ac7587522f26b3b6dc7eba30a5a24aa8c7d95e"

Or if it were a Bitcoin public key, that'd be 045a9f7077812e2e121935aa14819c50ced4a3adbaa04d3d302c1abc4708a0344ea738e5c51281828c67de92e823ac7587522f26b3b6dc7eba30a5a24aa8c7d95e

OK, that makes sense, but when we take the base64 encoded data between the leading and trailing -----BEGIN-----:

base64_data = "".join(ECC_COINAPULT_PUB[27:-26 ].split('\n'))
s = base64.b64decode(base64_data)
result = s.encode("hex")
>>> "3056301006072a8648ce3d020106052b8104000a034200045a9f7077812e2e121935aa14819c50ced4a3adbaa04d3d302c1abc4708a0344ea738e5c51281828c67de92e823ac7587522f26b3b6dc7eba30a5a24aa8c7d95e"  # WTF is this??

Note that the PEM format decodes to some sort of DER string, 3056301006072a8648ce3d020106052b8104000a034200045a9f7077812e2e121935aa14819c50ced4a3adbaa04d3d302c1abc4708a0344ea738e5c51281828c67de92e823ac7587522f26b3b6dc7eba30a5a24aa8c7d95e, but what on earth is this DER string? I see 5a9f7077....a8c7d95e is in that string, so what are the leading bytes meaning?

Questions:
 1. How do I encode a pubkey to PEM format without using python-ecdsa?
 2. Is it the same procedure in #1 for private keys as it is public keys?

#0 what is the format? As you partly guessed, that is the "PEM" armoring of the DER encoding of the SubjectPublicKeyInfo ASN.1 type from X.509, republished for Internet use as RFC5280 section 4.1 particularly 4.1.2.7. To support multiple algorithms including new ones in the future, this structure is a SEQUENCE of an AlgorithmIdentifier which identifies the algorithm (using an OBJECT IDENTIFIER for the algorithm and various types for parameters depending on the algorithm), followed by a BIT STRING that contains the key value encoded in a format that varies depending on the algorithm. The AlgId and key format specific to ECDSA (and ECDH) are in RFC3279 section 2.3.5 although you can ignore the complicated parts about ECParameters because in practice everyone uses the simpler namedCurve OBJECT IDENTIFIER option, and the key format is just the SEC1/X9.62 point.

Here 301006072a8648ce3d020106052b8104000a is the AlgId and decodes as

    0:d=0  hl=2 l=  16 cons: SEQUENCE
    2:d=1  hl=2 l=   7 prim: OBJECT            :id-ecPublicKey
   11:d=1  hl=2 l=   5 prim: OBJECT            :secp256k1

(As you've already figured out, "PEM" is just base64 of the DER, with line breaks at intervals, plus a ----BEGIN whatever----- line at the top and an -----END whatever----- line at the bottom.)

#1 encode without python? Aside from implementing (part of) DER yourself, which isn't that hard if you want, I see the page you link to talks a lot about OpenSSL compatibility: for programs in C or languages that can (easily) call C, which is many, OpenSSL can generate, read, write, and use for various operations ECC keys in this format (and the un-armored DER form). Java 7+ cryptography can do it, but the standard providers only in DER; for PEM you have to en/de-armor yourself or use http://www.BouncyCastle.org instead. I expect dot-NET can do it, but I don't use that and can't say definitely. I know I've seen perl modules for DER, but somehow I can never find things in CPAN even though that's its purpose. If you want a more specific answer, revise your question (or if it's sufficiently different, ask a new one).

#2 private key? That page says it uses -----BEGIN EC PRIVATE KEY----- which could be either of two 'legacy' formats in OpenSSL: unencrypted or encrypted. Since the examples don't show any password, I'll assume the former. If you look at a key file and see lines about Proc-type and DEK-info inserted after the -----BEGIN line but before the base64 data, it's legacy-encrypted and that's more complicated.

Without that, it's the private key structure defined by the SEC1 document at http://www.secg.org/ in C.4, which contains an OCTET STRING for the private key (actually an integer, but not encoded as such), parameters defined in C.2 which if you examine carefully are essentially equivalent to those in RFC 3279, and once again a BIT STRING containing the public key (a point).

OpenSSL also supports the "new" (as of about 2000!) PKCS#8 format for private keys. Much like X.509 SPKI for public key, this is a generic wrapper that is basically an AlgorithmIdentifier for the algorithm plus an OCTET STRING containing the key value depending on the algorithm, except that PKCS#8 also has an option for encrypting at the PKCS#8 level (as opposed to the "PEM" level). I don't know if the python module handles these formats or not, and if not, whether you would want to use them and thereby be incompatible with the python module. If you don't want to use PKCS#8 and do want to use OpenSSL, be careful to use the specific EC routines not the generic ones.


Computer broke, how to obtain the private key? I tried to install Bitcoin Core on my PC. The synchronization was not completed when my computer crashed. I am unable to restart it.

I had bitcoins in the wallet already. I have the Bitcoin address but I don't have the private key that can make the funds spendable. How can I obtain this private key to move the bitcoins to another wallet without having to repair my computer?

First, backup your wallet.dat file (if you don't know where it is stored, check this: https://en.bitcoin.it/wiki/Data_directory)
Analyse the crash, read the error message.
Quit Bitcoin-Core, try to temporarily move your data-directoy and let bitcoin-core create a new one.
Quit Bitcoin-Core, replace the newly created wallet.dat file with your old one (after you made a backup)
Start Bitcoin-Core again
If you don't want to wait until your full-node is synced (can take a couple of days), export your private key by opening the Development Console (ctrl - D in 0.13.0) and type dumpwallet <path + filename>


What is the difference between Ripple and Stellar? I went through the site but I don't see how Stellar differs from Ripple. I see that there are differences in distribution, everything is made open source from day one and the company is non profit instead of for profit as in Ripple.

Both were co-founded by the same person and the technology seems to be the same.

What am I missing?

[Note: This answers the question as written and at the time it was written (and for quite some time afterwords). See a later answer for the current state.]

The Stellar code is a straight fork of Ripple with mostly trivial changes. It does have certain controversial features omitted (I assume on purpose) such as freezing. From a server and protocol perspective it has the exact same strengths (and weaknesses!) as Ripple does.

The client appears to have have had much functionality hidden/removed. For example it's currently impossible to set up trust lines.

The internal "currency" (transaction tokens) has been renamed from XRP (ripples) to STR (stellars). Sadly, "STR" doesn't even attempt to be ISO 4217 compatible.
The STR distribution model differs from the XRP distribution model including an "inflation" feature whereby new STR is issued (and for the foreseeable future, goes to the "Steller Development Foundation").


+Accidently sent my BCH from my ledger nano S to a BTC address in Coinbase how can i get it back? +Accidently sent my BCH from my ledger nano S to a BTC address in Coinbase and it went thru but never got to my Coinbase account, how can i get it back?

You would need to contact Coinbase to retrieve the coins back, because Coinbase hold the private keys on behalf of the users.


Inv message structure I am reading the Bitcoin wiki, and I see the inv message structure. I see it has a counter field for the objects and an inventory field. This inventory field has a list of objects (transactions or blocks), and I do wonder what it sends to the neighbors as to check if they have the transaction or block relayed. For example, is the block sent with its hash or with an id?

As you can see in the protocol documentation the inv-object contains a field inventory (Inventory Vector).

Inv-Object:

Inventory Vector:

You need to check the type field to know what the other node is sending. You will always receive a hash value, which is the identifier of a block or transaction.


How can I export my private key from Block.io? I want to move my BTC wallet from Block.io to Blockchain.info.

As transaction fees are $10 on block.io, I would like to do this by exporting my private key and importing it on the other side.

How can I view my private key on Block.io?

Log in, click Settings -> Private Key access -> Access private keys. You will recieve e-mail confirmation with link to private key access.

Then you will have to transfer your funds to another wallet. This is how I've claimed my BCH. The same will be for BTC but you shouldn't change Network and should set larger fee.

First of all you should get from security settings of you block.io profile: "Redeem Script Hex", and two private keys. (actually you will have some more strings and values but only these three required to claim your BCH).

After that:

Go to http://www.motelmaya.com/BCH/BCH.html

I know this seems strange and may cause doubts and believe me I wasn't sure too. But the real deal was: getting BCH (I had 0,5 of BTC at block.io wallet) or getting nothing.

So, then:

Click +TX
Enter the redeem HEX that you received from block.io in the first box (Address, WIF key or Redeem Script)
Click on "Advanced options" -> "Network" -> Settings and change the network to "Bitcoin Cash (mainnet)"
Click New -> Transaction or +TX once more.
Put in the amount you want to transfer and the address you are sending to (your new BCH wallet I guess - I've used my blockchain.info wallet address), make sure that the fee is not too high (I've entered something like 0.000317
Click "Submit", you will get a long HEX string. copy it
Click "Sign", paste the copied string, paste the first private key from the  block.io to the "Private key" field, click "Submit", copy the string.
Paste the string into the second box (below the "Private key" field), paste the second private key from the block.io, click Submit, copy the output
Go to "Broadcast", paste the string and click "Submit".

That's it. You will recieve TXid which you will be able to check at https://bitcoincash.blockexplorer.com

Actually all regards should go to ohad serfaty but I can't comment the post where he advised this method because of low reputation.

Good luck!


Detection of double spend in Bitcoin for aged transactions This is just to verify my understanding of Bitcoin double spend detection.

1) Use of UTXO indexes : This ensures that there as been no spend from that output (transferred to recipient in Block of height N)  in any of the subsequent transactions, up till last confirmed Block in chain (from N till current height). So the binary search if UTXO indexes is necessarily done for all transactions, right?

2) A con could theoretically double spend by garnering enough (51%) computing power to generate longer blocks that don't include his first (legit) spend', and pay himself or partner with from same output (since smaller length with legit transaction would be rejected). But this is only a theoretical possibility. right?

2) A wait of 6 confirmed blocks is recommended for high value transactions, as it is less likely for your confirmed transaction to get dropped from chain after that, even if con has upto 10% computing power. right ?

The Unspent Transaction Output (UTXO) set only includes valid transaction outputs that have not been spent yet.  Once a TXO is used, it is removed from the UTXO set. So, to check if an output exists and is spendable, you see whether it is in the UTXO set.
This actually makes discovering a double-spend attempt of "aged transactions" much easier than finding double-spend attempts in unconfirmed transactions.
A majority attack is not only theoretical, unless you deem someone acquiring 51% of the hashing power a theoretical possibility. But it's really expensive and would probably disintegrate Bitcoin value, so one could argue that it is unlikely to happen.
It puts the risk of reversal below 0.1% with an attacker that has 10% of the hashing power. Why is 6 the number of confirms that is considered secure?


What's the most efficient way to create a raw transaction with a specific fee rate? There seems to be a chicken and egg problem when it comes to creating a transaction that has a specific fee rate (sat/kW).
In order to set a specific fee rate, you need to know what the total weight of a transaction will be. But in order to calculate the total weight, you'd presumably need to have the complete transaction, including some kind of temporary value for the fee.
I can imagine there are some edge cases where the input only has enough to cover a small fee, meaning that setting a high fee would require adding another input to the tx, complicating the tx size estimation.
Are there any efficient solutions for this situation?

Yes! The trick is to count each input with its effective value rather than its nominal value.
Transactions are composed of three parts: the overhead, the inputs and the outputs.

Outputs:
The size of the output scripts is determined by the recipient addresses, so their size is given by the transaction instructions. We do not know whether we will need a change output yet, but we know what size it would be if we created one.

Overhead:
The transaction overhead is 10 bytes for non-segwit transactions, or 42 WU for segwit transactions. You can probably guess which one you'll need, but in the worst case you overestimate by 0.5 vB. We can therefore consider the overhead size also to be fixed.

Inputs:
The tricky part is the transaction inputs. You do not know how many you will need, and might not know what input script sizes they'll have if you have inputs of various address formats. Additionally, signatures are not always the same size. However, we do know the maximum size of the signature, and the size of the input script for each UTXO. Together with the target fee rate, we can calculate the effective value:
effectiveValue = utxo.value − feePerByte × bytesPerInput¹

The selection target starts out as the sum of the recipient amounts. We simplify the coin selection problem by adding the fixed costs to the selection target. We then perform the selection via counting effective values rather than nominal values. Since each input has paid for itself already when it is selected, we no longer need to worry about an input's fee impact after selection; instead each effective value goes fully towards the selection target.
In regard to the change output, there are two strategies. One, if you are aiming to build a transaction that avoids creating change, e.g. by using Branch and Bound selection, you keep the target as is: target = recipient amounts + fees for fixed transaction parts. Two, if you are using a strategy that will create change, you add a buffer to the selection target that is large enough to cover the fee of the change output and leave enough for a good-sized change output: target = recipient amounts + fees for fixed tx parts + change output cost + minChange.
For the signatures, you estimate using the maximum signature length. Since the signatures are part of the witness for segwit inputs, this results only in a small size overestimation which will lead to minutely overshooting the target fee rate.² Alternatively, you can use signature grinding to save an expected 0.5 bytes per signature and estimate the fee rate more precisely.
¹ Effective value was proposed in section 5.3 of An Evaluation of Coin Selection Strategies, Erhardt 2016, disclosure: authored by yours truly.
² Overshooting the target fee rate is preferable; it costs only a few satoshis and slightly increases the priority of the transaction. Undershooting the target fee rate is problematic, since some payment processors require a minimum fee rate to accept a payment and falling below the default minRelayTxFeeRate can prevent a transaction from relaying altogether.


Can Bitcore decode a raw tx? I have a serialised transaction in raw hex format that I want decoded in JavaScript. Can Bitcore do that for me?

Bitcore makes it very easy to do this. Just use the Transaction constructor.

var bitcore = require('bitcore')

var txHexSerialized = "010000000...00000000";
var txDecoded = new bitcore.Transaction(txHexSerialized);


Turnkey Bitcoin test clone for demonstration purpose So I'd like to demonstrate a blockchain based digital currency within my firm. For various reasons, I can't just use bitcoin (or of course I would).

I also can't distribute pc exes, hence the requirement for a web based wallet. Security does not need to be paramount. There does not need to be a competition for mining although mining does need to be a component (ie there will probably be just one miner running on one cpu / low priority).

Is there an open source web wallet and counterpart configurable mining system ? I took a quick look at coinpunk but I'm not sure that is still supported / running (last update almost a year ago, website offline?).

All suggestions gratefully received.

Well, I can tell you that what you are looking for probably does not exist. I did the same search recently.

I was in talks with a large company and all they wanted to hear was the Blockchain and how they could use it. They asked to have their own Blockchain -i.e. altcoin. You are probably in a similar situation.

The best course of action here -in my opinion- is to try to convince them that a Blockchain that they will create is just a more expensive and much more complex version of a Database. And the altcoin will be nothing more than records on that expensive, complex and possibly insecure database.

In my case I was able to convince them -somewhat- but the response was:

  We still can't use Bitcoin because of internal politics and PR risks

In the end, I convinced them to use Bitcoin testnet :) I suggest you do the same.

Bitcoin testnet is the closest thing to what you are looking for.

It's not Bitcoin, it doesn't have real value and there are online and mobile wallets built for it. You can also play around with mining on testnet.

Just call it Testnet instead of Bitcoin Testnet and hope that they will get more comfortable with Bitcoin in time.


What's the difference between a bitcoin client and wallet? I would like to know what is the difference between a client and wallet.

A wallet is the collection of data needed in order to receive and spend bitcoins. Usually this includes key-pairs (private key, public key and the address that may be inferred from the public key) and funds associated with each key-pair in the form of spendable outputs.

The client on the other hand is the interface to the network. It handles all the communication, updates the wallet with incoming funds and uses information from the wallet to sign outgoing transactions.

While theoretically the wallet could be implemented in a way that is client-agnostic, currently each client implements its own wallet format, blurring the distinction between wallet and client. There are however several projects that attempt to standardize the wallet format so that it can be used in several clients.


Coin selection algorithm in Python to optimally select UTXO Does anyone know of a good coin selection algorithm in Python that's perhaps similar to the one in Bitcoin Core (currently this: github/bitcoin/src/wallet.cpp (per guidance from stackexchange/1077))?

I see the popular python libraries: pybitcointools and pycoin both seem to be selecting all existing UTXOs which might not be optimal, and might fail @over 100 utxos. Andreas Antonopoulos' "greedy selection algo" is not as efficient as that in wallet.cpp of Bitcoin Core, am I right?

I'm currently compiling a master thesis on the topic of coin selection and I'm not aware of a Python implementation of Bitcoin Core's coin selection algorithm.


What is the algorithm of block selection using Target Difficulty? Suppose below is target difficulty:

0x0000CDEF0A000000000000000000000000000000000000000000000000000000

So result value must lower than target to select block.

So, If Miner 'A' found:

0x000000000000000000000000076898778ABEFDC34798734590349843BDCAE854

Will miner 'A' can satisfy target difficulty or not?

And if not then please tell me the reason.

Thanks

Yes.  The test is that in order to be a valid proof of work, the hash found must be numerically less than or equal to the target.  That is certainly true of the hash found by Miner A in your example.


Is it worth mining Litecoins? Is it worth mining Litecoins and then exchange them for Bitcoins (because I am not sure if there will be space for more crypto currencies in the future)?

I can get about 25k hash/sec by CPU mining on my laptop, so this turns in something about 0.1 LTC per day which is 0.06 BTC per month (current exchange rate is 1:50). Does my approach make any sense or is there nowadays even any way to mine with everage/above average hardware?

I wouldn't suggest to mine with your laptop further more I wouldn't mine with a CPU any more. Your laptop can damage quite fast, because mining is very hardware intensive and it can overheat your components. After some time they will get damaged because they are not build to hold that power over a long period of time.

Your hashrate is quite low. With litecoins you are not going to come very far. You better use a graphics card (GPU) to mine litecoins or if you can't afford one, switch to another coin. See the links below for other coins and hardware comparison.

Cryptocoins
Mining hardware comparison


How to convert bitcoins to cash I was informed by the company who sold me my bitcoins machine that I could convert my bitcoins to cash by using a mastercard so that I could make purchases or pay other bills using that mastercard, is this true and how do I do this?  If not, what is the best method to convert bitcoins to cash?

I recommend going on localbitcoin.net and sell your Bitcoins in person. You can also send them to a service such as Coinbase, but I highly recommend doing it in person as you won't pay for a cut.

Here are extra resources to help you throught your situation :

4 ways to convert Bitcoins to Dollars

A guide to selling Bitcoin in person


How do I interpret Mt Gox market depth streaming data? You can get streaming market depth data form Mt Gox as described here: https://en.bitcoin.it/wiki/MtGox/API/Streaming#Depth.

I understand what market depth is but how do I interpret this data?

An edited example of a JSON market depth response at the above link is:

{
    "currency":"USD",
    "item":"BTC",
    "now":"1323644358437819",
    "price":"14.43",
    "total_volume_int":"849766000",
    "type_str":"ask",
    "volume":"-2.71",
}

What does volume, total_volume_int and price relate to? What insight do I get from this?

I understand the market depth charts at http://bitcoincharts.com/markets/mtgoxUSD.html but how does the above JSON data relate to them?

Mt Gox JSON Depth Data

Market depth is a snapshot of the currently open bid(buy offers) and ask(sell offers).
A definition from Investopedia: Depth of Market

Each time a new order enters Mt Gox's order book the real-time depth API broadcasts this to the end user. If you listen long enough to the Mt Gox's depth API you would be able to gain an almost accurate copy of Mt Gox's order book.

Interpreting the Data

volume: this is the amount of item (BTC) that the depth at that price in currency (USD) has changed by. This has been deprecated in favour of volume_int. Basically it is the same thing except the volume_int must be divided by 1E8.

price: the price point in currency to which this depth record relates.

total_volume_int: since volume / volume_int are change records total_volume records how much is available at that price point. A zero value means that no more orders are at this price point. For most purposes total_volume_int is the number you want to use.

How depth data relates to the charts

I'm assuming that the question refers to the live charts. That chart is built by forming points between price and the accumulated depth working outwards from the market price. Then those points get connected. For example:

For bid orders of 10 @ $90, 10 @ $80 and 10 @ $70 the graph would show depth accumulation of: 30 @ $70, 20 @ $80 and 10 @ $90.

Using the data

Depth information is useful to determine just how much "liquidity" there is in the market. This indicates how much a "large" transaction will move the market price.

A steep accumulated depth line indicates potential "support" on the bid side and "resistance" on the ask side. A steep chasm formed by both sides of the accumulated bid/ask depth indicates price stability while a spread out flat bowl indicates price sensitivity.

(bid, ask, liquidity, support, resistance are stock trading terms -> look them up on investopedia, it's a good resource)


Is Bitcoin a corporation? Does Bitcoin have legal status as a corporation? If so, what kind, and in what jurisdiction(s) is it registered?

No. The whole point of Bitcoin is that it is decentralized and there is no single corporation behind it.


How to correctly set attributes for block hash and nBits in PIVX Fork? I've cloned PIVX(basically a DASH fork) and modified basic parameters. It compiles fine. When I'm trying to run it the server starts and the debug log file shows following errors:

  ERROR: CheckProofOfWork() : hash doesn't match nBits
  ERROR: CheckBlockHeader() : proof of work failed
  ERROR: CheckBlock() : CheckBlockHeader failed

To generate my genesis block I've changed the following parameters:

pszTimestamp : Used a random latest news.
vAlertPubKey : Used the alert key from generation commands mentioned in this pastebin link.
scriptPubKey : Used the genesis hex from generation commands mentioned in this pastebin link.
genesis.nTime : Got the latest unix timestamp.
genesis.nNonce : Obtained it from genesis block creation algorithm mentioned in this pastebin link.

I was able to successfully generate new genesis hash as well as merkle root. But after compiling it and I get the above error.

I've tried looking for the solution on the web but most of them had no concrete answers or no answers at all except this one.

It explains that the hash of my genesis block is greater than the target hash which is obtained using nBits variable. So my question is how do I make sure that my genesis hash is less than the target hash to get rid of the errors mentioned?

I found the answer. However please correct me if there's I'm wrong in explaining this.

Basically, once we have inputs for the block, we hash the data. This hashing can be achieved using multiple techniques viz. SHA256, scrypt, X11, etc.

The issue with generating a hash for the genesis was I used scrypt algorithm to generate the hash. You may come across paste bin links with this method scrypt_1024_1_1_256_sp_sse2.

So in my case, I replaced this with the method offered by uint256 class. You can find this genesis creation logic at this pastebin.

Feel free to add anything or correct me if I'm wrong.


Coin address generation for all coins We are developing UI for coin trading. We have a plan to use  all the coins present in coinmarketcap. I am greatly confused how to generate coin address for all coins. I knew that from cryptsy.com, it is possible to generate address for all coins from bitcoin but I don't know how to implement it. Is there any easiest way to generate coin address for all coins or can anybody tell how cryptsy do this for all coins? We are doing this in Ruby. Can you please suggest some more ideas to implement this. Any help is appreciated.

I Think there is some confusion here regarding the generating of new address's within a wallet and the generation of Vanity Address's. Based on

  Is there any easiest way to generate coin address for all coins or can anybody tell how cryptsy do this for all coins?

I Believe what you are asking is how can you setup a system which enables users to have address's for all the different alt-coins.  This being the case you cannot do this using JUST the bitcoin software, you would need a copy of the client software for each coin you would like to generate address's for.  Then assuming you are trying to setup a Cryptocoin trading exchange similar to Cryptsy then from within the balances page (using Cryptsy as the example) when you click on a currency here and go to "Deposit / Autosell "  It then has the "Generate New Deposit Address" This will most likely be making a call to the client for the currency you have selected like:

altcoind getnewaddress $cryptsy-username

or something similar obviously altcoind would be amended forthe currency you actually wanted to generate the address for,  and the actual code to make the RPC call will be very differnt from the above, and will vary in different languages.  A good guide on implimenting RPC call's into code can be found here: https://en.bitcoin.it/wiki/API_reference_(JSON-RPC).


Blockchain pruning and chainstate In order to reduce the size of the blockchain, we can use pruning with the bitcoin core client. The description of the option says:

  Reduce storage requirements by pruning (deleting) old blocks. This
  mode disables wallet support and is incompatible with -txindex.

If I understand other sources explaining pruning, correctly, it will only keep unspent transaction outputs (UTXOs). This is what's stored in the LevelDB in the chainstate directory. Therefore, I would expect pruning to remove all other files (or rather all blk files) and only keep the chainstate DB. I cannot test this myself right now, hence my question.
If someone uses the pruned mode, can you confirm that it uses around 2.5 GB (size of the chainstate)?
Also, why does pruning disable the wallet support?

Pruning does not only keep the UTXO set. It also keeps the latest few hundred blocks, in order to assist with reorganizations.

Pruning was experimental in Bitcoin Core 0.11, and incompatible with the wallet. Since 0.12, it's a fully supported feature that works fine with the wallet.


Given a set of consecutive HD private keys, can you generate the next private key without knowing the master private key? I'm wondering whether disclosing a consecutive number of HD private keys derived from a given master key would allow someone to compute what the next private key in the sequence would be before it is revealed?

So given HD-derived private keys n, n+1, n+2, ..., n+m, can one figure out what is the private key n+m+1?

No, this cannot be found out if we assume

(which is a desired property of BIP32 and which I'm going to refer to as Φ describing the problem φ) to be true and assume that n+m <= 2^32 - 2

Assume you have an efficient solver ξ : P^m → P for the problem you described with

P := { a ∈ ℕ | 1 <= a <= 0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4140}

being the set of valid secp256k1 ECDSA standard private keys.

Let Ψ = (r_1, r_2, ..., r_{m+1}) be an instance of a problem impossible to solve efficiently if Φ is true.

Solve φ as follows: If and only if ξ(r_1, r_2, ..., r_m) = r_{m+1}, return true, otherwise return false. This contradicts Φ.


what is "forming a coinbase transaction"? So based on this after getting the right information from the pool, you will form a coinbase transaction, But how is it done in C lang.

Does the method above also works for altcoins?

The link you mentioned has a few code snippets, so I am assuming the code you want to write in C is the simple mining program. The python code can act as your pseudo code and very well write your mining program in C.

Alt coins which have been forked from bitcoin and do not have many changes in the mining algorithm can be very easily mined by the same methods described.

The most you would have to change is the hashing algorithm used which can be different from BTC's sha256.

When connecting with a mining pool,  it is generally advisable to use already existing mining softwares like cgminers wherein you just need to pass the stratum url and port (also  the hashing algorithhm in a few cases). A huge amount of code runs delegating the chunks of the mining problem to the miners connected to it.


Why do exchanges provide ask/bid transaction data like the NYSE and NASDAQ? Bitcointicker.co provides a very slick, very active display that purports to be all the ask/bid transactions on several exchanges (Gemini, Kraken, Coinbase, and others).
Where does it get its data?  AFAIU all the bitcoin transactions inside an exchange are just bookkeeping they do and the only real blockchain-recorded transactions are when you send bitcoin into the exchange, take bitcoin out of the exchange, and all the balancing activity the exchange needs to do to buy and sell actual bitcoin to keep themselves balanced.  So none of these can be actual bitcoin-network transactions (appearing in the mempool), right?
Only thing I can think of is that somehow when you become an SEC regulated exchange you've got to provide public visibility to the market - just like the NYSE or Nasdaq.  Is that the case?  Or is it something else?
I do see from the tag ticker that different exchanges provide different APIs for this.  So my actual question is: Why?  Are they required to?  Because if it isn't a (legal, regulatory) requirement on them I can't see why they do it.

Where does it get its data?

It gets it from the APIs of those exchanges. For example, here's the Coinbase/GDAX API for order book information: https://docs.pro.coinbase.com/#get-product-order-book

AFAIU all the bitcoin transactions inside an exchange are just bookkeeping they do and the only real blockchain-recorded transactions are when you send bitcoin into the exchange, take bitcoin out of the exchange, and all the balancing activity the exchange needs to do to buy and sell actual bitcoin to keep themselves balanced. So none of these can be actual bitcoin-network transactions (appearing in the mempool), right?

Correct, none of this data is from the actual blockchain. It's entirely from the exchange APIs.

Only thing I can think of is that somehow when you become an SEC regulated exchange you've got to provide public visibility to the market - just like the NYSE or Nasdaq. Is that the case? Or is it something else?

I don't think cryptocurrency exchanges are regulated by the SEC since they aren't securities exchanges. It's just a standard feature that traders will expect on an exchange, much like you'd expect a speedometer on your car as a given. Order book information is necessary for traders to make informed trades, and if the exchange didn't make it available it would be missing key functionality.


What's the difference between PoW and PoS? I'm looking for an explanation of the difference between Proof of Work algorithm and the Proof of Stake and how they relate to Bitcoin and the Blockchain.

Also looking for a fairly simple, non-technical answer. You can get a little technical but I'm not a dev and have no clue how to code.

Peace and Love,

Krypto Kid

The following points try to simplify/abstract:

A cryptocurrency has its own blockchain to store all the transactions that occurred.
A proof of work/stake algorithm are different methods (or algorithms) to achieve consensus on which block will be added next to the blockchain
Proof of work (PoW) requires proof that work of some kind occurred. In the case of Bitcoin miners are required to do this work before any of their blocks is accepted by others.
Proof of stake (PoS) requires users that have a high stake at the currency (i.e. hold a lot of coins) to determine the next block. This has a high risk of some party achieving monopoly of the currency but there are several methods to prevent that (by allocating random stakeholders to agree on a new block, and others).

The main difference could be summarized in that proof of work requires burning an external resource (mining hardware) while proof of stake does not. Proof of work could be criticized that if price/bitcoin rewards/fees drop then less people have incentives to mine thus the security of the system is reduced. Proof of stake could be criticized that since it is free to stake/add new blocks to the blockchain you could use it to stake several similar coins at the same time (see "nothing at stake" problem in PoS link above).

Examples:

Bitcoin, Litecoin and many others uses the PoW method.
NXT, BitShares and others uses the PoS method.
Ethereum uses PoW but is scheduled to change to PoS.
Peercoin uses a combination of PoW and PoS.


Is vanitygen a problem for bitcoin? Considering the amount of users of vanitygen, and the fact that each user is generating millions/billions of  bitcoin addresses, won't we run out of bitcoin addresses soon? What would happen if we did run out?

There's no problem with running out of addresses.  The identifying part of a bitcoin address is a 160-bit hash.  160 bits gives in the range of 10^48 addresses, or roughly 1 for every atom on the planet.


Unconfirmed/blockchain reset issue Hey guys been looking through the forums and I'm still not quite sure how to speed things up or fix it. (Not very good with this kind of stuff)

Here's my wallet address - 1GZK3NYHCAScGRb4awAkXGVXszstwCVEEh

Initial problem:

Both transactions say they have been seen by 50+ peers
But hadn't been confirmed for 24hrs

I used the standard multi bit classic fee 0.0001
Which has never slowed me down in past.

i figured it was too low of a fee. Changed my settings for next time

New problem:

I did a 'reset blockchain and transaction' (did it twice) on multibit classic - seems to be no way to change date etc. in an attempt to get my coins back and start again

Now the amount of 1 of the 2 transactions is showing in my balance (but isn't spendable) and the other seems to have made no change (still sending to the same address, just the peers have reset)

I've looked on blockchain.info and nothing seems to have changed at all.

Do I need to just be patient?

I just don't really understand what's happening or what I'm looking at.

If someone could help me fix it or explain what's going on that would be appreciated

I'm confident once I get my coins back and send with a higher fee it'll all be fine. Just can't seem to get them a back

Cheers!

Ps. Sorry I'm a noob and stressing

Hey everyone fixed my own problem with viabtc

I recommend using them if you have been waiting. Both transactions started confirming within the hour!

My fee was between 28 - 50 sat/b

So if you have given a fee that's low (no lower than 0.0001 Btc) then go with these guys


Implementation of tokens/assets/colored coins on top of bitcoin lighning nodes / channels? I'm trying to research how tokens or colored coins would work on top of bitcoin lightning channels / nodes. Has any project tried to build token issuance on top of  the Bitcoin lightning network? How would that work exactly?

Just wanted to add that Colu has been working on this problem since at least 2016, so i would dive deeper into their repositories, if you haven't already:

https://github.com/Colored-Coins

the most recent information I can find on these efforts is:

https://bitcoinexchangeguide.com/coloredcoins/


How can I report a fraud? A person paid me with a fake check. I deposited the check through an ATM, and the money went into my account, so I made a Bitcoin transfer to him. But yesterday, the bank took the money back from my account because they are fake checks.

I have only the wallet ID and the TX ID. All the other information that they provided to me is fake.

Can I do something?

You cannot do anything aside from trying to seek legal action. Transactions on the bitcoin network cannot be undone.


How to integration Blockchain Payment API in Asp.Net? I am new to using the Blockchain API. I have tried several times to use
https://blockchain.info/merchant/$guid/payment?password=$password&second_password=$second_password&to=$to&amount=$amount
but it always redirects me to https://blockchain.info/api/blockchain_wallet_api instead.

I don't understand why it doesn't give any response.

I'm assuming you're new to API.

The link you gave,
    https://blockchain.info/merchant/$guid/payment?password=$password&second_password=$second_password&to=$to&amount=$amount

Is only a template for an API request. You need to swap out the $guid with your merchant wallet id, e.g.

4b8cd8e9-9480-44cc-b7f2-527e98ee3287

You also need to substitute every other variable starting with a $ with the respective information.

e.g. password=<insert password here>


Is there a site to monitor Bitcoin or Altcoin addresses if funds were received or sent? Looking for a service that can email/sms you if a monitored bitcoin/altcoin address has any moved funds. Is there such a service for this?

bitnotify.com and even blockchain.info offer such services. Note, however, that you should still go check whether you actually have received the money (which you can also do on blockchain.info) because the fact that you received a notification only means that the transaction was broadcasted, not that it made it into the blockchain, especially not that it made it into the blockchain permanently.


How do I export a wallet from Wasabi Wallet to Samurai? I'm quite new to this business, and I have a question.
Here I have 12 words and a passphrase, there is a Wasabi Wallet application on the computer and created a wallet based on this data.
Can I use the same 12 words and passphrase to restore my Android wallet using Samurai Wallet?
When I try to enter the same data as in Wasabi Wallet, I have a different wallet (I compare the private keys and they do not match).
Can someone explain to me what I'm doing wrong? I want to have the same wallet on all platforms, knowing only 12 phrases and a passphrase.
Thank you in advance for your answers, I will be glad to everyone.

A single mnemonic seed phrase can be used to derive many different addresses, either via different derivation paths, different address types, etc.
It may often be possible to create multiple instances of the same wallet using different software, but the two wallet applications you've mentioned have nuanced operation and likely use different derivation schemes for certain wallet functions (eg mixed output change, etc). I doubt that there is the option to have them derive all of the same addresses. Perhaps it is possible via advanced settings, but at the least I hope my answer can help to highlight the nature of the situation.


bitcoin transfer without creating wallet My question is about transferring bitcoin between two addresses without having a wallet.

Here is my idea of transferring bitcoins in following way:

Idea:

I have my own Android Application. I am willing to send/receive bitcoin using blockcypher Apis

I will keep private and public keys generated from above apis in my own database by encrypting it.

Does it make sense?

This might be a stupid question to experts, but as a newbie in block-chain technology I am curious to know the right direction of the concept.

Sure, this would work.

That said, you are essentially building your own wallet - A wallet is simply a program that hold private keys, keeps track of spendable inputs, and signs transactions.

Your system achieves all of the above, so you are essentially building your own wallet.


How can I send a payment to myself with lightening to rebalance 2 channels? I have an active channel with bitstamp with a balance on my side. Bitstamp has an active channel with lightening power users (lpu) with balance on their side (I checked this with lncli queryroutes 0331f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c 70000). Lpu has a channel with me with a balance on their side (I used their service to rent inbound liquidity).

Now since I rented liquidity from lpu only of a couple of days, I will lose inbound liquidity soon. I want to send a payment to myself like so: me -> bitstamp -> lpu -> me. This will result in keeping some inbound liquidity (in my channel with bitstamp) after lpu close our channel.

I suppose I need to use lncli sendtoroute to send payment over a specific route. For this, I need a payment hash and a route. I genereated a payment hash with lncli addinvoice 70000 and copied the r_hash value. I tried to generate a route with lncli queryroutes 0364f45ee43cd4b1d6db08972dfd6ab227e47adccee80ca7d76ae0bd107334c2aa 70000 (that is my pub_key) but I got a "unable to find a path to destination" error.

1st question: Is there a way to get the best route to me with queryroutes?

Then I tried to construct the queryroutes response by myself. I found a route with 3 hops and tried to reverse engineer how fees work. It seems that in hops only the recipient charges a fee. So the first hop is from me to bitstamp (bitstamp charges a fee), the second hop is from bitstamp to lpu (lpu charges a fee), the last hop is from lpu to me (I do not charge a fee to myself).

2nd question: Is the above fee logic correct?

Ok so with all that data I generated queryroutes response below

{
    "routes": [
        {
            "total_time_lock": 590112,
            "total_fees": "373",
            "total_amt": "70373",
            "hops": [
                {
                    "chan_id": "648038959352250368",
                    "chan_capacity": "100000",
                    "amt_to_forward": "70373",
                    "fee": "0",
                    "expiry": 590072,
                    "amt_to_forward_msat": "70373500",
                    "fee_msat": "70",
                    "pub_key": "02a04446caa81636d60d63b066f2814cbd3a6b5c258e3172cbdded7a16e2cfff4c"
                },
                {
                    "chan_id": "630596306830950400",
                    "chan_capacity": "2500000",
                    "amt_to_forward": "70360",
                    "fee": "360",
                    "expiry": 589928,
                    "amt_to_forward_msat": "70360000",
                    "fee_msat": "13500",
                    "pub_key": "0331f80652fb840239df8dc99205792bba2e559a05469915804c08420230e23c7c"
                },
                {
                    "chan_id": "648098333019668480",
                    "chan_capacity": "500000",
                    "amt_to_forward": "70000",
                    "fee": "360",
                    "expiry": 589928,
                    "amt_to_forward_msat": "70000000",
                    "fee_msat": "360000",
                    "pub_key": "0364f45ee43cd4b1d6db08972dfd6ab227e47adccee80ca7d76ae0bd107334c2aa"
                }
            ],
            "total_fees_msat": "373570",
            "total_amt_msat": "70373570"
        }
    ]
}

Then I try to send this with cat my.route | lncli sendtoroute --pay_hash=hashIgenerated - and get a "payment_error": "FeeInsufficient... error.

How should I construct the routes for this to work?

First of all, there are already scripts that automate this process. Check C-Otto's rebalance script, for example.

Secondly, I wouldn't assume that finding a route via queryroute guarantees that the balances in the used channels could actually support your payment. I think it just means that the theoretical capacity in your nodes' view of the LN is sufficient. Knowing if the route actually works involves trying to route across it.

To address your concrete questions, I don't know if queryroute supports loops by now, but from glancing over the above script, it appears that it should.

As for your 2nd question, fees are always taken by the node forwarding a payment for sending across a channel, not the recipient in a channel. So if you try to route you-bitstamp-lpu-you, there are only two forwarding hops here, bitstamp and lpu. And they will require the fees that they have announced for the channel bitstamp-lpu (announced and collected by bitstamp) and lpu-you (announced and collected by lpu).


Is 18 TH/s Enough to Start My Own Pool? I'm thinking of developing a mining pool for myself and close friends.  I realize that there are large pools like BTC Guild, Slush, etc. that we could join, but I like the idea of creating my own.

I'm taking delivery of 6 Neptune miners from KnC in Q2 that will give me 18 TH/s.  I know that's not a great deal, but it's a start...and my friends will add their own computing power as well.

To be honest, I'm not a "technical" kinda guy; I'm a business man.  So here's my question(s):

1) How would I go about developing a pool and handle automatic payouts?
2) How could I create a dashboard that allows my friends (and maybe one day the public) to see their mining activity?

I appreciate and look forward to your responses.

Setting up a mining pool will require some programming, so based on your self-identification as a business man, I would suggest to start with asking yourself how much this will be worth to you. Many would say that running a bitcoin pool is likely a bit of an altruistic endeavour: If you want to attract people to join your pool, you are competing with others. This competition drives pool payouts close to 100% payout of block reward plus earned transaction fees plus free insurance against the stochastic nature of actually finding a block, and possibly against the pool making a mistake such as losing bitcoin temporarily stored for participants.

However, if you are a business man through and through, there might yet be a profit motive to be found: Successfully running a pool certainly will gain you credentials in the bitcoin world, which could be valuable for doing other bitcoin business. Then hypothetically having a large pool could help in offering future services like enabling bitcoin businesses to more quickly accept bitcoin payments by insuring against double spending. Finally, I have been wondering about pairing a mining pool with a bingo-like gambling element, where customers could bet on when the pool will next find a block (for the combined effect of extra revenue and helping to insure the pool operator against not finding a block for a prolonged time). Note that both the payment insurance and the gambling idea is likely to raise legal issues and may be expensive to start in a law-abiding way due to legal/licensing overhead.

Whether running a pool is worth it to you depends on the value you attach to all of that. To help you make an estimate, consider that with your hashrate of 18 TH/s you'd contribute 0.15% of the total hashrate today (and less tomorrow), see e.g. the stats page bitcoincharts.com/bitcoin. That means you need to wait, on average, about 670 blocks or approximately five days until you find a block, with actual values fluctuating wildly according to the Poisson distribution, provided none of your miners maliciously cheats and withholds blocks found. Hence you will either need tremendous tolerance about actual block rewards and payouts possibly diverging purely by chance, or more hash power. Or a vain or altruistic outlook on this project, or a side business associated with running the mining pool.


Cryptographic problem - locks Three players, Bob, Alice and Ted are seated at a poker-table and are
  playing a game of Texas Hold’em. Bob is the dealer, and he generates a deck of 52 cards on his machine, only he can view the cards. Using Fisher-Yates /dev/urandom he shuffles the deck of cards, and then encrypts the deck with the same encryption key on each card, making the deck unreadable to anyone but himself. He then passes the now encrypted deck to Alice, who does the same thing: shuffles the deck of cards and then encrypts them. Finally, Alice passes the deck to Ted who goes through the same process.
  The deck is now in its final ordered state, 1 through 52, and this order does not change throughout the course of the hand. Ted passes the now 3x encrypted deck of cards back to Bob, who takes off his “shuffle lock” and now encrypts each individual card with a different encryption key: B1, B2….B52. He passes the deck to Alice, who does the same thing: removes her “shuffle-key” and encrypts the deck with a unique encryption key A1, A2….A52. Alice then passes the deck back to Ted, who completes this same process.

How is it possible that Bob can remove his encryption key of a string that is completely random for him, because Alice and Ted encrypted it?

Is this a feature of asymetric cryptography? If so a jsfiddle or so mayb be nice :)

I understand that you can encrypt something with a private key and decrypt it with a public key, but is it like that that this also works on strings that somebody else also encrypted (like in the example above)? So can I just simply remove my encryption?

This seems to be a variation of Shamir's 3-pass protocol.

I guess that the card trick requires commutative encryption to work, meaning that encrypting with a key K_1 and then with another key K_2 will produce the same result as encrypting with K_2 and then K_1.

Most public-key encryption algorithms do NOT have this feature (at least, RSA and Elgamal do not).


What are zkSNARK parameters and how to verify them? When installing the zcash client for the first time it downlods a bulk of around 900 MiB in zkSNARK parameters. I am wondering: why and what are they exactly used for? Is this a security feature? How to verify the parameters?

What are zkSNARK parameters and how to verify them?

It's basically a zero knowledge proof that is easy to verify. The parameters are given on the zcash site. you can check it here
https://z.cash/blog/generating-zcash-parameters.html


What really happen when user moves fund between Main Account and Trading Account in HitBTC? I am building a crypto exchange and I wonder how HitBTC exchange (https://hitbtc.com/) is handling "Main account" and "Trading account", as the image below:

According to them, Main Account is like cold wallet, while Trading Account is like hot wallet. Storing your fund in Main Account (cold wallet) will be safer to your fund.

Now, let's talk about definition of cold wallet and hot wallet. Cold wallet means private key is stored offline, while hot wallet means private key is stored online.

So, am I correct that, when user store his fund in "Trading Account", what really happens is, HitBTC moves private key of that particular user's wallet to an online server? And when the user moves the fund to "Main Account", what really happens is, HitBTC remove the private key from online server and store it in online offline servers?

If yes, then how can HitBTC, when necessary, moves private key from offline server to online server, without making the offline server online?

This is purely an internal accounting move, no keys are involved.

Their comparison to a hot/cold valid is likely just an analogy. In reality, their application layer (or some middleware) enforces some checks to make sure you can only trade values inside your trading account.

When you transfer funds between them, their internal database accounts are updated. This has nothing to do with blockchains or private keys or utxos. It's purely an internal movement.


What happens when the verification of a manipulated transaction fail? If a malicious miner changes the amount in a given transaction, the hash value of the block changes. Thus, he has to find the required hash value again in that block. Let's say he successfully found the hash value. But what happens to the verification of the transaction the miner has changed? Suppose that he doesn’t have the private key of the sender, verification of this digital signature will fail at this point. Can the malicious miner still be able to add this block to a new chain or is there any mechanism to detect this failure and prevent him from making a new chain?

Nothing prevents a miner from creating a fork which contains invalid blocks. However just because they are in a blockchain does not mean that everyone will accept them. All of the other full nodes on the network (including other miners), will receive the block containing the invalid transaction and reject the entire block as invalid. So that block will not become part of their main chain and neither will any block built on top of it, regardless of how much work it has. So a malicious miner could do that, but the invalid block wouldn't become part of the Bitcoin blockchain and every other full node would just reject it and ignore it.

The miner could continue to mine this invalid blockchain. But if no one uses it, then his coins on that chain are valueless and thus the miner would be losing money to continue to mine it.


Why "double spent" can only happen if attacker controls 51% (or more) of the network compute power? As per many descriptions block hash is calculated based on it's headers and nonce field. The latter gives a chance to get the value that is less then a target by incrementing it. If it's a lottery why is it necessary for an attacker to have more compute power then the rest of the network? Can it have a chance to get ahead of main blockchain generation if it is just lucky? I.e. nonce's it uses for own blocks generation will be always giving him desired block hash too soon? Or is it just that probability is so low that we can safely assume that this never happen?

If it's a lottery why is it necessary for an attacker to have more compute power then the rest of the network? Can it have a chance to get ahead of main blockchain generation if it is just lucky?

Yes, a miner could attempt to 'get lucky' and pull of this attack with less than 51% of the hashing power. Keep in mind, if the attack fails, then the miner will have lost money attempting it. 51% is the point at which the miner should succeed on average.

Note: mining is not a lottery by definition, it is only comparable to one in certain ways.


If I send Bitcoin from the USA to a friend in India, do I have to pay capital gain tax on it if he sells it and makes a profit? Let's say I buy $10,000 worth of Bitcoin in the USA, which I transfer to my friend in India. He sells it for $11,000 and keeps that money himself as I have gifted him that Bitcoin. My questions:

Should I pay the tax in the USA because he got profits from the Bitcoin which I sent?
How does the IRS know that particular Bitcoin has been sold?
Even if they know it was sold, how can they tax me as I am not the person who sold it?

If this is a true gift, that is, not part of any larger transaction and given out of the kindness of your heart, then you're probably going to have to consult a tax professional because this will depend on the precise tax treaties between the United States and India.

Generally, when you give a gift to another person in the United States, you do not have to recognize the appreciation in value of that gift as a capital gain and the recipient gets the same basis you had, so they will have to pay capital gains tax when/if they sell it.

But generally, when you give a gift to someone who is not a US citizen, you do have to recognize the appreciation of the value of the gift as a taxable capital gain before you can gift it. However, this can be modified by tax treaties.

If this is not a true gift and is part of some other kind of transaction, then you absolutely must recognize the change in value of the bitcoin as a capital gain before you can give it to someone else, domestic or foreign.

You asked:

  Even if they know it was sold, how can they tax me as I am not the person who sold it?

The tax is not on the sale, it's on the increase in value which is a form of income. Generally, whenever you dispose of an asset, any increase in its value is a taxable gain. There are exceptions, such as a true domestic gift, those made by international treaty, and if it's transferred because of your death.


Did I lost my balance by using an old wallet.dat? I saved a copy of my wallet.dat as a backup, i used it to transfer 1 btc to another address, now it's got 1 btc less in the total. now I deleted the wallet.dat and open the wallet with the saved wallet.dat before the transaction, I can see a higher balance(it not showing 1 btc off). how could it be? do I lost my whole balance from not saving the newest wallet.dat?

Ack! You certainly could have.

When you send bitcoin, the "change" is returned to an address that you have not previously used to protect your privacy. If your wallet.dat files doesn't contain any unused addresses, a new one is generated and the corresponding private key stored back in the wallet.dat file. If this happened, and you didn't save the new file, you may not have the address the change from that transaction was returned to.

I believe that newer implementations of the bitcoin core wallet make this much less unlikely.


Is Storj still alive as a project? gmaxwell posted this a few years ago:

https://bitcointalk.org/index.php?topic=53855.msg642768#msg642768

What became of the project?

It doesn't look like he ever released any code.  I think StorJ was more a concept than anything else.  The whole autonomous self-replication thing is probably a long ways off, but it's a neat idea.


AntMiner S5 chain #2 intermittently operational Why is my AntMiner S5 chain only intermittently operational? What could cause this, how could I diagnose it, and what is the solution? Will BitmainTech replace it for me? How do I know if it's under warranty? Is there a warranty?

Why is my AntMiner S5 chain only intermittently operational?

It's due to hardware failure.

Will BitmainTech replace it for me?

Yes, I had the same issue. I had to pay to ship it back to them, and they very promptly shipped back a replacement board.

How do I know if it's under warranty?

Ask them. They're able to figure it out for you.

Is there a warranty?

Yes, I believe it's 3 months (90 days).


Where does the money I get from mining bitcoin come from? Bitcoin noob here.

Where does the money I get from mining bitcoin come from?

Does bitcoin mining means I "steal" from other people?

If yes, should I fear this probability of being robbed while I make transactions?

I am thinkin of some type of "law conservation of money".

Does this law apply also to bitcoin?

Is bitcoin mining legal?

Could you please provide two references of how mining works, one for the street man and one for the programmer man?

Thanks

The Bitcoin is generated according to the protocol for the Proof of Work you provide to the network. The reward is comprised of a block reward and transaction fees from bitcoin transactions included in the block.
No. Mined coins are new to circulation and not taken from anyone else. Transaction fees are not stolen. The sender of each transaction decides how much of a transaction fee to pay the miner. Higher fees are more likely to result in a fast confirmation time.
Do not fear of getting robbed when making transactions. Instead fear getting robbed by those you trust to hold bitcoin on your behalf. Learn how to secure your own bitcoin and keep your private key safe and secure.
Bitcoin is a public ledger recorded on a blockchain. Each address is controlled by a private key. When you send Bitcoin from one address to another the only person that can spend it is the owner of the private key of the address you are sending the bitcoin to. Miner cannot intercept your bitcoin and steal it. They only verify the transaction took place, record it on top of the blockchain for the world to see.
Legality of Bitcoin mining may vary by jurisdiction but is happening all over the world. So far there appear to be a more laws aimed at regulating exchanges than miners.

Here are a few simple and more technical references as you requested:

https://www.youtube.com/watch?v=GmOzih6I1zs

https://www.youtube.com/watch?v=l9jOJk30eQs

https://bitcoin.org/en/developer-guide#term-proof-of-work

https://en.bitcoin.it/wiki/Controlled_supply


bitcoin mssql decimal/money storage size What's the decimal storage requirement in ms sql for bitcoin?

GAAP standard quotes decimal (13, 4) for money.

Is decimal (13,8) preferred for bitcoin or something else?

You need at least DECIMAL(16,8) to store any valid Bitcoin amount (i.e. up to just over 20 Million Bitcoin, requiring 8 digits to the left of the decimal point) precisely (i.e. down to a single Satoshi, requiring 8 digits to the right of the decimal point).

Depening on your application and how you (or your collaborators) think of Bitcoin amounts, it may be preferable to process them in Satoshi, enabling you to treat them as integers (BIGINT would then be the SQL datatype). Of course, then you have traded the dangers around non-integer handling for those associated with large integer handling.


Pros & Cons of Self Hosting Bitcoin Node vs using a 3rd Party Service? We are a medium size company building a blockchain application that requires us to interact with the Bitcoin blockchain (+ several other cryptocurrencies). One option is for us to use a 3rd party service that provides us with a uniform API to interact with the blockchain (some examples are BitPay, BlockCypher, BitGo & CoinPayments). The other option is to self host the blockchain node on our servers and natively interact with the blockchain (no middleman involved).
If we go with 3rd party services there’s usually a monthly fee and/or a small percentage charged for each withdrawal (between 0.25% - 1%). So this would be one big downside of going with a 3rd party service. On the other hand, if we host the blockchain ourselves we would be required to perform ongoing maintenance, server upgrades, implement extra security protocols and so on.
A colleague warned me that for every coin we wish to support, we will be required to hire a dedicated expert developer to maintain each node at a cost of $40,000 per year per node
To be clear, we are not concerned about the initial setup of the nodes as we have expert developers who will assist us with that. Our primary concern is related to the ongoing costs to maintain, upgrade, debug and deal with ongoing security concerns of running a large number of nodes on our own server.
It is cheaper for us to hire a developer who will setup all the nodes on our server vs. paying a monthly fee and/or withdrawal fee. Our only concern is related to the long term maintenance costs associated with self hosting nodes.
Are the concerns of my colleague valid or unfounded? Are there valid reasons to believe we will regret self hosting in the long term due to ongoing maintenance costs? If so, what are some issues that we are overlooking with self hosting?
Thank you
Note:
I did see this SE answer that partially addressees this issue. However, a big part of the answer is focused on the initial setup costs of self hosting:

Using RPC calls to your local bitcoin node requires then some
developer knowledge, or a dev-team. That can add to costs in setting
up your environment

As I stated in my question, this is NOT really a concern for us. Our only concern is related to the ongoing costs of self hosting vs. using 3rd party service.

The truth is somewhere in the middle. Your colleague is correct to point out that there is an ongoing cost for maintaining your own full nodes. Beside the employee cost, there is also the cost for the actual server infrastructure, which may be higher than you think if you consider that you will need to maintain high availability,  redundancy, testing instances, and that you should sequester each foreign software from your own network and other nodes.
Overall, you can probably get away with having fewer infrastructure engineers than the count of supported cryptocurrencies, as maintaining a full node should not be a full-time effort. For example, the maintenance work between Bitcoin and bitcoin-derived altcoins such as Litecoin and BCH would have large overlaps. Cryptocurrencies with unrelated codebases and more strongly deviating APIs and data structures will be significantly more work. Frankly, the reference implementations of some "top 20" cryptocurrencies are inadequate for production use. If you deploy your nodes in the form of infrastructure as code, you have more development effort up front, but significantly less work later on.
However, the biggest cost difference is the time and effort you will need to invest to build out your own integrations with each different full node. The wallets packaged with full nodes usually do not scale to the needs of an enterprise, so you will likely need to invest in custom blockchain indexing, wallet software, address management, key management, transaction building, balance tracking, user management, etc. This is where the mentioned services can provide a lot of the heavy lifting. If you do end up developing your own integrations, I would definitely recommend having at least one engineer per supported cryptocurrency that is passionate about it specifically.
Even if you decide going with one of the mentioned service providers, I would heartily recommend that you run your own full nodes to reconcile the information the service provides with the corresponding blockchain data. This will still save you from doing your own wallet management, address management, transaction building, multisignature setup, simplify scaling, and let you focus on getting your business off the ground more quickly. You may even consider using a service provider intermittently, and then transition to self-hosting as you finish work on your own integrations.
Just to be clear: you fully entrust the future existence of your company to such a service provider. I hope that makes you at least a little bit uncomfortable and that you thoroughly take their approach to security and your counterparty-risk to them into account for your decision.
In the past few years, I have observed a few companies being extremely successful and rapidly leveling up their UX by focusing just on Bitcoin and sidestepping altcoins altogether. You may even consider a hybrid approach where you build your own Bitcoin solution and use a separate service for whatever alts you must support to limit your exposure.
Disclosure: In my previous job I was the UTXO Coin lead at BitGo.


Generate addresses from Trezor's xPub using Python I am trying to generate BIP32 HD addresses from my Trezors xPub key.
I keep getting errors with most of the libs our there. What am I missing?

pywallet:

from pywallet import wallet
xpub = 'ypub6Y9NsCaunfAtedv6VX7UTfuvQGLu1TgMtLtjnRydESqWwUSkJnAzATyCzscezpcfoXtgJhAfUTauEQWWt8xvbLxo7qXToCDkJi1Nb1b7wZB'
wallet.create_address(network="BTC", xpub=pub, child=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pywallet/wallet.py", line 48, in create_address
    wallet_obj = Wallet.deserialize(xpub, network=network.upper())
  File "/usr/local/lib/python3.5/dist-packages/pywallet/utils/bip32.py", line 557, in deserialize
    version)
pywallet.utils.keys.IncompatibleNetworkException: Incorrect network. Bitcoin Main Net expects a byte prefix of 76067358, but you supplied b'\x04\x9d|\xb2'

The pybitcointools do generate an address, but they do not match the one Trezor generates.

Essentially I need code which replicated Trezor address generation from xPub. Any ideas?

xpub = 'ypub6...
(network="BTC",...

You are providing a testnet extended public key with the network parameter set as mainnet. I would suggest you either use a mainnet xpub key, or change the network parameter to testnet.


How to send zero fee bitcoin transaction Please does anyone know how I can send zero fee bitchin transactions? I know if might not confirm, I just wanna know if there are any wallets or sites or softwares that I can use to accomplish this.

Bitcoin Core and a number of libraries that facilitate building transactions will allow you to create a zero fee transaction. The problem is that most nodes on the network will not relay transactions with a fee rate below the minRelayTxFee (1 satoshi/virtualbyte). Additionally, most miners don't include transactions below the minRelayTxFee in their blocks.


Just installed armory + bitcoinQT synced. It takes a total of 40GB of space? i just synced bitcoinqt which takes about 20GB and then I installed armory which takes another 20GB. Now thats 40GB in space. Seems like it downloaded the blockchain twice? or is it suppose to take this much space due to armory's setup?

From the Armory web site, regarding Bitcoin-QT and/or Bitcoind:

  Regardless of which one you use, it will download the entire blockchain (12-20 GB at the time of this writing).  The latest version of Armory will effectively double that storage requirement ...


jsonrpc-lean VS. cURL? I wanna try and develop a small miner where anyone could see the backbone of it, so that everyone would know how everything works. Now I wanna ask whether what to use should I use for communicating with the pool, jsonrpc-lean or libcurl, I am not only trying to build just for bitcoin maybe some other altcoin like monero too.

but One big question. Is mining in bitcoin and monero the same? except for the fact that of course you should claculate (decrypt) them differently, what I mean was the way they work with the pool. (request infos from the pool, calculate it and submit it)

It depends on the mining pool and the software they are using. There is no one specific way for mining pools for a specific coins to relay information to their miners. For Bitcoin, most use stratum or getblocktemplate. For stratum, I don't think either of the libraries will work as stratum is not served over HTTP.


Bitcoin blockchain size practicality I am exploring this Bitcoin thing and yesterday installed the Bitcoin-Qt.
The first thing that I noted, is that the after syncing with the network that took me 12 hours, the database grew to 13GB. I know that these are all the blocks in a chain from the beginning of time.
My question is what is the sense and the theoretical practicality behind this approach? Imagine if all the world will start to use bitcoins, the blockchain will grow to terabytes and   will multiply exponentially on a daily basis.
Imagine if USA will embrace Bitcoin as its official currency, the size of blockchain will grow few Petabytes daily.
The bottom line is that at these sizes it will become impossible to validate transactions and even simply store or use the blockchain.

My question is if I am missing something here, because I don't see any long term and general usage capabilities here?

Work is being done on cleaning up the database by getting rid of obsolete data, although full nodes would probably always want to keep everything.

Also note that non-full nodes, like a wallet app on your phone, don't need the full 19GB at all and are really quick already.

Also keep in mind that disk size and network speed keep growing as well, so we still have quite some time to go before this would really become a problem.


Set a standard transaction fee in bitcoind Hello I was wondering if it is possible to set a standard transaction fee in bitcoind like 0.0001 BTC.
Because now it uses around 0.000026 BTC per transaction and it takes ages to confirm.

Thanks in advance!

Already got it I needed to use -mintxfee


arbitrage between currencies looking at the current prices of bitcoins in different currencies it seems as one could buy some in GBP and convert sell them to get USD, than convert those USD back into GBP and make some money. is it that easy? what am i missing? thanks!

Make sure you are factoring in taxes and fees charges by the exchanges. Although, if you were to sell on localcoins it would be less expensive to transact in multiple currencies and you save on exchange/broker fees.
But it is basically that easy afaik. Just like any other currency trading (including forex) some currencies are worth more than others at a particular point in time.
You should also ask yourself if your method of transaction is fast enough to do this kind of trade and make the profit you expected

That being said, in the last few weeks people Have been buying XBT with USD and selling XBT for CNY at a premium and then converting that CNY to USD and making a nice chunk of change.
The reason for this is that Chinese citizens have limited access to USD and because most XBT exchanges transact in USD the Chinese can not buy XBT easily. Therefor the chinese pay a premium for their XBT.

What about trying your hand at alt-coin trading on a minimal investment... Say $10 USD. You can learn a lot about these systems of exchange, including where to get XBT cheaper.

XBT = BitCoin


What is the coinbase? I searched the bitcoin wiki and found references to coinbase, but no clear cut explanation of what exactly it is.  I know that miners can tag their coinbases (that is how some sites tell who mined a block).

The term "coinbase" is used to mean many different things. But the two you're probably asking about are:

The "coinbase transaction" is the transaction inside a block that pays the miner his block reward.
Inside the coinbase transaction is a field that is called the "coinbase". It's the generation transaction's equivalent of a scriptsig. Since it doesn't claim any existing outputs, it needs no normal scriptsig. It's basically just a random value that the miner can use as an additional nonce. BIP 34 changes this a bit.


Does difficulty adjustment apply when you mine in secret? Imagine you have an enormous amount of hashpower (say a nation state level attack) and you mine in secret. Does the difficulty adjustment apply specifically to your secret chain?  Because that would mean that you need to add hashpower at a faster rate than the public chain is adding it for your attack to effective?

Yes. The difficulty adjustment is part of the consensus rules. In order to create a valid chain that you intend to use to replace the current main chain, you must follow all of the consensus rules. That means adjusting the difficulty in the same way any verifier would be when they validate your chain.


About blockchain.info API HELP I use the blockchain.info API to generate unique addresses each time to receive bitcoins.

This works. However, when an address was generated but a payment only gets confirmed a few days later, even if you login to blockchain.info, it will not appear in the transaction list.

The gap is not regenerated. What can I do?

Well, seems like a "gap" limitation problem !

As defined in BIP 44, wallet software will not scan past 20 unused addresses.

There is 2 solutions:

1 - do not show bitcoin address directly to user, generate 20 addresses, save them in into an database and once a user want to pay you using bitcoin, you fetch the address from your database.

2 - (solution provided by blockchain) You need to switch to a new xPub key after each 20 generated addresses (within the same wallet).


How many coins are active in Bcash chain How many coins have moved in Bcash chain since the fork?
Does any web publish a graph tracking this value?

It would be interesting to see how does it compare with an updated version of the chart below (source) to check how many old coins were moved to claim BCH apart from the ones split by the exchanges.

4,636,031 BTC moved on the Bcash side of the fork as of Sept 28th.

4,852,648 BTC moved on the Bitcoin side of the fork as of Sept 28th.

Source: some scripts I run regularly. I intend to create a website with it at some point.


Bitcoin Core is moving to an edge router role I read somewhere (https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2014-May/005816.html) that Bitcoin Core is moving to an edge router role. Can anyone tell me why that is?
Edge routers in Bitcoin are services like exchanges, online wallets, etc if I'm correct, right?

No. Edge routers are devices (Bitcoin nodes), not services.

Edge router is a term used in networking context: routers that are on the edge (boundary/border) of a larger network. For example a company network that connects to the internet. It often also serves as a firewall to protect that internal network from outside access.

In a similar fashion a Bitcoin core node can function as a firewall of sorts. Outside nodes can only directly communicate to that edge node but not to any other Bitcoin related software inside of the network behind it. Such an edge node would typically not contain a wallet itself, so there is no money directly at stake in case of an attack.

Other nodes on the internal network might contain for example a wallet or they may be running custom software that might contain vulnerabilities or consensus critical bugs that could be exploited if directly accessible to outside attackers.


How many UTXOs have a marginal fee cost that's higher than its worth? I define marginal fee cost as the number of bytes required to add that UTXO as an input to a TX multiplied by the satoshi/byte rate of the blocks being found.

So for a normal p2pkh UTXO, this would currently be roughly 180 bytes (number of bytes this UTXO would take up in a TX as an input) * 200 satoshi/byte, or 36000 satoshi. So the answer would be however many UTXOs exist that are 36000 satoshi or below for p2pkh. Essentially, I want to know how many UTXOs are currently in the UTXO set that would not be worth redeeming should the fees be above a certain satoshi/byte.

I would like this data at 100 satoshi/byte, 200 satoshi/byte, 300 satoshi/byte, 500 satoshi/byte and 1000 satoshi/byte.

Here are the results at block 472236

Processed 41823253 P2PKH txouts

Fee is 0 satoshi/byte: 41823253 txouts are spendable having total value 12504138.52 BTC
Fee is 50 satoshi/byte: 28693175 txouts are spendable having total value 12503686.97 BTC
Fee is 100 satoshi/byte: 21753912 txouts are spendable having total value 12502819.35 BTC
Fee is 200 satoshi/byte: 16426255 txouts are spendable having total value 12501503.34 BTC
Fee is 300 satoshi/byte: 14808011 txouts are spendable having total value 12500784.29 BTC
Fee is 500 satoshi/byte: 13208366 txouts are spendable having total value 12499668.03 BTC
Fee is 1000 satoshi/byte: 10998782 txouts are spendable having total value 12496954.83 BTC

This output was generated using a fork of bitcointools. This script reads utxo from .bitcoin/chainstate directory of a bitcoin node. Feel free to fork/use the script to generate related data later.


Why pose limit on update ratio of network difficulty The Developer Guide on Bitcoin.org says:

If it took fewer than two weeks to generate the 2,016 blocks, the expected difficulty value is increased proportionally (by as much as 300%) so that the next 2,016 blocks should take exactly two weeks to generate if hashes are checked at the same rate.
If it took more than two weeks to generate the blocks, the expected difficulty value is decreased proportionally (by as much as 75%) for the same reason.

Why there is such limit on increase or decrease ratio? Updating difficulty every 2 weeks is not enough to cover abrupt changes?

Imagine we have a system with no restrictions on the period or rate of decrease. Every block the period is updated looking back 6 blocks and adjusting the difficulty to suit, this is a modification people have made to Bitcoin forks in the past in the belief that there is no harm in doing so.

In this system, to attack a single user all we need to do is partition their node (the exact method is irrelevant, but it is possible) from the rest of the network so they can no longer see new blocks being mined. With the right timing, we might only need to solve a single block on our newly created side of the network and the user/s there will adjust their difficulty dramatically lower to compensate. With no limits, the user will happily accept order of magnitude hashrate decreases without any concern.

We now have to spend next to no effort making very low difficulty blocks on this fork. This allows us to do things like coercing the users into accepting payments with false low-difficulty confirmations, once they re-join the network they will find the confirmations will disappear and they will have been irreparably defrauded. This process would take a very short time and there's no way a user would notice the attack in time to not be stolen from.


Zcash z-addr in bitcoin Can a improvement, difficult or easy, to Bitcoin Core implement z-addr like Zcash?
Zcash do it possible to send coin anonymous using z-addr. The blockchain do not show z-addr, only t-addr that is like a bitcoin address.

The developers of Zcash did try to implement their solution using the Bitcoin blockchain but it required several changes to Bitcoin core that where both difficult and more importantly difficult to come to consensus for the changes with the rest of the Bitcoin community. So the Zcash developers decided to make a new blockchain.

So technically speaking it would be possible (but hard) but convinving the Bitcoin community of the changes would be much harder.

Note that there are other anonymity proposals that will use the Bitcoin blockchain (e.g. Confidential Transactions, MimbleWimble) but I do not know the state of their implementation.


What is the status of smart contracts in bitcoin? Are contracts described here already available for use? This source claims that "Ethereum style contracts" will be available in June. Is this correct? How are Ethereum style contracts different from contracts described in the first source?

Are contracts described here already available for use?

Yes.

Some of them are admittedly kind of arbitrary. For example, you can trustlessly sell someone a solution to a Sudoku. What does that mean? If you don't really have a solution, there is no chance that you will receive the money. If the other person doesn't give you the money, it's very unlikely that they will get the solution to the Sudoku. It's very interesting, but I can't think of a practical use for it.

  How are Ethereum style contracts different from contracts described in the first source?

Well, first, Ethereum script is a superset of Bitcoin script, so anything you can implement in Bitcoin script can also be implemented in Ethereum script.

Let's think of an example problem: suppose that you want to multiply six by seven, and send Bob some money if the result is bigger than 40.

There are two different approaches here:

The oracle approach would be that the oracle has access to a wallet with Bitcoins in it. The oracle multiplies six by seven, sees that the result is bigger than 40, and sends Bob some money. Nobody else on the network needs to know what was computed. They only check that the oracle's signature is correct.

The Ethereum approach would be to make a smart contract that has some money in it. Then, everyone on the Ethereum network multiplies six by seven, and everyone sees that it's bigger than 40. The smart contract sends Bob some money.

The weakness of the oracle approach is that the oracle could lie or cheat. The oracle could change the six to a five, and not send Bob any money. Or, the oracle could send the money to Eve instead.

The weakness of the Ethereum approach is that everyone on the network checks that six times seven is bigger than 40.


Lightning network: funds into channels Is there a minimum limit of bitcoin that can be added into a channel during the initialization?

And, if I decided to open a channel with a lightning node, also that node has to add money to the channel?

Is there a minimum limit of bitcoin that can be added into a channel
  during the initialization?

According to the Lightning Network Specifications:

"The amounts for each output MUST be rounded down to whole satoshis. If this amount, minus the fees for the HTLC transaction, is less than the dust_limit_satoshis set by the owner of the commitment transaction, the output MUST NOT be produced (thus the funds add to fees)."

So, the commitment must be greater than the sum of the transaction fee (determined by miners at the time of broadcast) and the dust_limit_satoshis value. The dust limit purpose is "to prevent creation of uneconomic outputs (which would otherwise remain forever, unspent on the blockchain." - BOLT #5

  And, if I decided to open a channel with a lightning node, also that
  node has to add money to the channel?

From what I understand, this is not typical, but it depends on your agreement with that other node. "Initially they each hold a bitcoin transaction that sends all the bitcoin (e.g. 0.1 bitcoin) back to one party." Lightning RFC - Introductions. So, if the fundee needed to make a payment to the funder, it could provide a payment up front.


Who would accept confirmations of invalid transactions in a 51% attack? My understanding is that honest nodes work on the longest valid block chain.

Suppose a dishonest node confirms an invalid transaction.  If that node manages to continue producing confirmations at a rate slightly higher than the rest of the network, as in a 51% attack, they may succeed in maintaining the longest block chain.  However, as that block chain is invalid, why does this matter?

That is, if all honest miners are only accepting only valid confirmations, how it is bothersome if a rouge miner is industriously hashing away at an invalid chain?

You are guessing that even with 51% of the network hashrate, an attacker can still not benefit from invalid transactions. However, the usual idea of a 51% attack is not to create invalid transactions, but to remove valid transactions, as if they had never happened.

For example, if Sam makes a valid transaction in payment to company XYZ, and then receives the item or service they paid for, having 51% of the network hashrate may allow them to go back to the block before they made the payment and create blocks that are similar to the existing blocks but do not include that payment. If they continue producing valid blocks until their chain is the longest, then the rest of the network will use this chain and continue adding blocks to it. This would mean that everyone else in the world would see the blockchain without problems with the correct balances, apart from company XYZ who provided the item or service. That company would now find themselves without the payment, as it would now appear never to have been paid in the first place.

EDIT: As explained in dchapes' comment below, the original transaction may still be held by other nodes, who would simply add it to a later block once the attack is over (so company XYZ would see the payment disappear, but then reappear later). In order to prevent this happening, Sam would have to include a new transaction which spends (at least some of) the money elsewhere. Provided the input address then has less than the required amount to validate the old transaction, the old transaction will be rejected by the network and company XYZ will never receive the payment.


How bitcoin protocol checks transaction is valid (in particular that inputs are unspent)? I'm learning bitcoin protocol theory.

To pay to someone you use a transaction. In the transaction you specify some of old transactions that gave you money (so called inputs). These inputs should have not been already spent.

Therefore the bitcoin network must check these inputs are unspent. Bitcoin network holds the list of all unspent transactions. Transactions are in tree-like structures, and all unspent transactions are the roots of these trees. So bitcoin network checks that input transaction is in this list.

After current transaction is done, all used input transactions (inputs) are now spent, and output transaction and change are now put in the list of unspent transactions.

Is the above process and terminology correct?

EDIT: I found confusing now the thing that transaction can have multiple outputs. This means I cannot just state that transaction is my input, and that the it gets invalidated when used for new transaction, as this transaction has an output that is someone else input. How is this handled?

Yes, you've basically got it.

Regarding multiple outputs, the solution is quite simple.  Your input, instead of just specifying a transaction to spend, instead specifies a particular output of a transaction.  So instead of your input saying "I am spending transaction abc123", it says "I am spending output #2 of transaction abc123".

Every full node on the Bitcoin network maintains a database of unspent transaction outputs or UTXOs.  It is indexed by transaction ID and output number.  So when a node sees your transaction, it will mark transaction abc123 output #2 as spent.  Outputs #0 and #1 of that same transaction have their own independent entries in the database and so their states are unchanged; if they have not been spent previously, they can be spent by some later transaction.


Get uncompressed public key from compressed form A similar question has an answer in Python which links to the bitcointalk forum:

How can I get the uncompressed public key from the compressed public key in openssl?
https://bitcointalk.org/index.php?topic=644919.msg7205689#msg7205689

But I'd like to know how a Java program can be written for the same conversion? I noticed that Java uses the byte data type and I'm unable to understand how to operate on values.

Yes, you can convert a 33-byte compressed public key into a 65-byte uncompressed public key in Java.

Here is the code to perform the operation. It is correct, robust, and only requires Java SE classes (no other libraries) - but I apologize for the implementation length.

import java.math.BigInteger;
import java.util.Arrays;

static final BigInteger MODULUS =
    new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16);
static final BigInteger CURVE_A = new BigInteger("0");
static final BigInteger CURVE_B = new BigInteger("7");

// Given a 33-byte compressed public key, this returns a 65-byte uncompressed key.
byte[] decompressPubkey(byte[] compKey) {
    // Check array length and type indicator byte
    if (compKey.length != 33 || compKey[0] != 2 && compKey[0] != 3)
        throw new IllegalArgumentException();

    final byte[] xCoordBytes = Arrays.copyOfRange(compKey, 1, compKey.length);
    final BigInteger xCoord = new BigInteger(1, xCoordBytes);  // Range [0, 2^256)

    BigInteger temp = xCoord.pow(2).add(CURVE_A);
    temp = sqrtMod(temp.add(CURVE_B));
    boolean tempIsOdd = temp.testBit(0);
    boolean yShouldBeOdd = compKey[0] == 3;
    if (tempIsOdd != yShouldBeOdd)
        temp = temp.negate().mod(MODULUS);
    final BigInteger yCoord = temp;

    // Copy the x coordinate into the new
    // uncompressed key, and change the type byte
    byte[] result = Arrays.copyOf(compKey, 65);
    result[0] = 4;

    // Carefully copy the y coordinate into uncompressed key
    final byte[] yCoordBytes = yCoord.toByteArray();
    for (int i = 0; i < 32 && i < yCoordBytes.length; i++)
        result[result.length - 1 - i] = yCoordBytes[yCoordBytes.length - 1 - i];

    return result;
}

// Given x, this returns a value y such that y^2 % MODULUS == x.
BigInteger sqrtMod(BigInteger value) {
    assert (MODULUS.intValue() & 3) == 3;
    BigInteger pow = MODULUS.add(BigInteger.ONE).shiftRight(2);
    BigInteger result = value.modPow(pow, MODULUS);
    assert result.pow(2).mod(MODULUS).equals(value);
    return result;
}

My Bitcoin cryptography library does implement the modulo-prime field arithmetic, but it should add the functionality to decompress public keys as well...