{'fraction_non_alphanumeric': 0.0290955091714105, 'fraction_numerical': 0.006624721195778821, 'mean_word_length': 4.934413275385223, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A Blockchain-Based Approach for Collaborative Formalization of Mathematics and Programs

Formalization of mathematics is the process of digitizing mathematical knowledge, which allows for formal proof verification as well as efficient semantic searches. Given the large and ever-increasing gap between the set of formalized and unformalized mathematical knowledge, there is a clear need to encourage more computer scientists and mathematicians to solve and formalize mathematical problems together. With blockchain technology, we are able to decentralize this process, provide time-stamped verification of authorship and encourage collaboration through implementation of incentive mechanisms via smart contracts. Currently, the formalization of mathematics is done through the use of proof assistants, which can be used to verify programs and protocols as well. Furthermore, with the advancement in artificial intelligence (AI), particularly machine learning, we can apply automated AI reasoning tools in these proof assistants and (at least partially) automate the process of synthesizing proofs. In our paper, we demonstrate a blockchain-based system for collaborative formalization of mathematics and programs incorporating both human labour as well as automated AI tools. We explain how Token-Curated Registries (TCR) and smart contracts are used to ensure appropriate documents are recorded and encourage collaboration through implementation of incentive mechanisms respectively. Using an illustrative example, we show how formalized proofs of different sorting algorithms can be produced collaboratively in our proposed blockchain system.

partial progresses respectively. Thus, there are various prior works, such as Qeditas [8], Mathcoin [9] and Proofgold 1 , that discuss approaches on how computer scientists and mathematicians can share their completed work, and contribute to the world of formalized mathematics through the use of blockchain. On the other hand, the Polymath project [10], initiated by Timothy Gowers, is a project where mathematicians collaborate to solve difficult and important mathematical problems by sharing their partial results, presented as traditional "handwritten" proofs. However, to our best knowledge, there is no system currently that combines these two ideas where participants (human or automated AI tools) can collaborate to solve and formalize common problems.
To this end, we propose a blockchain-based architecture for formalizing mathematics and programs that allows participants to share, not only completed, but also formalized partial results. Our system architecture can be broken down into three interconnected layers: data layer (what is recorded?), client layer (what is meaningful?) and incentive layer (what is rewarded?). We will discuss how Token-Curated Registries (TCR) [11,12] are used to filter document submissions and how smart contracts are essential to implement incentive mechanisms to encourage participants to come together and tackle common problems. The details and underlying mechanisms for each layer of our system are described in Section 4. Furthermore, we provide a simple but illustrative algorithmic example in Section 5, where we present how different sorting algorithms can be formalized 2 collaboratively between human and automated AI tools using our proposed blockchain-based system.

Formalized Proofs and Its Current State
Thanks to intuitionistic type theory [13] and the Curry-Howard correspondence [14], mathematical knowledge can be written as code through the means of proof assistants, such as Isabelle [2], Coq [3] and Lean [4]. Such proofs are said to be formalized. The main driving mechanism in proof assistants is the use of tactics for users to guide the proof engine to derive the proofs interactively. The goal of a tactic is to break down complicated theorem statements into multiple simpler statements that are hopefully easier to complete.
Other than having proofs formally and automatically verified by the proof assistants' proof systems, there are a lot of efforts to formalize both existing and new mathematical knowledge due to several reasons, including: Verified programs and protocols We can use proof assistants to formally verify programs, e.g., CompCert [15], and protocols, e.g., CBC Casper protocol [16], as well. Moreover, with the extraction features, such as the one implemented in Coq [17], one can even state a program specification as a theorem statement and extract its proof as a working program.
Proofs with gaps In proof assistants, we can write partial proofs -proofs with gaps, where parts of the proofs can be left empty for future completion by either the owner or someone else. We shall use the proof of the proposition, sum_f irst_n, ∀n ∈ N, , as an illustration. The owner of Coq file shown in Listing 1 created a partial proof through the use of the induction tactic, and left the proofs of both base and inductive cases empty as conjectures for future completion.

Listing 1: Partial proof of sum_first_n viewed as a Coq file
Automated AI tools There has been an increasing number of automated tools implemented for proof assistants, such as Sledgehammer [18] (for Isabelle), TacticToe [19] (for HOL4 [20]), CoqHammer [21] and Tactician [22] (both for Coq). These tools make use of machine learning methods such as k-NNs, RNNs and neural networks to help with the proof searches. The goal of most of these tools is to have an automated proof search function that generates a proof automatically given some theorem statement, and hence, ease the mathematicians' load in formalizing proofs.

Related Works and Gaps
Through the use of blockchain, decentralization enables fast dissemination of information, allowing users to be notified with first-hand problems and state-of-the-art results. If users were to collaborate to formalize and solve a common theorem statement, they do not need to worry about the authorship of their partial progresses due to the time-stamped verification provided by blockchain. Furthermore, with the use of smart contracts, one can trigger incentive mechanisms to allocate rewards appropriately to encourage users to share their partial results and collaborate to solve a common problem.
There are several prior projects such as Qeditas [8], Mathcoin [9] and Proofgold tackling the use of blockchain technology to tie sources of formalized mathematics together in a decentralized way. Nevertheless, there are several gaps that these projects do not address adequately and which we aim to improve upon: Filtering submissions Documentation of formalized mathematical objects, i.e., definitions, theorem statements and proofs, are organized in terms of libraries, such as the Mathematical Components library of Coq ssreflect [23] and the Lean mathematical library, mathlib [24]. To be documented in any of these libraries, experts from the respective community will determine whether each submitted document fulfills certain criteria. Yet, in a decentralized system, there will be no "expert" to filter out submissions. Qeditas suggested strategies such as inclusion of "salted" documents and having fees proportionate to the size of the submitted documents to deter duplicate submissions. Having said that, to filter out novel, non-duplicate and relevant work from the rest, we believe a much stronger mechanism needs to be in place so that the decentralized library will be streamlined. Our approach featuring a TCR allowing users to accept or reject a given submission would be particularly useful, but has not been discussed in any of the prior works.
Collaborative work Although there are several useful ideas suggested by these prior projects to incentivize users to formalize proofs, such as rewarding ownership as intellectual property, bounties and token betting, there has been little to no mention of the use of smart contracts to implement complex incentive mechanisms to split rewards appropriately to collaborators. With the right incentive mechanism in place and the ability to leave proofs with gaps as mentioned in Section 2, we aim to reward contributors for completed as well as partial results. Contributors need not worry about the authorship of their partial work due to the time-stamped verification provided by blockchain, serving as a motivation for them to submit partial, incomplete results and formalize proofs collaboratively.
Automated AI tools' participation None of prior projects mention about the involvement of automated AI tools, which are discussed in Section 2. Some of these automated tools require high computing power to produce better automated proof searches. Developers could deploy these tools as nodes in the blockchain environment to look for conjectures to solve instead of requiring users to have the necessary computing capabilities in order to use them. Automated tools, such as TacticToe [19] and Tactician [22], show that there is a drift towards implementing incremental proof construction [25], i.e., suggesting the next best proof step instead of automating the whole proof of a given theorem statement. These tools could help human provers by suggesting the "next best move" in their proofs, facilitating collaboration between human and machines. In the future, once these automated tools reach a certain efficiency level, different tools could even come together through this blockchain environment to generate the proofs, with little to no human intervention, as an unified proof synthesizer.

System Architecture
We assume the availability of a public, programmable blockchain, where smart contracts are deployed. We call prover an account (or address) on the blockchain participating in the protocol. A human or AI participant (prover using automated AI tool) may operate several prover accounts. For simplicity, we consider the case where one entity corresponds to one prover only. Our system architecture can be broken down into three interconnected layers: A) the data layer (what is recorded?), B) the client layer (what is meaningful?) and C) the incentive layer (what is rewarded?). Fig. 1 shows a flowchart of how a prover's contribution gets recorded and eventually rewarded in our blockchain system across these three layers. The types of smart contracts and the need of bootstrapping our system with some initial library are also discussed at the end of this section.

