Skip to content

Instantly share code, notes, and snippets.

@gokulsan
Last active May 21, 2019 23:27
Show Gist options
  • Save gokulsan/36facaaa5deaa9d37992685b9335fd7f to your computer and use it in GitHub Desktop.
Save gokulsan/36facaaa5deaa9d37992685b9335fd7f to your computer and use it in GitHub Desktop.
Tezos can instantiate any blockchain based protocol. Its seed protocol specifies a procedure for stakeholders to approve amendments to the proto- col, including amendments to the amendment procedure itself. Upgrades to Tezos are staged through a testing environment to allow stakeholders to recall potentially problematic amendments.
Tezos Transaction Management
A manager operation, such as a transaction, has 3 important parameters: counter, gas and storage limit.
The counter belongs to each account, it increases at each operation signed by that account and enforces some good intuitive properties:
In Tezos there are two kinds of accounts: implicit and originated.
The implicit accounts are the tz1 we have used up to now.
They are created with a transfer operation to the account public key hash. Originated accounts have addresses KT1 and are created with an origination operation.
A Michelson contract is semantically a pure function, mapping a pair (parameter, storage) to a pair (list_of_operations, storage). It can be seen equivalently as an object with a single method, and a single attribute.
The method updates the state (the storage), and submits operations as a side effect.
Tezos Implements a functional module based interface as a shell to the networking layer in a Blockchain.
Tezos demposes a Blockchain into the confluence of three protocols : networking, transaction and consensus protocols
A blockchain protocol is fundamentally a monadic implementation of concurrent mutations of a global state. This is achieved by defining “blocks” as operators acting on this global state. The free monoid of blocks acting on the genesis state forms a tree structure. A global, canonical, state is defined as the minimal leaf for a specified ordering.
Mining algorithms are an emergent property of the network, given the incentives for block creation.
Network shell acts as the interface between the gossip network and the protocol
Context module uses memory caching and disk storage to efficiently provide the apperance of an immutable store.
Tezos starts with a seed protocol
Generating Random Seed
Every block mined carries a hash commitment to a random number chosen by the miner. These numbers must be revealed in the next cycle under penalty of forfeiting the safety bond. This harsh penalty is meant to prevent selective whitholding of the numbers which could be sued to attack the entropy of the seed.
The origination operation may be used to create a new contract, it specifies the code of the contract and the initial content of the contract’s storage. If the handle is already the handle of an existing contract, the origination is rejected
The role of the counter is to prevent replay attacks. A transaction is only valid if the contract’s counter is equal to the transaction’s counter. Once a transaction is applied, the counter increases by one, preventing the transaction from being reused.
The transaction also includes the block hash of a recent block that the client considers valid. If an attacker ever succeeds in forcing a long reorganization with a fork, he will be unable to include such transactions, making the fork obviously fake.
The pair (account_handle, counter) is roughly the equivalent of an unspent output in Bitcoin.
To understand the economics of forks, one must first understand that monetary value is primarily a social consensus. It is tempting to equate a cryptocurrency with its rules and its ledger, but currencies are actually focal points: they draw their value from the common knowledge that they are accepted as money.
An attacker capable of changing social consensus controls the currency for all intents and purposes. The option to stick with the original protocol is widely irrelevant if the value of its tokens is annihilated by a consensus shift.
There is an even deeper problem with proof-of-work, one that is much harder to mitigate than the concentration of mining power: a misalignment of incentives between miners and stakeholders.
Shumpterian Creative Destruction
Proof-of-stake fixes these bad incentives by aligning the incentives of the miners and stakeholders: by very definition, the miners are the stakeholders, and are thus interested in keeping the transaction costs low. At the same time, because proof-of-stake mining is not based on destruction of resources, the trans- action cost (whether direct fees or indirect inflation) are entirely captured by miners, who can cover their operating costs without having to compete through wealth destruction.
Comparison of Smart Contracts in Bitcoin and Ethereum
Though Bitcoin does allow for smart contracts, most of its opcodes have been historically disabled and the possibilities are limited. Ethereum introduced a smart contract system with some critical differences: their scripting language is Turing complete and they substitute stateful accounts to Bitcoin’s unspent outputs.
Downside of Turing Complete Languages for Contracts
A downside of a Turing complete scripting language for the contracts is that the number of steps needed to execute a script is potentially unbounded, a property which is generally uncomputable.
Tezos Smart Contract Approach
Our solution is to cap the maximum number of steps that a program is allowed to run for in a single transaction. Since blocks have a size limit that caps the number of transactions per block, there is also a cap on the number of computation steps per block. This rate limitation foils CPU-usage denial-of- service attacks.
@gokulsan
Copy link
Author

In Tezos Blockchain, a protocol can be described by only two functions:

  • apply which takes a Context and a block and returns either a valid Context or an invalid result (should the block be invalid)
  • score which takes a Context and returns a score allowing us to compare various leafs of the blockchain to determine the canonical one. In Bitcoin, we would simply record the total difficulty or the chain inside the Context and return this value.

@gokulsan
Copy link
Author

Two important amending functions of the Tezos protocol:

  • set test protocol which replaces the protocol used in the test-net with a new protocol (typically one that has been adopted through a stakeholder voter).
  • promote test protocol which replaces the current protocol with the protocol currently being tested

@gokulsan
Copy link
Author

Future roadmap for the self amending protocols in Tezos can be described as :

While the seed protocol relies on a simple super-majority rule with a quorum, more complex rules can be adopted in the future. For instance, the stakeholders could vote to require certain properties to be respected by any future protocol. This could be achieved by integrating a proof checker within the protocol and requiring that every amendment include a proof of constitutionality.

@gokulsan
Copy link
Author

Transactions can reference blocks belonging to the canonical blockchain, thus implicitly signing the chain. An attacker attempting to forge a long reorganization can only produce transactions involving coins he controlled as off the last checkpoint.

@gokulsan
Copy link
Author

TAPOS - This family of techniques (often called TAPOS, for “transactions as proof of stake”) does not work well for short forks where the sample is too small to perform a reliable statistical test. However, they can be combined with a technique dealing with short term forks to form a composite selection algorithm robust to both type of forks.

@gokulsan
Copy link
Author

@gokulsan
Copy link
Author

gokulsan commented May 21, 2019

Lamtez - An ML-inspired smart contract language, compiling to Tezos' Michelson VM >> https://github.com/fab13n/lamtez

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment