ブロックチェーンとは (bitcoin wiki 和訳)

ブロックチェーンとはbitcoin wikiの文章を和訳してみる。
誤訳等指摘いただければ喜びます
Block chain - Bitcoin Wiki

A block chain is a transaction database shared by all nodes participating in a system based on the Bitcoin protocol. A full copy of a currency's block chain contains every transaction ever executed in the currency. With this information, one can find out how much value belonged to each address at any point in history.

ブロックチェーンとはBitcoinプロトコルに則ってシステムに参加しているすべてのノードの間でシェアされている取引(transaction)のデータベースである。ある通貨のブロックチェーンのフルコピーは、その通貨において今までに行われたすべての取引を含んでいる。この情報から、それぞれのアドレスが、歴史上の任意の時点においてどれだけの価値を持っているかを各自が見出すことができる。

Every block contains a hash of the previous block. This has the effect of creating a chain of blocks from the genesis block to the current block. Each block is guaranteed to come after the previous block chronologically because the previous block's hash would otherwise not be known. Each block is also computationally impractical to modify once it has been in the chain for a while because every block after it would also have to be regenerated. These properties are what make double-spending of bitcoins very difficult. The block chain is the main innovation of Bitcoin.

それぞれのブロックは前のブロックのハッシュを含んでいる。これは原初のブロック(the genesis block)から現在のブロックまでを一つのブロックの連なり(a chain of blocks)にする効果を持っている。それぞれのブロックは時系列的に前のブロックの後ろにくることが保証されている、というのはもしそうでなければ前のブロックのハッシュが知られることができないからである。また、それぞれのブロックは一度チェーンに含まれてしばらくすると改変することは、その後のそれぞれのブロックを再生成しなければならないため計算量的に実行不可能である。これらの性質によりBitcoinの多重利用(double spending)はとても難しいものとなる。ブロックチェーンはBitcoinの主たるイノベーションである。


Honest generators only build onto a block (by referencing it in blocks they create) if it is the latest block in the longest valid chain. "Length" is calculated as total combined difficulty of that chain, not number of blocks, though this distinction is only important in the context of a few potential attacks. A chain is valid if all of the blocks and transactions within it are valid, and only if it starts with the genesis block.

もしそれが最長のValidなチェーンの最新のブロックである場合、正直な生成者達はブロックの上に(それを彼らが生成するブロックの中で参照しながら)構築するのみである。「長さ」はブロックの数ではなく、チェーンの難しさの総和として計算されるが、この区別はいくつかの潜在的な攻撃の文脈においてのみ重要になるものである。あるチェーンは、それに含まれるすべてのブロックと取引が有効であり、原初のブロックから始まっている場合においてのみ有効である。

For any block on the chain, there is only one path to the genesis block. Coming from the genesis block, however, there can be forks. One-block forks are created from time to time when two blocks are created just a few seconds apart. When that happens, generating nodes build onto whichever one of the blocks they received first. Whichever block ends up being included in the next block becomes part of the main chain because that chain is longer. More serious forks have occurred after fixing bugs that required backward-incompatible changes.

チェーン上のどのブロックにも、原初のブロックに至るたった一つのパスがある。しかしながら、原初のブロックから来るときには分岐が存在しうる。2つのブロックがほんの数秒の違いで生成されたときに、一つのブロック分岐が生まれることが時々ある。これが起きたときには、ノードはどちらでも先に受信した方のブロックの上に構築を行う。次のブロックに含まれるブロックはそれがより長くなるため結局はメインチェーンの一部となる。後方互換性の無い変更が必要なバグの修正後により深刻なフォークが起こったこともある。


Blocks in shorter chains (or invalid chains) are not used for anything. When the bitcoin client switches to another, longer chain, all valid transactions of the blocks inside the shorter chain are re-added to the pool of queued transactions and will be included in another block. The reward for the blocks on the shorter chain will not be present in the longest chain, so they will be practically lost, which is why a network-enforced 100-block maturation time for generations exists.