Data layer
The data layer is composed of two elements: a deployed smart contract on the blockchain, registry, and a decentralized file storage.

Client interface
Incentive contract/s: Smart contract from client to trigger incentive mechanism once proof is completed Appropriate token distribution from the incentive mechanism (larger coin ⇒ more tokens in figure) Licensing sublayer Client /User can set the right-to-use: free, restricted or pay-to-use Partial contributions Figure 1: Flowchart of how a prover's contribution gets recorded and eventually rewarded in our blockchain system across the three layers of our system architecture.
Images' sources: IPFShttps://en.wikipedia.org/wiki/InterPlanetary_File_System, TCR https://0xcert.org/ news/token-curated-registries-william-entriken/, right-to-usehttps://reasonstreet.co/ business-model-pay-per-use/ The registry accepts records written by provers. A record contains minimal information to identify a unique contribution. A contribution consists of a Coq file kept in the storage, while the record contains as an attribute the address of the contribution.
We suggest the use of decentralized file storage such as IPFS [26]. Clients running the IPFS protocol publish content (such as the Coq .v files) over the IPFS network. The content is addressed by a unique hash, a random string of characters, obtained by hashing the file content. Other IPFS clients interested in the content will request it by its hash to other peers on the network, until they obtain the file from a peer who is hosting it. The design pattern of hosting longer-form content, such as text, code or media over IPFS while referencing the hash in a blockchain transaction has become commonplace. While not guaranteeing availability (a file could either be missing or held offline), it is sufficient for just one party holding the file to be online for it to be available.

