無知

갈 길이 먼 공부 일기

기술 공부/블록체인

스마트 컨트랙트 (11) | Tezos, 테조스

moozii 2022. 6. 1. 17:38

 

https://tezos.com/tez/tez-banner.jpg

 

Tezos의 역사

 

Backroom battle imperils $230 million cryptocurrency venture

By Anna Irrera, Steve Stecklow and Brenna Hughes Neghaiwi
Filed Oct. 18, 2017, 11 p.m. GMT


The people running a blockchain computer project called Tezos staged a hugely successful fundraiser in July. But its central players are waging a bitter feud over control that threatens to derail one of the biggest-ever digital currency offerings.

Just three months ago, a tech project called Tezos raised $232 million online in a wildly successful “initial coin offering,” in which new digital currency is parceled out to buyers. At the time, it was the most money ever raised from the public in the white-hot cryptocurrency sector.

The acrimonious dispute pits Tezos’ two young founders – Arthur and Kathleen Breitman – against Johann Gevers, the president of a Swiss foundation the couple helped establish to handle the coin offering and promote and develop the Tezos computer network.

...

Arthur Breitman, 35, was an early fan of bitcoin, which first appeared around 2009. But he came to believe there were flaws in the blockchains behind bitcoin and other cryptocurrencies, finding them hard to upgrade and not secure. He tried to come up with something better. In the summer of 2014, while working at Morgan Stanley in quantitative finance, Breitman released two papers online that presented his concept for a new type of blockchain. He called it Tezos, a name his wife has said he coined after creating an algorithm that searched for the names of unclaimed websites pronounceable in English. The papers were published under a pseudonym, “L. M Goodman,” but emails and messages from Arthur Breitman reviewed by Reuters make it clear he was the author.

In an email Breitman sent to an acquaintance in early 2015, he said he was seeking to create a business based on Tezos but was trying not to be associated publicly with the project at the time. He expressed worry that his activities might conflict with his employment at Morgan Stanley, messages show.

...

In 2015, Arthur Breitman was pitching “Tezos Inc.” in the hope of creating a consortium of four to five banks to adopt the technology and fund the operation. The business plan reviewed by Reuters called for raising $5 million to $10 million over two to three years. By then, blockchain was beginning to pique the interest of large financial institutions for its potential to help cut costs of cumbersome back-office processes, such as the clearing and settlement of securities trades. Tezos’ 37-page business plan called it “an Internet for financial transactions” and said the technology could be used to automate the over-the-counter derivatives trading market. But Breitman failed to attract backers. He told Reuters in June that he blamed his fundraising failures on the decision to develop the technology first, rather than just selling “a dream” as other blockchain startups were doing.

...

In April 2016, Arthur left Morgan Stanley, and by that September, the Breitmans had started working on a new strategy for Tezos – to conduct an online fundraiser to distribute digital tokens, whose holders would maintain the Tezos blockchain. But the couple needed funds to keep the project going. Over the next six months, they received $612,000 from 10 early backers, including several cryptocurrency hedge funds, according to the Tezos.com website. To conduct the ICO, the Breitmans chose a complex structure. Earlier this year, they helped to create a foundation based in Zug, Switzerland – dubbed “Crypto Valley” because of its many blockchain startups – that is seeking not-for-profit status, emails show. The idea, according to documents on the Tezos website, was that the foundation would raise money via the ICO, then acquire DLS, the Breitman-controlled company that has been developing Tezos. Working through a Swiss foundation, the Breitmans thought, would provide regulatory oversight but not too much. Kathleen Breitman told Reuters in June that she and her husband opted to use a foundation based in Zug because Switzerland has “a regulatory authority that had a sufficient amount of oversight but not like anything too crazy.”

...

