Is there a way to transfer money from Dwolla to MtGox without paying BitInstant a 3.99% transaction fee? I want to transfer some money from Dwolla to MtGox however I've noticed that MtGox's Dwolla account isn't working. I've tried transferring using BitInstant to my MtGox account directly and that works fine, however BitInstant takes 3.99% of the amount I'm transferring as a fee which is pretty big when you start moving larger amounts. I'm wondering is there a way to transfer money to buy up some Bitcoins without losing so much to transaction fees?

Im not aware of a method other then BitInstant with the 3.99% fee.  This can be confirmed at...

https://bitcointalk.org/index.php?topic=160604.0

However, there are other ways to buy bitcoins besides USD deposits to Mt.Gox which may have lower fees.


What was the timeline of the Bitcoin Unlimited Hack as of 2017-March and where was it in the code? I've been trying to follow the Bitcoin Unlimited hack timeline (2017-Mar) and there seems to be conflicting stories on both sides. It's obviously to confuse the 3rd party into finding the truth. My main questions are:

When was the exploit discovered and by whom?
When was the fix issued after the discovery of the exploit?
When did the hack occur to knock out over 700+ Bitcoin Unlimited nodes?
There were reports of these 700+ nodes going offline and then within a few hours, it all came back online. If this is the case, how does one conclude that these 700+ nodes are controlled by a few people?
Who are the main characters on both sides in this hack to affect news stories and perception?
Where was the hack in the code exactly?

The commit implementing the fix was issued Mar 14, 2017, 3:16 PM GMT. A Github release was made at 7:39 PM GMT. It was announced on Reddit at 7:59 PM GMT. The vulnerability was discovered sometime before the git commit, but it's unclear how long before.

According to nodecounter, things were fine at about 6 PM GMT, when there were 776 nodes. That rapidly dropped, with 696 nodes at 7 PM GMT. It bottomed out at 11 PM, with 182 nodes. At 9 AM GMT the following day, things were mostly back to normal, with 626 nodes. I don't think it's very accurate to say that BU reacted abnormally quickly, or that 100% of nodes came back.

  Where was the hack in the code exactly?

There were two unrelated issues. Both issues were in how Bitcoin Unlimited responds to network packets asking for thinblocks.

Reachable assert.

BU had this code:

void SendXThinBlock(CBlock &block, CNode* pfrom, const CInv &inv)
{
    if (inv.type == MSG_XTHINBLOCK)
    {
        // code
    }
    else if (inv.type == MSG_THINBLOCK)
    {
        // code code code
    }
    else
    {
        assert(0);
    }
    // more code
}