Client layer
The data layer accepts any record and contribution. However, contributions that contain syntactically incorrect code must be disregarded by users of the protocol. The data layer cannot run the checks required to decide whether a contribution is valid or not, as it would have to run the Coq interpreter to find out the validity of the code. While this is theoretically possible in a Turing-complete environment, the cost of such operation would be prohibitively high.
The protocol also needs to deal with the issue of spam and duplicates. Contributions of dubious quality may well be registered, as well as identical copies of previous statements, copies aggregating multiple previous contributions or copies with refactored variable names. Heuristics may be developed to "flag" copies by comparing their Coq types against previously published contributions, a first step towards creating a canonical registry.
To increase the importance of novel and useful contributions over duplicates and tautological statements, we add an incentive for provers in the protocol to vote on the inclusion of newly registered statements into the canonical registry. This incentive is deployed as a Token-Curated Registry (TCR) [11,12], a smart contract where provers stake some amount of tokens (becoming bonded provers) to earn the right of voting in or voting out contributions from the canonical registry.
Provers may adopt the role of contributors or curators, the former when they add a record to the registry, the latter when they vote on the inclusion of a record to the canonical registry. As contributors, provers attach an inclusion stake along with their record. Any prover may challenge the inclusion of the record to the canonical registry by posting a dispute stake. As curators, provers are rewarded for voting on the correct outcome, determined by a majority rule, in the event of a challenge. If the record is voted out, the challenger receives part of the inclusion stake, while the remainder is divided among voters who rejected the record. If the record is voted in, the dispute stake of the challenger is lost to the contributor and curators who voted to include the record. Bonded provers may choose to participate in a vote or not. After some delay period, either the record enters the canonical registry unchallenged, or following a successful vote in favor of inclusion.
Although "canonical" appears to refer to a binary property, in effect a quantitative measure of weight distinguishes one contribution from another, as a varying number of curators engage in the voting process for each incoming record. Uncontroversial inclusion ought to bring more positive votes from curators, who need not expend a lot of time to identify novelty or usefulness, as would uncontroversial rejection, e.g., in the case of an invalid Coq code, which is also trivial to detect assuming provers run a Coq client themselves.
The client layer is responsible for presenting the current state of the canonical registry to the prover, as an interface to the data layer. Essentially, the client layer could function as a plug-in to popular Coq editors/interpreters, allowing provers to maintain and track the contributions they are working with, associated with their weights to provide contextual information on their validity, novelty and usefulness. The client layer additionally runs the Coq engine to decide on the validity of a contribution, as well as heuristics on the Coq types of the statement to determine their potential novelty. These checks allow the bonded validators to input their votes to the TCR via the client layer.
The client remains loosely coupled with the data layer. Any interface capable of reading data from the registry, verifying validity of the contributions and publishing progress to the registry functions as a client, allowing for diversity in implementations and features. For instance, a protocol for provers to include metadata in their contribution, e.g., as a header in the Coq file. Metadata include compatibility with Coq versions, contribution type (theorem, proof, ...), as well as imports. For imports of previous contributions, the client holds a string diagram (more details and examples in Section 5) , linking a contribution to its ancestors. This string diagram could provide the structure necessary for the definition of incentives explored in the next section. In a future iteration, it may be possible to compose the TCR instantiation described above with the contextual information received from the string diagram of proofs, akin to the citation graph of Ito and Tanaka [27]. Contributions building on previously registered items would then add weight to their ancestors, indirectly recognising their usefulness and/or novelty.