The Tezos fundraiser began on July 1. The Breitmans had wide-ranging expectations about how much they might raise. A document on Tezos.com suggested that if they received more than $20 million, they might use it to “negotiate with a small nation-state” to adopt Tezzies, or acquire mainstream print and TV media outlets to promote the technology. In June, Kathleen Breitman told Reuters that about a year ago, when the price of bitcoin was lower, “we were like, ‘Hey, we would be lucky if we get 20 million.’” When it ended after 13 days, the project received about 66,000 bitcoins and 361,000 ethers, worth about $232 million at the time. The hoard is now worth about twice that.

...

Gevers, who founded the Tezos Foundation, said it has a contract that stipulates the Breitmans will either sell the Delaware company to the foundation “within a reasonable point of time” or, if they don’t, “the foundation can take it.” He declined to provide a copy of the contract. When the foundation will acquire the Breitmans’ company remains unclear. Kathleen Breitman told Reuters in June, “Essentially, you know, they’re going to buy out the company in like July or so, I guess.” The Breitmans stand to receive millions of dollars if the deal goes through. According to the “Transparency Memo,” the new blockchain “must launch and operate successfully” for three months, then DLS’s shareholders – the Breitmans and Draper – are entitled to receive 8.5 percent of the fundraiser proceeds in cash. That amount, according to Gevers, is about $19.7 million. The shareholders also are slated to receive another 10 percent of the Tezzies issued, with the coin distribution spread out over four years. Those coins currently are worth about $140 million in futures trading. Prior to the fundraiser, Kathleen Breitman effused about Gevers, 52, a Zug-based South African entrepreneur who has never before run a foundation. During an “Ask Me Anything” session in May on an online chat channel, she posted: “He’s awesome. Total mensch and very philosophically committed to our project.” Relations later soured. The Breitmans objected to people the foundation suggested it wanted to hire, Gevers said. Another sticking point: The couple’s company hasn’t relinquished control over the foundation’s own website, www.tezos.ch. “They control the foundation’s domains, websites and email servers, so the foundation has no control or confidentiality in its own communications,” Gevers said.

https://www.reuters.com/investigates/special-report/bitcoin-funding-tezos/

 

Backroom battle imperils $230 million cryptocurrency venture

The people behind blockchain computer project Tezos raised millions in July. But they are now waging a bitter feud that threatens to derail their plans.

www.reuters.com

 

 

Tezos Position Paper |
Tezos: A Self-Amending Crypto-Ledger Position Paper

"Laissez faire les propriétaires." -- Pierre-Joseph Proudhon

The popularization of Bitcoin, a decentralized crypto-currency has inspired the production of several alternative, or “alt”, currencies. Ethereum, CryptoNote, and Zerocash all represent unique contributions to the cryptocurrency space. Although most alt currencies harbor their own source of innovation, they have no means of adopting the innovations of other currencies which may succeed them. We aim to remedy the potential for atrophied evolution in the crypto-currency space by presenting Tezos, a generic and self-amending crypto-ledger.

Tezos can instantiate any blockchain based protocol. Its seed protocol specifies a procedure for stakeholders to approve amendments to the protocol, including amendments to the amendment procedure itself. Upgrades to Tezos are staged through a testing environment to allow stakeholders to recall potentially problematic amendments.

The philosophy of Tezos is inspired by Peter Suber’s Nomic, a game built around a fully introspective set of rules. In this paper, we hope to elucidate the potential benefits of Tezos, our choice to implement as a proof-of-stake system, and our choice to write it in OCaml.

In our development of Tezos, we aspire to address four problems we perceive with Bitcoin:
- The “hard fork” problem, or the inability for Bitcoin to dynamically innovate due to coordination issues.
- Cost and centralization issues raised by Bitcoin’s proof-of-work system.
- The limited expressiveness of Bitcoin’s transaction language, which has pushed smart contracts onto other chains.
- Security concerns regarding the implementation of a crypto-currency.

...
Tezos can implement any type of blockchain algorithm: proof-of-work, proof-of-stake, or even centralized. Due to the shortcomings of the proof-of-work mechanism, the Tezos seed protocol implements a proof-of-stake system. There are considerable theoretical hurdles to designing a working proof-of-stake systems, we will explain our way of dealing with them.
...
Robin Hanson has proposed that we vote on values and bet on beliefs. He calls such a system “Futarchy”. The main idea is that values are best captured by a majoritarian consensus while the choice of policies conducive to realizing those values is best left to a prediction market. This system can quite literally be implemented in Tezos. Stakeholders would first vote on a trusted datafeed representing the satisfaction of a value. This might be, for example, the exchange rate of coins against a basket of international currencies. An internal prediction market would be formed to estimate the change in this indicator conditional on various code amendments being adopted. The market-making in those contracts can be subsidized by issuing coins to market makers in order to improve price discovery and liquidity. In the end, the amendment deemed most likely to improve the indicator would be automatically adopted.
...
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. While emphasis has been put on the Turing complete aspect of the language, the second property is by far the most interesting and powerful of the two. In Bitcoin, an output can be thought of as having only two states: spent and unspent. In Ethereum, accounts (protected by a key) hold a balance, a contract code and a data store. The state of an account’s storage can be mutated by making a transaction towards this account. The transaction specifies an amount and the parameters passed to the contract code. (...) 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-ofservice attacks. Meanwhile, legitimate users can issue multiple transactions to compute more steps than allowed in a single transaction, though at a limited rate. Miners may decide to exclude too long of an execution if they feel the included fee is too small. Since the Tezos protocol is amendable, the cap can be increased in future revisions and new cryptographic primitives included in the scripting language as the need develops.
...
Fortunately, Bitcoin’s implementation has proven very resilient to attacks thus far, with some exceptions. In August 2010, a bug where the sum of two outputs overflowed to a negative number allowed attackers to create two outputs of 92233720368.54 coins from an input of 0.50 coins. More recently, massive vulnerabilities such as the heartbleed bug have been discovered in the OpenSSL libraries. These vulnerabilities have one thing in common, they happened because languages like C and C++ do not perform any checks on the operations they perform. For the sake of efficiency, they may access random parts of the memory, add integers larger than natively supported, etc. While these vulnerabilities have spared Bitcoin, they do no not bode well for the security of the system. Other languages do not exhibit those problems. OCaml is a functional programming language developed by the INRIA since 1996 (and itself based on earlier efforts). Its speed is comparable to that of C++ and it generally features among the fastest programming languages in benchmarks. More importantly, OCaml is strongly typed and offers a powerful type inference system. Its expressive syntax and semantics, including powerful pattern matching and higher-order modules, make it easy to concisely and correctly describe the type of logic underpinning blockchain based protocols.
...

https://wiki.tezosagora.org/positionpaper 
 

Tezos Position Paper - Tezos Agora Wiki

Fortunately, Bitcoin’s implementation has proven very resilient to attacks thus far, with some exceptions. In August 2010, a bug where the sum of two outputs overflowed to a negative number allowed attackers to create two outputs of 92233720368.54 coins

wiki.tezosagora.org

 

 

What is Tezos?

Tezos is an open-source platform for assets and applications that can evolve by upgrading itself. Stakeholders govern upgrades to the core protocol, including upgrades to the amendment process itself.

Self-Amendment
Self-amendment allows Tezos to upgrade itself without having to split (“fork”) the network into two different blockchains. This is important as the suggestion or expectation of a fork can divide the community, alter stakeholder incentives, and disrupt the network effects that are formed over time. Because of self-amendment, coordination and execution costs for protocol upgrades are reduced and future innovations can be seamlessly implemented.

On-Chain Governance
In Tezos, all stakeholders can participate in governing the protocol. The election cycle provides a formal and systematic procedure for stakeholders to reach agreement on proposed protocol amendments. By combining this on-chain mechanism with self-amendment, Tezos can change this initial election process to adopt better governance mechanisms when they are discovered.