(I've removed irrelevant parts to make it issue easier to see.)

This means,

If the request is a thinblock, reply in this way,
if the request is an xthinblock, reply in that way,
if it's neither, crash.

Why does it do that? I assume that the person who wrote this code assumed that this function would only be called for one of those two types of requests. This function is called in two places. In the first place where this function is called, that assumption is correct. In the second place, it is wrong. This bug was introduced May 2016 in this commit.

The fix is to DoS ban the node that sent the request, rather than crashing.
Unchecked return value

BU had this code:

BlockMap::iterator mi = mapBlockIndex.find(inv.hash);
// code code
if (!ReadBlockFromDisk(block, (*mi).second, consensusParams))
    assert(!"cannot load block from disk");

The problem here is that if inv.hash does not exist in mapBlockIndex, the first line will return mapBlockIndex.end(). The next line will then pass a null pointer to ReadBlockFromDisk. Then, the node will crash. This bug was introduced Jan 2016 in this commit.


How to manually rebalance Lightning Network channels? I'm running an LND node that has a few dozen channels open to various relevant vendors/routing nodes. There are a couple specific channels that are open with stores that are getting used with most of the balance being on the remote side. I'm unsure how to manually rebalance these specific channels without closing them.

Is it possible to manually rebalance the channels from within my own LND node using the command line or some other way?

Lnd itself does as far as I remember not provide an api for rebalancing channels.

However there is the lndmanage repository that uses the lnd api to provide a pretty strong rebalancing tool

https://github.com/bitromortac/lndmanage

Such rebalancing will cost you routing fees as they are regular (circular) payments.

That being said it is not clear why you would want to rebalance your channels before an onion on them actually fails. There is currently the discussion about JIT routing (which rebalance just in time if a channel such should be used can't be used) and fee free rebalancing taking place on the lightning-dev Mailinglist.


How to set Bitcoin-Qt setgenerate mining recipient? I know it's inefficient and a bad idea and all that, but I just discovered the setgenerate console command in Bitcoin-Qt (v0.8.1-beta, MAC) and I was wondering how to set the recipient address of "all those" Bitcoins I'm about to generate?

By default, Bitcoin-QT will generate new addresses to mine to.  If you use the Encrypt Wallet feature, it appears to always mine to the same address instead, but it's still not user-selectable.

If you do want to CPU mine to a specific address (e.g. for testing on the RegTest mode), you can use mining software like cpuminer/minerd in "solo mining" mode to do so.


Push deposit notification through HTTP requests Is there any alternative to bitcoinnotify? That send a POST request to a URL on an deposit event to a chosen address.

I know there is blockchain.info that send email. And instawallet that where you keep a open socket connection. But I am looking specifically for one that sends a HTTP request.

Bitping.net is the new service that replaces BitcoinNotify and can provide the service you are requesting.


How do we know that the suprnova worker is producing value? I followed this tutorial to attempt to mine bitcoin cash on https://bcc.suprnova.cc/.  It seems to be working.  My terminal prints out stuff like this:

[2017-11-11 14:47:51] Stratum requested work restart
[2017-11-11 14:47:51] thread 1: 85454192 hashes, 3397 khash/s
[2017-11-11 14:47:51] thread 4: 92140688 hashes, 3351 khash/s
[2017-11-11 14:47:51] thread 6: 80503816 hashes, 3464 khash/s
[2017-11-11 14:47:51] thread 3: 84560368 hashes, 3376 khash/s

But if I look at the Dashboard and scroll down to Worker Information it says No Active Workers.  So how do we know that https://bcc.suprnova.cc/ is actually giving us credit for running the worker?

There's also an earnings link in the side panel and after running the miner for a day, the earning table is showing all 0s.  So it appears that after one day of running the miner nothing has been accomplished.

You are mining so slowly that the mining pool thinks you are not mining.

You can't mine sha-256 coins with CPU. You are several hardware generations too late.

CPUs had to give up bitcoin mining in 2011 when GPUs took over completely. Then came FPGAs which made life hard on GPU miners. Finally in 2013 the ASICs arrived which made GPU and FPGA mining completely pointless. Now in 2017 this is old news and sha-256 mining has been ASIC-only for years.

Just like with BTC, BCH (BCC) is also mined with ASICs.

Why do people give up on old and inefficient ways of mining:

It would take several hundred years before you have earned the minimum amount to cash out from the pool. Not only is this tiny amount not worth 5 minutes of your time - you are not going to live long enough to cash it out.
If you lived for 1000 years and mined the whole time, earning 1 US dollar worth of BTC or BCH/BCC, you would have paid a million dollars in electricity to get there. How would it make sense to do so?

Back in 2009 some people would mine 50 bitcoins per day with the CPU of an old laptop. Unfortunately it is not 2009 anymore. Today you earn zero with CPU.


Can you mine your own transactions yourself? If no, why not? And is it you physically/theoretically or practically cannot?

If yes, is this ever practical and does anyone do it?
As I see it now, no matter what you are taking a fraction/subset of bitcoins entire hashing power so the difficulty of finding a nonce would take longer than 10 minutes to confirm.

As I see it, for this to be practical...
Block reward + saved fees > mining costs * time

Where saved fees are the result of not having to pay other miners fees since you are doing it yourself and time is the time it takes to find the nonce.
note: this miner wouldnt have to be running full time

Theoretically, if you can mine blocks then you can certainly include your own transactions in the block.

Practically, you are competing with every other miner on the planet to find the next block. If you "win", you get the block reward plus you get to choose which transactions are included in your block. If somebody else wins, you get no say in the matter. Unless you have a very large mining operation, the chance of you winning is so small that it's never going to happen.

Miners who do make new blocks today (somebody has to, after all) may choose to include their own transactions in their blocks.


What economics/finance methods and tools can be used to analyze and predict the Bitcoin market? Bitcoin differs from standard markets in many ways. Some standard market analysis tools are inapplicable due to unique features of Bitcoin. Hence the question

What methods/tools can used to analyze and predict the Bitcoin market?

It is better if the tools have a proven trackrecord of actually working for predicting the Bitcoin market, but it is unlikely that such examples exist. Therefore, I am perfectly happy with references to the literature on econ/finance tools that should work for the bitcoin market but maybe haven't been applied yet.
Related questions
Is there a correlation between Technical Analysis predictions and actual prices?
Can bitcoin transaction data be used to study markets?

Technical analysis is important, but right now I think that one should not rely exclusively on chart analysis and indicators to predict Bitcoin's price movement. For example, at the end of July and mid-August some indicators, such as MACD or RSI, clearly showed a trend inversion that did not happen.

One of Bitcoin's unique features is the mining system and I think that, right now, this plays an important role in price analysis. After Bitcoin hit $30 in July, many people invested in mining rigs and difficulty rose a lot. Those people are looking forward to get their investment back and, since Bitcoin is extremely infalctionary right now (50 new coins every 10 minutes), there is a big selling force at the markets.
If miners sell 30 coins out of each block, we need around 1 million dollars per month to keep the price at $5.

I also believe that the $30 spike was caused by media exposure. Such a small market can be easily manipulated by a few serious investors.

Main points:

Use Technical Analysis carefully.
Consider the number of coins per block and the money invested by miners
Keep an eye for important news that may attract new investors to the market

To finish, here is one stock behaviour that I could identify: the dead cat bounce.

  A dead cat bounce is a trading term used to define when a stock in a
  severe decline has a sharp bounce off the lows.


Does the bitcoin block contain minimal transaction detail? (Is it as private as possible given the proof-of-work design?) From https://crypto.stackexchange.com/questions/508/could-one-prevent-double-spending-in-decentralized-digital-currencies-like-bitc

"Now, the only information about the transaction that needs to be public is enough information to prove I have the coins and prove that I didn't transfer them elsewhere. As it happens, the Bitcoin protocol leaks much more information than this (for example, the account I transferred the coins to). The protocol could have been designed to make less information public if that was desired."

Is this true, could the block-chain report less data but still gain the proof-of-work mechanism's benefits?  If so, what aspects of the blockchain are non-essential and what is the reason for including them?

In order to send someone some coins, you need to know their public address.
In order for them to redeem their coins, they have to show everyone that they possess the private address associated with that public address.

You could try encrypting your public key by some means and later decrypt it when you want to spend the coins, but you'd probably have to provide something that could identify you similarly to using a public key.

You could alternatively encode only transaction hashes in the block, rather than actual transactions and only send the actual transaction to the peer you are sending the coins to. This approach though creates a lot of new problems with validation and so forth.

All in all, Bitcoin protocol doesn't have much excess data. In fact, by today's standards one may say it is trying to be too slick at times (say by using something like VarInt).


What is a "half" in Bitcoin? I saw in an article something about a Bitcoin algorithm half in 2020. What exactly is this? I have tried looking this up but I couldn't find anything that told me what it was only a website counting down to the next.

Bitcoin controls the supply of coins by halving the miner subsidy (reward) every 210,000 blocks or roughly every 4 years. The miner subsidy started at 50BTC. See Mining Reward.

This is a simple chart that illustrates the Bitcoin distribution schedule:


Verify paper wallets I generated a paper wallets with offlineaddress.com. Is there a way to check if the private key corresponds to the public key without compromising the wallet by loading it onto an online computer?

First off, only trust highly-reputable software to generate private keys, especially if they're web-based. It seems like this software has only 16 stars on GitHub and only 2 contributors: https://github.com/mikewoods/OfflineAddress.com

To answer your question, the only way to verify that a private key corresponds to the public key is to actually run the algorithm on a computer. My best advice here is to use a computer that is offline and that boots a highly-reputable open source operating system.


Unable to access Wallet in Multibit HD - currupt password After my computer died and was rebuilt I'm trying to restore access to my bitcoin wallet.

I have my wallet words with I've confirmed are correct as I've used them in the past.

I try to restore my wallet by entering my wallet words, which are accepted, then select my backup which is located correctly.
Then I get the restore report saying
 Backup location created
 Wallet Created
 security certificates
 wallet is synchronising. please wait until complete.

but as the wallet fails to create I don't think it can synchronise. the screen stays like this until I cancel.

I have the same issue. It seems MultibitHD is not able to restore wallet at all. I removed everything related to it from AppData (first created backup), uninstalled application, restarted PC, installed again and tried to restore wallet. Wallet words accepted, wallet backup file loaded and last screen hangs with "X wallet not created" and "Synchronizing please wait till completed". It never completes I can tell.


Fees/Taxes on Each Block Found Haven't found a clear answer to this, but I have heard that various coins charge a sort of "developer tax". I've looked through a bunch of various crypto's sourcecode, but I haven't found any hints as to how it's implemented, let alone in what portion of the code it would be in.
Could someone reveal a little sunlight onto this behavior?

Some mining programs (designed for use with mining pools) will mine on behalf of the mining software developer for a short time, before switching to the actual user account.

I've only seen this once and I don't even remember which coin it was for, so I don't know how widespread it is.


why is bitcoin leveldb separated in so many small pieces? Currently I could see 1418 ldb files on my box, from 210040.ldb to 215423.ldb (some missing).

Why are they separated in this way?
I want to read the leveldb using golang, but I don't know which one should I use.
Can I load them altogether?

At the moment I try out creating my own leveldb I understand.. The chainstate folder itself is the entry point of the database; all the files within it are just the data.

This is what the data looks like after I put some dummy data


Understanding the iquidus API settings I am trying to understand what values I am being asked for in the settings.json to install the block explorer for Iquidus. I know how to get the genesis block as I have hard coded it when I did a fork to create a new altcoin, however, I am unsure how to get the genesis_tx. I know you can convert it from the genesis block but I am unsure how?

"genesis": {
"genesis_tx": " ",
"genesis_block": " "}

In terms of the API settings, they are asking for an address, blockindex, blockhash, and txhash. The blockindex can be any value within your block height... so do I pick just any one value for the index with the corresponding address in the transaction list? Also, how do I get the txhash and the blockhash? These values to my understanding are subject to change and I know they are stored in the blockchain... does anyone know how I can retrieve this information?

"api": {
"blockindex": " ",
"blockhash": " ",
"txhash": " ",
"address": " "
},

I appreciate your time and consideration.

Figure out your blockhash with index=0
(normally in your coind debug window,s you can: do a

getblockhash 0
(0 = genesis block number)

With the return value from that, you do a
getblock xxxx

eg:

￼
getblockhash 0
 ￼
5597f25c062a3038c7fd815fe46c67dedfcb3c839fbc8e01ed4044540d08fe48

￼
getblock 5597f25c062a3038c7fd815fe46c67dedfcb3c839fbc8e01ed4044540d08fe48

{
"hash" : "5597f25c062a3038c7fd815fe46c67dedfcb3c839fbc8e01ed4044540d08fe48",
"confirmations" : 4142183,
"size" : 240,
"height" : 0,
"version" : 1,
"merkleroot" : "2bad42ac6e0ccc4808d8df0fd50ac8634eea335b1412b1ef52864b430a87b262",
"tx" : [
"2bad42ac6e0ccc4808d8df0fd50ac8634eea335b1412b1ef52864b430a87b262"
],
"time" : 1394102925,
"nonce" : 2482334,
"bits" : "1e0ffff0",
"difficulty" : 0.00024414,
"nextblockhash" : "df34593a55b7ed0ff076766805023c8262fe26c84ba8624b77abae446c402dea"
}


Is it theoretically possible to limit the hash rate? I am thinking of developing an altcoin that is truly asic/pool proof. I haven't tried yet (or even downloaded the source code), but I was wondering if it is possible for the network to behave in such a way that it will not accept a block found by a peer if the hash rate of that peer is above a certain threshold.

Would that be possible? If not, how could one achieve it?

Given the current proof-of-work paradigm, no. What do I mean by this? A coin which is mined by computing the hash* of data depending on both the previous block (so that the integrity of the blockchain is preserved) and the payload of the current block (so that the integrity of each individual block is preserved) as well as a nonce, such that the hash satisfies certain criteria (typically, being smaller than a certain value determined by the difficulty). In such a case, there is no way of telling whether a hash was found after trying trillions of times or just one lucky guess.

That said, I wouldn't rule it out entirely. But it will be very hard. In fact, I can relax some of the assumptions I just made and it would still not be possible to discriminate based on hashrate. To be able to discriminate effectively, you must have some way of preventing someone with a large hashrate from pretending like they are multiple people with small hashrates.

*Technically, any collision-resistant function mapping to a sequence of n bits will apply. I believe Primecoin's PoW is also applicable.


How miner deduct Transactions fees from transaction? How is it possible for a miners to deduct the transactions fees from the UTXO output which is locked by locking script or encumbrances?

The sum of a transaction's inputs must be greater than or equal to the sum of outputs as part of the validation rules.  This difference is the transaction fee.

So to answer your question directly, when a UTXO is spent, it is referenced as part of a transaction input.  A UTXO is always completely consumed (analogous to how if you spend a dollar bill, you have to spend the whole bill and get change), so the fees are not taken from that per se.  It is the difference of the inputs (sum of the UTXO values being spent) and the outputs of a properly formed transaction that becomes the miner's fee.


How does a constant opcode become negative in Script I am doing some tutorial and in this chapter we are suppose to reproduce the Script scripting language

I am struggling to understand one of the exercises, here it is:

Create a ScriptSig that can unlock this ScriptPubKey:
767695935687

and the answer is 0x52 so that :

>>> from script import Script
>>> script_pubkey = Script([0x76, 0x76, 0x95, 0x93, 0x56, 0x87])
>>> script_sig = Script([0x52])
>>> combined_script = script_sig + script_pubkey
>>> print(combined_script.evaluate(0))

and that OP_2 or 52 will satisfy the equation x² + x – 6 = 0.

I guess I get the whole part execution except when the OP_6 is pushed on the stack, how does it become negative ?

I was not sure how it would work there but it is in fact basic arithmetic, we have this x^2 + x = 6 then we substract 6 from both sides x^2 + x - 6 = 6 - 6 then we simplify x^2 + x - 6 = 0


How to lower difficulty on blockchain? I created a coin (hexco.in)

The problem now is, sometimes some user create pools and use rented mining rigs to mine on my coin. But after a while they stop and my blockchain stucks at a certain block.

My question now is, how can I solve this problem? I only have a homserver and a raspi2 running as mining service 24/7 for my coin and a seednode running 24/7.

How to lower difficulty on blockchain?

  The problem now is, sometimes some user create pools and use rented mining rigs to mine on my coin. But after a while they stop and my blockchain stucks at a certain block.

You could include in your expected difficulty calculation a factor of time, where say, for example, every 10 minutes since expected next block time (supposing you have a ten minute average block time) the expected difficulty is lowered by a factor, say divided by 2.

The problem with this method is that it may allow cheating unless you also carefully control network time. If it is not carefully managed then a cheat could submit a block with a future time and a lower difficulty.


Bitcoin 0.8.5 - Paper wallet since some answers seem to be outdated, I ask now explicit for version 0.8.5 of the official BitcoinQT-client.

I want to save my wallet to paper and hide them in a safe - could you tell me if following points look valid?

This topic seems really complex, I dont know why there is not an easy option like "Export wallet to pdf"...

Ok so here we go:

1) I would like to export my private keys to textfile?
(How does it work?) I only see how it works for one single private/public key-pair?

2) Print it out and hide it in safe

3) When I do a transaction or receive something, i should print out again all private keys, because otherwise something can be lost?

Thanks!

As of the 0.8.x series, the reference client does not support paper wallets. You can export individual keys, and print them to paper, but you are very likely to shoot yourself in the foot unless you're familiar with the implementation details.

In particular, change (the difference in value between coins used to create your transaction, and the amount being sent) is sent to a fresh address in order to increase privacy of the system. When you're using a paper wallet, you will likely miss these, as well as key pool entries.

There is support planned for deterministic wallets (BIP32), which means a single backup of a wallet seed will be enough to create the wallet. This may or may not end up in 0.9, though.