短い方のチェーン(もしくは無効なチェーン)に含まれるブロックは何にも用いられない。Bitcoinクライアントが他のより長いチェーンに切り替わった場合、短い方のチェーン内のすべての有効な取引のブロックはキューに積まれた取引のプールに再度追加され、他のブロックに組み込まれることとなる。短い方のチェーンへの報酬は最長のチェーンにおいては贈呈されないため、それらは事実上失われる。これが、生成に対してネットワークにより強制された100ブロックの熟成期間が存在する理由である。

These blocks on the shorter chains are often called "orphan" blocks. This is because the generation transactions do not have a parent block in the longest chain, so these generation transactions show up as orphan in the listtransactions RPC call. Several pools have misinterpreted these messages and started calling their blocks "orphans". In reality, these blocks have a parent block, and might even have children.

短いチェーン上のこれらのブロックはしばしば「孤児」(orphan) ブロックと呼ばれる。これはその生成取引(?: 原文 the generation transactions )が最長ブロックにおいて親ブロックを持っておらず、そのためこれらの生成取引はlisttransaction RPCコールにおいて孤児となって現れる。幾つかのプールはこれらのメッセージを誤解して、これらのブロックを「孤児」と呼び始める。実際にはこれらのブロックは親ブロックを持っており、子供さえ持っているかもしれないのだ。

Because a block can only reference one previous block, it is impossible for two forked chains to merge.

ブロックは前のブロック一つを参照することしかできないため、二つの分岐したチェーンをマージすることは不可能である。

It's possible to use the block chain algorithm for non-financial purposes: see Alternative chain.

ブロックチェーンアルゴリズムを金融ではない目的に使うことは可能である:Alternative chain を見よ

The block chain is broadcast to all nodes on the networking using a flood protocol: see Block chain download.

ブロックチェーンはfloodプロトコルを使ってネットワーク上のすべてのノードにブロードキャストされる: Block chain download を見よ

ーーー
この文書のライセンスは
http://creativecommons.org/licenses/by/3.0/

bitcoinのアドレスについて[和訳]

例によってあんまり日本語で転がってなかった情報のbitcoin wikiの和訳シリーズ。Bitcoinクライアントをダウンロードして使ってみたらアドレスが沢山あってどういう仕組みかわからなかったので勉強がてら翻訳してみた。

      • -

Address - Bitcoin Wiki

Bitcoinアドレス、もしくは単にアドレス、は数字1か3から始まる、英数字26-35文字の識別子であり、あり得るBitcoin支払の宛先を表す。アドレスはいかなるBitcoinユーザもコスト無しに作ることができる。例えば、Bitcion-Qt (訳者注: Bitcoinのクライアント名) を使うと、「New Address」を一回押すとアドレスが一つ割り当てられる。Bitcoinアドレスは取引所やオンラインウォレットサービスのアカウントを用いても作ることができる。

Bitcoinアドレスの一つの例は 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy である。

  1. Bitcoinアドレスは使い捨てトークンである

Emailアドレスのように、あなたはBitcoinをアドレスのうち一つに送ることでBitcoinを人に送ることができる。しかしながら、Emailアドレスとはことなり、人は沢山の異なるBitcoinアドレスを持ちそれぞれの取引でユニークなアドレスが用いられるはずである。ほとんどのBitcoinソフトウェアやウェブサイトであなたが請求や支払リクエストを行うたびに真新しいアドレスを利用できるようになっている。

  1. アドレスはオフラインで生成できる

アドレスの生成はインターネット接続無しに行うことができ、Bitcoinネットワークとの接続や登録も求められない。無料で入手できるソフトウェアツールを使って大量のアドレスの束をオフラインで作ることも可能である。大量のアドレス束を生成することは、eコマースウェブサイトとしてあらかじめ生成したユニークなアドレスを「Bitcoinで支払う」オプションを選択したそれぞれの顧客に分配するなど幾つかのシナリオで有用である。最近の「 決定論的ウォレット(HD wallets) 」は(Webサーバのような)信頼できないシステムに受け取ったBitcoinを消費させることなく限りない数のアドレスを作らせられるように「シード」となるトークンを生成することができる。

  1. アドレスはケースセンシティブで厳格である

Bitcoinアドレスはケースセンシティブ(大文字/小文字を区別する)である。Bitcoinアドレスはどこであれれ可能であればコンピューターのクリップボードを用いてコピー、ペーストするべきである。もしBitcoinアドレスを手写し、それぞれの文字が厳密にー大文字小文字含めてー書き写されなかったら、間違ったアドレスはBitcoinソフトウェアによって大抵は拒否されるだろう。もう一度自分の入力を確認しもう一度試さなければならないだろう。

ミスタイプしたアドレスが妥当であるとして受理される可能性は1/2^32であり、おおよそ429万回に1回である。

  1. あるアドレスであなたが受信することを示す

ほとんどのBitcoinウォレットはメッセージに「署名」する機能を持っており、そのアドレスで資金を受け取った存在がメッセージに賛成したことを示すことができる。

特定のアドレスを認可専用とし、そのアドレスが実際のBitcoin取引に決して利用されることがないようにすることでこの能力に便乗するサービスも出てくるだろう。あなたがこういったサービスにログイン、もしくは使用しようとするときには、あなたが前に署名したアドレスを持った人と同一であることを署名を提供して示すことになるだろう。

これらの署名はあるアドレスが受け取ることを示すだけであるということは重要な留意すべきことである。というのはBitcoin取引は"from"アドレスを持っておらず、あなたが資金の送り元であることを示すことはできないからである。

Current standards for message signatures are only compatible with "version zero" bitcoin addresses (that begin with the number 1).
現在のメッセージ署名の標準は「バージョンゼロ」Bitcoinアドレス(番号1から始まる)のみと互換性がある。

  1. アドレスの検証

If you would like to validate a Bitcoin address in an application, it is advisable to use a method from this thread rather than to just check for string length, allowed characters, or that the address starts with a 1 or 3. Validation may also be done using open source code available in various languages or with an online validating tool.

  1. Multi-signature addresses

Addresses can be created that require a combination of multiple private keys. Since these take advantage of newer features, they begin with the newer prefix of 3 instead of the older 1. These can be thought of as the equivalent of writing a check to two parties - "pay to the order of somebody AND somebody else" - where both parties must endorse the check in order to receive the funds.

The actual requirement (number of private keys needed, their corresponding public keys, etc.) that must be satisfied to spend the funds is decided in advance by the person generating this type of address, and once an address is created, the requirement cannot be changed without generating a new address.

  1. What's in an address

Most Bitcoin addresses are 34 characters. They consist of random digits and uppercase and lowercase letters, with the exception that the uppercase letter "O", uppercase letter "I", lowercase letter "l", and the number "0" are never used to prevent visual ambiguity.

Some Bitcoin addresses can be shorter than 34 characters (as few as 26) and still be valid. A significant percentage of Bitcoin addresses are only 33 characters, and some addresses may be even shorter. Every Bitcoin address stands for a number. These shorter addresses are valid simply because they stand for numbers that happen to start with zeroes, and when the zeroes are omitted, the encoded address gets shorter.

Several of the characters inside a Bitcoin address are used as a checksum so that typographical errors can be automatically found and rejected. The checksum also allows Bitcoin software to confirm that a 33-character (or shorter) address is in fact valid and isn't simply an address with a missing character.

  1. Testnet

Addresses on the Bitcoin Testnet are generated with a different address version, which results in a different prefix. See List of address prefixes and Testnet for more details.

  1. Misconceptions
    1. Address reuse