Decentralized Innovation
Proposed amendments that are accepted by stakeholders can include payment to individuals or groups that improve the protocol. This funding mechanism encourages robust participation and decentralizes the maintenance of the network. Fostering an active, open, and diverse developer ecosystem that is incentivized to contribute to the protocol will facilitate Tezos development and adoption.

Smart Contracts & Formal Verification
Tezos offers a platform to create smart contracts and build decentralized applications that cannot be censored or shut-down by third parties. Furthermore, Tezos facilitates formal verification, a technique used to improve security by mathematically proving properties about programs such as smart contracts. This technique, if used properly, can help avoid costly bugs and the contentious debates that follow.

Proof-of-Stake (PoS)
Participants (“nodes”) in decentralized, peer-to-peer networks provide the necessary computational resources that keep a network up and running. Proof-of-Stake (PoS) is the mechanism by which the various participants in Tezos reach consensus on the state of the blockchain. Unlike other PoS protocols, any stakeholder can participate in the consensus process in Tezos and be rewarded by the protocol itself for contributing to the security and stability of the network. Additionally, PoS is less costly than other consensus mechanisms and lowers the barriers to entry for involvement.

Delegation
In PoS, a security deposit is required to participate in the consensus process and avoid being diluted by inflation. As in proof-of-work, the consensus protocol relies on an honest majority for its security which is incentivized directly by the Tezos protocol by penalizing dishonest behavior and rewarding honest behavior. If a participant behaves dishonestly, they can lose their deposit. Users who do not wish to participate directly in the consensus protocol have the option to delegate their rights to other users to participate on their behalf.

https://tezos.com/learn/what-is-tezos/ 
 

Tezos: A blockchain designed to evolve

Tezos is an open-source platform that addresses key barriers facing blockchain adoption for assets and applications, backed by a global community of validators, researchers, and builders.

tezos.com

 

 

 

 

 

Tezos 스마트 컨트랙트

 

Smart Contracts on Tezos

Tezos offers a platform to create smart contracts and build decentralized applications that cannot be censored or shut-down by third parties. Furthermore, Tezos facilitates formal verification, a technique used to improve security by mathematically proving properties about programs such as smart contracts. Formal verification methods are commonly used in mission-critical environments including aerospace, nuclear, and semiconductor industries where unexpected code behavior can have tragic and costly consequences.

...

Tezos has several popular high-level languages which offer more approachable syntaxes and familiar developer experience (e.g. local variables) compared to writing Michelson directly. While Michelson is the domain-specific smart contract language that was developed for Tezos, SmartPy and LIGO are the most popular and widely-supported languages for writing Tezos smart contracts.

https://wiki.tezosagora.org/learn/smartcontracts 
 

Smart Contracts on Tezos - Tezos Agora Wiki

Smart contracts are programs that are stored on the blockchain. Once a pre-defined condition in the code is met, the smart contract will execute its functions. While this may sound no different than regular code, the key distinction is that following execu

wiki.tezosagora.org

 

 

Michelson

Michelson is the domain-specific language used to write smart contracts on the Tezos blockchain. Michelson is a stack-based language and does not have variables. Stack-oriented languages operate on one or more stacks, each of which may serve a different purpose.

Michelson is a low-level, stack-based programming language used to write smart contracts on the Tezos blockchain. Michelson was designed to facilitate formal verification, allowing users to prove the properties of their contracts.

It uses a stack rewriting paradigm, whereby each function rewrites an input stack into an output stack. (The meaning of this will be fully explained below.) This runs in a purely functional way and does not modify the inputs at all. Thus, all data structures are immutable.

https://wiki.tezosagora.org/learn/smartcontracts/michelson 
 

Michelson - Tezos Agora Wiki

To see what mean it means to rewrite stacks, we will run through a transaction in Michelson. First, before a transaction runs, the blockchain state at a certain hash is deserialized and put onto the stack as the variable storage. We have a from function th

wiki.tezosagora.org

 

 

Michelson: the language of Smart Contracts in Tezos

This specification gives a detailed formal semantics of the Michelson language and a short explanation of how smart contracts are executed and interact in the blockchain.

The language is stack-based, with high level data types and primitives, and strict static type checking. Its design cherry picks traits from several language families. Vigilant readers will notice direct references to Forth, Scheme, ML and Cat.

A Michelson program is a series of instructions that are run in sequence: each instruction receives as input the stack resulting from the previous instruction, and rewrites it for the next one. The stack contains both immediate values and heap allocated structures. All values are immutable and garbage collected.

The types of the input and output stack are fixed and monomorphic, and the program is typechecked before being introduced into the system. No smart contract execution can fail because an instruction has been executed on a stack of unexpected length or contents.

This specification gives the complete instruction set, type system and semantics of the language. It is meant as a precise reference manual, not an easy introduction. Even though, some examples are provided at the end of the document and can be read first or at the same time as the specification. The document also starts with a less formal explanation of the context: how Michelson code interacts with the blockchain.


Semantics of smart contracts and transactions

The Tezos ledger currently has two types of accounts that can hold tokens (and be the destinations of transactions).
- An implicit account is a non programmable account, whose tokens are spendable and delegatable by a public key. Its address is directly the public key hash, and starts with tz1, tz2 or tz3. A smart contract is a programmable account.
- A transaction to such an address can provide data, and can fail for reasons decided by its Michelson code. Its address is a unique hash that depends on the operation that led to its creation, and starts with KT1.
From Michelson, they are indistinguishable. A safe way to think about this is to consider that implicit accounts are smart contracts that always succeed to receive tokens, and does nothing else.


Intra-transaction semantics

Alongside their tokens, smart contracts keep a piece of storage. Both are ruled by a specific logic specified by a Michelson program. A transaction to a smart contract will provide an input value and in option some tokens, and in return, the smart contract can modify its storage and transfer its tokens.

The Michelson program receives as input a stack containing a single pair whose first element is an input value and second element the content of the storage space. It must return a stack containing a single pair whose first element is the list of internal operations that it wants to emit, and second element is the new contents of the storage space. Alternatively, a Michelson program can fail, explicitly using a specific opcode, or because something went wrong that could not be caught by the type system (e.g. gas exhaustion).

A bit of polymorphism can be used at contract level, with a lightweight system of named entrypoints: instead of an input value, the contract can be called with an entrypoint name and an argument, and these two components are transformed automatically in a simple and deterministic way to an input value. This feature is available both for users and from Michelson code. See the dedicated section.


Inter-transaction semantics

An operation included in the blockchain is a sequence of “external operations” signed as a whole by a source address. These operations are of three kinds:
1. Transactions to transfer tokens to implicit accounts or tokens and parameters to a smart contract (or, optionally, to a specified entrypoint of a smart contract).
2. Originations to create new smart contracts from its Michelson source code, an initial amount of tokens transferred from the source, and an initial storage contents.
3. Delegations to assign the tokens of the source to the stake of another implicit account (without transferring any tokens).
Smart contracts can also emit “internal operations”. These are run in sequence after the external transaction completes, as in the following schema for a sequence of two external operations.

Smart contracts called by internal transactions can in turn also emit internal operation. The interpretation of the internal operations of a given external operation uses a stack, as in the following example, also with two external operations.

https://tezos.gitlab.io/active/michelson.html 
 

Michelson: the language of Smart Contracts in Tezos — Tezos (master branch, 2022/06/01 08:08) documentation

The specification up to this point has been mostly ignoring existence of entrypoints: a mechanism of contract level polymorphism. This mechanism is optional, non intrusive, and transparent to smart contracts that don’t use them. This section is to be rea

tezos.gitlab.io

 

 

테조스 세 가지 특징

1. 프로토콜이 갖고 있는 “스스로 변경해갈 수 있는 능력”.

온체인 선거를 통해서 좋은 알고리즘이 나오면 쉽게 새로운 알고리즘으로 변경 가능.


2. Proof-of-stake

