# ZPrize as a DAO via Proof Market
## Background
__Statement__ is one of the main structures of Proof Market.
It contains information about "what should be proved" and "how the results can be verified". From the user's perspective, a statement means something that the user wants to be confirmed. For instance, "I want to know that this transaction was included in Mina's cluster state".
Statement developers transform this understandable-by-human request into a set of arithmetic operations.
Proof producers use this representation to generate proofs for users.
__Proof Producer__ (or __Producer__) is an actor who generates proofs (results) and provides them to Proof Market.
ZPrize __Track__ (or __Prize__) is defined by the following elements:
* __Speification__ is a human-readable text describing the competition's main goal, hardware and software requirements, reward, etc.
* __Reward__ sum
* Statement definition for Proof Market
* __Committee__ size
* __Timeline__ which describes the beginning and the end of the track
## Overview
There is an obstacle to decentralizing such competition as ZPrize: in the general case, there is no way to validate which software and hardware were used by producers. Thus, the stakeholders' voting procedure is the only way to provide "fair" decentralized judgment.
To achieve this, ZPrize can be represented as a DAO.
DAO mechanism handles all major solutions, including payments to the participants.
However, it requires complex verification logic as well as statistics collection.
Here Proof Market comes in.
The idea is to split decentralized ZPrized responsibilities into two modules: Proof Market and DAO Module.
It helps to delegate the correctness of results and statistic collection to Proof Market and specifies the DAO module on the primary responsibilities: registration, voting, and payments.
```mermaid
flowchart TB
subgraph dao["ZPrize DAO"]
daodesc("Tracks storage, committee formation, voting, payments")
end
subgraph pm["Proof Market"]
pmdesc("statements storage, orders matching, validation, statistics")
end
dao <--> pm
```
## Track Progress
The process of the track from the beginning to the reward payment:
1. Track info is published
2. Track is started with a fixed committee
* The committee members play the role of "opinion leaders" to make voting easier for other stakeholders.
3. Track statement is published on Proof Market
3. Producers registration is open
* Producers can register during the competition
* Each committee member also becomes a producer
4. Participants registration is open
* Participants can register during the competition
5. Producers provide first statistics
* It becomes a baseline
* To do this, ZPrize DAO sends a bunch of proof requests
* The bunch of requests is needed to: have a control over the number of participiants and to provide ability for set of producers to participiate in the contest.
6. Participants work on their solutions
7. Participants provide their solutions
8. Producers provide new statistics
* All producers provide their results for multiple orders
* This helps to partially mitigate malicious behavior
* * Proof Market contains detailed statistics on history of "works"
10. Committee provides a proposal
* It contains something like "Team X should get Y reward for their work"
11. Challenging period
* Any user can try to challenge the committee's proposal because they disagree with it
* Even if the producers provided wrong data, it would be revealed during the challenging period
12. Stakeholders vote
* All holders of the DAO tokens vote for/against the proposal (or delegate this right to one of the commitee members)
13. Track is closed
### Example
Let's consider as an example the acceleration of the Placeholder proof system with Mina's account proof circuit. The short description is something like this:
> This prize will be awarded to the fastest WebAssembly prover implementation Placeholder proof system and Mina's account proof circuit.
The main idea is to use Proof Market as a platform to help organize all processes to communicate with participants and their solutions.
First of all, we need a circuit for the track.
In this case, the circuit is generated by [zkLLVM]((https://github.com/NilFoundation/zkllvm)).
When the circuit is prepared, the next step is preparing and pushing the statement to Proof Market.
#### Prepare a statement with circuit description for Proof Market
Circuits are stored as a statement structure on Proof Market. Statement description example can be found in _example/statements/_ directory of Proof Market Toolchain [repository](https://github.com/NilFoundation/proof-market-toolchain).
Please ensure you have selected the option to create *ll IR files in the zkLLVM setup.
To prepare a statement next command should be used:
`python3 scripts/prepare_statement.py -c <zkllvm output> -o <statement description file> -n <statement name> -t <statement type>`
As a result we will have an output file with statement description which we will use for pushing statetent to Proof Market.
Next step is publishing statement on Proof market.
#### Publishing statement on Proof market
The structure of the statement object is presented on the image below.

When the statement is prepared, we can push it to Proof Market using the Python script:
`python3 scripts/statement_tools.py push --file <json file with statement description>`
As a result, an object containing a _key filed -- unique descriptor of the statement will be returned.
When the statement is added to Proof Market, the next step is to prepare a bunch of proof requests. Each request will be matched only on one task from proof producers.
Each request has additional details such as cost and public inputs.
The following command can be used for push requests.
`python3 scripts/bid_tools.py push --cost <cost of the bid> --file <json file with public_input> --key <key of the statement> `
There is a tool to check the current state of the order:
`python3 scripts/bid_tools.py get --key <key of the bid> `
Proof Market runs a matching algorithm between requesters and proof producers. It chooses the cheapest or fastest proposal that fits the requirements of the proof requester.
Proof producers who want to participate in the contest provide their proposal, which the matching engine will use. After the matching process, Proof Market will wait for proof from the assigned proof producer.
Alternatively, the request can be made via Ethereum smart contract.
To do this:
1. Prepare an order structure:
```solidity
// struct OrderInput {
// uint256 statementId;
// bytes input;
// uint256 price;
// }
const yourOrder = {
statementId: statementId,
input: <fill your input>,
price: <provide desired price>
};
```
2. Submit the order:
```solidity
// createOrder(OrderLibrary.OrderInput memory orderInput) public returns (uint256)
const createOrderTx = await contract.connect(signer).createOrder(yourOrder);
// fetch your order id from the tx
```
3. Wait for the event that shows that the proof was provided:
```solidity
event OrderClosed(uint256 indexed id, address producer, uint256 finalPrice, bytes proof);
```