The reason why no "Export wallet to PDF" exists, is exactly because in the current model, this would result in many misconceptions and lost coins. Without deterministic key generation, no immutable dump of the wallet can survive (a series of) spends.


XPub to YPub Converter (python) - Last digits wrong The code below is generating an YPub from XPub with the last 6 digits wrong.
How can I verify what's happening and fix this error?
e.g.:
It should be  ypub6X7aFbqxwbJHJQqUhfTEZDWxVT8qbu4qjN8fCz9ADRuAwaZQ243YiB1w5yTE2qRJzRJ3Kza9DbefU8pnqjk3GEmn6g9usvkZZrP94VcBVdz
but it returns ypub6X7aFbqxwbJHJQqUhfTEZDWxVT8qbu4qjN8fCz9ADRuAwaZQ243YiB1w5yTE2qRJzRJ3Kza9DbefU8pnqjk3GEmn6g9usvkZZrP94YkSjSS
The code is adapted from this function in JS, that works well.
import hashlib
import base58

prefixesPub =  {
  'xpub': '0488b21e',
  'ypub': '049d7cb2',
  'Ypub': '0295b43f',
  'zpub': '04b24746',
  'Zpub': '02aa7ed3',
  'tpub': '043587cf',
  'upub': '044a5262',
  'Upub': '024289ef',
  'vpub': '045f1cf6',
  'Vpub': '02575483'
}

def convert_pub_key(_xpub, target_prefix):
  decoded_extended_publicKey = base58.b58decode(_xpub.strip())
  extended_public_key_no_prefix = decoded_extended_publicKey[4:]
  extended_public_key_new_prefix = bytes.fromhex(prefixesPub[target_prefix]) + extended_public_key_no_prefix
  print(base58.b58encode(extended_public_key_new_prefix))

pub_key = "xpub6CHJwwB3nukoT7eMsJfcM8RTKUzPfH5LpFcSRbFGqRXHtUkAmPsz67Mo4mVe2vmPanBEaWyakwJ7arDE83L2U16BELTVJ1w5J8KVfyMqtzE"
prefix = "ypub"
convert_pub_key(pub_key, prefix)

The base58.b58decode and base58.b58encode functions only do the Base 58 decode/encode. However xpubs are encoded with Base 58 Check encoding. The difference is that Base 58 Check encoding computes a checksum of the payload and appends the first 4 bytes of that to the payload before the base 58 encoding.
You need to be using base58.b58decode_check and base58.b58encode_check which will drop the checksum for the decode, and add the checksum for the encode.


Wallet loading failed: Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex I have bitcoin core installed, with a sub wallet with some bitcoin on it. The default wallet appears to be working fine, but when I try to open the sub wallet with bitcoin on it, I get the error message

Wallet loading failed: Prune: last wallet synchronisation goes beyond pruned data. You need to -reindex. (download the whole blockchain again in case of pruned node)

and I am unable to open it. The prune settings are the default 2GB block storage and 450MiB size of database cache. I have reindexed Bitcoin Core one time but that did not help the problem, and I still get the error message every time I attempt to open the sub wallet.
debug.log
What should I do? Thanks.

I was able to solve the problem for the moment by reindexing the entire bitcoin core wallet, making sure that pruning was disabled in the settings. This allowed me to access my funds again. I'm not sure what caused the issue in the first place.


Does anyone have a formula for dynamic block durations? I want to implement this, so does anyone have a formula for dynamic block durations instead of a fixed target of 10 minutes?

Block duration is only controlled by difficulty (although indirectly) and network hashrate, so you'd want to increase difficulty when there are very few transactions in the last X blocks, and vice versa, decrease difficulty when blocks become too full, but also decrease difficulty when there is a low hashrate, and increase difficulty when there is a high hashrate.

At the same time, you'd need to incentivize mining, so you might want to have a reward relative to target time, instead of constant per block, as otherwise miners could spam the network in order to increase revenue.

A draft

Let's say, we are aiming to adjust from looking at the last 100 blocks for blocks that are 50% full.

findNewBlockTime():
  newTimeTarget = (avBlockInterval100)*(0.5/averageFullness); //shorter interval with many transactions, longer with less

setReward():
  newReward = newTimeTarget*totalIntervalReward/rewardInterval; //rewardInterval could be four years like Bitcoin, or some other interval, with four years totalIntervalReward would be 11.5M coins for first interval

calculateDifficulty():
  newDifficulty = sumDiffLast100/last100BlocksTime*newTimeTarget;


Why is there "Change" in Bitcoins? I have read about a change address and wondered why there even is the concept of change?
Let's say I received 1 BTC from some person A and I want to send 0.4 BTC to another person B, afterwards. From what I have understood, I have to send the 1 BTC, as a whole and then get 0.6 BTC as change.
Is that right? And if so, why don't you just send 0.4 BTC in the beginning?

Bitcoin follows a Unspent Transaction Output (utxo) model.
Our modern banking systems follow an account model - you're assigned a bank account number (similar to an address), and send and receive money from it. Any incoming funds increase your total account balance, and any outgoing funds decrease it. The bank does not keep track of which funds came from which deposit. It's just a single balance.
Bitcoin is closer to cash - Any funds in your Bitcoin wallet are the result of a previous incoming transaction, exactly how any notes in your physical wallet are the result of previous real life transactions you've made (whether an ATM/bank withdrawal, or received as change at a store).
Bitcoin tracks the output of each individual transaction, just like real life notes. When you receive 1 BTC, you receive an output (note) of exactly 1 BTC. This must be spend in its entirety, and cannot be split. So if you'd like to send 0.4 BTC, you put in the entire 1 BTC into the transaction, and send 0.6 BTC to one of your own addresses in the outputs.
This works much the same way as buying a $5 item with a $20 note - you must put in the entire $20 note, and you will get $15 back. You can't simply tear the $20 note into four equal pieces and create 4 $5 notes.
Of course, unlike real cash, in Bitcoin there is no risk of the recipient simply taking your BTC and refusing to return the change - the change is sent back to an address owned by you as part of the transaction building process. The recipient of the rest of the funds has no control over it.
A cleaner way to think about it is using the coin (physical coins, not bitcoin) analogy mentioned by Abdussamad in the comments - You can treat each output in your wallet as a single, indivisible coin of a fixed value.
When you spend these coins, transactions act as a melting pot - you can add in multiple coins to create a pot with a value of the sum of all coins, and you can use the melted coins to mint new ones of the values you want - 1 coin for the payment you're making, and one coin for the change that you keep with you. This even accounts for transaction fees - every time you melt down some coins, the pot claims a small amount that sticks to it, resulting in a final output that is slightly lower than the input.


Should I always run "make clean" between building different PR branches of Bitcoin Core? I am switching between building different PR branches (ie I built one PR author's branch and now I am building a different PR author's branch).
Jon Atack's doc suggests:

On the other hand, when you change the build configuration, and in some cases when testing different PRs, or when the build isn't working, it's often best to start with a clean slate using make clean or make distclean before configuring.

Should I always run make clean in between builds?
edit: Jon Atack has since updated his doc. Here is the updated guidance.

On the other hand, when you change the build configuration (e.g. for a fuzz build), or you are building a branch containing substantial changes to the autoconf/automake scripts, or when the build isn't working, it's often best to start with a clean slate using make clean or make distclean.

You could always run make clean between builds but a lot of the time it won't be necessary and it is slower.
Pieter Wuille usually doesn't run make clean and only runs it when the build fails.
If it still fails after that he runs git clean -dfx. Warning: This deletes everything and resets your work directory to a fresh checkout. You'll need to autogen.sh again.
(Glen Willen suggests running git clean -dfX instead of git clean -dfx as X only removes ignored files, x also removes locally added non-ignored files, including e.g. new code you did not yet call git add on)
make clean is only necessary when the configuration changes. This could be because you run ./configure with different flags or it could be because there are substantial changes to the autoconf/automake scripts when changing branches. Of course the act of changing branches isn't relevant as the build system doesn't know or care that you are using Git. The build system just sees some code and/or configure scripts changed and re-runs them as necessary. Without make clean it will just see existing .o files not realizing that the rules used to build them have changed
Jon Atack usually doesn't run make clean but does if there is slight weirdness or if switching to fuzz build or back.
Thanks to Pieter Wuille, Jon Atack, Marco Falke and Glen Willen for answering this question on IRC.


When running a Lightning Network hub, who pays the fees when a transaction has to be broadcast to the blockchain? I've been educating myself on how the Lightning Network protocol works, and I have some questions.

Let's say that a user sends a small payment to someone and it makes multiple hops through the network before reaching the recipient. The payment then propagates backward through the chain until it reaches the payer, and everything settles out.

It's possible that a node in the middle either either intentionally or unintentionally does not pay the next node down the line. The recourse is for the node that did not get paid to broadcast the transaction to the blockchain (and close the channel?).

Who pays the fees for for that transaction? What happens if the fee is significantly larger than the amount of money the node would gain by broadcasting the transactions?

This seems like it could potentially be a large attack vector. Is there something I am misunderstanding?

It's possible that a node in the middle either either intentionally or unintentionally does not pay the next node down the line. The recourse is for the node that did not get paid to broadcast the transaction to the blockchain (and close the channel?).

No, that's not accurate. If a node in the middle of a multi-hop payment rejects a payment request, the sender simply makes another attempt along a different route omitting this node. On the other hand, if the payment contract is already established, the node is already cryptographically committed to pay. It's impossible at that point for them not to pay. A forwarding node can merely fail to collect the reimbursement for what they've already forwarded.
If a node continuously fails to forward payments, their channel partner is still free to close the channel of course, but this is for different reasons.

  Who pays the fees for for that transaction? What happens if the fee is significantly larger than the amount of money the node would gain by broadcasting the transactions?

The fee for Lightning payments is paid by the sender. They must include sufficient funds to pay fees to all nodes along the route. If the fee for closing a channel is higher than the channel's capacity, it probably makes more sense to leave it open until fees get lower.


Basic Concept of Bitcoin (public and private) Keys Can anyone please tell me the difference in the following Bitcoin terms?

Difference between xpriv and xpub
Difference between xpub and tpub.
Difference between ypub and upub.
Difference between public key and standard public key.
Is xpub and ypub are same? also tpub and upub?