더 많은 지분을 갖고 있을수록 그에 비례해서 블록에 기록할 권한이 더 많이 부여되고 블록을 생성하면서 보상을 받게 되는 합의 알고리즘. 대신에 보증금을 걸어놓고 그 블록이 거짓으로 작성되면 보증금을 잃게 되는데 지분이 많을수록 잃어버리는 보증금도 많아지기 때문에 역설적으로 더 안전할 수 있다는 장점


3. 스마트 컨트랙트
- 정적 타입이며 함수형 언어를 사용하는 스마트 컨트랙트 Virtual Machine을 사용해 개발자들이 좀 더 읽기 편하고 검증도 가능한 환경을 제공

- 테조스에서는 개발자가 읽기 쉬운 형태로 코드가 생성. 이는 사람뿐만 아니라 다른 분석 도구를 통해 검증하기에도 용이한 특징

 


테조스에서의 스마트 컨트랙트

- 스마트 컨트랙트 = 암호화폐 tez를 담고 있는 어카운트.

- typed storage, typed parameter, typed script가 첨부

- typed storage란 미리 지정해둔 storage의 type
- 마찬가지로 parameter와 script 모두 type이 존재
- script의 경우는 순수 함수로 side-effect가 없음
- 컨트랙트는 Michelson(미켈슨) programming language로 구현

 

Michelson

- 정적 타입 언어로 타입을 명세

- 다른 함수형 언어처럼 type inference engine을 통해서 타입을 명세하지 않아도 시스템이 알아서 타입을 찾아줄 수도 있지만 이런 inference engine을 blockchain 안에서 실행하려면 gas 비용이 늘어가기 때문에 inference engine을 구현하는 대신에 간단한 타입 checking system을 구현하고 있습니다.
- Michelson은 스택 언어이고 이더리움 VM 바이트코드에 해당하지만, 가변형 정수 타입이나 map, lambda 같은 여러 고급 abstraction들을 제공



 

 

 

LIGO, Tezos Integration

 

LIGO

LIGO is a programming language for Tezos with support for different syntaxes:

- CameLIGO, an OCaml inspired syntax
- ReasonLIGO, a functional JavaScript-like syntax inspired by ReasonML
- PascaLIGO, a Pascal inspired syntax

These syntaxes are transformed into an intermediate representation, which is type checked and efficiently translated into Michelson.

https://wiki.tezosagora.org/learn/smartcontracts/ligo 
 

LIGO - Tezos Agora Wiki

These syntaxes are transformed into an intermediate representation, which is type checked and efficiently translated into Michelson.

wiki.tezosagora.org

 

 

Introduction to LIGO

LIGO is a programming language for writing Tezos smart contracts. Smart contracts are a unique domain with extreme resource constraints and even more extreme security risks. Unlike desktop, mobile, or web application development, smart contracts cannot rely on cheap CPU time and memory. All resources used by contracts are expensive, and tracked as 'gas costs'. Smart contracts often directly control money or assets, which if stolen could rack up to a large financial loss to the contracts controllers and users. Tezos smart contracts live on the blockchain forever, if there's a bug in them they can't be patched or amended. Naturally, under these conditions, it's not possible to develop smart contracts the way we're used to developing user-facing applications.

LIGO is designed with these problems in mind. The design philosophy can be described in a few bullet points:

1. Make a clean, simple language with no unnecessary parts.
2. Offer multiple familiar syntaxes so users can get up and running quickly.
3. Encourage people to write simple code, so that it's easy to formally verify the compiled output using a project like Mi-Cho-Coq.
4. Significantly reduce the risk that your smart contract will lose its balance to an avoidable exploit.

LIGO is a functional language designed to include the features you need while avoiding patterns that make formal verification hard. Most useful smart contracts can express their core functionality in under a thousand lines of code. This makes them a good target for formal methods, and what can't be easily proven can at least be extensively tested. The simplicity of LIGO also keeps its compiled output unbloated. Our hope is to have a simple, strongly typed language with a low footprint.

