Skip to content

Commit

Permalink
hotfix: Remove inappropriate example
Browse files Browse the repository at this point in the history
  • Loading branch information
ltfschoen committed Jan 31, 2018
1 parent 5f3e195 commit 1f87968
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 61 deletions.
55 changes: 19 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,16 @@ TENDERMINT-ELIXIR
* [X] Install Tendermint Core (BFT Consensus) in Go `tendermint --help`
* [X] Install Tendermint ABCI-CLI `abci-cli --help`
* [X] Create Boilerplate Elixir Tendermint Application
* [X] Load [Merkle Tree Elixir Library](https://github.com/yosriady/merkle_tree) with [Mix](https://elixirschool.com/en/lessons/basics/mix/) into Elixir Tendermint Application
* [X] Load [Merkle Tree Elixir Library](https://github.com/yosriady/merkle_tree) with [Mix](https://elixirschool.com/en/lessons/basics/mix/) into Elixir Tendermint Application. Merke Tree Erlang Library is used perform Merkle Proof Calculations to verify State-Replication https://github.com/yosriady/merkle_tree#usage
* [X] Load [Tendermint ABCI Server (Erlang)](https://github.com/KrzysiekJ/abci_server) with Mix into Elixir Tendermint Application
* [X] Run Elixir Tendermint Application (optionally using Interactive Elixir (IEx))
* [X] Start the Tendermint ABCI Server (Erlang)
* [X] Stop the Tendermint ABCI Server (Erlang)
* [X] Create Shell Script to generate Tendermint Testnet with four (4) Nodes `bash launch_testnet_nodes.sh`
* [.] Write Elixir Tendermint Application that implements the Tendermint ABCI (Application BlockChain Interface. Handle Byzantine Fault Tolerance (BFT) replication of the following State:
* [.] Root Hash `root_hash` is Pre-Agreed at Genesis and is Generated from the Merkle-Hash of an Array of Whitelisted Participants Addresses
* `whitelisted = ["a", "b", "c", "d"]`
* [.] Verification of the passing the "Ball" Transaction
* [.] Simulate the Act of passing a "Ball" around with a Transaction comprising `from`, `to`, `to_index`, `proof` fields
* [.] Verify before passing the "Ball" around using a succinct Merkle Proof Calculation that the Sender of the "Ball" in the `from` field of the Transaction actually held the "Ball" and is a Whitelisted Participants
* [.] Verify before passing the "Ball" around using a succinct Merkle Proof Calculation that the Recipient of the "Ball" in the `to` field of the Transaction is actually a Whitelisted Participant
* [ ] Verify before passing the "Ball" around using a succinct Merkle Proof Calculation that the Recipient of the "Ball" is at the Address of the `to_index` field of the Transaction and is proven by the `proof` field of the Transaction, which is a List of Hashes
* [ ] Verify using a succinct Merkle Proof Calculation that only a Single Whitelisted Participant is holding the "Ball" at a time
* [ ] Verify using a succinct Merkle Proof Calculation that the Recipient of the "Ball" is the Whitelisted Participant of the `to` field in the Transaction only after successful Validation of the passing the "Ball" Transaction
* [.] Verify that only the Merke Tree Erlang Library is implemented to perform succinct Merkle Proof Calculations to demonstrate State-Replication https://github.com/yosriady/merkle_tree#usage
* [.] Verify that State-Replication of the Whitelisted Participant Addressses (`whitelisted`) is only performed on the Merkle Tree `root_hash` and not verbosely
* [ ] Write Functions to handle calls for `CheckTx` and `DeliverTx` in Elixir
* [ ] Write Stubs for Tendermint Commits, Inits, BeginBlocks, EndBlocks, and Infos if necessary
* [ ] Generate Documentation with [ExDoc](https://github.com/elixir-lang/ex_doc) and published on [HexDocs](https://hexdocs.pm)
* [ ] Release on Github with ZIP file
* [ ] Publish on [Hex](https://hex.pm/docs/publish)
* [ ] Create Elixir ABCI Application and processes ABCI-CLI (Tendermint Client) and cURL requests to say the `broadcast_tx_commit` endpoint of the Tendermint ABCI (Tendermint's server-side Application BlockChain Interface API) that uses the Tendermint Core, which is a Byzantine Fault Tolerance (BFT) Blockchain Engine Middlware that processes a State Transition machine input from any language (i.e. Elixir) and replicates it on many Tendermint Testnet Nodes as output. Successful transactions are included in the Mempool, broadcast to Peers, and eventually committed in a Block with the return value containing `check_tx` and `deliver_tx` properties (each containing `data` and `log` sub-properties) to signify that the transaction was run through the CheckTx and DeliverTx ABCI messages of the TMSP (Simple Messaging Protocol)
* [ ] Implement the Merkle Tree Elixir Library example code https://github.com/yosriady/merkle_tree#usage
* [ ] Generate Documentation with [ExDoc](https://github.com/elixir-lang/ex_doc) and published on [HexDocs](https://hexdocs.pm)
* [ ] Publish on [Hex](https://hex.pm/docs/publish)

# Installation (of Elixir and Tendermint)<a id="chapter-2"></a>

Expand Down Expand Up @@ -285,15 +272,15 @@ TENDERMINT-ELIXIR

* Send cURL Request to ABCI Server endpoint.
```
curl -s 'localhost:46658/broadcast_tx_commit?tx="from=___&to=___&to_index=___&proof=___"'
curl -s 'localhost:46658/broadcast_tx_commit?tx="sender=___&receiver=___&data=___"'
```

* View Logs from ABCI Server in IEx Terminal Window. Shows Outputs of `handle_request` function in Elixir ABCI App
```
iex(1)> BlockchainTendermint.start_server
{:ok, #PID<0.168.0>}
iex(2)> Processing Transaction
Received Arguments to handle_request: "from=a&to=b&to_index=0&proof=''"
Received Arguments to handle_request: "sender=a&receiver=b&data=''"
58c89d709329eb37285837b042ab6ff72c7c8f74de0446b091b6a0131c102cfd
Validity of Transaction: true
Expand Down Expand Up @@ -799,7 +786,7 @@ https://tendermint.readthedocs.io/en/master/how-to-read-logs.html
* After `timeoutProposer` -> Step 2
* After `PoLC Round` receipt of Proposal Block and all Prevotes -> Step 2
* After "Common Exit Conditions"
* QUESTION - HOW? ALL THE COMMON EXIT CONDITIONS ARE POST- STEP 1
* Question Raised - How does this make sense when all the common exit conditions occur after "Step 1"
* https://matrix.to/#/!vIMgGaMqkLIWPCZvPF:matrix.org/$15167017365754249pwRYF:matrix.org
* Step 2: `Prevote (H, R)`
* Start:
Expand Down Expand Up @@ -939,11 +926,8 @@ https://tendermint.readthedocs.io/en/master/how-to-read-logs.html

* TODO
* Proof of Fork Accountability - https://github.com/tendermint/tendermint/wiki/Byzantine-Consensus-Algorithm#proof-of-fork-accountability

* Alternative Algorithm - https://github.com/tendermint/tendermint/wiki/Byzantine-Consensus-Algorithm#alternative-algorithm

* Censorship Attacks - https://github.com/tendermint/tendermint/wiki/Byzantine-Consensus-Algorithm#censorship-attacks

* Overcoming Forks and Censorship Attacks - https://github.com/tendermint/tendermint/wiki/Byzantine-Consensus-Algorithm#overcoming-forks-and-censorship-attacks

* Benefits:
Expand Down Expand Up @@ -996,20 +980,19 @@ https://tendermint.readthedocs.io/en/master/how-to-read-logs.html
# References <a id="chapter-14"></a>

* Tendermint
* TODO
* TODO - TendermintCore Wiki - https://github.com/tendermint/tendermint/wiki/
* TODO - Application Developers Guide - https://github.com/tendermint/tendermint/wiki/Application-Developers
* TODO - Byzantine Consensus Algorithm - https://github.com/tendermint/tendermint/wiki/Byzantine-Consensus-Algorithm
* TODO - Tendermint Documentation - https://tendermint.readthedocs.io/en/master/getting-started.html
* TODO - Tendermint Documentation Release - https://media.readthedocs.org/pdf/tendermint/master/tendermint.pdf
* TODO - Tendermine: BFT in the Age of Blockchains - https://allquantor.at/blockchainbib/pdf/buchman2016tendermint.pdf
* TODO - Cosmos usage of Tendermint
* https://cosmos.network/about/whitepaper
* https://cosmos.network/about/faq
* TODO - Merkle Tree Proof Calculation and Checking - https://github.com/yosriady/merkle_tree
* TendermintCore Wiki - https://github.com/tendermint/tendermint/wiki/
* Application Developers Guide - https://github.com/tendermint/tendermint/wiki/Application-Developers
* Byzantine Consensus Algorithm - https://github.com/tendermint/tendermint/wiki/Byzantine-Consensus-Algorithm
* Tendermint Documentation - https://tendermint.readthedocs.io/en/master/getting-started.html
* Tendermint Documentation Release - https://media.readthedocs.org/pdf/tendermint/master/tendermint.pdf
* Tendermine: BFT in the Age of Blockchains - https://allquantor.at/blockchainbib/pdf/buchman2016tendermint.pdf
* Cosmos usage of Tendermint
* https://cosmos.network/about/whitepaper
* https://cosmos.network/about/faq
* Merkle Tree Proof Calculation and Checking - https://github.com/yosriady/merkle_tree

* Erlang
* TODO - Erlang Standard Library - http://erlang.org/doc/apps/stdlib/index.html
* Erlang Standard Library - http://erlang.org/doc/apps/stdlib/index.html

# Unsorted Notes <a id="chapter-15"></a>

Expand Down
47 changes: 23 additions & 24 deletions blockchain_tendermint/lib/blockchain_tendermint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ defmodule BlockchainTendermint do
end

@doc """
Starts the ABCI Server (Erlang) on given Port and delegates calls to Foo module
Starts the ABCI Server (Erlang) on given Port and delegates calls to BlockchainTendermint module
that has not yet been implemented
References:
- https://github.com/KrzysiekJ/abci_server/blob/master/doc/overview.edoc
Expand Down Expand Up @@ -61,13 +62,14 @@ defmodule BlockchainTendermint do
{:ok, true}
"""
# Default args using \\
def handle_request(tx_args \\ "from=a&to=b&to_index=0&proof=''") do
def handle_request(tx_args \\ "sender=a&receiver=b&data=''") do
# Important Note: Value of `inspect tx_args` is `{:RequestInfo, '0.15.0'}`
# Temporarily override value of `tx_args`
tx_args =
if tx_args === {:RequestInfo, '0.15.0'}, do: "from=a&to=b&to_index=0&proof=''"
IO.puts("Elixir ABCI Application Processing Transaction")
# Temporarily override value of `tx_args` for demonstration purposes only
IO.puts("handle_request Received Arguments: #{inspect tx_args}")
tx_args =
if tx_args === {:RequestInfo, '0.15.0'} || "", do: "sender=a&receiver=b&data=''"
IO.puts("Elixir ABCI Application Simulation")
IO.puts("handle_request Override Arguments: #{inspect tx_args}")

# Send Transaction to Tendermint Node via the `broadcast_tx_commit` Endpoint.
# Note: Tendermint Node will run via CheckTx against the Elixir ABCI Application.
Expand All @@ -78,10 +80,10 @@ defmodule BlockchainTendermint do
# The return value includes `check_tx` and `deliver_tx`, which is result of running the
# transaction through those ABCI messages
# - Option 1 (Preferred) - Use cURL to send ABCI requests from the CLI
# i.e. curl -s 'localhost:46658/broadcast_tx_commit?tx="from=___&to=___&to_index=___&proof=___"'
# i.e. curl -s 'localhost:46658/broadcast_tx_commit?tx="sender=a&receiver=b&data=''"'
# - Option 2 - Use ABCI-CLI to send ABCI requests from the CLI
#
# Note: Transaction with bytes "from=___&to=___&to_index=___&proof=___" are stored as Key and
# Note: Transaction with bytes "sender=a&receiver=b&data=''" are stored as Key and
# Value in Merkle Tree

# Reference:
Expand All @@ -108,11 +110,8 @@ defmodule BlockchainTendermint do
# }
# }

# Destructure Transaction Key/Value pairs from tx_args "from=___&to=___&to_index=___&proof=___"

# Simulate Generation of the Genesis Block whose Root Hash `root_hash` (32 Bytes) is:
# - Pre-Agreed at Genesis
# - Initial Data Blocks are the Array of Whitelisted Participant Addresses
# Simulate Generation of the Genesis Block with Root Hash `root_hash`:
# - Initial Data Blocks are assigned an Array
# - Generate Merkle Tree by:
# - Creating a Leaf Nodes from Merkle-Hashing (with the Merkle Tree's hash_function) each Data Block
# - Recursively Build each Parent Node Hash from Hashing the Concatenation of their immediate
Expand All @@ -122,14 +121,14 @@ defmodule BlockchainTendermint do
# - Verify that Transaction from only the Block Headers and Merkle Tree Root Hash
# - Reference: https://yos.io/2016/05/19/merkle-trees-in-elixir/

# Data Blocks
whitelisted_participants = ["a", "b", "c", "d"]
# Initial Data Blocks
my_merkle_tree = ["a", "b", "c", "d"]
# Genesis Block Header - https://github.com/tendermint/tendermint/wiki/Block-Structure#header
block_0_merkle_tree = MerkleTree.new whitelisted_participants
block_0_merkle_tree = MerkleTree.new my_merkle_tree
block_0_merkle_tree_root = block_0_merkle_tree.root()
# Genesis Block Merkle Tree Root Hash (LastBlockHash)
block_0_merkle_tree_root_hash = block_0_merkle_tree_root.value
IO.puts block_0_merkle_tree_root_hash
IO.puts ("Genesis Block Merkle Tree Root Hash (LastBlockHash): #{block_0_merkle_tree_root_hash}")

# Genesis Block Merkle Proof
# - Reference: https://blog.ethereum.org/2015/11/15/merkling-in-ethereum/
Expand All @@ -144,20 +143,20 @@ defmodule BlockchainTendermint do
block_0_merkle_proof_chunk_path_branch_3
]

# Simulate Receipt of Transaction: "from=___&to=___&to_index=___&proof=___"
# Simulate Receipt of Transaction: "sender=a&receiver=b&data=''"
# - Convert Query String Parameters into Key/Value Pairs
# FIXME - Should expect "from='a',..."
# FIXME - Should expect "sender='a',..."
# FIXME - Convert Map to Stringified for `proof=#{block_0_merkle_proof}`
# - https://gist.github.com/ltfschoen/749a5c141fa3536a5e678757d0022c7a
tx_args_map = String.split(tx_args, ~r/&|=/)
|> Enum.chunk(2)
|> Map.new(fn [k, v] -> {k, v} end)

# Verify using a succinct Merkle Proof Calculation that the Sender in the `from` field of the
# Transaction is a Whitelisted Participants. Note: Non-Validators have `seed: ""` in genesis.json
# Verify using a Merkle Proof Calculation that the Sender in the `sender` field of the
# Transaction was in the Initial Data Blocks. Note: Non-Validators have `seed: ""` in genesis.json
proven_from_sender_field = Enum.any?(block_0_merkle_proof, fn(block_0_merkle_proof_chunk_path_branch) ->
MerkleTree.Proof.proven?(
{tx_args_map["from"], 0}, # If `from=a` then use 0, else if `from=b` then use 1, etc
{tx_args_map["sender"], 0}, # If `sender=a` then use 0, else if `sender=b` then use 1, etc
block_0_merkle_tree_root_hash,
block_0_merkle_proof_chunk_path_branch
)
Expand All @@ -172,10 +171,10 @@ defmodule BlockchainTendermint do
# )

# Verify using a succinct Merkle Proof Calculation that the Recipient in the `to` field of the
# Transaction is a Whitelisted Participants.
# Transaction was from the Initial Data Blocks.
proven_to_recipient_field = Enum.any?(block_0_merkle_proof, fn(block_0_merkle_proof_chunk_path_branch) ->
MerkleTree.Proof.proven?(
{tx_args_map["to"], 1}, # If `from=a` then use 0, else if `from=b` then use 1, etc
{tx_args_map["receiver"], 1}, # If `from=a` then use 0, else if `from=b` then use 1, etc
block_0_merkle_tree_root_hash,
block_0_merkle_proof_chunk_path_branch
)
Expand Down
2 changes: 1 addition & 1 deletion blockchain_tendermint/test/blockchain_tendermint_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule BlockchainTendermintTest do
use ExUnit.Case
doctest BlockchainTendermint

test "verifies that sender and recipient of a transaction are from genesis whitelist" do
test "verifies that handle_request processes a request" do
assert BlockchainTendermint.handle_request("") == {:ok, true}
end
end

0 comments on commit 1f87968

Please sign in to comment.