This is not complete answer, but hope this will help you to understand some concepts.

xpriv and xpub are key pairs, which are possessed by every (online) wallet when it is created. xpriv is actually the private key of the wallet (which you must not share with anyone). while xpub is the public key of the wallet (which is used to derive the receiving addresses of wallet, where it can receive funds or coins).

This is brief explanation. you can read more to understand its working and purpose from given link.
How are public and private keys related to the wallet?

In order to create wallet we use Network Parameters. So, in bitcoinj, we use MainNet (ProdNet) and TestNet. So, xpub is the public key which is used to create the public addresses of Online wallet using MainNet. while tpub is the public key, which is used to create the Receiving addresses of Testing wallet (which doesn't contain real coins).

You can check more difference between mainNet and testNet in following questions.

Practical difference between mainnet and testnet
https://ethereum.stackexchange.com/questions/6278/whats-the-difference-between-the-testnet-and-the-production-network-technical

Good Day!


How does the mining pool know our hashrate/our share? Scenario:

Person A: has a good mining rig and run for 24 hours and produces: 1000 mega hashes, but found only 1 share.

Person B: has a bad mining rig and run for 24 hours and produces: 1 mega hash, but found 1 share on first attempt

Question:
So, how does mining pool know, if we have actually gone through all the 1000 mega hashes to submit one share to the mining pool (Person A has done more work than person B)?
But person B who has low hashing power already found a share but has not done any work compared to person A
How does mining pool get to know if Person A has done more work than Person B, as miner does not submit any unsuccessful hashes but the successful ones, but already more work has done.

So, how does mining pool know, if we have actually gone through all the 1000 mega hashes to submit one share to the mining pool (Person A has done more work than person B)?

The mining pool don't know and don't care how many attempts your miner made to solve a share, he care about how many shares you actually solve. (person A and person B get the same rewards if they submit the same number of shares of the same difficulty, regardless of how much work they spend to find these shares)

But person B who has low hashing power already found a share but has not done any work compared to person A

If the person B found the same amount of shares than the person A but with much less work, the person B have been luckier than the person A.
Take in account that not all share have the same difficulty and consequently the same value, typically mining pools serve easier share (which require less work) to slower miners and more difficult ones to faster miners (to better exploit the different speeds).

How does mining pool get to know if Person A has done more work than Person B, as miner does not submit any unsuccessful hashes but the successful ones, but already more work has done.

As already mentioned above, you are not paid for the work you do but for the shares you produce.
The mining pool does not know your hashrate, estimates it based on the speed with you solve the shares and their difficulty: if you are lucky and you find more shares than you should, your hashrate will be overestimated, if you are unlucky and you find less shares the hashrate reported by the pool will be lower than the actual one.


How to update balance of imported address in electrum Imported an address into electrum, but the balance of the address shows up as zero.

Checked the address on http://blockexplorer.com and it's not zero.

The address was imported from bitcoinqt when the blockchain is out of date and the transactions were never attributed to the address.

Nothing was sent from the address.

How would you refresh the transaction history for the imported address in electrum, so it becomes spendable again?

Thanks

EDIT: The problem has been solved - see workaround below

A workaround for this is to send a small amount of bitcoins to the the imported address

This was done by watching an ad at www.bitvisitor.com.

Once payment was confirmed in the blockchain, Electrum refreshed the balance and the transaction history.

The imported address balance is now spendable :)

You could try with other server, maybe the one you were using was lagging in the moment you imported the address.

To switch servers just go to the green ball at the bottom-right Network and select other server.


Why is not possible for a hacker to intercept the hashes calculated by a miner, and send it all himself as if he was a miner? (I tried to make a more specific question, but is a bit confusing to me. Sorry.)
When a miner calculate a hash, where exactly does he send to in order to validate it? To all the nodes in the network?
Which protocol does it use to send this hashes? For example, HTTPS requires a trusted third party to sign server-side digital certificates, but there is no "server-side" in a decentralized network.
Why is not possible for a hacker to intercept all the hashes been sent by a miner or pool, and send it all himself as if he was a miner?

Miners don't send hashes, they send blocks. Blocks are public information to be broadcast to the entire network. When a miner completes a block, he sends it to nodes that he is connected to. Those nodes verify the block, and if they find it to be valid, they will send the block to the nodes that they are connected to. This peer to peer gossip is how blocks and transactions reach every node in the Bitcoin network.
An attacker an intercept a block, but that won't do anything for him. He would just become another thing relaying the block to nodes on the network.
Miners aren't paid by submitting aa block to something specific. They are paid by including a special transaction in the block which pays them Bitcoin by essentially creating them from nothing. There are rules about what amount this can be, so if it doesn't fit those rules, the block is invalid. The miner essentially pays himself and the rest of the network agrees on whether he is entitled to that payment. An attacker intercepting this cannot change the miner's payment without having to completely redo the proof of work, i.e. mining the block themselves.


What is the counterpart of mining when using blockchain for traceability? Our project is to create a blockchain so that a customer can traceback any registered good (such as food or drugs). The idea is to replace money with product IDs. (ERC721 from Ethereum does not do the job because people do not want to own IDs).
Each member of the production chain adds a transaction to indicate to whom the product is given.

The advantages of this system are its immutability and robustness.

We have developed a working blockchain that is very close to Bitcoin but we are wondering how to adapt it.
Indeed, the most important thing is to know what happens to mining. We can't offer IDs when a block is checked, so how do we get people to take care of the chain?
Perhaps we should introduce a digital currency to reward them, but it is not elegant.

To summarise: how to create blocks in a such architecture?

The attacker: a company that wants to hide part of a product's history because a problem with it has been discovered.

The user: a customer who wants to know where his or her purchase is coming from. from.

The Bitcoin blockchain achieves immutability through proof of work mining. It is considered immutable because many economic actors commit their computing power to finding new blocks. If not "enough" people are mining, the blockchain is not immutable. Recently both the Bitcoin Gold and the Ethereum Classic blockchain have been manipulated through a 51 % attack so these weak (i.e. low hash rate) blockchains are not immutable.

If you do not want to worry about having enough miners, you could consider building a token on top of either the Bitcoin blockchain or on top of the Ethereum blockchain (e.g. an ERC20 token). On Bitcoin, the Omni protocol allows for you to build your own token which is transferred on the Bitcoin blockchain. This means that you have to pay transaction fees (to the Bitcoin miners) to transfer the tokens but the benefit is that you will not have to worry about a 51 % attack (other people are trying to prevent that).

If you want non-fungible assets (each with their own ID attached), the Ethereum protocol standard ERC721 is made for this purpose. I am not aware of a similar solution on top of the Bitcoin blockchain.

If you want something else, like a more general, immutable log system that you can define yourself, you may have to write your own contract in Solidity (for the Ethereum blockchain) and only allow specific addresses (one for each member of the production chain) to write to this log.


Can I have a transaction where the source and destination are the same? If challenged, I could do this on demand with an amount of the challenger's choosing, to 'prove' I have control of the funds.

Yes, it is possible to send to the same address. However, to prove control of an address, you could instead sign a message.


Inter-wallet transaction Suppose I buy 1 bitcoin on unocoin at 174,000.
Now I see that the selling price on unocoin is 160,000 and selling price on coinsecure is 170,100.
So can I sell my bitcoin on coinsecure directly?

Assuming these are exchanges with their own wallets, you would need to first transfer your coins to your wallet on that exchange, while of course paying the required fees.. Using the numbers in your example, it would seem far more prudent to sit on your funds until you can sell at a gain (you don't lose until you sell).

Regardless, yes, you can game different exchanges. The risks are (IMO)

1) you pay a fee
2) you hope that the price doesn't drop on your intended target
   during your pending transaction.


How to use getblocktemplate method with Bitcoinlib Library I am using
bitcoinlib to communicate with bitcoin-qt
This is the code i tried:
 Dim BitcoinService As Services.RpcServices.RpcService.IRpcService = New Services.Coins.Bitcoin.BitcoinService("http://localhost:8332", "Username", "Password", "wallet password", 200)

for getblocktemplate this is the call
   Dim seg As JToken = "{""rules"": [""segwit""]}"

        RichTextBox5.Text = BitcoinService.GetBlockTemplate(seg).PreviousBlockHash

It gives me this error
BitcoinLib.ExceptionHandling.Rpc.RpcInternalServerErrorException
  HResult=0x80131500
  Message=JSON value is not an object as expected
  Source=BitcoinLib
  Arborescence des appels de procédure :
   à BitcoinLib.RPC.Connector.RpcConnector.MakeRequest[T](RpcMethods rpcMethod, Object[] parameters)
   à BitcoinLib.Services.CoinService.GetBlockTemplate(Object[] parameters)
   à WindowsApp3.Form1.Button2_Click(Object sender, EventArgs e) dans C:\Users\Hama\source\repos\WindowsApp3\WindowsApp3\Form1.vb :ligne 76
   à System.Windows.Forms.Control.OnClick(EventArgs e)
   à System.Windows.Forms.Button.OnClick(EventArgs e)
   à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   à System.Windows.Forms.Control.WndProc(Message& m)
   à System.Windows.Forms.ButtonBase.WndProc(Message& m)
   à System.Windows.Forms.Button.WndProc(Message& m)
   à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   à WindowsApp3.My.MyApplication.Main(String[] Args) dans  :ligne 81

  Cette exception a été levée à l'origine dans cette pile des appels :
    System.Net.HttpWebRequest.GetResponse()
    BitcoinLib.RPC.Connector.RpcConnector.MakeRequest<T>(BitcoinLib.RPC.Specifications.RpcMethods, object[])

Exception interne 1 :
WebException : Le serveur distant a retourné une erreur : (500) Erreur interne du serveur.

I dont understand what i am doing wrong, i think it's a json problem
Help is appreciated, thank you

If anyone else need it i post the solution here:
Dim seg As JToken = JToken.Parse("{""rules"": [""segwit""]}")


Using btc-e in the United States and depositing/withdrawing USD into btc-e? I am located in the United States, and was wondering about the complications of using btc-e to make trades in the USA, such as the complications in depositing and withdrawing money in the form of USD.