https://ligolang.org/docs/intro/introduction/ 
 

Introduction to LIGO | LIGO

LIGO is a programming language for writing Tezos smart contracts.

ligolang.org

 

 

Tezos의 스마트 컨트랙트

1. 먼저 LIGO language를 이용해서 smart contract를 작성

2. Michelson으로 컴파일.

Currently LIGO compiles to Michelson, the native smart contract language supported by Tezos. This page explains the relationship between LIGO and the underlying Michelson it compiles to. Understanding Michelson is not a requirement to use LIGO, but it does become important if you want to formally verify contracts using Mi-Cho-Coq or tune the performance of contracts outputted by the LIGO compiler.
https://ligolang.org/docs/advanced/michelson-and-ligo 

3. Tezos 노드에 originate, 즉, deploy

 

 

Tools : Taquito & Truffle

* deploy 된 smart contract와 내 application을 연동시키기 위한 다양한 library

- taquito는 typescript 기반의 library로써 블록체인에 배포된 스마트 컨트랙트와 쉽게 연동

* truffle이 Tezos 스마트 컨트랙트 개발을 지원

- Deploy 된 Contract를 테스트하거나 디버깅해보기 위해서 truffle console을 사용

 

 

LIGO

- functions이 기본 빌딩 블록이 되고 이들을 entrypoint라고 부름.

LIGO functions are the basic building block of contracts. For example, entrypoints are functions and each smart contract needs a main function that dispatches control to the entrypoints (it is not already the default entrypoint).
The semantics of function calls in LIGO is that of a copy of the arguments but also of the environment. In the case of PascaLIGO, this means that any mutation (assignment) on variables outside the scope of the function will be lost when the function returns, just as the mutations inside the functions will be.
https://ligolang.org/docs/language-basics/functions 

 

- 각 smart contract는 main function이 있어서 이 main function이 여러 entry point로의 dispatch 역할

- Main 함수의 규칙 = 두 개의 파라미터를 받고 operation과 새롭게 업데이트된 storage의 pair 값을 반환

In LIGO, the design pattern is to have one main function called main, that dispatches the control flow according to its parameter. Those functions called for those actions are called entrypoints. As an analogy, in the C programming language, the main function is the unique main function and any function called from it would be an entrypoint. The parameter of the contract is then a variant type, and, depending on the constructors of that type, different functions in the contract are called. In other terms, the unique main function dispatches the control flow depending on a pattern matching on the contract parameter.

https://ligolang.org/docs/advanced/entrypoints-contracts

 

- Contract를 deploy 할 때는 두 번째 파라미터인 storage value를 넘겨줘서 초기값을 설정

- 한번 deploy 된 이후에는 이 값은 Tezos protocol에서 현재의 storage 값을 찾고 이를 넘겨주기 때문에 이 함수를 호출할 때 첫 번째 파라미터만 넘겨주게 됨.

- 함수의 결과로 새롭게 변경된 storage를 반환. 즉, contract의 storage는 이렇게 contract의 메인 함수를 통해서만 변경될 수 있음.

 

- Ligo는 강 타입 그리고 정적 타입 언어. 즉, 컴파일러의 type checking을 통과하면 실행 중 타입 에러 없음.

LIGO is strongly and statically typed. This means that the compiler checks how your contract processes data, ensuring that each function's expectations are met. If it passes the test, your contract will not fail at run-time due to some inconsistent assumptions on your data. This is called type checking.
https://ligolang.org/docs/language-basics/types 


- Ligo에서 함수는 block을 사용해서 선언 가능
- Block 안에는 여러 명령어가 나열될 수 있고, 하나의 scope를 형성

- With는 함수가 반환하는 값을 선언합니다.

 

- 절차형 언어인 PascalLigo에서 variable은 선언 이후 값을 변경 가능

- 함수형 언어인 Cameligo에서는 변수가 한번 선언되면 값 변경 불가. 값의 변경은 assignment operator를 사용.