Tezos operations: how to build, simulate and inject

This article explains the details how Tezos wallets originate (= deploy) smart contracts, without using any wallet, with a working OCaml code!

To read the code you have to be familar with OCaml.

The whole code is available at https://gitlab.com/dailambda/tezos-origination-demo.

RPC via JSON

JSON

We can access Tezos nodes via RPC and they talk in JSON over HTTP. Don’t confuse it with JSON-RPC.

Here is a small module Json to handle JSON data. It is based on Data_encoding. Tezos protocol provides lots of t Data_encoding.t to encode its data to+from JSON and binary and we use them in this example.

[続きを読む]

Nagoya Web3 Hackathon で Tezos のチュートリアルを行いました

I had “Block chain and how to build Tezos DApps” tutorial at Nagoya Web3 Hackathon organized by Nagoya Web3 Society, using SmartPy and Taquito. It was very challenging for me to cover from the very basics of blockchain to how to use these Tezos tools in a limited time (about 100mins), but the participated teams had smalll but nice ideas to implement in the later session.

先日、名古屋大学Web3研究会主催の Hackathon で Tezos で DApps を書くためのチュートリアルを行いました。

[続きを読む]

Tezos+Plebeia context subsystem benchmark

Introduction

As Tezos core developers, we DaiLambda and Tarides are working together to improve the perfomance of Tezos context: the version controlled store of Tezos block chain states.

DaiLambda has Plebeia, an append-only style data storage system based on Merkle Patricia binary tree. It is similar to Irmin by Tarides used for the Tezos context but incompatible. DaiLambda and Tarides have worked together to improve the performance of Tezos context subsystem, sometimes using what we have learned from Plebeia. For example, we provided the context tree for faster file access from the middle of the directory tree. Our context flattening done at Hangzhou upgrade speeded up the node by 30%. Recently, we have worked together to provide efficient Merkle proof encoding of Tezos context, using the idea of extender nodes of Plebeia, which will be used for the layer 2 solutions introduced in Tezos Jakarta upgrade.

[続きを読む]

Proposal of Micheline encoding optimization

Summary

The encoding of Micheline has several points to be improved. We propose to extend it to reduce the encoding size. Our quick survey shows that the possible size reduction is -22%.

The size reduction directly affects the storage burn fee. It should also improve the context disk access and reduces the storage access gas costs.

The new enconding is not yet implemented. The extension may have runtime overhead of the serialization but we expect it minimum.

[続きを読む]

Gradual migration to remove garbage files from Tezos context

Abstract

We are developing a technique of gradual migration to perform huge context modification at a protocol upgrade in multiple blocks to reduce the migration downtime ultimately to an unnoticeable level.

As the first example of this gradual migration, we plan to remove garbage files spendable left in 283K contract directories in Tezos mainnet. They should have been removed at the Babylone upgrade but some were left untouched until today.

[続きを読む]

Optz Michelson オプティマイザをリリースしました

Optz は Tezos ブロックチェーンのスマートコントラクトで使われている Michelson プログラムの最適化器です。 Optz は Michelson プログラムを入力として受け取り、(可能ならば)最適化を行って同じ動作をするより小さい、効率的な Michelson プログラムを出力します。

[続きを読む]

First release of Optz Michelson optimizer

We have released Optz, an optimizer of Michelson programs, the base language for Tezos smart contract. It takes a Michelson code as input and then returns a smaller and more efficient equivalent code.

Optimization of Michelson opcode sequences

The optimization consists of 2 parts: rule-based transformation and optimal stack manipulation search by A* algorithm.

Rule based code transformation
Dozens of rewriting rules replace opcodes with better ones, such as:
PAIR; CDR  =>  DROP
   
DIP n { a }; DIP n { b }  =>  DIP n { a; b }
   
SWAP; op  =>  op  # when op is a commutative binary operator
   
NOT; IF { a } { b }  =>  IF { b } { a }
Search for the optimal stack manipulation sequences
A* algorithm finds the most optimal sequence of stack manipulation opcodes such as DROP, SWAP, DIG, DUG, DIP, DUP, and the push only opcodes like PUSH and EMPTY_SET. For example, the following opcode sequence :
DIG 1; DUP 1; DUG 2; PUSH c0; DIG 2; PUSH c1; DIG 4

is replaced with a shorter equivalent one:

[続きを読む]

Optz: Michelson optimizer

Optz is an optimizer of Michelson programs, the base language for Tezos smart contract. It takes a Michelson code as input and then returns a smaller and more efficient equivalent code.

Optimization of Michelson opcode sequences

The optimization consists of 2 parts: rule-based transformation and optimal stack manipulation search by A* algorithm.

Rule based code transformation

Dozens of rewriting rules replace opcodes with better ones, such as:

PAIR; CDR  =>  DROP

DIP n { a }; DIP n { b }  =>  DIP n { a; b }

SWAP; op  =>  op  // when op is a commutative binary operator

NOT; IF { a } { b }  =>  IF { b } { a }

Search for the optimal stack manipulation sequences

After the rule-based transformation, A* algorithm finds the most optimal sequence of stack manipulation opcodes such as DROP, SWAP, DIG, DUG, DIP, DUP, CAR, CDR, PAIR, UNPAIR, and the push only opcodes like PUSH and EMPTY_SET. For example, the following opcode sequence found in an existing contract in Tezos mainnet:

[続きを読む]

Tezos via JSOO - 03, Structured value

This mini tutorial series shows how to access Tezos network from web browsers using JSOO, js_of_ocaml library. This is the 3rd tutorial. The previous tutorials are available at:

Structured value from Tezos RPC

In the last tutorial, we have got the balance of an account. Tezos account balance is returned as a JSON string like "12345678". We used JS’s JSON parser _JSON##parse to convert it to a JS string, then to an arbitrary precision integer Z.t.

[続きを読む]

Tezos via JSOO - 02, Account balance

This mini tutorial series shows how to access Tezos network from web browsers using JSOO, js_of_ocaml library. This is the second tutorial. The first one is available at:

Balance of an account

To get the balance of given account, we can use RPC endpoint

GET /chains/main/blocks/<block_id>/context/contracts/<contract_id>/balance

which is described here. Let’s get the balance of the account tz3RDC3Jdn4j15J7bBHZd29EUee9gVB1CxD9 via this RPC. Its URL is https://mainnet.smartpy.io/chains/main/blocks/head/context/contracts/tz3RDC3Jdn4j15J7bBHZd29EUee9gVB1CxD9/balance:

$ curl https://mainnet.smartpy.io/chains/main/blocks/head/context/contracts/tz3RDC3Jdn4j15J7bBHZd29EUee9gVB1CxD9/balance:
"423271651423"

It returns double-quoted string of an integer, the balance of the account in mutez, micro tez. Therefore the above tells us the account has 423,271,651,423 mutez, that is 423,271.651,423 tez.

[続きを読む]