Incentive layer
The data layer and the client layer ensure consensus over the canonical registry. Consistent with our modular architecture, the incentive layer is once again loosely coupled with the previous client layer.
The incentive layer is a set of incentive mechanisms, embodied by smart contracts. Any entity may deploy an incentive mechanism, either of their own conception or from existing templates. We start with the simplest possible template, a fixed prize payment for the completion of a single proof. In this scenario, an entity deploys a smart contract holding the prize, with a single signer ("owner") deciding to offer the prize to a contribution that formally proves the proposed statement. The mechanism records the identifier of the winning contribution and the author of the contribution receives the prize money.
The previous template requires trust assumptions on the signer deciding on the winner. It is easily extended to a multisignature implementation, where some set of signers must approve the winner before the prize money is unlocked. Further, it may be extended to the whole set of bonded provers.
More complex incentive systems may be added later on in a compatible manner, as long as they make reference to the original contribution string diagram. For instance, staking tokens on some branch of partial progress from a statement could entitle stakers to a share of future rewards obtained should that branch terminate with a proof of the statement, with the final prover earning a larger share in proportion to the amount staked. Via this partial ownership, stakers are rewarded for detecting promising branches, while provers are induced to progress on these promising branches.

Licensing sublayer
Up to this point, we have addressed how we can implement incentive mechanisms via smart contracts to encourage provers to collaborate and solve common open conjectures. This leads to the next question: how can we incentivize users to post new formalized definitions, theorems with completed proofs and tactics? To answer this, we will have a licensing sublayer that allows the author to set the right-to-use for each of his or her formalized object. This idea was introduced in one of the prior works, Qeditas [8], where the right-of-use can be categorized into three types of uses -free-to-use (free to use without payment), restricted-to-use (unable to use at all) and pay-to-use (pay some x tokens in order to use). The rights are set to free-to-use by default, and any change to this setting will have to be done by the author. We include this sublayer within the incentive layer as rewards in terms of payments can be involved to the authors of completed objects.

Smart Contracts
Several types of smart contracts are available for the users in our blockchain system: Contribution registry A contract, registry, stores records of contributions, including their necessary metadata such as IPFS hash address, Coq versions, contribution type (conjecture, theorem, proof, ...), imports and right-to-use. Examples of how they may look like are shown as ct00Cont, ct01Cont and ct02Cont in Section 5.
Incentive contracts These contracts implement incentive mechanisms to distribute tokens to a prover or a group of provers based on their contributions and their payout rules. An example is provided as iCont00 in Section 5.
TCR contract A contract deploys TCR voting mechanism to determine the weight supporting inclusion in the canonical registry of some contribution, detailed in Section 4.2.

Bootstrapping
The registry is easily bootstrapped with the current Coq standard library, providing the foundation for new proofs and tactics to be added to the registry. In addition, to decentralize further inputs to the TCR voting mechanism, initial allocation of voting tokens may be done with respect to the amount of work provided on the Coq library itself as well as contemporary work on proof and tactics.

An Illustrative Example
We will assume that the documents in the Coq standard library are already stored in IPFS. For simplicity, we will use 0x0file to represent the hash address of the Coq file, file.v, in IPFS.
Suppose a prover, client C, starts a new project to find proof/s of the specification of a sorting program as a conjecture through the Coq script, ct00.v, as shown in Listing 2. Listing 2: Coq script of ct00.v C will upload the file in IPFS and get its hash address, 0x0ct00, and create a contract, ct00Cont, that records the conjecture, its necessary metadata and incentive contract, iCont00, as shown in Listing 3. If the proof of sort_prog is completed by a set of Provers, iCont00 will run the pre-defined allocation function to measure the weights of the contributions and allocate the TokenReward appropriately. Otherwise, all the TokenReward will be transferred to the unique prover. ... file = " 0 x0ct00 " ; CoqVer = " 8.12 " ; filetype = " Conjecture " ; imports =[ " 0 x0Arith " ," 0 x0Sorted " ," 0 x0Permutation " ," 0 x0List " ]; // Activate Icont00 to set of provers = Provers iCont00 ( Provers , TokenReward ) ; ... } Listing 3: Pseudo-code example of ct00Cont and iCont00 At the client interface, C can do any validity check that cannot be done in the data layer through the Coq plug-in editor and a string diagram can be presented for C to track any progression of the conjecture, as shown in Fig. 2. After ct00Cont is posted in the blockchain system, human prover P is the first one to provide a partial proof of sort_prog via the Coq script, ct01.v, as shown in Listing 4. He initiates the proof by using induction and leaves both the base case and inductive case empty. He uploads this file in IPFS and record a ct01Cont entry as shown in Listing 5.
Require Export ct00. After which, C and other users will get a notification through the client interface, which shows an update in the string diagram of Fig. 2, as shown in Fig. 3. Figure 3: Update in the string diagram shown in Fig. 2 after P uploads ct00.v entry.
At this point, the unsolved conjectures are sort_prog, sort_base and sort_prog_IH. An AI prover, A, using automated AI tool, say Coqhammer [21], will try to automate the proofs for these three conjectures. Although it only manages to automate the proof of sort_base, it records its attempts via the Coq script, ct02.v (Listing 6) and a ct02Cont entry (Listing 7) in the system. The client interface will then update the progress in the string diagram shown in Fig. 3, as shown in Fig. 4.
Require Import ct01. From Hammer Require Import Hammer. Eventually all subproofs will be completed, i.e., no more dotted circles between sort_prog and True, through the collaboration of contributions from both human provers and automated AI tool/s as shown in Fig. 5. The completed proof from this network of subproofs is essentially a verification proof of an insertion sort algorithm.
Once this is achieved, the reward function in iCont00 will be triggered to allocate each contribution, seen in Fig.  5, with the appropriate rewards based on the allocation function. It is important to have the right allocation rule such that it would encourage each prover to share his or her partial result immediately instead of withhold any partial progress and release only when he or she completes the whole proof. For the existence of such allocation rule, one can implement, for example, the mechanism discussed by Banerjee et al [28]. Measuring of the weights in any allocation rule may involve the use of TCR as mentioned in Section 4. Figure 4: Update in the string diagram shown in Fig. 3 after A uploads ct02.v entry. We use green circles to represent entry from automated AI tools. Besides insertion sort, there are many different sorting algorithms, including merge sort, quick sort, etc. Unlike in mathematics, where it is sufficient to have one proof for each theorem, different proofs for a specification of a program may yield algorithms with different efficiencies. Thus, it is important to implement incentive mechanism/s via smart contract/s to encourage users to produce different proofs collaboratively as well. For example, C could implement an incentive mechanism similar to what was studied by Babaioff et al. [29] via a smart contract. That is, C will reward the first completed proof with TokenReward, followed by the second completed proof with TokenReward/2, then the third completed proof with TokenReward/4 and so on. This mechanism of halving the TokenReward for each completed proof will eventually cost C a maximum of 2×TokenReward.
As a result, another prover T is motivated to create an alternative proof to sort_prog, which will eventually lead to a proof of merge sort algorithm. This can be done by first, creating a new tactic, div_conq_split, which is a formalization of the divide-and-conquer algorithmic paradigm, in the Coq file ct04.v (Listing 8). The file is uploaded in the IPFS network and records an ct04Cont entry (Listing 9). This entry will state that anyone who wishes to use the div_conq_split tactic needs to pay a fee of some x token/s. This is done as the tactic can be used to prove any property of lists other than the sort_prog.
Conjecture sort_prog_split : forall (ls l' l'0: list nat), sorted l'0 → permutation l'0 (fst (split nat ls)) → sorted l' → permutation l' (snd (split nat ls)) → {l'1 : list nat | sorted l'1 ∧ permutation l'1 ls}. Once T uploads the contribution of ct05.v to the system, C and the rest of the users will be notified of a new string diagram presentation of the alternative proof as shown in Fig. 6. Suppose the insertion sort's proof (Fig. 5) is completed before the merge sort's proof. Once the latter proof is completed, the incentive mechanism will trigger and distribute TokenReward/2 appropriately to all the contributors in Fig. 7 as it is the second completed proof.

Conclusion and Future Directions
In our paper, we propose a blockchain-based approach to allow agents, human provers and automated AI systems, to formalize mathematics and programs collaboratively through the means of some proof assistants such as Coq. We broke down our system architecture into three dependent layers. The data, client and incentive layers describe what information is to be recorded, to be deemed as meaningful and to be rewarded respectively. We differentiate our work from the prior projects through i) the use of TCR to vote contributions in or out from the canonical registry, ii) smart contracts to implement incentive mechanisms to encourage both collaboration within the same proof and diversification of proofs, and iii) inclusion of automated AI tools. Moving forward, there are several directions we are looking to improve and decide upon before the implementation of our proposal:

Game theory of incentive mechanisms
The flexibility of implementing complex incentive mechanisms via smart contracts allows us to reward the contributions within a proof and across different proofs appropriately. Thus, it is important to have the right incentive mechanism/s to encourage users to not only generate a single proof but also multiple proofs of a common problem collaboratively in a decentralized manner. Other than the incentive mechanisms mentioned in Section 5 [28,29], a game theoretical study on incentive mechanisms would provide us different ways to reward contributors appropriately.
It is natural to model the process of formalizing proofs collaboratively as a cooperative game where the contribution graph encodes the current state of knowledge and progress across a wide variety of open problems. Thus, it can be assigned a global value that can be captured natively in the system via publicly trade-able tokens. In any such cooperative game, the overall system value can be distributed amongst its contributors using, e.g., the Shapley value distribution rule [30]. The Shapley value distribution rule has a number of well known and desirable axiomatic properties. For example, it is budget balanced 3 meaning that the sum of the agents' payoffs is equal to the global value of the system. Moreover, it is the unique distribution rule that is efficient, symmetric, additive, and assigns zero payoffs to dummy players. Finally, recent works have pointed out that within the set of budget balanced rules, it is effectively optimal [31,32,33].

Usage of tokens
There can be two usages of the tokens generated for our blockchain. First, they can be used as a virtual currency purely to measure the contributions a user has made in the world of formalized mathematics and programs. This is analogous to the h-index [34] to measure the productivity of a researcher's publications. Second, they can be exchanged for actual currencies, e.g., USD. This approach gamifies the process of formalization through monetary rewards, and hence, attracts more users to take part. The decision to use tokens as "scores" or as monetary incentive may depend on the community participating in our protocol.