Tezos智能合约的正式验证
2 个回答
- 投票数
-
- 2019-01-31
如果我们同意分析的目的是证明属性并帮助智能合约的用户理解它们,我会说:
- 价值:研究存储的每个元素在未来将具有什么价值.
- 影响:研究将来可能发生的影响:通常会发生什么转移以及在什么条件下发生.
- 所有权:谁可以触发对存储的哪一部分进行更改.
If we agree that the purpose of analyses is to both prove properties and help users of smart contracts to understand them, I would say:
- Values: studying what values each element of the storage can take in the future.
- Effects: studying what effects can occur in the future: typically what transfers can occur and on what conditions.
- Ownership: who can trigger a change on what part of the storage.
-
这个答案的相当长的版本:https://link.medium.com/ru9idRDePUA rather long version of this answer: https://link.medium.com/ru9idRDePU
- 2
- 2019-03-06
- FFF
-
- 2019-01-31
所以这是一个很大的问题,我认为还有很多人比我更胜任,但我会提供一些初步指导.
在Software Foundations(一本关于Coq的书)中,他们谈论了一种称为Imp的隐含语言. Imp的语法如下:
Z ::= X;; Y ::= 1;; WHILE ~(Z = 0) DO Y ::= Y * Z;; Z ::= Z - 1 END
应该容易理解为赋值和一些简单的循环.
::=
用于赋值,一个while循环直到z为0.在python中为:def foo(x): z = x y = 1 while z != 0: y = y * z z -= 1
然后我们可以为符号定义一些基础逻辑.例如,
Fixpoint aeval (a : aexp) : nat := match a with | ANum n ⇒ n | APlus a1 a2 ⇒ (aeval a1) + (aeval a2) | AMinus a1 a2 ⇒ (aeval a1) - (aeval a2) | AMult a1 a2 ⇒ (aeval a1) * (aeval a2) end.
这将定义算术运算.
您还可以解析保留字,例如:
Inductive com : Type := | CSkip | CBreak (* <--- NEW *) | CAss (x : string) (a : aexp) | CSeq (c1 c2 : com) | CIf (b : bexp) (c1 c2 : com) | CWhile (b : bexp) (c : com).
然后,您可以将程序映射到Coq中这些已定义的类型,例如:
CSeq (CAss Z X) (CSeq (CAss Y (S O)) (CWhile (BNot (BEq Z O)) (CSeq (CAss Y (AMult Y Z)) (CAss Z (AMinus Z (S O))))))
然后,我们可以使用形式逻辑来证明使用此语言编写的功能或语句.这是一个示例,证明如果z不是4,则x不是2:
Example ceval_example1: empty_st =[ X ::= 2;; TEST X ≤ 1 THEN Y ::= 3 ELSE Z ::= 4 FI ]⇒ (Z !-> 4 ; X !-> 2). Proof. (* We must supply the intermediate state *) apply E_Seq with (X !-> 2). - (* assignment command *) apply E_Ass. reflexivity. - (* if command *) apply E_IfFalse. reflexivity. apply E_Ass. reflexivity. Qed.
现在,我希望智能合约的应用程序会有所体现.如果您可以将智能合约抽象为Coq,则可以使用Coq严格证明智能合约的某些组件.也有可能在Coq中概述智能合约的条件并将其编译为Michelson,但这只是一种可能性,我还没有看到任何有关其构建的证据.
ref: https://softwarefoundations.cis.upenn.edu/lf-当前/Imp.html
So this is a huge question and I think there are many people more qualified than me, but I'll offer some initial guidance.
In Software Foundations, a book on Coq, they talk about an implied language called Imp. Imp has a syntax like:
Z ::= X;; Y ::= 1;; WHILE ~(Z = 0) DO Y ::= Y * Z;; Z ::= Z - 1 END
Which should be somewhat easily understood as assignment and some simple looping.
::=
is for assignment, a while loop until z is 0. In python this would be:def foo(x): z = x y = 1 while z != 0: y = y * z z -= 1
We can then define some of the underlying logic for the symbols. For example,
Fixpoint aeval (a : aexp) : nat := match a with | ANum n ⇒ n | APlus a1 a2 ⇒ (aeval a1) + (aeval a2) | AMinus a1 a2 ⇒ (aeval a1) - (aeval a2) | AMult a1 a2 ⇒ (aeval a1) * (aeval a2) end.
This will define arithmetic operations.
You could also parse out reserved words, like:
Inductive com : Type := | CSkip | CBreak (* <--- NEW *) | CAss (x : string) (a : aexp) | CSeq (c1 c2 : com) | CIf (b : bexp) (c1 c2 : com) | CWhile (b : bexp) (c : com).
Then you could map the program to these defined types in Coq, like:
CSeq (CAss Z X) (CSeq (CAss Y (S O)) (CWhile (BNot (BEq Z O)) (CSeq (CAss Y (AMult Y Z)) (CAss Z (AMinus Z (S O))))))
We can then make some proofs about the functions or statements made in this language using formal logic. Here is an example proving that if z is not 4, then x is not 2:
Example ceval_example1: empty_st =[ X ::= 2;; TEST X ≤ 1 THEN Y ::= 3 ELSE Z ::= 4 FI ]⇒ (Z !-> 4 ; X !-> 2). Proof. (* We must supply the intermediate state *) apply E_Seq with (X !-> 2). - (* assignment command *) apply E_Ass. reflexivity. - (* if command *) apply E_IfFalse. reflexivity. apply E_Ass. reflexivity. Qed.
By now I hope the application to a smart contract is somewhat apparent. If you could abstract the smart contract into Coq, you could use Coq to prove some components of your smart contract rigorously. There is also potential to outline conditions of a smart contract in Coq and compile it to Michelson, but that's just a possibility and I haven't seen any evidence of its construction.
ref: https://softwarefoundations.cis.upenn.edu/lf-current/Imp.html
-
感谢您的详细回答.看来您正在向我解释使用Coq的*如何*使智能合约适合形式分析的策略.我想我的问题更多地集中在什么样的结果/保证与静态分析可实现的以及从区块链应用程序角度所期望的相交处.Thanks for the detailed answer. It seems you are explaining to me a strategy of *how* to make smart contracts amenable to formal analysis, here by using Coq. I guess my question was more focused on what sorts of results/guarantees are at the intersection of of what is achieveable by static analysis and desireable from a blockchain application perspective.
- 0
- 2019-01-31
- Ezy
-
如果这是问题,则可以构建一个模糊器.合同的输入非常严格,因此尝试各种输入并查看给出的响应并不难.https://zh.wikipedia.org/wiki/模糊化if that's the question, you could just build a fuzzer. Contracts have very rigid inputs so it wouldn't be too hard to try a wide variety of inputs and see the responses given. https://en.wikipedia.org/wiki/Fuzzing
- 0
- 2019-02-01
- Rob
-
@Rob我认为智能合约必须存在于对抗性世界中,因此像模糊测试这样的简单调试工具可能还不够.@Rob I feel that smart contracts must live in an adversarial world so simple debugging tools such are fuzzers might not be enough.
- 1
- 2019-02-02
- FFF
-
您可以做更多的事情,但是考虑到各种对抗性合同对输入模糊测试的严格限制,可能会涵盖大量可能的情况.我认为像实心蜜糖这样的蜜罐场景将更易于测试,也难以组织,因为所有外部呼叫都是在合同完成之后发生的.you could ALWAYS do more, but considering the very strict constraints on inputs fuzz testing from a variety of adversarial contracts would probably cover a large number of possible scenarios. I think a honeypot scenario like in solidity would be easier to test for and harder to orchestrate since all external calls happen after the contract's completion.
- 0
- 2019-02-02
- Rob
最能使dapps受益者的Tezos智能合约分析有哪些?
请明确一点,这里的"分析"是指"静态程序分析".例如,请此处.
基本的想法是,在将智能合约提交给链之前,人们将对高级源代码执行静态分析,或者直接在michelson中对编译目标进行静态分析,以评估程序的各种运行时属性./p>