When I try to deposit USD into btc-e, almost all the options there to deposit money are not supported for US residents such as Perfect Money, OKpay, EgoPay. The other options are Interkassa and Payeer but these sites are in Russian and hard to navigate. There is one more option of wire transfer, but this requires a $2000 minimum. Does anyone have any advice in relation to depositing USD?

Even if we get over the hurdle of depositing USD funds by bypassing it and buying a bitcoin from coinbase and transfering it over to btc-e, and then buying other currencies such as ltc and nmc, eventually when I sell these for USD on btc-e, am I going to have trouble taking the USD out of btc-e? I ask this because it was so hard putting USD in, that I am wondering if it is the same way taking it out?

If anyone in the USA has been using btc-e lately, please advise me on the difficulty or liklihood of depositing USD but more importantly withdrawing USD from btc-e, and how? Thank you.

I guess a second question would be if BTC-e is hard to use in the USA, is there any other exchange in the USA for trading alternative currencies such as LTC, NMC, etc...?

If you're willing to buy BTC on Coinbase to xfer to BTC-e, when you want to cash out wouldn't you just trade over to BTC on BTC-e to xfer to Coinbase to sell for USD then withdrawal?


How does blockchain.info determine when a payment is received? Can anyone help me understand how their payment API works at a bitcoind rpc level?  As far as I can tell, there is no way to see what the balance of an address is, only the number of bitcoins that address has received along with the confirmations for it.

If I were to replicate the blockchain API, i would have to:

create an address and associated it to an account (destination address)
check the balance of all accounts
get a list of all addresses in that account
check all the addresses looking for the lowest confirmations

if value < balance loop back to ensure to check other addresses

locate callback and call that
move btcs from account to destination address
repeat

Is it really that convoluted or am I missing something much simpler?  I currently run a website that processes BTC payments but i'd like to move away from relying on blockchain.info.

What you're describing is one way to do it but there are much better ways. Take a look at https://bitlab.co/wallet which is an open source real-time wallet API that you can learn from. The back-end source that interfaces with the bitcoind service is at https://github.com/bitlabco/bitlab-nodejs


Can I run 2 Bitcoin nodes with the same wallets? We have a full Bitcoin node with its wallets on the server. The issue is that the majority of our wallets were synchronized long time ago. For us, it would seem that this synchronization task can take a significant amount of time in which the Bitcoin node will be unreachable for all other requests and our server will be unavailable for users.

We think about replicating the current Bitcoin node on the separate server and synchronize wallets there. After this process will be finished we will copy wallets back to the origin server.

Is it doable? Or we can't have the same wallets on two different Bitcoin nodes?

This is doable. You can run as many nodes with the same wallets as you want.
I imagine you want to do this because the synchronisation process will be faster on another node?
After the process is done, you will have to copy the complete blockchain data, not the wallet itself.

You might want to consider checking for what your bottleneck is - could be the hard disk or the CPU, or in some cases the internet bandwidth.


how to compile brainflayar in window based Linux hi can any one explain how they do it like this 1EpisodeiV111111111111111111wbq9i2 1ANewHope1111111111111111111vnYm6D 1itisAPeriodofCiviLWarRebeLyzK2rV 1SpaceshipsStrikingFromA111vh24Fi 1HiddenBaseHaveWonTheirFirstVCugGV 1VictoryAgainstTheEviL111123YSBKF 1GaLacticEmpire1111111111111xsW5HG 1DuringTheBattLeRebeLSpies11ybfhTP 1ManagedToSteaLSecretPLansToxvKf4K 1TheEmpiresULtimateWeapon11zoRcyn 1TheDEATHSTARAnArmoredSpacezUyCHa 1StationWithEnoughPowerTo11vFTWwP 1DestroyAnEntirePLanet1111122KUcy5 111111111111111111112xT3273 111111111111111111114ysyUW1 1111111111111111111141MmnWZ 1111111111111111111114oLvT2 1PursuedByTheEmpiresSinisterypjWrk 1AgentsPrincessLeiaRacesHomewxuNTT 1AboardHerStarshipCustodian1yhX6zg 1ofTheStoLenPLansThatCan111zCJt3F 1SaveHerPeopLeAndRestore111yULD1y 1FreedomToTheGaLaxy1111111122roNk3

last 6 char dont care

but how it is possible can any one help me to gen address in specific private key from to option

i try to use brainflayar , bitcoin-rnn , blockparser but unable to compile i run Linux Ubuntu command line in windows pls help

You can use ThePiachu's online tool: https://gobittest.appspot.com/ProofOfBurn

Note that burn addresses are not the same as vanity addresses. Private keys of burn addresses are infeasible to find. Therefore, the addresses you listed weren't generated from private keys. So, Vanitygen wouldn't help in this case.


What is TxIn's sequence? I'm currently trying to generate the genesis block with my code and I've stumbled upon the TxIn sequence field that is not explained in the Protocol Specification wiki page, nor does it seem to appear in the block explorer. What is the way the value of this field is calculated, and what was its value for the genesis block?

Sequence numbers aren't shown on the Bitcoin Block Explorer HTML pages because they are not used by the network currently. Non-default sequence numbers would be shown on raw block/tx pages, but I'm not sure whether this has ever happened.

Sequence numbers are intended to be used for replacement. Replacement is currently disabled, but how it would work is:

You send a transaction with a LockTime in the future and a sequence number of 0. The transaction is then not considered by the network to be "final", and it can't be included in a block until the specified LockTime is reached.
Before LockTime expires, you can replace the transaction with as many new versions as you want. Newer versions have higher sequence numbers.
If you ever want to lock the transaction permanently, you can set the sequence number to UINT_MAX. Then the transaction is considered to be final, even if LockTime has not been reached.

This is useful in several cases. For example, two parties can use it to set up a "prepared transaction". Once the prepared transaction is created, the parties can move money between each other instantly, securely, and without fees. So you could set one of these up with an exchange and withdraw and deposit without waiting for confirmations.

Since replacement is not used currently, all transactions Bitcoin creates have LockTime = 0 and Sequence = UINT_MAX. This is the case with the genesis block's generation transaction.


How are P and ((z1*s2 - z2*s1)/(r*(s1-s2))) calculated? Given:

p  = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
r  = 0xd47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad1
s1 = 0x44e1ff2dfd8102cf7a47c21d5c9fd5701610d04953c6836596b4fe9dd2f53e3e
s2 = 0x9a5f1c75e461d7ceb1cf3cab9013eb2dc85b6d0da8c3c6e27e3a5a5b3faa5bab
z1 = 0xc0e2d0a89a348de88fda08211c70d1d7e52ccef2eb9459911bf977d587784c6e
z2 = 0x17b0f41c8c337ac1e18c98759e83a8cccbc368dd9d89e5f03cb633c265fd0ddc

How is "P" calculated?
Which calculator/script is used to calculate z1*s2, in here ((z1*s2 - z2*s1)/(r*(s1-s2))) and so on????

Thanks so much, I will appreciate your clarification.

How is "P" calculated?

P is one of the parameters for the secp256k1 curve as defined in http://www.secg.org/sec2-v2.pdf.

  Which calculator/script is used to calculate z1*s2, in here ((z1*s2 - z2*s1)/(r*(s1-s2))) and so on????

Any calculator you want. They are just integers (albeit large integers) so you can use anything that can do large integer computations.


What if my Transaction is in differently assembled blocks I understand, that the miner decides which transactions she chooses to include in a block. Often dependent on fees.
So the blocks that are mined in parallel might include different transactions. Say my transacting is in two blocks ... Then one bock is confirmed ... Will it be taken out from the other attempt to mine the block? #transaction

Those two blocks can never exist in the same chain. Whichever one came in the later block would be invalid because it would attempt to consume an unspent transaction output that did not exist.

If those two blocks claim to be in the same chain, then nobody will ever recognize the later block as valid and it will be as if that block does not exist. If those two blocks are in different chains, eventually one chain will be clearly longer than the other, and that will be the one that makes that transaction forever valid.

It is also possible that some third chain, including neither of those blocks, becomes definitively longer. In that case, a miner is free to include that transaction in a third block, assuming that chain doesn't already contain a conflicting transaction.


bitcoinj get raw block I'm trying to get the raw blocks with bitcoinj. I use Block.bitcoinSerialize() to get the bytes of each block when it is downloaded, but does not include transactions. How can I get the full raw block?

I have found a temporary solution:

BlockStore blockStore = new MyCustomBlockStore(NETWORK_PARAMETERS);
blockStore.getChainHead();

blockChain = new BlockChain(NETWORK_PARAMETERS, blockStore);

PeerGroup peerGroup = new PeerGroup(NETWORK_PARAMETERS, blockChain);
peerGroup.setDownloadTxDependencies(1000);
peerGroup.setBloomFilteringEnabled(false);
peerGroup.addPeerDiscovery(new PeerDiscovery() {
    private final PeerDiscovery normalPeerDiscovery = new DnsDiscovery(NETWORK_PARAMETERS);

    @Override
    public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
        final List<InetSocketAddress> peers = new LinkedList<InetSocketAddress>();
            peers.addAll(Arrays.asList(normalPeerDiscovery.getPeers(services, timeoutValue, timeoutUnit)));
            InetSocketAddress[] isas = new InetSocketAddress[0];
            return peers.toArray(isas);
        }

    @Override
    public void shutdown() {
        normalPeerDiscovery.shutdown();
    }
});

peerGroup.startAsync();
peerGroup.startBlockChainDownload(new PeerDataEventListener() {
    public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int i) {

        List<Transaction> transactionsList = block.getTransactions();
        int transactions = transactionsList == null ? 0 : transactionsList.size();

        long height = peer.getBestHeight() - i;
        //If the block contains transactions, it is likely to be complete.
        Log.e(TAG, "Downloaded block " + height + " with " + transactions + " transactions");
        blockUpdate(block);
    }

    private void blockUpdate(Block fBlock) throws IOException {
        //TODO: Update blockchain database with the full block.
    }

    public void onChainDownloadStarted(Peer peer, int i) {
        Log.i(TAG, "Started to download chain on peer " + peer);
    }

    @Nullable
    public List<Message> getData(Peer peer, GetDataMessage getDataMessage) {
        //Log.i(TAG, "getData from " + peer);
        return null;
    }

    public Message onPreMessageReceived(Peer peer, Message message) {
        //Log.i(TAG, "onPreMessageReceived (" + message.getClass().getSimpleName() + ") from " + peer);
        return message;
    }
});