Addresses are not intended to be used more than once, and doing so has numerous problems associated. See the dedicated article on address reuse for more details.

    1. Address balances

Addresses are not wallets nor accounts, and do not carry balances. They only receive funds, and you do not send "from" an address at any time. Various confusing services and software display bitcoins received with an address, minus bitcoins sent in random unrelated transactions as an "address balance", but this number is not meaningful: it does not infer the recipient of the bitcoins sent to the address has spent them, nor that they still have the bitcoins received.

An example of bitcoin loss resulting from this misunderstanding is when people believed their address contained 3btc. They spent 0.5btc and believed the address now contained 2.5btc when actually it contained zero. The remaining 2.5btc was transfered to a change address which was not backed up and therefore lost. This has happened on a few occasions to users of Paper wallets.

    1. "From" addresses

Bitcoin transactions do not have any kind of origin-, source- or "from" address. See the dedicated article on "from address" for more details.

  1. See Also

二次利用可能範囲の広いor制限無しの写真を探す方法

世界最大級の写真共有サイトFlickrwww.flickr.com二次利用可能な写真を探す方法。

Flickrでは、写真の利用ポリシーを選択して検索を行うことができる。 プレゼンテーション資料等を作る時に、著作権的にクリーンな素材を集められるので重宝している。 ただし、いわゆる完全な「著作権フリー」にあたるのはエントリ末のCC0のみなので注意。

Commercial Use allowed & mod allowed を選択する

f:id:mizti:20161214210824p:plain

商用利用、改変が認められた写真。 ただし、このカテゴリは出所表示義務があるため、ソースのURLと撮影者名を必ず引用元として示す必要がある。

No known copyright restrictionsを選択する

f:id:mizti:20161214205452p:plain

No known copyright restrictionsは正確には著作権フリーというわけではなく、 「著作権を主張する人の存在が知られていない」もしくは「公的資料」というカテゴリーに当たる。 同種のカテゴリを専門に探せるページも用意されている

CC0 ドメインから利用する

CC0、すなわち明示的に著作権を完全に放棄している写真。 このカテゴリは改変可能・出所明示義務なし・使途(商用含む)制限無しとなるので自由な利用が可能。

Flickr photos or video with a Creative Commons Public Domain Dedication (CC0)

デフォルトでは100枚までしか表示されないので、適当なワードで検索して探せばそれなりの数の画像が表示される。

第14回granpark.rb出題問題「少林寺秘棍房弟子のたかしくん 」

granpark.rb、久々のアルゴリズムペアプロ回で出題した問題です。

この問題はTopCoder SRM481 Div2 Level3の問題を改題して作っております。
たまには問題真正面からの幅優先・深さ探索ではなく、
イナリサーチとか使う問題出したいな、と思ってこの問題を出題しました。

次回のgranpark.rbはR言語とかについて話してくれそうな人に声かけてみようかと思ってます。

第11回granpark.rb出題問題「迷路職人の朝は早い」

久々にペアプロの課題。

指定された大きさの迷路を作れ、というのが問題の趣旨。
一応迷路の要件はつくったのですが、


#<#############
#.............#
#.#.#.#.#.#.#.#
#.............#
#.#.#.#.#.#.#.#
#.............#
#.#.#.#.#.#.#.#
#.............#
#.#.#.#.#.#.#.#
#.............#
#############>#

みたいな「迷路」を作られるのもやだなー、と思って評価関数を一応設定しました。
でも


#<##############
#..............#
##############.#
#..............#
#.##############
#..............#
##############.#
#..............#
#.##############
#..............#
##############>#

みたいな迷路を出力をするチームがいたのであんまり意味がなかったかもしれないです。
迷路の評点って難しい。

第0回granpark.rbで出題された、「あみだくじを作れ」みたいな
ふわっとした課題を出そうとおもったんですが、
1時間半じゃ短すぎましたね。。。

