You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- DEX with limit orders and partial matching [src](https://github.com/ergoplatform/ergo-contracts/blob/19e23fde8c94a71eb8ca839c829e4efb4e4e63ac/contracts/src/main/scala/org/ergoplatform/contracts/DexLimitOrder.scala#L45-L315)[docs](https://github.com/ergoplatform/ergo-contracts/blob/19e23fde8c94a71eb8ca839c829e4efb4e4e63ac/contracts/src/main/scala/org/ergoplatform/contracts/DexLimitOrder.scala#L319-L397)
12
+
13
+
## How to add a new certified contract
14
+
Certified contracts are written in ErgoScala (a subset of Scala, compiled with [ErgoScala compiler](https://github.com/ergoplatform/ergo-scala-compiler)) and have their properties verified using formal verification with [Stainless](https://stainless.epfl.ch/).
15
+
16
+
## Prerequisites for certified contracts:
4
17
- Install Z3 SMT solver from https://github.com/Z3Prover/z3
5
18
6
-
## How to add a new contract
7
-
8
19
### Create a method for the contract
9
20
Subclass `SigmaContract` in the `verified-contracts` project and put a contract code in a method. The first parameter has to be `ctx: Context`, and subsequent parameters may be contract parameters. The return value has to be `SigmaProp`. Make the first line of the contract code `import ctx._` to improve readability.
10
21
11
22
### Write contract code in the method.
12
23
See [DEX buy order](http://github.com/ergoplatform/ergo-contracts/blob/71f1ef745b7ffce80272e7050a65ec4f68bfd661/verified-contracts/src/main/scala/org/ergoplatform/contracts/AssetsAtomicExchange.scala#L12-L45) for an example.
13
24
14
-
### Contract compilation
25
+
### Contract compilation (ErgoScala)
15
26
Create a subclass (object) of the class with contract code to make an "instance" method to compile the contract's code.
16
27
It'll invoke the compiler (macros) and returns a compiled contract with embedded contract parameters. Create a method with parameters from the contract (without the `Context` parameter) and invoke `ErgoContractCompiler.compile`. See [DEX buy order](http://github.com/ergoplatform/ergo-contracts/blob/71f1ef745b7ffce80272e7050a65ec4f68bfd661/verified-contracts/src/main/scala/org/ergoplatform/contracts/AssetsAtomicExchange.scala#L150-L158) for an example.
17
28
Mark this method with `@ignore` annotation to hide it from Stainless.
18
29
19
30
### How to use compiled contract
20
-
Call the "instance" method in another module/project and it'll return 'ErgoContract'(compiled contract).
31
+
Call the "instance" method in another module/project, and it'll return 'ErgoContract'(compiled contract).
21
32
Call `ErgoContract.scalaFunc` to run the contract with given `Context`. See [DEX buy order](http://github.com/ergoplatform/ergo-contracts/blob/71f1ef745b7ffce80272e7050a65ec4f68bfd661/verified-contracts-test/src/test/scala/org/ergoplatform/contracts/tests/AssetsAtomicExchangeCompilationTest.scala#L319-L324) for an example.
22
33
23
34
### Verifying contract properties
24
-
Verification is done using [Stainless](https://epfl-lara.github.io/stainless/verification.html). Create a subclass(object) of the class where you put contracts (as methods). Use a method for each property you want to verify. Put pre-conditions in `require()` call, call the contract and verify post-conditions. See [DEX buy order](http://github.com/ergoplatform/ergo-contracts/blob/71f1ef745b7ffce80272e7050a65ec4f68bfd661/verified-contracts/src/main/scala/org/ergoplatform/contracts/AssetsAtomicExchange.scala#L90-L113) verified properties for an example.
35
+
Verification is done using [Stainless](https://epfl-lara.github.io/stainless/verification.html). Create a subclass(object) of the class where you put contracts (as methods). Use a method for each property you want to verify. Put pre-conditions in `require()` call, call the contract, and verify post-conditions. See [DEX buy order](http://github.com/ergoplatform/ergo-contracts/blob/71f1ef745b7ffce80272e7050a65ec4f68bfd661/verified-contracts/src/main/scala/org/ergoplatform/contracts/AssetsAtomicExchange.scala#L90-L113) verified properties for an example.
0 commit comments