In my case, I created a BlockStore that stores the blocks in a SQLite3 database. When I get the complete block, I overwrite the block register with the complete information (transactions, raw block, etc...)


C secp256k1 : ec_pubkey_parse successful on NULL context despite attribute Looking at the main API file secp256k1.h of the C library, we have:

SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_parse(
    const secp256k1_context* ctx,
    secp256k1_pubkey* pubkey,
    const unsigned char *input,
    size_t inputlen
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);

Hence I am expecting the function secp256k1_ec_pubkey_parse to fail if any of the three pointer arguments are NULL. This is indeed the case when pubkey or input are NULL (and in fact if we set up a callback function with secp256k1_context_set_illegal_callback, it will be duly called with the appropriate return value). However this function succeeds on NULL context. Does anyone know why this is happening? Is this the expected behaviour? I am guessing this isn't very important, but I am trying to learn and I don't like it when I don't understand. I attach a C snippet:

#include "secp256k1.h"
#include <assert.h>

int main()
{
  int return_value;

  secp256k1_context *ctx;
  secp256k1_pubkey pub;

  ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);

  // This is a valid public key
  const unsigned char *pub1 = "\x03"
    "\xf0\x28\x89\x2b\xad\x7e\xd5\x7d\x2f\xb5\x7b\xf3\x30\x81\xd5\xcf"
    "\xcf\x6f\x9e\xd3\xd3\xd7\xf1\x59\xc2\xe2\xff\xf5\x79\xdc\x34\x1a";

  // secp256k1_ec_pubkey_parse
  return_value = secp256k1_ec_pubkey_parse(ctx, &pub, pub1, 33);
  assert(return_value == 1);  // public key is indeed valid

  // same call with NULL context
  return_value = secp256k1_ec_pubkey_parse(NULL, &pub, pub1, 33);
  assert(return_value == 1);  // call is successfull

  // secp2561k1_context_destroy
 secp256k1_context_destroy(ctx);
}

If you look at the source code, secp256k1_ec_pubkey_parse doesn't actually use its ctx argument.  So no harm is done if it's null.

You can see in the code that there is a VERIFY_CHECK macro to test if ctx is non-null.  However, this is meant only for testing; you can see in util.h that nothing is actually done about the test unless the VERIFY macro is defined, which presumably is only the case for test builds.

The SECP256K1_ARG_NONNULL macro, defined here, uses the GCC function attribute mechanism to tell the compiler that this argument is supposed to be non-null.  The compiler will optimize on this basis.  It can try to issue a warning if it can determine, at compile time, that the argument is null; but only if you use the -Wnonnull option.