結局今回は全員方針発表だけで終わってしまいました。
いろいろ反省です。

正直、評価関数部分だけで出題しても良かったかもしれません...。

指定したファイルの更新があったらコマンドを自動実行するシェルスクリプト

プログラミングの作業をしていると、一旦コンパイルや実行を行なって結果を確認したくなることがあります。

C++Javaであればコンパイル -> 実行が必要ですし、rspecのようなコマンドでテストを行いたい場合もあると思います。

その度にエディタを終了-> (コンパイル実行 ->) 実行 -> またエディタを起動とかするのはとても手間です。(エディタ内でコンパイルとかするもありますが、それでも何らかのコマンドが必要です)

そこで、特定のファイルを監視下に入れてそのファイルの更新があったら指定されたコマンドを実行するようなシェルスクリプトを作ってみました。

#!/bin/sh
if [ $# -ne 2 ]; then
        echo "実行するには2個の引数が必要です。
        第一引数: 監視対象ファイル名
        第二引数: 監視対象ファイルが更新された際に実行されるコ>マンド
        例: ./autoexec.sh a.cpp 'g++ a.cpp && ./a.cpp'"
        exit 1
fi
echo "監視対象 $1"
echo "実行コマンド $2"
INTERVAL=1 #監視間隔, 秒で指定
last=`ls --full-time $1 | awk '{print $6"-"$7}'`
while true; do
        sleep $INTERVAL
        current=`ls --full-time $1 | awk '{print $6"-"$7}'`
        if [ $last != $current ] ; then
                echo ""
                echo "updated: $current"
                last=$current
                eval $2
        fi
done

第一引数で監視するファイルを第一引数で指定、第二引数に"javac a.cpp"のように実行したいコマンドを指定してください。

第一引数の監視対象ファイルに更新があると第二引数がトリガされます。
screenなんかで画面を分割して片側に表示させたりするといいかもしれません。

Mac (BSD) で使う場合、lsの引数体系がすこし違うので、こちらが使えます

#!/bin/sh
if [ $# -ne 2 ]; then
        echo "実行するには2個の引数が必要です。
        第一引数: 監視対象ファイル名
        第二引数: 監視対象ファイルが更新された際に実行されるコ>マンド
        例: ./autoexec.sh a.cpp 'g++ a.cpp && ./a.cpp'"
        exit 1
fi
echo "監視対象 $1"
echo "実行コマンド $2"
INTERVAL=1 #監視間隔, 秒で指定
last=`ls -l -T $1 | awk '{print $8}'`
while true; do
        sleep $INTERVAL
        current=`ls -l -T $1 | awk '{print $8}'`
        if [ $last != $current ] ; then
                echo ""
                echo "updated: $current"
                last=$current
                eval $2
        fi
done

不具合とかあったらご指摘ください。

第8回granpark.rb出題問題「銀将ご乱心」

恒例になってきたペアプロ課題出題。
今回は将棋の銀の動きがテーマです(、が問題設定自体は将棋のルールからだいぶ逸脱してます。)

スライドの解法は適切に切り分けることで問題を経路の場合の数を数え上げに
落としこむ感じです。

解法の補助線として1の場合の数を先に求めるようにするのもありだったかもしれません。

参加された各チームのコードはこちら
(Githubのお作法練習も兼ねて、branch -> 解けたらpush -> pullでやることにしました)

多分もっと良い解き方があるぜ!って人はぜひPULLリクエストを送ってください。

余談ですが、勉強会の最中、「コマ=インスタンス」とか「ショーギ=ボード」とか「アヴェイラブル=ギン」とかいう言葉が聞こえてきて、ニンジャめいた奥ゆかしいアトモスフィアを感じました。

//追記
答えは0.398%弱になるようです。
上記スライドを実装した回答コードはこんな感じです。
https://github.com/mizti/crazy_gin/blob/miz_answer_temp/a.cpp