Is it possible to speed up block chain syncing with a miner? Syncing the client with the network can take some time. As I have to do this fairly often, it quite bothers me, especially when on slow devices. (A Pi can't do it in a week.)

I don't know exactly what the client does when syncing. Does it verify the block hashes? Transaction hashes as well? If it does hashing, a miner should be able to speed it up. I noticed periodic CPU bursts of the client, so that's probably when the hashing is done.

So, I happen to have one of those little Block Erupter USB Miners. Is it possible to setup one of these to speed up syncing?

Syncing means:

Downloading the blockchain.
For every transaction, check that its inputs actually reference earlier unspent outputs, and that the signatures match.

Hashing is a completely negligible part of the process and a mining device will not help you. Computationally the major work is verifying ECDSA signatures, and you also need disk access to find the past outputs. Using an SSD will make things faster.


Can I send bitcoins straight from an ATM to a vendor? I want to buy something from a vendor on who accepts bitcoins.
Is is possible to go a bitcoin ATM and purchase bitcoins sent directly to his address?
Or do I have to purchase the bitcoin and have in my wallet then sending it to the vendor.

I think it is best to transfer to a wallet you control first.

This gives you full control of the transaction you send to make payment tp the vendor. This may be important in some situations. For example:

When a vendor gives you a payment address, it may come with a condition of sending payment within a certain amount of time (1 hour, for example). If you buy from an ATM, the ATM operator may only send a transaction to pay all customers once every couple of hours. So if you try to pay the vendor directly from the ATM, the vendor's payment page might time out by the time the payment is confirmed. In that case, you'd probably have to contact their customer service to resolve your order.


How to unset fee rate after setting with RPC `settxfee` After setting the fee rate with settxfee -- how do I re-allow bitcoind to set the fee automatically again? Or does the settxfee command only apply to the next outgoing transaction?

Looking at the source code suggests that settxfee 0 should return you to the automatic fee setting.  However this behavior is undocumented and there is a TODO suggesting that it might go away in the future.  Otherwise, you can restart bitcoind.


Will coinbase.com have replay protection for receives? According to this, "Bitcoin Segwit2x does not have any built-in replay protection, but Coinbase has implemented our own replay protection system. You can safely send any BTC or B2X from Coinbase without worrying about replays on the other chain."

But will they have any replay protection for receives, as well as sends? I don't imagine they can do anything to prevent a transaction sent to them from being replayed on both chains, but at least they could detect the replay, and credit both currencies to your account.

I'll probably try to avoid this, but just wondering if I have some backup protection if I make a mistake.

It is impossible for the receiver of a transaction to prevent transaction replay of the transaction. They cannot do anything to that transaction to make it unreplayable.

However it is likely that Coinbase will credit both your Bitcoin and Segwit2x if a transaction is replayed. This is because they should be operating nodes for Bitcoin and nodes for Segwit2x which will inform their backend of the transactions occurring on each chain. Since a replayed transaction will be seen on both chains, both nodes will see it and thus their backend will credit your accounts.


Any way that running a node could help speed up confirmations at exchanges When making transfers between exchanges and wallets that are time sensitive it would be great to be able to some how reduce times to have transfers confirmed.  Is there any way that running a node (or any other method) would be able to be used to target transactions for faster confirmation?

No. The Bitcoin protocol is written such that the target block generation time is 10 minutes. The actual block generation time varies depending on the difficulty and hash rate of the network, in addition to luck.

Also, there is no guarantee that your transaction will be included in the next mined block. If you set a high transaction fee, your transaction is more likely to appear in the next block. If you set a low transaction fee, your transaction is likely to sit around in the mempool for hours or even days.

Once your transaction has been included in a valid block, then the confirmations start adding up every time a new block is found. There's nothing you can personally do to speed that up, unless you buy like a billion dollars worth of mining equipment and put it all online at the same time...and even then the effect will probably be negligible.


Best way to store fund on the lightning network Suppose that someone want to store 0.1 bitcoin on the lightning network for a period of 1 year to use services such as buying and selling things but doesnt know which one and with who yet.
What would be the best strategy here:

Open 10 channel for 0.01 BTC today and lock the fund for 1 year with the most used or most connected, funded channel at this day for 1 year, in the hope that they will be connected with the other nodes I want.
Open 1 channel for 0.1 BTC and lock the fund for 1 year with the single biggest node
Some custodial services with the impeding loss of control

The best strategy really depends on the user. You distinguish tradeoffs in all these solutions:

Open a new channel each time

This one does not make sense.

Open 10 channel for 0.01 BTC

More exposure to DOS (and onchain fees), but less exposure to censorship.
Probably the solution which makes the most of sense (or 5 channels for 2mBTC) since MPP.

Open 1 channel for 0.1 BTC

Less exposure to DOS (and onchain fees), but more exposure to censorship (you better chose well your single peer!).

Some custodial services

No exposure to DOS (and any other technical cost), but complete exposure to censorship.


I can not find a clear mathematical proof method with details and example for "near to zero chance of generating the same pair key wallet" A mathematical proof method with details for  "near to zero chance of generating the same pair key wallet"
I can not find a clear mathematical proof for the top sentence with example

According to https://en.bitcoin.it/wiki/Private_key

any 256-bit number from 0x1 to 0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4140 is a valid private key.

So if someone generates a private key using the usual random process, and then you generate a private key using a random process there is one chance in 0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4140 that you will generate the same key.
If my workings are correct, that is one chance in 115792089237316195423570985008687907852837564279074904382605163141518161494336
or one chance in around 1.158 x 1077
In terms of a probability, this is fairly close to zero. It is around
0.00000000000000000000000000000000000000000000000000000000000000000000000000000864

It is hard to grasp the scale of these numbers. According to https://www.universetoday.com/36302/atoms-in-the-universe/

it is estimated that the there are between 1078 to 1082 atoms in the known, observable universe

Related questions that might be informative

Is each Bitcoin address unique?
How long would it take to brute force an AES-128 key? (Bitcoin doesn't use AES but the answers give some idea of the scales involved)


Running a Bitcoin client with tor with a Debian based Linux OS I've received a question asking how to setup a Bitcoin client using Tor on a Debian based Linux system. Could someone provide a rough overview and perhaps a link to a tutorial?

Setting up Vidalia

Download the Tor Browser bundle
Extract, go to the App folder, and double click Vidalia (and select "Run"). Let Vidalia load.
If Vidalia doesn't work, run the "start-tor-browser" file at the top level of the extracted directory.
Ensure that the port is 9150 (it usually is). If you're not sure, go to Edit>Preferences>Network>Settings and check that the opened Firefox window is connected to a SOCKS v5 proxy on port 9150. If not, make note of the port and use it in place of 9150 in the rest of this post.
If Firefox was opened, close it. You don't need it for this.

Setting Tor up for your Bitcoin client
Bitcoin-QT

Ensure Vidalia is running
Download Bitcoin-QT, and extract
On your Debian command line, run sudo apt-get install libqtgui4
Go to the bin folder in the extracted Bitcoin, choose the 32 or 64 forlder depending on your system (32-bit/64-bit), double click the bitcoin-qt, select "Run"
Go to "Settings" in the menu bar, "Network" tab. Check the SOCKS proxy tickmark, set IP as 127.0.0.1, port as 9150, with version 5.

Setting it up with Electrum
Run the following lines in your command prompt:
sudo apt-get install python-qt4 python-pip
sudo pip install http://download.electrum.org/download/Electrum-1.7.3.tar.gz

If you have trouble using pip, download Electrum from here and run pip install /path/to/Electrum-1.7.3.tar.gz (Usually will be pip install ~/Downloads/Electrum-1.7.3.tar.gz)
Run electrum on the command line
At this screen, you can choose either option depending of whether or not you've already used Electrum before:

Now, use these settings for the next screen:

You may use a different default server if you wish. Try to get one that is situated close to your physical location.
If you selected "restore", fetch your seed (should look something like the one entered below) and enter it in the text field. If you had a lot of addresses in your old wallet, increase the gap limit. (that is the number of unused addresses Electrum generates before giving up on this)

Follow the remaining instructions: Safely store the wallet seed, and set a password if you wish. If the connection is working, you should see a green light at the bottom:

Setting Tor up with bitcoind
Simply run bitcoind  -proxy=127.0.0.1:9150 (or whatever the port is)


How to transfer Bitcoin Cash from a multi-sig vault? I have two private keys for a multi-sig vault. I have a tool that will sign transactions to move BTC out of this address.

Where can I find a tool that will use my two private keys to move BCC (Bitcoin Cash) out of this address? I want to move this BCC to an exchange for trading.

For the curious: this multi-sig vault was created via coinbase. And while their official position is that they don't give users access to their BCC, since I have control of two private keys I can move BTC out without their cooperation, so I should be able to do the same with BCC in that same address. Coinbase's own tool only works with BTC, so perhaps a fork of it that works with BCC would be ideal.

After a long, painstaking process, I developed the manual steps required and thoroughly documented it here:

How to sell your Coinbase Multi-sig wallet coins on the Bitcoin Cash (BCC) network


There's talk of increasing the blocksize - if this can be achieved - does this mean that the 21m btc limit can also be changed? My understanding of the blocksize debate is that it would require 51% consensus to change the algorithm and accept the new blocksize.

If the algorithm can be changed like this - would the exact same mechanism allow miners to also change the limit of bitcoin?

Or is there something fundamental that prevents this?

Flat-out increasing the blocksize is a hardfork. Hardforks require the overwhelming support of all parts of the Bitcoin sphere to be adopted, otherwise they will create a forkcoin. 51% would be unlikely to suffice to implement a hardfork.

Changing the reward schedule and thus the Bitcoin supply would also require a hardfork. From a technical perspective, changing the reward schedule would probably require a similar level of changes in Bitcoin software to be rolled out.
However, getting support for a change in the Bitcoin supply would be much more difficult as it's a key precept of what Bitcoin is, while the blocksize is "merely" an operational value that has implications for the network's security and how the Bitcoin project develops. I therefore consider it extremely unlikely that the Bitcoin supply will change in the future, while a blocksize increase is almost certain.


How to build a bitcoin trading bot I'd like to experiment with bitcoin technology, crypto currency, and encryption. I thought the best way to accomplish that is building my very own bitcoin trading bot.

It seems like a daunting task, but I think I can accomplish this in the following outlined steps:

The bot has to be connected to a wallet. I think I can accomplish
this by connecting it to a 3rd party wallet with public API.
My bot has to be connected to an exchange that also provides public
API which allows automated buying and selling
My bot has to be able to read the exchange's order book and price.
Create a simple algorithm for trading.

I'd like to know, what is the best way to build a wallet for my bot? And which exchange should I connect my bot to?

I know I am probably missing some key points. So if someone can point me to the right direction, I'd greatly appreciated.

Thanks

Building trading bots that interact with the exchanges is very similar to interacting with other RESTful APIs. Basically, you make query objects to whichever exchange you like to use. Here is a simple example: https://github.com/AdamCox9/nickelbot/blob/master/adapters/poloniex/poloniex_lib.php

Nickelbot is development platform written in PHP that has all the boilerplate code for interacting with several exchanges. You can write a bot once, like https://github.com/AdamCox9/nickelbot/blob/master/bots/make_min_orders.php that will give you full control and it works with multiple exchanges.

Take a look at all the example code on https://github.com/AdamCox9/nickelbot to see exactly what you need to do.


What is a good approach to learning the Bitcoin codebase? I've read Mastering Bitcoin and other high level resources and I believe I have a decent understanding of Bitcoin. I'd now like to read and understand the source code. However, I'm very new to cpp and don't know a good way to approach this task. Is there a systematic approach I can use to effectively learn the codebase?

Some good places to start are the places that the user or the network input something into Bitcoin Core. The obvious two places for these are the RPC functions and the network message processing. The RPC code is in src/rpc, src/wallet/rpcwallet.cpp and src/rpcdump.cpp. The network message processing is in src/net_processing.cpp. By tracing through the function calls and also looking up where the global variables are being added to and set, you can get into most parts of the codebase.

For example, suppose you looked at sendtoaddress. You would start at the RPC function in src/wallet/rpcwallet.cpp and trace the execution path. You would see that it eventually goes to src/wallet/wallet.cpp and how it uses the CreateTransaction function. From here, you would learn how coin selection works.

Now you would see how the wallet chooses coins for transaction spending. But how does it find out about those in the first place? Well, as you are tracing sendtoaddress, you will come across the AvailableCoins which iterates through some variable named mapWallet and pulls from stuff in mapWallet to build a list of selectable coins. Thus mapWallet must be where transactions are stored, so you can search for the variable mapWallet in the codebase. This will tell you where that variable is being used and you can trace through the uses of mapWallet to learn how it is populated and used.

Doing so will lead you to the functions that populate mapWallet. So now you want to trace backwards: what are calling those functions, how did we get to that function. For example, for populating mapWallet, you will run into AddToWallet. What calls AddToWallet? The function AddToWalletIfInvolvingMe. And you can keep going backwards to get an idea of how it all works.

The same methodology can be applied to the network message processing. For example, suppose you wanted to learn about block processing. The place to start is when a block is received, so in src/net_processing.cpp, look for NetMsgType::BLOCK within the ProcessMessage function. From here you can trace the function calls and global variables like we did with the RPCs. It will take you to the Proof of Work validation and how the target is calculated for a block. It will take you to transaction validation. You will end up looking at the script interpreter and how it evaluates scripts in a transaction. And so on.

You can repeat this for every RPC and every network message type to find out where and how things are processed. This will get you through the majority of the codebase. Network message processing will get you through all of consensus and the bulk of the codebase. Tracing RPCs will get you through basically everything else because almost everything a user can do can be done through the RPCs. These two general entry points are great places to go through the codebase and learn about what Bitcoin  Core is doing internally.


Transfer wallet to new server I have been running a bitcoin app in an old server. I need to move everything to a new server but my question is this: is there a way I can transfer my bitcoin wallet (bitcoin core) to the new server with a clean O/S installation without losing the tx history from my old server's wallet?

Just shut down the bitcoin app on the old server, copy the wallet.dat file to the new server, then start the bitcoin app on the new server. Don't remove anything from the old installation until you 100% confirm that the new installation works.


Is it necessary for blocks to record the nBits difficulty parameter? The next difficulty to solve a block is determined from how fast blocks were solved before it. In addition, the difficulty only changes once every two weeks or so.

So, couldn't every node keep track of the expected difficulty and not need to have it in each block header? Or is there a reason nodes need to be communicating the current difficulty in each block? Not that it would be a major savings, or anything, it just seems strange that this is included when it's just a function of all the other pieces of a chain.

Maybe it's because calculating nBits would take a long time eventually if you had to go through all the block headers every time you wanted to calculate the next difficulty?

Recall from the Nakamoto Whitepaper that for Simplified Payment Verification (SPV) clients, security is measured mainly by the amount of work done to secure a particular transaction.  SPV nodes can't use past headers alone to verify that an incoming payment is valid, so there's technically not much need to store past headers[1].

Of course, if you're not going to store all the headers, you need some way to measure difficulty for the headers you do have---and nBits provides that.

Note that storing recent headers can increase an SPV client's security by allowing it to calculate proper difficulty for later headers.  This ensures an attacker trying to lie to the client has to create proper-difficulty blocks.  Still, a complete headers chain isn't needed here, so nBits is still useful as a starting value.

[1] But BitcoinJ and all other SPV clients I know about still do store complete headers.  At a guess, the reason they do is to help them detect chain re-organizations (reorgs) that would render a previously-received payment invalid.


Details on Genesis Block The question asked here displays the genesis block in pretty good detail. I am still trying to get a breakdown of some of the elements seen here (and some others not seen here):

The Merkle Root
Time
Bits
Nonce
The Transaction Section:

Coinbase
scriptSig
scriptPubKey

It is still unclear to me where all these elements come from.

The Merkle Root, as I understand it, is basically a hash of many hashes (Good example here) - to create a Merkle Root you must start by taking a double SHA-256 hash of the byte streams of the transactions in the block .What is this data (the byte streams), what does it look like, and where does it come from? I think, to understand those questions, one should better understand the data found under "Example tx message" here.

After studying this data, I don't understand it completely either. I am unsure as to where the TxIn, TxOut, and OutPoint come from. What do they look like for the genesis block? I saw that one fellow had a similar question but it was never answered really (unless TxIn sequence is something totally different from just TxIn).

If the coinbase is "the first input of the first transaction" I think knowing more about TxIn and TxOut would explain what the coinbase for the genesis block looks like also, which is another thing I don't understand.

Can anyone explain or point me to what these bits of data look like for the genesis block?

Note that all hex numbers and hashes here and in the protocol are little endian. So the ones I show will look backwards from a lot of sites which show them in big endian format.

The Merkle Root

This is a way to combine all the hashes of the transaction together into 1 hash. To do this we first need the hashes of all the transactions. There is only one transaction in the genesis block so let's find its hash. This is based off of this format.

import hashlib

#version 1, uint32_t
version = "01000000"

#1 input transaction, var_int
tx_in_count = "01"

#the default for generation transactions since there is no transaction to use as output
OutPoint_hash = "0000000000000000000000000000000000000000000000000000000000000000"

#also default for generation transactions, uint32_t
OutPoint_index = "ffffffff"

previous_output = OutPoint_hash + OutPoint_index

#77, var_int
script_length = "4d"

#The coinbase. In a regular transaction this would be the scriptSig, but unused in generation transactions.
#Satoshi inserted the headline of The Times to prove that mining did not start before Jan 3, 2009.
#???????EThe Times 03/Jan/2009 Chancellor on brink of second bailout for banks
signature_script = "04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73"

#final sequence, means it can't be replaced and is immediately locked, uint32_t
sequence = "ffffffff"

tx_in = previous_output + script_length + signature_script + sequence

#1 transaction output, var_int
tx_out_count = "01"

#5000000000 satoshis == 50 bitcoin, uint64_t
value = "00f2052a01000000"

#67 var_int
pk_script_length = "43"

#The scriptPubKey saying where the coins are going.
pk_script = "4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac"
#We can decode this.
#41 push the next 65 bytes onto the stack
#04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f the 65 bytes that get pushed onto the stack
#ac OP_CHECKSIG
#This is a pay-to-pubkey output, which is the default for generation transactions.

tx_out = value + pk_script_length + pk_script

#immediately locked, uint32_t
lock_time = "00000000"

transaction = version + tx_in_count + tx_in + tx_out_count + tx_out + lock_time

transaction_bin = transaction.decode("hex")
transaction_hash_bin = hashlib.sha256(hashlib.sha256(transaction_bin).digest()).digest()
transaction_hash = transaction_hash_bin.encode("hex")
print(transaction_hash)
3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a

So now that we have the transaction hash for the 1 transaction, we need to find the Merkle root. It turns out that the Merkle root of a single hash is... that single hash. So that is the Merkle root.

Time

29ab5f49, uint32_t. This is 1231006505 in decimal and is a unix timestamp meaning January 3, 2009 at 6:15:05pm UTC.

Bits

ffff001d == 486604799, uint32_t. This is a way to represent the difficulty. It's a sort of floating-point-ish type number. This is difficulty 1 and requires hashes to be below or equal to the target of 0000000000000000000000000000000000000000000000000000FFFF00000000.

Nonce

1dac2b7c == 2083236893, uint32_t

Transaction section

I covered most of this in the merkle root section.

If you want someone else's explanation of each byte of the genesis block, look here.


A couple of questions on Schnorr sig In the BIP by Pieter Wuille it is told that the key prefixed version of Schnorr signature is needed when the scheme is used in combination with BIP32's unhardened derivation. Could someone provide an example showing this necessity? I couldn't figure out one by myself.

Always in the BIP, when coming to batch validation we can see that there is the need for random number generation. Again, could someone provide an example showing that the simpler version is insecure? I found out that the reason is the so called "cancellation attack". I would like to figure out how it can be exploited.

Thanks in advance for your answers!

A schnorr signature, without key prefixing, is a tuple {pubkey (P), message (m), R, s} where the equation R == sG +  H(R||m)P holds.

Now, assume you have pubkeys P and P2 who's discrete logs differ by c which is known to me, as is the case for non-hardened BIP 32 when I know the extended pubkey (P2 == P + cG). If I know a signature by pubkey P of message m, I can use it to forge a signature of m by pubkey P2: {P2, m, R, s - H(R||m)c} because if you write out the relation for P2 and then express it in terms of the relation for the first signature, that's what you get.

For batching: The task there is we have two to n equations of the form R_n = s_nG + h_nP_n, we could naively batch verify by first rewrite them as  0 = sum(s_n)G + sum(h_nP_n) - sum(R_n) and then using an efficient multiexp to compute the big product-sum. E.g. if we want to make {P1, m1, R1, s1} hold we can add to the batch {-P1, m1, R1, -s1} so now the errors cancel.

To resolve this, the verifier should delinearize the equations by multiplying each one by an attacker unknown value which makes them unable to cancel with odds better than chance. This can be done without hurting efficiency much by substituting it into the scalars in the multiexp.

For an even simpler example: consider the batch verification where the attacker knows  all valid signatures. The attacker can simply shuffle the s values between signatures in the batch. Without delinearization the batch would obviously still pass (as the naive sum doesn't care about the order of s values), yet the signatures would all be invalid.


How do wallet-devs profit? As far as I know there are several e-wallet services for Bitcoin that provide same standard integrated API service functionality for users. I am curious about where are they finding benefits in this? Do those service providers charge for transfer by themselves and receive left-overs personally?

It's different for each wallet but here are the top ways.

Coinbase Method
You put a fee on USD->BTC and vice versa. Downside of this is that you can exploit the user using the delay created by using fiat and banks, Coinbase purportedly buys bitcoins when user buys, then a few days later takes bitcoin and refunds (by marking transaction as "suspicious") user if price goes up and holding is profitable.

Blockchain.info Method
You gain revenue from allowing services to put links on your website. Downside to this is that you can't just advertise more if you aren't making the hosting costs.

Patron Method
You gain revenue from often your own services, basically your just a free wallet that the owner supports himself. No real downside. Inputs.io used this, revenue gained from CoinLenders, ultimately "hacked" which makes you wonder the motivation of a non-profit wallet service.


Query Blockchain: Reference previous transaction in "txin" I'm currently working with a postgresql database I've downloaded here which has the following schema and has probably been parsed using Bitcoin-ABE (I added some indexes and redundant columns):

Now I'm stuck trying to make a connection between a transaction input and the previous output. According to the API that belongs to the sql dump, the field prev_out references "the output that this input spends". My problem is, that I can't find any of the txin.prev_out values in tx.hash. Is this line of thinking correct, or am I connecting the wrong fields?

FYI: As you can see both fields are of the type bytea. I was able to use the function encode(hash, 'hex') to get the actual transaction hash and find it at blockchain.info. For the field txin.prev_out however, the hash cannot be found at blockchain.info.

txin.prev_out contains the txid in internal byte order. This is the opposite of tx.hash

You need to reverse the bytes. Here's a short python program that will do that:

import binascii
hash = '32d7724fb0d244f50281a500f505818bb655bc029158fd59d477f4445a6ed64a'
def reverse_hash(hash):
    hash = binascii.unhexlify(hash)
    hash = hash[::-1]
    return binascii.hexlify(hash)

print reverse_hash(hash)


Bitcoin unconfirmed long Time no confirmations Been forever my bitcoin hasn’t been confirmed can someone help me

3JHLiBT2Tu6uFotFRY1mF1bAnRdRS8XTqt

Congratulations! Your transaction at the time of writing has 65 confirmations!

blockchain.info


Electrum's "script hash" form with NBitcoin? I've come across how scripts are hashed in the electrum (stratum) protocol implementation by looking at the docs.

I'm using NBitcoin, and I've tried to generate this hash from a segwit address, first this way:

myPublicKey.WitHash.ScriptPubKey.Hash.ToString()

However, electrum servers throw an error saying that this hash is not valid. I'm guessing because this hash is of type HASH160 instead of SHA256 like the docs claim? (As I see that the hash generated by this technique is the same hash that appears below the address in a page like this.)

Also I'm wondering if I need to reverse the chain of characters myself or if NBitcoin's SHA256 methods would do it for me? All in all, how to get this hash with NBitcoin API so that Electrum servers are happy?

In F#:

let address = BitcoinAddress.Create("1HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1",
                                    NBitcoin.Network.Main)
let sha = NBitcoin.Crypto.Hashes.SHA256(address.ScriptPubKey.ToBytes())
let reversedSha = sha.Reverse().ToArray() // add `open System.Linq` at the top
NBitcoin.DataEncoders.Encoders.Hex.EncodeData reversedSha


lightning node data visibility on explorers I'm trying to set my first c-lightning node with docker-compose using image from https://hub.docker.com/r/elementsproject/lightningd. currently, my node can connect and open channel with other nodes (and I can open a channel to the node just fine), but it's still not updated (ie has no information) on most explorers.

the following is result of getinfo and listconfigs

getinfo
{
   "id": "03db40337c2de299a8fa454fdf89d311615d50a27129d43286696d9e497b2b027a",
   "alias": "TestName",
   "color": "fff000",
   "num_peers": 3,
   "num_pending_channels": 0,
   "num_active_channels": 3,
   "num_inactive_channels": 0,
   "address": [
      {
         "type": "ipv4",
         "address": "68.183.195.14",
         "port": 9735
      }
   ],
   "binding": [
      {
         "type": "ipv4",
         "address": "172.18.0.3",
         "port": 9735
      }
   ],
   "version": "v0.7.1-906-gf657146",
   "blockheight": 601917,
   "network": "bitcoin",
   "msatoshi_fees_collected": 0,
   "fees_collected_msat": "0msat"
}

listconfigs
{
   "# version": "v0.7.1-906-gf657146",
   "lightning-dir": "/root/.lightning",
   "wallet": "sqlite3:///root/.lightning/lightningd.sqlite3",
   "plugin": "/usr/local/bin/../libexec/c-lightning/plugins/pay",
   "plugin": "/usr/local/bin/../libexec/c-lightning/plugins/autoclean",
   "plugin": "/usr/local/bin/../libexec/c-lightning/plugins/fundchannel",
   "network": "bitcoin",
   "allow-deprecated-apis": true,
   "always-use-proxy": false,
   "daemon": "false",
   "rpc-file": "lightning-rpc",
   "rgb": "fff000",
   "alias": "HubTest",
   "bitcoin-rpcuser": [redacted],
   "bitcoin-rpcpassword": [redacted],
   "bitcoin-rpcconnect": "bitcoind",
   "bitcoin-retry-timeout": 60,
   "pid-file": "lightningd-bitcoin.pid",
   "ignore-fee-limits": false,
   "watchtime-blocks": 144,
   "max-locktime-blocks": 2016,
   "funding-confirms": 3,
   "commit-fee-min": 200,
   "commit-fee-max": 2000,
   "commit-fee": 500,
   "cltv-delta": 14,
   "cltv-final": 10,
   "commit-time": 10,
   "fee-base": 0,
   "rescan": 15,
   "fee-per-satoshi": 1,
   "max-concurrent-htlcs": 30,
   "min-capacity-sat": 10000,
   "bind-addr": "172.18.0.3:9735",
   "announce-addr": "68.183.195.14:9735",
   "offline": "false",
   "autolisten": true,
   "disable-dns": "false",
   "enable-autotor-v2-mode": "false",
   "encrypted-hsm": false,
   "log-level": "DEBUG",
   "log-prefix": "lightningd(7):"
}

is there something wrong with this configuration? or is it another issue?

I understand that explorers update their node list irregularly, and as far as the node can open channels (and can be connected), everything is fine. but this thing has bugging me for weeks.

updated the docker image and put bind-addr to 0.0.0.0:9375 somehow fixed the problem for some unknown reason.